0

why wont this Work

the code is class Program { static str[] strs = new str[10]; static void Main(string[] args) { strs[1].Name = "d"; } } the error it giveing me is System.NullReferenceException: 'Object reference not set to an instance of an object.' and the str class is [System.Serializable] public class str { public string Name = " "; public string Var = " "; }

5th Feb 2021, 7:50 PM
Crazy games
Crazy games - avatar
1 Odpowiedź
+ 3
you are declaring a new ARRAY of str, but you never initialize content... that's why you get the undefined error when you try to acess the Name property of strs[1]. quick fix: strs[1] = new str(); by adding this line at start of Main....
5th Feb 2021, 8:25 PM
visph
visph - avatar