Click here to Skip to main content
15,890,438 members
Home / Discussions / C#
   

C#

 
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 
As has been explained, it can't be done with an implicit or explicit cast.
Here is a little method to do it for you.
C#
public 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;
       }));
}

To use:
C#
List<Base> listBase = DerivedConverter<Base, Derived>(listDerived);

where Base is the base class and Derived is a class derived from Base.
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 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 
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 
GeneralRe: Need help with co/contravariance and generic lists :s Pin
Pete O'Hanlon6-Sep-10 3:41
mvePete O'Hanlon6-Sep-10 3:41 
AnswerRe: Need help with co/contravariance and generic lists :s Pin
PIEBALDconsult6-Sep-10 7:32
mvePIEBALDconsult6-Sep-10 7:32 
QuestionHow to deploy an Outlook 2003 add-in application(C# and VS 2008)? Pin
milestanley5-Sep-10 22:57
milestanley5-Sep-10 22:57 
QuestionCould use some help please. Pin
pestman5-Sep-10 22:01
pestman5-Sep-10 22:01 
AnswerRe: Could use some help please. Pin
Kubajzz5-Sep-10 22:21
Kubajzz5-Sep-10 22:21 
GeneralRe: Could use some help please. Pin
pestman6-Sep-10 6:27
pestman6-Sep-10 6:27 
GeneralRe: Could use some help please. Pin
Kubajzz6-Sep-10 9:51
Kubajzz6-Sep-10 9:51 
Question"Cannot connect back" - Visual Studio 2008 Remote Debugger for C# apps Pin
Maxwell Chen5-Sep-10 20:19
Maxwell Chen5-Sep-10 20:19 
QuestionQuestion about RegEx Class Pin
Mazdak5-Sep-10 16:24
Mazdak5-Sep-10 16:24 
Answercross-post Pin
Luc Pattyn5-Sep-10 16:54
sitebuilderLuc Pattyn5-Sep-10 16:54 
AnswerRe: Question about RegEx Class [modified] Pin
PIEBALDconsult5-Sep-10 17:34
mvePIEBALDconsult5-Sep-10 17:34 
QuestionNot able to delete original jpeg file after it is copied with System.IO.File.Copy() Pin
Aseem Sharma5-Sep-10 2:39
Aseem Sharma5-Sep-10 2:39 

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.