Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Generic list question
Message
 
To
All
General information
Forum:
ASP.NET
Category:
Other
Title:
Generic list question
Environment versions
Environment:
C# 5.0
OS:
Windows 7
Network:
SAMBA Server
Database:
MS SQL Server
Application:
Desktop
Miscellaneous
Thread ID:
01611163
Message ID:
01611163
Views:
92
Hi All, I need to declare a generic list of a type which is decided at runtime, the type is one of several classes that all implement a common interface , I'm unsure how to do this, at first I thought I could use the Type of the class to create a list but this is not so - a small example of what I mean is shown below
IMyInterFace  i = GetClassType();

List<i> mylist = new List<i>();


IMyInterFace GetClassType()
{
  if(SomeCondition)
    return ClassA;
  else
    return classB;
}
Regards,
Peter J. Kane



Pete
Next
Reply
Map
View

Click here to load this message in the networking platform