我想创建一个动态数组的动态数组,我该怎么做?
我已尝试使用AddRange()
方法的列表列表。
我也试过迭代数组。
显示我正在尝试做的事情可能更有意义。我无法让它发挥作用:
String[] lines = System.IO.File.ReadAllLines(fileName);
String[] linesArr;
String[][] MultiArr;
int i = 0;
foreach (string line in lines)
{
if (line.Contains("EFIX"))
{
linesArr = line.Split(delimiterChars);
for (int x = 0; x < linesArr.Length; x++)
{
MultiArr[i][x] = linesArr[x];
}
Console.WriteLine(fixationsData[i]);
i++;
}
}
答案 0 :(得分:1)
使用字符串列表列表应该可以正常工作。这就是我写的东西。
var lines = System.IO.File.ReadAllLines(fileName);
var multiArr = new List<List<string>>();
var i = 0;
foreach (var line in lines.Where(line => line.Contains("EFIX")))
{
multiArr.Add(line.Split(delimiterChars).ToList());
Console.WriteLine(fixationsData[i]);
i++;
}
答案 1 :(得分:1)
LINQ使这非常简单。
string[][] data = File.ReadLines(filename)
.Where(line => line.Contains("EFIX"))
.Select(line => line.Split(delimiterChars))
.ToArray();//omit this last call to allow the data to be streamed,
//greatly removing the memory footprint of the application at no real
//additional cost, assuming you have no compelling reason to eagerly
//load the whole file into memory.
foreach(var line in data)
Console.WriteLine(line);
答案 2 :(得分:0)
String[] lines = System.IO.File.ReadAllLines(fileName);
String[] linesArr;
List<String[]> MultiArr = new List<String[]>();
foreach (string line in lines)
{
if (line.Contains("EFIX"))
{
linesArr = line.Split(delimiterChars);
MultiArr.Add(linesArr);
Console.WriteLine(fixationsData[i]);
}
}
这是一个字符串数组列表。这就是你要找的东西。