C# Extension Method: Object - ToStringSafe

CSharp · Console

/Program.cs

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

// @nuget: Z.ExtensionMethods

using System;			

public class Program
{
	public static void Main()
	{
        int thisValue = 1;
        string thisNull = null;

        // C# Extension Method: Object - ToStringSafe
        string result1 = thisValue.ToStringSafe(); // return "1";
        string result2 = thisNull.ToStringSafe(); // return "";

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