C# Extension Method: Object - NullIfEquals

CSharp · Console

/Program.cs

// C# Extension Method
// Doc: https://csharp-extension.com/en/method/1002565/object-nullifequals

// @nuget: Z.ExtensionMethods

using System;			
using System.Linq;
using System.Collections.Generic;

public class Program
{
	public static void Main()
	{
        string @this = "1";

        // C# Extension Method: Object - NullIfEquals
        string result1 = @this.NullIfEquals("1"); // return null;
        string result2 = @this.NullIfEquals("2"); // return "1";

        Console.WriteLine(result1);
        Console.WriteLine(result2);
	}
}
;