Click here to Skip to main content
15,914,820 members
Home / Discussions / C#
   

C#

 
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 
GeneralRe: Use of << and >> Pin
Joe Rozario16-Dec-09 17:59
Joe Rozario16-Dec-09 17:59 
AnswerRe: Use of << and >> Pin
harold aptroot11-Dec-09 21:45
harold aptroot11-Dec-09 21:45 
QuestionHow to show multiple crystal reports in single Report Viewer. [modified] Pin
sher_azam11-Dec-09 18:35
sher_azam11-Dec-09 18:35 
GeneralRe: How to show multiple crystal reports in single Report Viewer. Pin
Abhinav S11-Dec-09 23:02
Abhinav S11-Dec-09 23:02 
GeneralRe: How to show multiple crystal reports in single Report Viewer. Pin
sher_azam11-Dec-09 23:13
sher_azam11-Dec-09 23:13 
QuestionCustom User Control for Multipoint SDK! Pin
Kushal Gautam11-Dec-09 17:53
Kushal Gautam11-Dec-09 17:53 
AnswerRe: Custom User Control for Multipoint SDK! Pin
krunal255-Feb-10 1:53
krunal255-Feb-10 1:53 

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.