I would like to create an extension method for the System.Array
class that will take in a char[]
or byte[]
array and return its Length. I need this method for in case the array is null, and I don't want to litter the code with whole bunch of (arr == null) ? 0 : arr.Length
calls.
I want to call it like this: Array.ReturnLength(arr)
.
I tried implementing it, but I only see it when I do arr.ReturnLength()
, but not as an Array method.
public static int ReturnLength(this Array arr)
{
if (arr == null)
return 0;
return arr.Length;
}
Any ideas? Thanks.