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

C#

 
GeneralRe: BSCS FINAL PROJECT PinPopular
Pete O'Hanlon6-Sep-10 2:25
mvePete O'Hanlon6-Sep-10 2:25 
GeneralRe: BSCS FINAL PROJECT Pin
Smithers-Jones6-Sep-10 2:31
Smithers-Jones6-Sep-10 2:31 
GeneralRe: BSCS FINAL PROJECT Pin
Dave Kreskowiak6-Sep-10 3:52
mveDave Kreskowiak6-Sep-10 3:52 
Generalzoo Pin
Luc Pattyn6-Sep-10 5:15
sitebuilderLuc Pattyn6-Sep-10 5:15 
GeneralRe: BSCS FINAL PROJECT Pin
DaveyM696-Sep-10 2:38
professionalDaveyM696-Sep-10 2:38 
GeneralRe: BSCS FINAL PROJECT Pin
Smithers-Jones6-Sep-10 2:39
Smithers-Jones6-Sep-10 2:39 
GeneralRe: BSCS FINAL PROJECT Pin
Pete O'Hanlon6-Sep-10 2:41
mvePete O'Hanlon6-Sep-10 2:41 
GeneralRe: BSCS FINAL PROJECT Pin
DaveyM696-Sep-10 3:05
professionalDaveyM696-Sep-10 3:05 
GeneralRe: BSCS FINAL PROJECT Pin
Pete O'Hanlon6-Sep-10 3:15
mvePete O'Hanlon6-Sep-10 3:15 
GeneralRe: BSCS FINAL PROJECT Pin
DaveyM696-Sep-10 4:19
professionalDaveyM696-Sep-10 4:19 
GeneralRe: BSCS FINAL PROJECT Pin
Mycroft Holmes6-Sep-10 22:51
professionalMycroft Holmes6-Sep-10 22:51 
QuestionCalendarExtender popup appearing when Enter key is pressed. Pin
dev_asp_shreshtha6-Sep-10 0:48
dev_asp_shreshtha6-Sep-10 0:48 
AnswerRe: CalendarExtender popup appearing when Enter key is pressed. Pin
dan!sh 6-Sep-10 0:59
professional dan!sh 6-Sep-10 0:59 
QuestionNeed help with co/contravariance and generic lists :s Pin
Lee Reid5-Sep-10 23:12
Lee Reid5-Sep-10 23:12 
AnswerRe: Need help with co/contravariance and generic lists :s Pin
Kubajzz5-Sep-10 23:50
Kubajzz5-Sep-10 23:50 
GeneralRe: Need help with co/contravariance and generic lists :s [modified] Pin
Lee Reid6-Sep-10 0:41
Lee Reid6-Sep-10 0:41 
GeneralRe: Need help with co/contravariance and generic lists :s Pin
Kubajzz6-Sep-10 1:06
Kubajzz6-Sep-10 1:06 
GeneralRe: Need help with co/contravariance and generic lists :s Pin
Lee Reid6-Sep-10 2:02
Lee Reid6-Sep-10 2:02 
GeneralRe: Need help with co/contravariance and generic lists :s Pin
Kubajzz6-Sep-10 2:13
Kubajzz6-Sep-10 2:13 
AnswerRe: Need help with co/contravariance and generic lists :s Pin
DaveyM696-Sep-10 0:41
professionalDaveyM696-Sep-10 0:41 
GeneralRe: Need help with co/contravariance and generic lists :s Pin
Lee Reid6-Sep-10 1:12
Lee Reid6-Sep-10 1:12 
GeneralRe: Need help with co/contravariance and generic lists :s Pin
DaveyM696-Sep-10 1:31
professionalDaveyM696-Sep-10 1:31 
GeneralRe: Need help with co/contravariance and generic lists :s Pin
DaveyM696-Sep-10 1:54
professionalDaveyM696-Sep-10 1:54 
Perhaps something like this will help. This implementation doesn't allow you to add items to the base list, I don't know if that is a requirement or not. This won't be particularly efficient but should work (untested!). You would need to add checks to make sure the lists aren't null too.
C#
public class BaseList<TBase, TDerived1, TDerived2>
    where TDerived1 : TBase
    where TDerived2 : TBase
{
    private List<TDerived1> derived1List;
    private List<TDerived2> derived2List;

    public List<TDerived1> Derived1List
    {
        get { return derived1List; }
        set { derived1List = value; }
    }
    public List<TDerived2> Derived2List
    {
        get { return derived2List; }
        set { derived2List = value; }
    }
    public ReadOnlyCollection<TBase> BaseCollection
    {
        get
        {
            List<TBase> baseList = DerivedConverter<TBase, TDerived1>(derived1List);
            baseList.AddRange(DerivedConverter<TBase, TDerived2>(derived2List));
            return baseList.AsReadOnly();
        }
    }

    private static List<TBase> DerivedConverter<TBase, TDerived>(List<TDerived> derivedList)
            where TDerived : TBase
    {
        return derivedList.ConvertAll<TBase>(
               new Converter<TDerived, TBase>(delegate(TDerived derived)
               {
                   return derived;
               }));
    }
}

Dave

If this helped, please vote & accept answer!


Binging is like googling, it just feels dirtier.
Please take your VB.NET out of our nice case sensitive forum.(Pete O'Hanlon)

BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)

GeneralRe: Need help with co/contravariance and generic lists :s Pin
Lee Reid6-Sep-10 2:08
Lee Reid6-Sep-10 2:08 
GeneralRe: Need help with co/contravariance and generic lists :s Pin
DaveyM696-Sep-10 2:13
professionalDaveyM696-Sep-10 2:13 

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.