文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>Lambda 表达式(C# 编程指南)

Lambda 表达式(C# 编程指南)

时间:2011-04-18  来源:liyonghui

 什么也不说,直接上代码!!

 

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;

    }


}

http://msdn.microsoft.com/zh-cn/library/bb397687.aspx

 

相关阅读 更多 +
排行榜 更多 +
找茬脑洞的世界安卓版

找茬脑洞的世界安卓版

休闲益智 下载
滑板英雄跑酷2手游

滑板英雄跑酷2手游

休闲益智 下载
披萨对对看下载

披萨对对看下载

休闲益智 下载