Generics

  • Thread starter Thread starter mick
  • Start date Start date
M

mick

Still dabbling in Generics. Couple of questions

1 . If I pass a generic list into a generic method, how do I
find the type of the objects in the list - cant work out
the syntax.

2. The placeholders that are used like "<T>" cant they be
anything <A> <B> <X> <Z>?

mick
 
Still dabbling in Generics. Couple of questions

1 . If I pass a generic list into a generic method, how do I
find the type of the objects in the list - cant work out
the syntax.

typeof(T) will return the type of T.

static void GenericMethod<T>(List<T> list)
{
Console.WriteLine(typeof(T));
}
2. The placeholders that are used like "<T>" cant they be
anything <A> <B> <X> <Z>?

You can use anything you like.

Regards.
 
kndg said:
typeof(T) will return the type of T.

static void GenericMethod<T>(List<T> list)
{
Console.WriteLine(typeof(T));
}

Thanks for that. I faffed around for ages:-)
You can use anything you like.

Ok. I`d seen a few examples using different letters and wasnt sure
if they actually stood for something specific.

mick
 
Back
Top