C#怎么把两个FileInfo数组的内容合并到一个中?

大哥,请分析下,C#怎么把两个FileInfo数组的内容合并到一个中?
最新回答
你伴我暖

2024-10-02 01:32:49

方法一:

public FileInfo[] JionArray(FileInfo[] First, FileInfo[] Second)
{
FileInfo[] result = new FileInfo[First.Length + Second.Length];
First.CopyTo(result, 0);
Second.CopyTo(result, First.Length);
return result;
}
方法二:
FileInfo[] first = new FileInfo[5];
first[0] = new FileInfo(@"c:\1.txt");
first[1] = new FileInfo(@"c:\2.txt");
first[2] = new FileInfo(@"c:\3.txt");
first[3] = new FileInfo(@"c:\4.txt");
first[4] = new FileInfo(@"c:\5.txt");
FileInfo[] second = new FileInfo[5];
second[0] = new FileInfo(@"c:\1.txt");
second[1] = new FileInfo(@"c:\2.txt");
second[2] = new FileInfo(@"c:\3.txt");
second[3] = new FileInfo(@"c:\4.txt");
second[4] = new FileInfo(@"c:\5.txt");
List<FileInfo> ls = new List<FileInfo>();
ls.AddRange(first);
ls.AddRange(second);
foreach (FileInfo item in ls)
{
Console.WriteLine(item.Name);
}
Console.Read();