BasicKnowledgeCSharp/LessonsAndTasks/Lesson 42_2 - Example 1 - Оператор условного NULL/Program.cs
Dvurechensky bf6a7c2b4e 1.1
2025-05-12 02:48:54 +03:00

44 lines
873 B
C#

/*
* Author: Nikolay Dvurechensky
* Site: https://www.dvurechensky.pro/
* Gmail: dvurechenskysoft@gmail.com
* Last Updated: 12 мая 2025 02:47:11
* Version: 1.0.3
*/
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; }
}