A
acb
Hi,
I have a list of different objects in a <List> Structure. There is only
one category of each kind of object.
Current I have the following methods:
public static Flag GetFlagObj()
{
foreach (Thingy s in _Thingies)
{
if (s is Flag)
return (Flag)s;
}
return null;
}
public static Cloth GetFlagObj()
{
foreach (Thingy s in _Thingies)
{
if (s is Cloth)
return (Cloth)s;
}
return null;
}
public static BedSprd GetFlagObj()
{
foreach (Thingy s in _Thingies)
{
if (s is BedSprd)
return (BedSprd)s;
}
return null;
}
Is there a way I could have one generic method that would take as a
parameter the item I wish returned?
Thank you for your help.
Al
I have a list of different objects in a <List> Structure. There is only
one category of each kind of object.
Current I have the following methods:
public static Flag GetFlagObj()
{
foreach (Thingy s in _Thingies)
{
if (s is Flag)
return (Flag)s;
}
return null;
}
public static Cloth GetFlagObj()
{
foreach (Thingy s in _Thingies)
{
if (s is Cloth)
return (Cloth)s;
}
return null;
}
public static BedSprd GetFlagObj()
{
foreach (Thingy s in _Thingies)
{
if (s is BedSprd)
return (BedSprd)s;
}
return null;
}
Is there a way I could have one generic method that would take as a
parameter the item I wish returned?
Thank you for your help.
Al