Click here to Skip to main content
15,904,288 members
Home / Discussions / C#
   

C#

 
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 
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 
fyi : < note code only tested in VS Studio beta 2 against FrameWork 4.0 >

If you are defining a generic class template that inherits from a generic List whose type is specifically defined as a "real" type at compile time like this :

public class anyDamnList3<T> : List<int>
{
    public List<int> innerList
    {
        set
        {
            this.Clear();
            this.AddRange(value);
        }
    }
}

the above will work. Of course you have to use its public property 'innerList to assign its "inner hidden list" value :

anyDamnList3<int> myList5 = new anyDamnList3<int> { 12, 21, 32 };

anyDamnList3<int> myList6 = new anyDamnList3<int> { 42, 53, 66 };

myList6.innerList = new List<int> { 33, 44, 55 };

So : no getting around having to define at least property in the class, and use Clear and AddRange !

The much more interesting case is this : where you are defining a generic strongly typed class which inherits from a List whose content type is generic <t> at compile time :

public class anyDamnList<T> : List<T>
{

    public List<int> innerList
    {
        set
        {
            this.Clear();
            this.AddRange(value as List<T>);
        }
    }
}


Yes, of course, you could define a method to set the "hidden inner list" rather than a property. Define to your own taste Smile | :)

You may note that in both cases above in actual use the "indexer" [] is exposed automatically. In essence you have every facility that comes with a List<t> type available to you except the ability to automatically assign to the "internal list it embodies." And, of course, just using the instance name returns the contents of what I am calling the "internal list" : in effect you have an automatic 'getter.

Thanks for the responses. I am going back to studying Skeet's magnificent book for a while !

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

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 
AnswerRe: Use of &lt;&lt; and &gt;&gt; Pin
harold aptroot11-Dec-09 21:45
harold aptroot11-Dec-09 21:45 

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.