Lambda 表达式 - 参数未知?
我已经声明了这个类:
public class SimpleArea<T> where T: Control
{
private T control;
public SimpleArea(T control)
{
this.control = control;
}
}
在我的主程序上,我想做这样的事情:
var SimpleAreaPanel = SimpleArea<Panel>(p => { p.Height= 150; })
问题是他无法定义“p”的类型,智能感知显示“参数???p”
我该如何完成这个指令?
I've this class declared:
public class SimpleArea<T> where T: Control
{
private T control;
public SimpleArea(T control)
{
this.control = control;
}
}
And on my Main Program, i want to do something like this:
var SimpleAreaPanel = SimpleArea<Panel>(p => { p.Height= 150; })
The problem is that he can't define the type of "p" the intellisense shows "Parameter ???p"
How can i accomplish this instruction?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的构造函数不接受 lambda - 它接受一个
T
实例,因此是一个Panel
。要么给它一个Panel
,或者编写一个可以采用该表达式的构造函数 - 可能是一个Action
。就我个人而言,我怀疑你的意思很简单:
这是一个对象初始值设定项,而不是 lambda - 即
Your constructor doesn't take a lambda - it takes a
T
instance, so aPanel
. Either give it aPanel
, or write a constucor that can take that expression - maybe anAction<T>
.Personally, I suspect you mean simply:
which is an object initializer, not a lambda - i.e.
如果我理解正确的话,你根本不需要使用 lambda 。
If I understand correctly, you don't need to use lambda at all.
MB你需要这样的东西:
所以你可以写:
但我不知道为什么......
Mb you need something like this:
So you can write:
But I don't know what for...