Lambda表达式问题 [英] Lambda Expression Problem

查看:106
本文介绍了Lambda表达式问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我很累,而且我确定我知道这个问题的答案,但是我现在无法想出它来获得它。


什么是VB.NET相当于以下C#代码?


/////////////

行动< FooClassmethod = x = x.FooSub(null);

/////////////


其中''FooSub'是一个子(不是函数)因此没有返回

所以:


////// ///////

Dim方法As Action(Of FooClass)= Function(x as BikeClass)

x.FooSub(Nothing)

/////////////


不工作。


谢谢,

Seth Rowe [MVP]
http:// sethrowe .blogspot.com /

解决方案

8月20日,1:52 * pm,rowe_newsgroups< rowe_em ... @ yahoo。 comwrote:


好​​的,我累了我确定我知道这个问题的答案,但我现在无法想出它来获得它。


什么是VB.NET相当于以下C#代码?


/////////////

* *动作< FooClassmethod = x = x.FooSub(null);

/////////////


其中''FooSub''是sub(不是函数)因此没有返回

所以:


/////////////

* * Dim方法As Action(Of FooClass)= Function(x as BikeClass)

x.FooSub(Nothing)

//// /////////


不工作。


谢谢,


Seth Rowe [MVP] http://sethrowe.blogspot.com/



小修正:


In第二个样本Function(x as BikeClass)应该是功能(x

As FooClass)。此代码用于VB.NET中的演示文稿,

示例代码代表一个虚构的自行车商店。


谢谢,


Seth Rowe [MVP]
http://sethrowe.blogspot.com/


Hi Seth,


不幸的是,VB目前还不支持多语句或无效返回

lambdas。但是,您可以将标准AddressOf与普通委托一起使用。


" rowe_newsgroups" < ro ******** @ yahoo.com写了留言

news:67 ********************** ************ @ a1g2000h sb.googlegroups.com ...


好​​的,我累了,我是确定我知道这个问题的答案,但我现在无法想象它是什么。


什么是VB.NET等价物以下C#代码?


/////////////

行动< FooClassmethod = x = x.FooSub(null ); $

/////////////


其中''FooSub'是子(不是函数)和所以没有返回

如此:


/////////////

Dim方法As Action(Of FooClass)= Function(x as BikeClass)

x.FooSub(Nothing)

/////////////


不工作。


谢谢,


Seth Rowe [MVP]
http://sethrowe.blogspot.com/


8月21日,1:44 * am,Bill McCarthy < B ... @ localhost.comwrote:


Hi Seth,


不幸的是VB目前还不支持多声明或无效返回

lambdas。 *但是,您可以将标准AddressOf与普通代表​​一起使用。


" rowe_newsgroups" < rowe_em ... @ yahoo.com写了留言


新闻:67 *********************** *********** @ a1g2000h sb.googlegroups.com ...


好​​的,我很累,我很确定我知道这个问题的答案,但我现在无法想出它。


什么是VB.NET等效于以下C#代码?


/////////////

*行动< FooClassmethod = x = x。 FooSub(null);

/////////////


Where''FooSub ''是一个子(不是函数)因此没有返回

所以:


// ///////////

* * Dim方法As Action(Of FooClass)= Function(x as BikeClass)

x.FooSub(Nothing)

/////////////


不行。


谢谢,


Seth Rowe [MVP]
http://sethrowe.blogspot.com/



感谢您的确认,这就是我所害怕的。

不幸的是,我不能做正常的事情。事情并使用代表,因为

这是第三方应用程序,不接受标准的

代表。


我最后刚刚将测试库转换为C#,严格的VB-only
我工作的
开发人员将不得不忍受:-)


谢谢,


Seth Rowe [MVP]
http://sethrowe.blogspot.com/


Ok, I''m tired and I''m sure I know the answer to this, but I can''t seem
to come up with it right now.

What is the VB.NET equivalent to the following C# code?

/////////////
Action<FooClassmethod = x =x.FooSub(null);
/////////////

Where ''FooSub'' is a sub (not a function) and therefore doesn''t return
anything so:

/////////////
Dim method As Action(Of FooClass) = Function(x as BikeClass)
x.FooSub(Nothing)
/////////////

Won''t work.

Thanks,

Seth Rowe [MVP]
http://sethrowe.blogspot.com/

解决方案

On Aug 20, 1:52*pm, rowe_newsgroups <rowe_em...@yahoo.comwrote:

Ok, I''m tired and I''m sure I know the answer to this, but I can''t seem
to come up with it right now.

What is the VB.NET equivalent to the following C# code?

/////////////
* *Action<FooClassmethod = x =x.FooSub(null);
/////////////

Where ''FooSub'' is a sub (not a function) and therefore doesn''t return
anything so:

/////////////
* * Dim method As Action(Of FooClass) = Function(x as BikeClass)
x.FooSub(Nothing)
/////////////

Won''t work.

Thanks,

Seth Rowe [MVP]http://sethrowe.blogspot.com/

Minor correction:

In the second sample "Function(x as BikeClass)" should be "Function(x
As FooClass)". This code is for a presentation in VB.NET and the
sample code represents a fictional bike shop.

Thanks,

Seth Rowe [MVP]
http://sethrowe.blogspot.com/


Hi Seth,

Unfortunately VB doesn''t currently support multi statement or void returning
lambdas. You can however use the standard AddressOf with a normal delegate.

"rowe_newsgroups" <ro********@yahoo.comwrote in message
news:67**********************************@a1g2000h sb.googlegroups.com...

Ok, I''m tired and I''m sure I know the answer to this, but I can''t seem
to come up with it right now.

What is the VB.NET equivalent to the following C# code?

/////////////
Action<FooClassmethod = x =x.FooSub(null);
/////////////

Where ''FooSub'' is a sub (not a function) and therefore doesn''t return
anything so:

/////////////
Dim method As Action(Of FooClass) = Function(x as BikeClass)
x.FooSub(Nothing)
/////////////

Won''t work.

Thanks,

Seth Rowe [MVP]
http://sethrowe.blogspot.com/


On Aug 21, 1:44*am, "Bill McCarthy" <B...@localhost.comwrote:

Hi Seth,

Unfortunately VB doesn''t currently support multi statement or void returning
lambdas. *You can however use the standard AddressOf with a normal delegate.

"rowe_newsgroups" <rowe_em...@yahoo.comwrote in message

news:67**********************************@a1g2000h sb.googlegroups.com...

Ok, I''m tired and I''m sure I know the answer to this, but I can''t seem
to come up with it right now.

What is the VB.NET equivalent to the following C# code?

/////////////
* Action<FooClassmethod = x =x.FooSub(null);
/////////////

Where ''FooSub'' is a sub (not a function) and therefore doesn''t return
anything so:

/////////////
* *Dim method As Action(Of FooClass) = Function(x as BikeClass)
x.FooSub(Nothing)
/////////////

Won''t work.

Thanks,

Seth Rowe [MVP]
http://sethrowe.blogspot.com/

Thanks for the confirmation, that was what I was afraid of.
Unfortunately, I can''t do the "normal" thing and use a delegate, as
this is for a 3rd party application that won''t accept a standard
delegate.

I finally just converted the test library to C#, the strict VB-only
developers I work with will just have to suffer through :-)

Thanks,

Seth Rowe [MVP]
http://sethrowe.blogspot.com/


这篇关于Lambda表达式问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