C#의뢰기초8―lambda표현식

4639 단어 C#위임
C# 위탁 기초 시리즈는 2011년 2월에 저의 시나닷컴 블로그에 발표되었는데, 지금은 본 블로그와 같습니다.

  
  
  
  
  1. class Program  
  2. {  
  3.         double AddInt(int x, int y)  
  4.         {  
  5.             return x + y;  
  6.         }  
  7.  
  8.         string AddString(string s1, string s2)  
  9.         {  
  10.             return s1 + s2;  
  11.         }  
  12.  
  13.         static void Main(string[] args)  
  14.         {  
  15.             Program p = new Program();             
  16.  
  17.             //  int, double, AddInt  
  18.             Func<intintdouble> funcInt = p.AddInt;  
  19.             Console.WriteLine("funcInt {0}", funcInt(100, 300));  
  20.  
  21.             Func<stringstringstring> funcString = p.AddString;  
  22.             Console.WriteLine("funcString {0}", funcString("xy""xy"));  
  23.  
  24.  
  25.             //   
  26.             Func<floatfloatfloat> fucFloat = delegate(float x, float y)  
  27.             {  
  28.                 return x + y;  
  29.             };  
  30.             Console.WriteLine("funcFloat {0}", fucFloat(190.7F, 99999.9F));  
  31.  
  32.             // Lambda  
  33.             Func<stringstringstring> funString2 = (x, y) => (x + y);  
  34.             Console.WriteLine("funString2 {0}", funString2("xy""xy"));  
  35.             Console.ReadLine();  
  36.         }  

좋은 웹페이지 즐겨찾기