Note that there are some explanatory texts on larger screens.

plurals
  1. POInheriting List<T> to implement collections a bad idea?
    primarykey
    data
    text
    <p>I once read an article by Imaar Spaanjars on how to build 3 tier applications. (<a href="http://imar.spaanjaars.com/416/building-layered-web-applications-with-microsoft-aspnet-20-part-1" rel="nofollow noreferrer">http://imar.spaanjaars.com/416/building-layered-web-applications-with-microsoft-aspnet-20-part-1</a>) which has formed the basis of my coding for a while now. </p> <p>Thus I implement collections as he has done, by inheriting a <code>List&lt;T&gt;</code>. So if I have a class named Employee,to implement a collection I will also have a class Employees as below.</p> <pre><code>class Employee { int EmpID {get;set;} string EmpName {get;set;} } class Employees : List&lt;Employee&gt; { public Employees(){} } </code></pre> <p>I never really questioned this as it did the work for me. But now that I started trying out a few things I am not sure if this is the correct approach.</p> <p>e.g. if I want to get a subset from Employees, such as </p> <pre><code> Employees newEmployees = (Employees) AllEmployees.FindAll(emp =&gt; emp.JoiningDate &gt; DateTime.Now); </code></pre> <p>This throws a System.InvalidCastException . However, if I use the following then there is no Issue. </p> <pre><code>List&lt;Employee&gt; newEmployees = AllEmployees.FindAll(emp =&gt; emp.JoiningDate &gt; DateTime.Now); </code></pre> <p>So how do I implement Employees so that I dont have to explicitly use <code>List&lt;Employee&gt;</code> in my DAL or BLL? Or maybe how do I get rid of the InvalidCastexception?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload