前辈们简单的和小弟说下“=>”的用法吧!感谢啦
解决方案 »
- 在Form2显示Form1的WebBrowser的网页源代码,不行啊。
- C#操作Word文档(Office 2007)
- TcpClien 和 TcpListener 怎么与别人交互
- 向高手请教后台代码写进前台页面出现的无法拿到变量的问题
- 我的问题很难熬!谁能弄出来?发扬精神啊!嘿嘿!
- 从Sql 2000向Sql 2005的转变问题
- VS 2010 URL 参数传递
- “System.DateTime”表示“类”,它在给定的上下文中无效
- xtrareport报表里如何知道最后一页table的高度
- 方法传递参数的问题!
- sql2005连接字符串问题
- 读取数据到listView,然后怎么再添加一列“状态”并对它赋值
Demo里有句这个
int verbType = module.GetModuleInfo.Verbs.Where(v => v.Name.Equals(verb)).FirstOrDefault().Type;能稍微解释下伐?谢谢啦
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace DelegatesSample
{
class Program
{
static void Main(string[] args)
{
//Predicate , Func , Action 泛型委托
List<string> l = new List<string>();
l.Add("a");
l.Add("b");
l.Add("s");
l.Add("t"); if (l.Exists(s => s.Equals("s")))
{
string str = l.First(s => s.Equals("s"));
Console.WriteLine(str);
//输出 : s
}
else
Console.WriteLine("Not found"); Func<string, bool> p = s => s.Equals("s");
if (l.Exists(p.ToPredicate()))
{
string str = l.First(p);
Console.WriteLine(str);
//输出 : s
}
else
Console.WriteLine("Not found"); string ss = l.First(s =>
{
if (s.Equals("s"))
{
return true;
}
return false;
});
Console.WriteLine(ss);
//输出 : s List<Entity> entities = new List<Entity>();
entities.Add(new Entity() { Name = "Name1" });
entities.Add(new Entity() { Name = "Name2" });
entities.Add(new Entity() { Name = "Name3" });
entities.Add(new Entity() { Name = "Name4" }); entities.ForEach(item =>
{
Console.WriteLine(item.Name);
//输出 : Name1
//输出 : Name2
//输出 : Name3
//输出 : Name4
}); Queryable(() =>
{
Console.WriteLine(0);
//输出 : 0
}); Queryable((a) =>
{
Console.WriteLine(a);
//输出 : 1
}, 1); Queryable((a, b) =>
{
Console.WriteLine(a + b);
//输出 : 3
}, 1, 2); Queryable((a, b, c) =>
{
Console.WriteLine(a + b + c);
//输出 : 6
}, 1, 2, 3); Queryable((a, b, c, d) =>
{
Console.WriteLine(a + b + c + d);
//输出 : 10
}, 1, 2, 3, 4); Console.Read();
} static void Queryable(Action action)
{
action.Invoke();
}
static void Queryable<T>(Action<T> action, T arg1)
{
action.Invoke(arg1);
}
static void Queryable<T1, T2>(Action<T1, T2> action, T1 arg1, T2 arg2)
{
action.Invoke(arg1, arg2);
}
static void Queryable<T1, T2, T3>(Action<T1, T2, T3> action, T1 arg1, T2 arg2, T3 arg3)
{
action.Invoke(arg1, arg2, arg3);
}
static void Queryable<T1, T2, T3, T4>(Action<T1, T2, T3, T4> action, T1 arg1, T2 arg2, T3 arg3, T4 arg4)
{
action.Invoke(arg1, arg2, arg3, arg4);
}
} public class Entity
{
public string Name { get; set; }
}
public static class Extensions
{
public static Predicate<T> ToPredicate<T>(this Func<T, bool> source)
{
Predicate<T> result = new Predicate<T>(source);
return result;
}
}}
这个是linq的
主要用于匿名对象和委托.