Let state I have a generic member in a class or method, so:
public class Foo<T>
{
public List<T> Bar { get; set; }
public void Baz()
{
// get type of T
}
}
At the point when I start up the class, the
T
becomes
MyTypeObject1
, so the class has a generic list property:
List<MyTypeObject1>
. The equivalent applies to a generic strategy in a non-generic class:
public class Foo
{
public void Bar<T>()
{
var baz = new List<T>();
// get type of T
}
}
I might want to know, what type of objects the listed of my group contains. So the listed property called Bar or the local variable baz, contains what sort of T?
I can't do Bar[0].GetType(), because the list might contain zero elements. How might I do it?