帮忙通译几句含有Lambda表达式的语句
帮忙翻译几句含有Lambda表达式的语句!
Lambda表达式的部分看不懂,谁能帮我翻译成常规写法……
万分感谢!
------解决方案--------------------
------解决方案--------------------
这个没什么翻译的,Lambda表达式相当于一个方法。()是参数,后面是函数体。仅此而已。
------解决方案--------------------
Dispatcher x = Dispatcher.CurrentDispatcher;
System.Threading.ThreadStart start = delegate()
{
Func<string> fu = new Func<string>(() => { return ""; });//工作函数
var 工作结果 = fu();
//异步更新界面
x.BeginInvoke(new Action(() =>{/*在界面线程操作 可以使用 工作结果*/}), DispatcherPriority.Normal);
};
new System.Threading.Thread(start).Start(); //启动线程
大致可以写
这里,不是什么“lamda表达式”的问题。c#可以在“匿名委托”直接引用外部的变量,也就是你贴出的代码中的“工作结果”变量。能够看到这个,才能了解那段代码的知识点。如果你只是看到了一个“lamda表达式”,那么还只是“标题党”,没有看到实质。
------解决方案--------------------
嗯,变量x也是委托外部的变量。
上面的再改一下:
Dispatcher x = Dispatcher.CurrentDispatcher;
System.Threading.ThreadStart start = delegate()
{
Func<string> fu = new Func<string>(() => { return ""; });//工作函数
var 工作结果 = fu();
//异步更新界面
x.BeginInvoke(new Action(() =>{/*在界面线程操作 可以使用 工作结果*/}), DispatcherPriority.Normal);
};
new System.Threading.Thread(start).Start(); //启动线程
Lambda表达式的部分看不懂,谁能帮我翻译成常规写法……
万分感谢!
------解决方案--------------------
Dispatcher x = Dispatcher.CurrentDispatcher;
System.Threading.ThreadStart start = delegate()
{
Func<string> fu = new Func<string>(delegate(){ return ""; });//工作函数
var 工作结果 = fu();
//异步更新界面
x.BeginInvoke(new Action(delegate(){/*在界面线程操作 可以使用 工作结果*/}), DispatcherPriority.Normal);
};
new System.Threading.Thread(start).Start(); //启动线程
------解决方案--------------------
这个没什么翻译的,Lambda表达式相当于一个方法。()是参数,后面是函数体。仅此而已。
------解决方案--------------------
Dispatcher x = Dispatcher.CurrentDispatcher;
System.Threading.ThreadStart start = delegate()
{
Func<string> fu = new Func<string>(() => { return ""; });//工作函数
var 工作结果 = fu();
//异步更新界面
x.BeginInvoke(new Action(() =>{/*在界面线程操作 可以使用 工作结果*/}), DispatcherPriority.Normal);
};
new System.Threading.Thread(start).Start(); //启动线程
大致可以写
void p1()
{
var obj = new MyInternalClass();
obj.工作结果 = fu();
Dispatcher x = Dispatcher.CurrentDispatcher;
x.BeginInvoke(new Action(obj.p2), DispatcherPriority.Normal);
}
string fu()
{
return "";
}
public class MyInernalClass
{
public string 工作结果;
void p2()
{
=>{/*在界面线程操作 可以使用 工作结果*/
}
}
这里,不是什么“lamda表达式”的问题。c#可以在“匿名委托”直接引用外部的变量,也就是你贴出的代码中的“工作结果”变量。能够看到这个,才能了解那段代码的知识点。如果你只是看到了一个“lamda表达式”,那么还只是“标题党”,没有看到实质。
------解决方案--------------------
嗯,变量x也是委托外部的变量。
上面的再改一下:
public class MyClass
{
Dispacher x;
void p1()
{
var obj = new MyInternalClass();
obj.工作结果 = fu();
x.BeginInvoke(new Action(obj.p2), DispatcherPriority.Normal);
}
string fu()
{
return "";
}
public class MyInernalClass
{
public string 工作结果;
void p2()
{
/*在界面线程操作 可以使用 工作结果*/
}
}
}
void test()
{
var obj = new MyClass();
obj.x = Dispatcher.CurrentDispatcher;
System.Threading.ThreadStart start = obj.p1;
new System.Threading.Thread(start).Start();