Lambda 表达式(C# 编程指南)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Dictionary<string, int> dict = new Dictionary<string, int>();
List<string> ListResult = new List<string>();
int num = 0;
string xx = string.Empty;
string[] str;
List<testobject> list = new List<testobject>();
list.Add(new testobject("testCoupon","121273"));
list.ForEach(
(t) =>
{
list.ForEach(
(t2) =>
{
if(t.pwid!=t2.pwid & t.num==t2.num)
{
string ListResultItems = string.Format("{0}#{1}#{2}", t.num, t.pwid, t2.pwid);
if (!ListResult.Contains(ListResultItems))
{
ListResult.Add(ListResultItems);
}
}
}
);
}
);
ListResult.ForEach(
(x) =>
{
num = x.IndexOf("#");
xx = x.Substring(num + 1, x.Length - num - 1);
if(dict.ContainsKey(xx))
{
dict[xx]+=1;
}
else
{
dict.Add(xx,1);
}
}
);
dict.ToLookup(
(t) =>
{
str= t.Key.Split(new char[]{'#'},StringSplitOptions.RemoveEmptyEntries);
Console.WriteLine(string.Format("{0}_{1}_{2}", str[0],str[1],t.Value));
return false;
}
);
Console.ReadLine();
}
}
public class testobject
{
public testobject(string num,string pwid)
{
this.pwid = pwid;
this.num = num;
}
public string pwid = string.Empty;
public string num = string.Empty;
}
public class testobb
{
public testobb(string pwid1, string pwid2, string num)
{
this.pwid1 = pwid1;
this.pwid2 = pwid2;
this.num = num;
}
public string pwid1 = string.Empty;
public string pwid2 = string.Empty;
public string num = string.Empty;
}
}