区分大小写,采用方法格式:
public List<string> ToDistinct(IEnumerable<string> input)
{
List<string> unique = new List<string>();
foreach (string s in input)
{
List<string> files = s.Split(',').ToList();
unique.Add(String.Join(",", files.Distinct()));
}
return unique;
}
这是一个控制台方法,可以像上面一样显示输出,如果您愿意,可以对其进行调整:
public static void Main(string[] args)
{
List<string> input = new List<string>{"A.txt,B.txt,A.txt,B.txt", "A.txt,C.txt,A.txt,C.txt"};
//Display Input
Console.WriteLine("Input");
Console.WriteLine("ItemNum FileNames");
for(int i = 0; i < input.Count(); i++)
{
Console.WriteLine(String.Format(" {0,-23:000}{1}", i + 1, input[i]));
}
//Build the Unique List
List<string> unique = new List<string>();
foreach (string s in input)
{
List<string> files = s.Split(',').ToList();
unique.Add(String.Join(",", files.Distinct()));
}
//Display Output
Console.WriteLine();
Console.WriteLine("Output");
Console.WriteLine("ItemNum FileNames");
for(int i = 0; i < unique.Count(); i++)
{
Console.WriteLine(String.Format(" {0,-23:000}{1}", i + 1, unique[i]));
}
Console.ReadKey();
}