Im trying to read variable array from string and show it in console but each time I run the program Im getting error: "Object reference not set to an instance of an object." Can anyone suggest how to do this?
my code:
public class Positions
{
public static string[] test = { "test", "test2" };
}
private void test()
{
Positions pos = new Positions();
Type type = typeof(Positions);
FieldInfo fi = type.GetField("test[0]");
Console.WriteLine(fi.GetValue(pos));
}
Aucun commentaire:
Enregistrer un commentaire