1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | using System; class Program { public static Person[] pArray = new Person[10]; public static void Main(string[] args) { pArray[0] = new Person("iowa"); pArray[1] = new Person("ssss"); foreach (Person person in pArray) { Console.WriteLine(person); //실행시 오류 없음 Console.WriteLine(person.name); //실행시 NullReferenceException 오류 } } } class Person { public string name { get; set; } public Person(string name) { this.name = name; } } | cs |
대체 왜 그런거죠? 똑같이 에러나야하지 않을까요?
no string? => ToString(), string? => just get. so error occurred
?? 저 영어 잘 못해요 ㅠㅠ
음 뭔 말인진 모르겠지만 대충 이해한 것 같아요