我假设您正在像这样设置 2D:
int?[][] myArrayA = new int?[][] { new int?[] {0,0,0}, new int?[] {1,1,1}, new int?[] {2,2,2} };
int?[][] myArrayB = new int?[][] { new int?[] {0,0,0}, new int?[] {1}, new int?[] {null} };
int?[][] myArrayC = new int?[][] { new int?[] {0,null}, new int?[] {1,1,1}, new int?[] {2,2,2} };
所以,使用 Linq 我们这样做:
bool FirstCheck(int?[][] theArray)
{
int size = (from arrays in theArray select arrays.GetUpperBound(0)).Max();
var check = from arrays in theArray
where theArray.All(sub => sub.GetUpperBound(0) == size)
select arrays;
return size + 1 == check.Count<int?[]>();
}
bool SecondCheck(int?[][] theArray)
{
int size = (from arrays in theArray select arrays.GetUpperBound(0)).Max();
var check = from arrays in
(from subs in theArray
where theArray.All(sub => sub.All(value => value != null))
select subs)
where arrays.GetUpperBound(0) == size
select arrays;
return size + 1 == check.Count<int?[]>();
}
bool ThirdCheck(int?[][] theArray)
{
int size = (from arrays in theArray select arrays.GetUpperBound(0)).Max();
var check = from arrays in theArray
where theArray.All(array => array[0].HasValue)
select arrays;
return size + 1 == check.Count<int?[]>();
}
希望这就是你想要的...