📜  非空数组长度 - C# 代码示例

📅  最后修改于: 2022-03-11 14:48:51.110000             🧑  作者: Mango

代码示例1
public static  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;
        }