Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

non null array length

public static <T> int getLength(T[] arr){
    int count = 0;
    for(T el : arr)
        if (el != null)
            ++count;
    return count;
}

// equivalently in pure C# :
public static int getUsedLength(string[] arr)
        {
            int count = 0;
            for (int i = 0; i < arr.Length; i++)
            {
                if (arr[i] != null)
                { 
                    ++count; 
                }
            }
            return count;
        }
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #null #array #length
ADD COMMENT
Topic
Name
5+9 =