zoukankan      html  css  js  c++  java
  • 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;

        }


    }

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

  • 相关阅读:
    Dart语言学习笔记(5)
    使用 Dart 调用 REST API
    JSON数据的解析和生成(Dart)
    趣味编程:静夜思(Dart版)
    正则表达式(Dart)
    Dart语言学习笔记(4)
    Dart语言学习笔记(3)
    C++11特性之右值引用
    各大编程字体比较
    优先队列的应用 C++实现
  • 原文地址:https://www.cnblogs.com/liyonghui/p/2019843.html
Copyright © 2011-2022 走看看