BasicKnowledgeCSharp/LessonsAndTasks/Lesson 42_2 - Example 1 - Оператор условного NULL/Program.cs
Dvurechensky 058c8f2679 1.0
Main
2024-10-05 09:59:53 +03:00

36 lines
698 B
C#

using System;
/*
* Оператор условного null
*/
class Program
{
private static Person GetPerson()
{
Person person = null;
return person;
}
static void Main()
{
Person person = null;
Console.WriteLine(person?.Contacts?.PhoneNumber ?? "no data");
person = GetPerson();
// person, Contacts и PhoneNumber - ссылочные типы - так как они class
Console.WriteLine(person?.Contacts?.PhoneNumber ?? "no data");
Console.ReadKey();
}
}
public class Person
{
public Contacts Contacts { get; set; }
}
public class Contacts
{
public string PhoneNumber { get; set; }
}