如何计算c#中数组索引中的元素数 [英] how to count number of element in an array index in c#
本文介绍了如何计算c#中数组索引中的元素数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我的数组像
hi all,
I have array like
root_result.MainDashboard[0].
在这个数组
root_result.MainDashboard[0]
有一些元素,如何查找此索引中的元素数量?
示例:
having some elements, how to find number of elements in this index?
example:
root_result.MainDashboard[0].One,root_result.MainDashboard[0].Two,root_result.MainDashboard[0].Three,root_result.MainDashboard[0].Four
..等。
如何计算此数组索引中元素的数量?
提前感谢...
..etc.
how to count number of element in an this array index?
thanks in advance...
推荐答案
这是字符串数组的答案:
string [] intArray = new string [10];
intArray [0 ] =一个;
intArray [1] =两个;
intArray [2] =三个;
int result = intArray.Count(i =>(!String.IsNullOrEmpty(i)&& i .Length> 1));
Here is the answer for string array:
string[] intArray = new string[10];
intArray[0] = "One";
intArray[1] = "Two";
intArray[2] = "Three";
int result = intArray.Count(i => (!String.IsNullOrEmpty(i) && i.Length > 1));
使用这样的东西:
int?[] intArray = new int?[10];
intArray [0] = 34;
intArray [1] = 65;
intArray [2] = 98;
int result = intArray.Count(i => i.HasValue);
Use some thing like this:
int?[] intArray = new int?[10];
intArray[0] = 34;
intArray[1] = 65;
intArray[2] = 98;
int result = intArray.Count(i => i.HasValue);
如果你的数组是root_result.MainDashboard
它的总索引是
int totalIndex = root_result.MainDashboard.Length;
array-length [ ^ ]
count-array [ ^ ]
if your array is root_result.MainDashboard
and it's total index is
int totalIndex=root_result.MainDashboard.Length;
array-length[^]
count-array[^]
这篇关于如何计算c#中数组索引中的元素数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文