static void Main(string[] args) { var miguel = new Person("Miguel", "de Icaza"); int length = GetLengthOfMiddleName(miguel); Console.WriteLine(length); var old = new Legacy(); string s1 = old.GetANullString(); // no error // Console.WriteLine(s1.ToUpper()); // legacy no error, runtime exception var newglory = new NewAndGlory(); string?s2 = newglory.GetANullString(); string s3 = newglory.GetAString(); var sc = new SomeClass(); string?s4 = sc.Foo(); string s5 = sc.Foo() !; // dammit }
static void Main() { var book = new Book("Professional C# 8", "Wrox Press"); // string isbn = book.Isbn; // error: converting null literal or possible null value to non-nullable type string?isbn = book.Isbn; var newglory = new NewAndGlory(); string?s1 = newglory.GetANullString(); string s2 = newglory.GetAString(); // string s3 = newglory.PassAString(null); // error: cannot convert null literal to non-nullable reference or unconstrained type parameter var old = new Legacy(); string s4 = old.GetANullString(); // no error, s1 is null! string s5 = old.PassAString(null); // no error var sc = new SomeClass(); string?s6 = sc.Foo(); string s7 = sc.Foo() !; // dammit }