Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace Nullable_2
- {
- class Program
- {
- //differenze tra ==null e is null
- static void Main(string[] args)
- {
- var x = new MyClass();
- if (x == null) { Console.WriteLine("Test 1: x is null"); }
- if (x != null) { Console.WriteLine("Test 2: x is not null"); }
- if (x is null) { Console.WriteLine("Test 3: x is null"); }
- if (!(x is null)) { Console.WriteLine("Test 4: x is not null"); }
- if (x is object) { Console.WriteLine("Test 5: x is not null"); }
- if (!(x is object)) { Console.WriteLine("Test 6: x is null"); }
- if (x is { }) { Console.WriteLine("Test 7: x is not null"); }
- if (!(x is { })) { Console.WriteLine("Test 8: x is null");}
- //c# 9
- //if (x is not null)
- // {
- // Console.WriteLine("Test 9: x is null");
- //}
- }
- #nullable enable
- static void f(string? s) => Console.WriteLine(s!.Length);
- }
- public class MyClass
- {
- public static bool operator ==(MyClass left, MyClass right) { return true; }
- public static bool operator !=(MyClass left, MyClass right) { return true; }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement