Click here to Skip to main content
15,886,362 members
Home / Discussions / C#
   

C#

 
AnswerRe: Replace "inner list" of a generic class inheriting from List<T> ? Pin
DaveyM6912-Dec-09 7:44
professionalDaveyM6912-Dec-09 7:44 
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 
Hi Bill,

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.

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 thought up an analogy, so please bear with me Smile | :)

Imagine List is a safe. You can use physical instances of a safe and they would be quite useful.

You can put one in your house and use it yourself: this is composition - you're house "has a" safe. But if people come to your door, they can't use your internal safe.

You could open a window and allow people to deposit and withdraw money from your safe: this is implementing IList on your house class - it's a bit of work for you, but now people can use your safe.

And now you can quite easily replace your instance of safe: just throw the old one away and set the new one. I think this is your original requirement.

Now, deriving from safe would be like building a bank. A bank "is a" safe, but it does more. The internal safe is there, but you cannot replace it because it's a part of your bank. You can, however, change it's contents: this would be the Clear and AddRange solution.

I hope that's useful Smile | :)

Nick

----------------------------------
Be excellent to each other Smile | :)

GeneralRe: Replace "inner list" of a generic class inheriting from List<T> ? [modified] Pin
BillWoodruff14-Dec-09 4:50
professionalBillWoodruff14-Dec-09 4:50 
Answera "partial solution" to : re : Replace "inner list" of a generic class inheriting from List<T> ? 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 << and >> [modified] Pin
Joe Rozario11-Dec-09 19:16
Joe Rozario11-Dec-09 19:16 
AnswerRe: Use of << and >> Pin
Abhinav S11-Dec-09 19:56
Abhinav S11-Dec-09 19:56 
AnswerRe: Use of << and >> [modified] Pin
DaveyM6911-Dec-09 21:27
professionalDaveyM6911-Dec-09 21:27 
GeneralRe: Use of << and >> Pin
Joe Rozario11-Dec-09 21:46
Joe Rozario11-Dec-09 21:46 
GeneralRe: Use of << and >> Pin
DaveyM6911-Dec-09 22:37
professionalDaveyM6911-Dec-09 22:37 

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.