Answer the question
In order to leave comments, you need to log in
How to get the elements of an array or list through reflection (reflection, reflection)?
It seems like a simple question, but superficial Google and msdn did not answer the question, apparently I was looking badly. I am processing some object. And if it turned out to be an array, I need to recursively access all of its elements. The main problem is that it may not necessarily be an array, i.e. I cannot use the index operator [] with it.
Those. Simplified code looks like this:
...
if (obj.GetType().IsArray)
{
//Получить элементы массива obj
}
Answer the question
In order to leave comments, you need to log in
I did not understand what "surface Google" means .
if (obj.GetType().IsArray)
{
obj.GetType().GetMethod("GetValue", typeof(int)).Invoke(obj, index);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question