معادلهای string.IsNullOrEmpty در C# 9.0 جهت اطلاع و آشنایی با Syntax جدید؛ اگر جائی آنها را دیدید!
using System; namespace CS9Features { public static class ModernizingACodebase { public static void PropertyPatternToReplaceIsNullorEmpty1() { string hello = null; // Old approach if (!string.IsNullOrEmpty(hello)) { Console.WriteLine($"{hello} has {hello.Length} letters."); } // New approach, with a property pattern if (hello is { Length: > 0 }) { Console.WriteLine($"{hello} has {hello.Length} letters."); } } public static void PropertyPatternToReplaceIsNullorEmpty2() { // For arrays var greetings = new string[2]; greetings[0] = "Hello world"; greetings = null; // Old approach if (greetings != null && !string.IsNullOrEmpty(greetings[0])) { Console.WriteLine($"{greetings[0]} has {greetings[0].Length} letters."); } // New approach if (greetings?[0] is { Length: > 0 } hi) { Console.WriteLine($"{hi} has {hi.Length} letters."); } } } }