Click here to Skip to main content
15,891,704 members
Home / Discussions / C#
   

C#

 
GeneralRe: Replace "inner list" of a generic class inheriting from List<T> ? Pin
BillWoodruff12-Dec-09 8:30
professionalBillWoodruff12-Dec-09 8:30 
GeneralRe: Replace "inner list" of a generic class inheriting from List<T> ? Pin
PIEBALDconsult12-Dec-09 9:06
mvePIEBALDconsult12-Dec-09 9:06 
GeneralRe: Replace "inner list" of a generic class inheriting from List<T> ? Pin
Gideon Engelberth12-Dec-09 10:56
Gideon Engelberth12-Dec-09 10:56 
GeneralRe: Replace "inner list" of a generic class inheriting from List<T> ? Pin
BillWoodruff13-Dec-09 12:28
professionalBillWoodruff13-Dec-09 12:28 
AnswerRe: Replace "inner list" of a generic class inheriting from List<T> ? Pin
Nicholas Butler12-Dec-09 23:28
sitebuilderNicholas Butler12-Dec-09 23:28 
GeneralRe: Replace "inner list" of a generic class inheriting from List<T> ? Pin
BillWoodruff13-Dec-09 12:21
professionalBillWoodruff13-Dec-09 12:21 
GeneralRe: Replace "inner list" of a generic class inheriting from List<T> ? Pin
Nicholas Butler13-Dec-09 22:45
sitebuilderNicholas Butler13-Dec-09 22:45 
GeneralRe: Replace "inner list" of a generic class inheriting from List<T> ? [modified] Pin
BillWoodruff14-Dec-09 4:50
professionalBillWoodruff14-Dec-09 4:50 
Hi Nick,

Nick Butler wrote:
I didn't mean to "short change" LINQ at all. I love it. IMHO, it should have been introduced earlier ( with generics in .NET 2.0 ) as it is just so useful.


Sorry, in the context of those terse remarks above, and your previous statement "LINQ won't help either. LINQ mostly knows about interfaces: IEnumerable and IQueryable; and a little about List and Array" : I drew what seemed like a logical conclusion to me that you were not fully aware of the wide gamut of functionality Linq exposes.

Nick Butler wrote:
You don't lose LINQ if you derive from IList because IList derives from IEnumerable and LINQ is implemented as extension methods on IEnumerable. You can use LINQ on List objects for the same reason: List derives from IEnumerable.

Your original question was about deriving from List and then replacing the "virtual" List object. I just suggested composition as a possible solution for you. If you're happy with using Clear and AddRange then that's good, but then you aren't changing the inner List, you're just changing it's contents.


I've never suggested any idea that Linq was "loseable" in this context, and I was aware from the get-go that an instance of List<T> and List<int> all implemente/derive from IEnumerable. In fact it's the common derivation from IEnumerable and the range of Linq operators that convert type like Cast and OfType that suggest to me possibility of a transformation of a "vanilla" List<int> theList = new List<int> { 1, 2 }; into something suitable for direct assignment to an instance of anyDamnList<int> was possible.

Nick Butler wrote:
Your original question was about deriving from List and then replacing the "virtual" List object. I just suggested composition as a possible solution for you. If you're happy with using Clear and AddRange then that's good, but then you aren't changing the inner List, you're just changing it's contents.


From my point of view the definition of a class which creates a strongly typed generic list that inherits from a <T> type generic list is nothing more than a template, an object factory, as it were, for manufacture of instances of strongly typed generic lists, and there's nothing "virtual" about the instances whatsoever. The instances, imho, are a List, and the fact you can directly "get at" all its properties and methods with simple dot notation indicates to me they are a "first class" List<whatever> object in every sense.

For me the notion of "composition," and the analogy of a "safe" just don't really work for me here. It is an adding an extra level of object wrapper that is unneeded, and in your example the class wrapper is untyped.

