我试图将一个数组复制到另一个只复制不同的数组。我在做多个模糊数组之前就已经开始工作了。现在,当我运行下面的代码时,它只是将原始数组复制到第二个数组。当我稍后在网页上输出数据时,我还需要将它们保持为数组格式。我做错了什么,还是不能用多个模糊点来做?
string[][] array;
string[][] array2;
array2 = array.Distinct().ToArray();在发布这篇文章之后,我可以编辑我的file.readalllines以不读取相同的行吗?代码在下面,表作为数组被传回。
 string[][] table = File.ReadAllLines(@path)
                       .Select(line => line.Split(';'))
                       .ToArray();发布于 2016-10-10 15:36:03
(我想我的评论根本听不懂,所以补充了一个答案)
假设您的文本文件是这样的(c:\temp\myFile.txt):
1; Name1; 100
1; Name1;100
1 ;Name1;100
11; Name1; 100
2;Name2;20然后,您可以使用如下代码获得不同的行:
void Main()
{
    int custId;
    decimal amount;
    var content =
      File.ReadAllLines(@"c:\temp\myFile.txt")
      .Select(f => f.Split(';'))
      .Select(f => new
      {
          CustomerID = int.TryParse(f[0], out custId) ? custId : -1,
          Company = f[1].Trim(),
          Amount = Decimal.TryParse(f[2], out amount) ? amount : 0M
      })
      .Where(f => f.CustomerID != -1)
      .Distinct();
    foreach (var c in content)
    {
        Console.WriteLine("CustomerID:{0}, Company:{1}, Amount:{2}", c.CustomerID, c.Company, c.Amount);
    }  
}https://stackoverflow.com/questions/39961265
复制相似问题