forked from dotnet/docs
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathProgram.cs
More file actions
35 lines (31 loc) · 885 Bytes
/
Copy pathProgram.cs
File metadata and controls
35 lines (31 loc) · 885 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
namespace MigrationStrategies;
internal static class Examples
{
public static void RunAll()
{
Console.WriteLine(LegacyHelper.GetGreeting("ada"));
Console.WriteLine(MigratedHelper.GetGreeting("ada"));
}
}
// <DirectiveOverrides>
#nullable disable
public static class LegacyHelper
{
// This file is nullable-oblivious. Reference types use the legacy rules.
public static string GetGreeting(string name) =>
name == null ? "hello" : $"hello {name}";
}
#nullable restore
#nullable enable
public static class MigratedHelper
{
// This file is fully migrated. Reference types are non-nullable by default.
public static string GetGreeting(string? name) =>
name is null ? "hello" : $"hello {name}";
}
#nullable restore
// </DirectiveOverrides>
internal static class Program
{
private static void Main() => Examples.RunAll();
}