repl.it
@kironroy/

nullabletypes

C#

No description

fork
loading
Files
  • main.cs
  • main.exe
  • notes.txt
main.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
using System;

namespace NullableTypes
{
    class Program
    {
        static void Main(string[] args)
        {
            DateTime? date = null; // nullable type syntax 
            DateTime date2 = date ?? DateTime.Today;

            // null coalescing operator 
            DateTime date3 = (date != null) ? date.GetValueOrDefault() : DateTime.Today;

            Console.WriteLine(date2);
            Console.WriteLine(date3);



        }
    }
}