1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
| using System;
using System.Collections.Generic;
using System.Collections.Concurrent;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SortAndConcat
{
class Program
{
class Soft
{
public string _s1;
public string _s2;
public string _s3;
public string _s4;
public string _s5;
public string _s6;
public Soft(string s1, string s2, string s3, string s4, string s5, string s6)
{
_s1 = s1;
_s2 = s2;
_s3 = s3;
_s4 = s4;
_s5 = s5;
_s6 = s6;
}
public Soft(Soft s)
{
_s1 = s._s1;
_s2 = s._s2;
_s3 = s._s3;
_s4 = s._s4;
_s5 = s._s5;
_s6 = s._s6;
}
}
static void Main(string[] args)
{
Soft _soft0 = new Soft("test", "test", "test", "etest", "test", "ee123*85**$");
Soft _soft1 = new Soft("ee", "ee", "ee", "ee", "ee", "ee123");
Soft _soft2 = new Soft("ee", "ee", "ee", "ee", "ee", "ee345");
Soft _soft3 = new Soft("ee", "ee", "ee", "ee", "ee", "ee678");
Soft _soft4 = new Soft("ee", "ee", "ee", "ee", "ee", "ee987");
Soft _soft5 = new Soft("ee", "ee", "ee", "ee", "ee", "ee654");
Soft _soft6 = new Soft("ee", "ee", "ee", "ee", "ee", "ee321");
List<Soft> list = new List<Soft>();
list.Add(_soft0);
list.Add(_soft1);
list.Add(_soft2);
list.Add(_soft3);
list.Add(_soft4);
list.Add(_soft5);
list.Add(_soft6);
list = list.GroupBy(x => String.Format("{0}_{1}_{2}_{3}_{4}", x._s1, x._s2, x._s3, x._s4, x._s5),
(string key, IEnumerable<Soft> softs) => new Soft(softs.First()) { _s6 = String.Join(", ", softs.Select(z => z._s6)) }).ToList();
foreach(Soft s in list)
{
string key = String.Format("{0}_{1}_{2}_{3}_{4}", s._s1, s._s2, s._s3, s._s4, s._s5);
Console.WriteLine("{0} = {1}", key, s._s6);
}
Console.ReadLine();
}
}
} |
Partager