If we thought of an instance of a class ... that is generic and inherits from a generic List<T> ... as a "safe" : it would be safe that holds only on type of object; a "transparent safe" where you could look inside and see what was it it with no combination or key required, a safe without "walls" where you could re-arrange, and add things, and delete things with no problem, but, also, a "safe" that in the special case you wanted to replace everything inside it at once required a special and awkward trick to open a "hidden trick" door and replace all of the contents easily; a "safe" that was transparent, had no walls except in one strange case, would not, for me, be a "safe" Smile | :)

Thanks for your time. Like I said, above, I'm going back to studying Skeet's book.

Yes, certainly, your thoughts are "useful" Smile | :)

best, Bill

"Many : not conversant with mathematical studies, imagine that because it [the Analytical Engine] is to give results in numerical notation, its processes must consequently be arithmetical, numerical, rather than algebraical and analytical. This is an error. The engine can arrange and combine numerical quantities as if they were letters or any other general symbols; and it fact it might bring out its results in algebraical notation, were provisions made accordingly." Ada, Countess Lovelace, 1844

modified on Monday, December 14, 2009 11:07 AM

Answera "partial solution" to : re : Replace "inner list" of a generic class inheriting from List&lt;T&gt; ? Pin
BillWoodruff13-Dec-09 12:51
professionalBillWoodruff13-Dec-09 12:51 
QuestionUsing Methods within a Switch Case Pin
DevonDaDude11-Dec-09 22:47
DevonDaDude11-Dec-09 22:47 
AnswerRe: Using Methods within a Switch Case Pin
Abhinav S11-Dec-09 22:56
Abhinav S11-Dec-09 22:56 
GeneralRe: Using Methods within a Switch Case Pin
OriginalGriff11-Dec-09 23:03
mveOriginalGriff11-Dec-09 23:03 
GeneralRe: Using Methods within a Switch Case Pin
Abhinav S11-Dec-09 23:09
Abhinav S11-Dec-09 23:09 
GeneralRe: Using Methods within a Switch Case Pin
Saksida Bojan12-Dec-09 1:49
Saksida Bojan12-Dec-09 1:49 
GeneralRe: Using Methods within a Switch Case Pin
Richard MacCutchan12-Dec-09 3:08
mveRichard MacCutchan12-Dec-09 3:08 
GeneralRe: Using Methods within a Switch Case Pin
DevonDaDude15-Dec-09 18:20
DevonDaDude15-Dec-09 18:20 
AnswerRe: Using Methods within a Switch Case Pin
OriginalGriff11-Dec-09 23:01
mveOriginalGriff11-Dec-09 23:01 
AnswerRe: Using Methods within a Switch Case Pin
PIEBALDconsult12-Dec-09 3:59
mvePIEBALDconsult12-Dec-09 3:59 
GeneralRe: Using Methods within a Switch Case Pin
DevonDaDude12-Dec-09 15:45
DevonDaDude12-Dec-09 15:45 
QuestionUse of &lt;&lt; and &gt;&gt; [modified] Pin
Joe Rozario11-Dec-09 19:16
Joe Rozario11-Dec-09 19:16 
AnswerRe: Use of &lt;&lt; and &gt;&gt; Pin
Abhinav S11-Dec-09 19:56
Abhinav S11-Dec-09 19:56 
AnswerRe: Use of &lt;&lt; and &gt;&gt; [modified] Pin
DaveyM6911-Dec-09 21:27
professionalDaveyM6911-Dec-09 21:27 
GeneralRe: Use of &lt;&lt; and &gt;&gt; Pin
Joe Rozario11-Dec-09 21:46
Joe Rozario11-Dec-09 21:46 
GeneralRe: Use of &lt;&lt; and &gt;&gt; Pin
DaveyM6911-Dec-09 22:37
professionalDaveyM6911-Dec-09 22:37 
GeneralRe: Use of &lt;&lt; and &gt;&gt; Pin
Joe Rozario16-Dec-09 17:59
Joe Rozario16-Dec-09 17:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.