Пример #1
0
    static void Main(string[] args)
    {
      // Null-conditional operator.

      string name = null;
      var nameLength = name?.Length;
      List<string> names = null;
      nameLength = names?[0].Length;

      var notifier = new Notifier();
      notifier.ChangeState();
      notifier.StateChanged += (sender, e) => WriteLine("StateChanged notification received...");
      notifier.ChangeState();

      // await in catch/finally blocks.
      notifier.ChangeStateAsync().Wait();

      // Auto-property initializers + expression-bodied members + string interpolation.
      var snapshot = new Snapshot();
      WriteLine(snapshot);
      WriteLine($"{snapshot.UserName} created on {snapshot.Timestamp} with name length of {name?.Length ?? 0}");

      // nameof expressions.
      WriteLine(nameof(args));
      WriteLine(nameof(notifier));
      WriteLine(nameof(Main));
      WriteLine(nameof(Program));

      ReadLine();
    }