当前位置: 代码迷 >> 综合 >> C# 匿名方法
  详细解决方案

C# 匿名方法

热度:94   发布时间:2024-01-25 01:19:01.0

匿名方法(Anonymous methods) 提供了一种传递代码块作为委托参数的技术。匿名方法是没有名称只有主体的方法。

using System;namespace CSharpTest01
{class Program{delegate string CallBack(int n);static void Int2String(CallBack callback, int n){Console.WriteLine("start");string str = null;if (callback != null){str = callback(n);}Console.WriteLine("{0}\nend", str);}static void Main(string[] args){CallBack cb = delegate (int x){string str = x.ToString();return str;};Int2String(cb, 100);}}
}

 

  相关解决方案