Object - IsArray
A T extension method that query if '@this' is array.
public static void Main() { string str = ""; string[] strArray = {"a", "b", "c"}; List<int> list = new List<int>(); IEnumerable<Char> charList = new List<char> (){ 'a', 'b' }; object[] objList = { str, strArray, 2.3, list, charList, 2 }; foreach (var t in objList) { //C# Extension Method: Object - IsArray Console.WriteLine("{0,-15} IsArray = {1}", t.GetType(), t.IsArray()); } }
View Source
public static partial class Extensions { /// <summary> /// A T extension method that query if '@this' is array. /// </summary> /// <typeparam name="T">Generic type parameter.</typeparam> /// <param name="this">The @this to act on.</param> /// <returns>true if array, false if not.</returns> public static bool IsArray<T>(this T @this) { return @this.GetType().IsArray; } }