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?
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With