FieldInfo[] fields = typeof(MyDictionary).GetFields();
MyDictionary is a static class, all fields are string arrays.
How to get get the Length value of each array and then itearate through all elements ?
I tried the cast like:
field as Array
but it causes an error
Cannot convert type ‘System.Reflection.FieldInfo’ to ‘System.Array’
via a reference conversion, boxing conversion, unboxing conversion,
wrapping conversion, or null type conversion
Edit after your edit: Note that what you have is reflection objects, not objects or values related to your own class. In other words, those
FieldInfoobjects you have there are common to all instances of your class. The only way to get to the string arrays is to use thoseFieldInfoobjects to get to the field value of a particular instance of your class.For that, you use FieldInfo.GetValue. It returns the value of the field as an object.
Since you already know they are string arrays, that simplifies things:
If the fields are static, pass
nullfor theobjparameter below.If you want to ensure you only process fields with string arrays: