public static void Demo() { var p1 = new PersonV1("Fred", "Flintstone"); GetMiddleNameLength(p1); var p2 = new PersonV2("Barney", "Rubble"); GetMiddleNameLength(p2); Weapon cantBeNull; Weapon?canBeNull; canBeNull = null; // Note the compiler warning cantBeNull = null; canBeNull = new Weapon(); cantBeNull = new Weapon(); canBeNull.Repair(); cantBeNull.Repair(); }
// This works, but will fail public static int GetMiddleNameLength(PersonV1 p) => p.MiddleName.Length;