如何在lambda表达式中将一个成员的值赋给另一个成员 [英] How do I assign value of one member to another in lambda expression

查看:479
本文介绍了如何在lambda表达式中将一个成员的值赋给另一个成员的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



无法为lamda表达式中的ReportNew类成员分配值。



我有使用lambda表达式的示例代码,但这不起作用:



var a =来自DataCollection中的dataRow d

选择新的ReportNew

{

a = d.value,

b = a * 2,

c = b * 3
};



这是错误的,a& b不在目前的情况下。但我想要b&的价值观c根据以前的成员变量动态计算。



能帮忙吗?



问候,



我尝试过:



var a =来自dataRow d在DataCollection中

选择新的ReportNew

{

a = d.value,

b = a * 2,

c = b * 3

};

Hello,

Not able to assign value to members of ReportNew class in the lamda expression.

I have sample code using lambda expression but this is not working :

var a = from dataRow d in DataCollection
select new ReportNew
{
a = d.value,
b = a*2,
c = b*3
};

This is giving error, a & b not in current context. But i want the values of b & c to be calculated dynamically based on the previous members variables.

Can you please help?

Regards,

What I have tried:

var a = from dataRow d in DataCollection
select new ReportNew
{
a = d.value,
b = a*2,
c = b*3
};

推荐答案

首先,什么是b和c?您 不能 为任何事物赋值,直到它在您使用它的范围内声明为止。



To start with, what are b and c? You cannot assign a value to anything until it has been declared within the scope of where you are using it.

Eg:  int b, c;





在哪里申报?这取决于。



如果b& c要存在于表达式之外,那么你必须考虑使用指向它们的指针作为c / c ++ / c#正常传递值。更改函数/表达式内部将不会粘贴



Where to declare them? That depends.

If b & c are to exist outside of the expression then you must consider using pointer to them as c/c++/c# normally pass values. Changing a inside the function/expression will not 'stick'


这篇关于如何在lambda表达式中将一个成员的值赋给另一个成员的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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