tags:

views:

346

answers:

2

Hej,

assuming I have a code that looks like this:

List<User> userList = GetUserByName (u => u.Name == name);
DoSomethingWithTheUsers (userList.ToArray ());

Now I want to know the type of the objects in the Array in the method DoSomethingWithTheUsers (object[] myObjects)

Simply done by myObjects.First ().GetType () but what is to be done if the array is empty? Is there a possibility to still get the Type?

+5  A: 

The array type will be an array of User, i.e. User[]. Why not just use Type.GetElementType() on the GetType() of the array? I.e. using your example:

myObjects.GetType().GetElementType()
Barry Kelly
ah thats what I was looking for, thanks
Calamitous
A: 

Thats what I would expect but I what I want is: User I need to save the FullName of the type for later, and I wondered if there is a better way, then removing the [] by string replace (or something like that)

Calamitous
I updated my answer to be more detailed.
Barry Kelly