我在C#中有一个2D矩阵,构建起来有点复杂。以下是该矩阵生成的代码:
不用担心上面的代码。问题是我想让矩阵成为正方形。硬编码的列没问题,但来自数据库
虽然这只是我所需要的东西的示例而不是解决方案,但我需要以如下形式定义数组大小。
在你建议解决方案之前,我必须指出
string[][] learningInputNotCodified = learningDataRaw.Select(ldr => new string[] {
ldr.ChangeType.ToString(),
ldr.MutationOperator.Name??"null",
ldr.MutationOperator.Before??"null",
ldr.MutationOperator.After??"null",
ldr.SLOC.ToString(),
dBContext.TestCases
.Count(tc => tc.UserMutantPlay.MutantId == ldr.Id).ToString(),
dBContext.TestCases
.Where(tc => tc.UserMutantPlay.MutantId == ldr.Id)
.Select(rtc => new {
killCount = dBContext.TestCases
.Where(tc => tc.IsMutantKilled
&& tc.UserMutantPlay.MutantId == ldr.Id
&& !tc.InputValues.Any(iv =>
rtc.InputValues.FirstOrDefault(iv1 => iv1.InputParameterId == iv.InputParameterId).ValueAsString != iv.ValueAsString))
.Count()
}).Sum(tc => tc.killCount).ToString(),
ldr.OriginalCode.Mutants.Count().ToString(),
ldr.ASTDiff??"null"
}.Concat(
ldr.ParseSubTrees.OrderBy(pst => pst.Height).Select(pst => pst.SerializedTree).ToArray()
).ToArray()).ToArray();
不用担心上面的代码。问题是我想让矩阵成为正方形。硬编码的列没问题,但来自数据库
ldr.ParseSubTrees.OrderBy(pst => pst.Height).Select(pst => pst.SerializedTree).ToArray()
的那些列会出问题。在到达这个语句(大语句)之前,我已经查询了数据库的最大大小。因此,我知道大小,只需要像这样:ldr.ParseSubTrees.OrderBy(pst => pst.Height).Select(pst => pst.SerializedTree).ToArray(maxParseTreeDepth)
虽然这只是我所需要的东西的示例而不是解决方案,但我需要以如下形式定义数组大小。
在你建议解决方案之前,我必须指出
Array.Resize
无法帮助。因为它需要一个保存的对象作为 ref
,而在选择表达式中我做不到。
Concat
内使用该实例。 - Federico DipumaToArray
时生成的那个数组。 - D Stanley