Object - IsValidChar
An object extension method that query if '@this' is valid char.
public static void Main() { string format = "{0, -10} {1, -15}"; object [] values = { "-128" ,"12.8", "-89", "ABC", "true", "128", "a", ".", "0", "10.2m"}; Console.WriteLine(format, "Object", "Is Valid Char"); Console.WriteLine(format, "------", "-------------"); foreach(var val in values) { // C# Extension Method: Object - IsValidChar Console.WriteLine(format, val, val.IsValidChar()); } }
View Source
public static partial class Extensions { /// <summary> /// An object extension method that query if '@this' is valid char. /// </summary> /// <param name="this">The @this to act on.</param> /// <returns>true if valid char, false if not.</returns> public static bool IsValidChar(this object @this) { char result; return char.TryParse(@this.ToString(), out result); } }