c#隐藏函数 lambda表达式 泛型综合使用代码
来源:互联网 发布:淘宝展现关键词是什么 编辑:程序博客网 时间:2024/06/05 00:35
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NimingHanshu
{
class Program
{
delegate void TestDelegate(string s);
delegate int del(int i);
//TResult 是返回值,Targ0是参数值
delegate TResult Func<Targ0, TResult>(Targ0 arg0);
static void M(string s)
{
Console.WriteLine(s);
}
static void Main(string[] args)
{
//DelegateHistory();
//StartTread();
Console.ReadLine();
}
private static void DelegateHistory()
{
TestDelegate testDelA = new TestDelegate(M);
//C#2.0 匿名函数
TestDelegate testDelB = delegate(string s) { Console.WriteLine(s); };
//C#3.0 Lambda表达式
TestDelegate testDelC = (x) => { Console.WriteLine(x); };
testDelA("this is a deletegate");
testDelB("this is a anonymous method");
testDelC("this is a lambda expression");
}
//匿名方法的使用范例
//匿名方法不能使用 ref out 作为参数列表
private static void StartTread()
{
System.Threading.Thread t1 = new System.Threading.Thread
(
delegate()
{
Console.WriteLine("Hello ");
Console.WriteLine(" World");
}
);
t1.Start();
}
//Lambda表达式
//语法要求 ()=>expression
private static void Lambda()
{
del mydel = x => x * x;
Console.WriteLine(mydel(5));
Func<int, bool> myFunc = x => x == 5;
Console.WriteLine(myFunc);
}
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace NimingHanshu
{
class Program
{
delegate void TestDelegate(string s);
delegate int del(int i);
//TResult 是返回值,Targ0是参数值
delegate TResult Func<Targ0, TResult>(Targ0 arg0);
static void M(string s)
{
Console.WriteLine(s);
}
static void Main(string[] args)
{
//DelegateHistory();
//StartTread();
Console.ReadLine();
}
private static void DelegateHistory()
{
TestDelegate testDelA = new TestDelegate(M);
//C#2.0 匿名函数
TestDelegate testDelB = delegate(string s) { Console.WriteLine(s); };
//C#3.0 Lambda表达式
TestDelegate testDelC = (x) => { Console.WriteLine(x); };
testDelA("this is a deletegate");
testDelB("this is a anonymous method");
testDelC("this is a lambda expression");
}
//匿名方法的使用范例
//匿名方法不能使用 ref out 作为参数列表
private static void StartTread()
{
System.Threading.Thread t1 = new System.Threading.Thread
(
delegate()
{
Console.WriteLine("Hello ");
Console.WriteLine(" World");
}
);
t1.Start();
}
//Lambda表达式
//语法要求 ()=>expression
private static void Lambda()
{
del mydel = x => x * x;
Console.WriteLine(mydel(5));
Func<int, bool> myFunc = x => x == 5;
Console.WriteLine(myFunc);
}
}
}
阅读全文
0 0
- c#隐藏函数 lambda表达式 泛型综合使用代码
- C#委托、事件、泛型委托、Lambda表达式各个详解与综合使用(1)
- C# 委托 事件 匿名函数 Lambda表达式
- C#编程指南 匿名函数 lambda表达式
- 【怎样写代码】函数式编程 -- Lambda表达式(二):C#常用委托
- C# 集合类之lambda表达式使用
- 函数式编程--使用lambda表达式
- C#函数式程序设计之函数、委托和Lambda表达式
- c#3.0新特性使用lambda表达式创建表达式树
- C# Lambda 表达式
- C# Lambda 表达式
- C#的Lambda表达式
- C# Lambda 表达式
- C# Lambda 表达式
- C#3.0 lambda表达式
- C# Lambda表达式
- C# Lambda表达式
- C# Lambda表达式
- 01爬虫概述
- AS(二) Android Studio连接真机
- MySQL-1.外键约束
- 16-JavaScript设计模式——责任链模式
- JavaOSC协议使用教程-以及遇到的坑(UTF-16BE中文乱码)
- c#隐藏函数 lambda表达式 泛型综合使用代码
- 推荐系统评价:NDCG方法概述
- linux安装ssh服务
- 编译libcurl+zlib+openssl
- Oracle Session Cursor
- linux的mount(挂载)命令详解
- 算法作业_35(2017.6.16第十七周)(算法机考模拟题3)
- kafka 工具类
- 面试题28:不能被继承的类