Main Object Empty Array Type

Hej

Assuming I have some code that looks like this:

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

Now I want to find out the type of objects in the array in the DoSomethingWithTheUsers (object [] myObjects) method

Just done myObjects.First (). GetType (), but what if the array is empty? Is it possible to still get the type?

+4
source share
2 answers

The type of the array will be the array of User, that is, User []. Why not just use Type.GetElementType () in the GetType () array? That is, using your example:

 myObjects.GetType().GetElementType() 
+12
source

Here is what I expect, but I want: user I need to save the FullName of this type for later versions, and I wondered if there is a better way, and then delete [] by replacing the string (or something like that).

0
source

All Articles