Click here to Skip to main content
15,924,317 members
Home / Discussions / C#
   

C#

 
QuestionIn sql error? (urgent) Pin
onlybabla24-Oct-06 1:54
onlybabla24-Oct-06 1:54 
AnswerRe: In sql error? (urgent) Pin
Colin Angus Mackay24-Oct-06 2:16
Colin Angus Mackay24-Oct-06 2:16 
AnswerRe: In sql error? (urgent) Pin
ednrgc24-Oct-06 2:43
ednrgc24-Oct-06 2:43 
QuestionBorder selection Pin
sathishtl00724-Oct-06 1:11
sathishtl00724-Oct-06 1:11 
Questionwindows form resize Pin
t_nedelchev24-Oct-06 1:03
t_nedelchev24-Oct-06 1:03 
AnswerRe: windows form resize Pin
V.24-Oct-06 2:28
professionalV.24-Oct-06 2:28 
AnswerRe: windows form resize Pin
Dan Neely24-Oct-06 3:35
Dan Neely24-Oct-06 3:35 
GeneralCasting generic lists Pin
Ed.Poore24-Oct-06 1:00
Ed.Poore24-Oct-06 1:00 
Is there a way of casting a generic list to another one, best way to explain what I want is, imagine the following scenario
public class Customer : Person { ... }
public class Criminal : Person { ... }
Now there's a dictionary object to provide a lookup table:
Dictionary<Type, List<Person>> lists;
And I'd like this dictioanry to contain a list of Customers and Criminals so...
lists.Add(typeof(Customer), new List<Customer>());
lists.Add(typeof(Criminal), new List<Criminal>());
However this complains that there's no conversion between List<Customer> and List<Person>.

This code will be accessed later on, for arguments sake through a method like this:
public List<T> GetList<T>() where T : Person
{
    return lists[typeof(T)];
}

Anybody have any ideas on how to accomplish this.  The objects (Customer and Criminal) can be cast to Person and back again but it does not like casting the lists.  Any ideas on "fooling" the compiler into doing what I want?



Sig cops got me...

GeneralRe: Casting generic lists Pin
Ed.Poore24-Oct-06 1:16
Ed.Poore24-Oct-06 1:16 
GeneralRe: Casting generic lists Pin
Not Active24-Oct-06 3:07
mentorNot Active24-Oct-06 3:07 
GeneralRe: Casting generic lists Pin
Ed.Poore24-Oct-06 3:47
Ed.Poore24-Oct-06 3:47 
GeneralRe: Casting generic lists Pin
Daniel Grunwald24-Oct-06 5:21
Daniel Grunwald24-Oct-06 5:21 
GeneralRe: Casting generic lists Pin
Ed.Poore24-Oct-06 5:36
Ed.Poore24-Oct-06 5:36 
QuestionNewbie: Porblem with ListView... Pin
Phillip Hodges24-Oct-06 0:10
Phillip Hodges24-Oct-06 0:10 
AnswerRe: Newbie: Porblem with ListView... Pin
baerten24-Oct-06 2:34
baerten24-Oct-06 2:34 
GeneralRe: Newbie: Porblem with ListView... Pin
Phillip Hodges24-Oct-06 22:03
Phillip Hodges24-Oct-06 22:03 
GeneralRe: Newbie: Porblem with ListView... Pin
baerten25-Oct-06 0:07
baerten25-Oct-06 0:07 
QuestionDate Of Birth Pin
bhanu1234523-Oct-06 23:33
bhanu1234523-Oct-06 23:33 
AnswerRe: Date Of Birth Pin
Jon Hulatt23-Oct-06 23:48
Jon Hulatt23-Oct-06 23:48 
AnswerRe: Date Of Birth Pin
V.24-Oct-06 0:43
professionalV.24-Oct-06 0:43 
AnswerRe: Date Of Birth Pin
Ed.Poore24-Oct-06 1:02
Ed.Poore24-Oct-06 1:02 
AnswerRe: Date Of Birth Pin
Guffa24-Oct-06 1:02
Guffa24-Oct-06 1:02 
AnswerRe: Date Of Birth Pin
Drew McGhie25-Oct-06 11:57
Drew McGhie25-Oct-06 11:57 
QuestionButton with Transparancy Pin
Jon Hulatt23-Oct-06 23:32
Jon Hulatt23-Oct-06 23:32 
AnswerRe: Button with Transparancy Pin
Dave Kreskowiak24-Oct-06 5:31
mveDave Kreskowiak24-Oct-06 5:31 

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.