CSharp · Console
using System;
using System.Collections.Generic;
using System.Linq;
public class Program
{
public static void Main()
{
List<LogData> logList = new List<LogData>();
logList.Add(new LogData("1,2,4", "Ver1", "pro", "etc"));
logList.Add(new LogData("1", "Ver2", "pro", "etc"));
logList.Add(new LogData("2", "Ver1", "pro", "etc"));
logList.Add(new LogData("1,2,4", "Ver1", "pro", "etc"));
logList.Add(new LogData("1,5", "Ver2", "pro", "set"));
var result = logList.SelectMany(x => x.IndexPattern.Split(',').Select(z => new { Index = z, Version = x.Version, Type1 = x.Type1, Type2 = x.Type2 }))
.GroupBy(x => new { x.Index, x.Version, x.Type1, x.Type2 })
.Select(x => new
{
Index = x.Key.Index,
Version = x.Key.Version,
Type1 = x.Key.Type1,
Type2 = x.Key.Type2,
Count = x.Count()
});
foreach (var item in result)
{
Console.WriteLine("Index: {0}",item.Index);
Console.WriteLine("Version: {0}",item.Version);
Console.WriteLine("Type1: {0}",item.Type1);
Console.WriteLine("Type2: {0}",item.Type2);
Console.WriteLine("Count: {0}",item.Count);
Console.WriteLine();
}
}
class LogData
{
public LogData(string ip, string v, string t1, string t2)
{
IndexPattern = ip;
Version = v;
Type1 = t1;
Type2 = t2;
}
public string IndexPattern { get; set; }
public string Version { get; set; }
public string Type1 { get; set; }
public string Type2 { get; set; }
//here has a constructor of this class
}
}