Public Property anonymousDelegate As [Delegate]
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
anonymousDelegate = Function(x)
TextBox1.Text = x : Return "Hello"
End Function
TextBox3.Text = anonymousDelegate.DynamicInvoke(TextBox2.Text)
End Sub
解决方案 »
- c# datatime.now当前日期,怎样初始化时间为06:30
- 请诸位帮帮忙!!!ids = Session["username"].ToString();未将对象引用设置到对象的实例。
- C/S 系统如何被动获知数据库数据被修改?
- 工厂模式中:
- 请教关于SOCKET双向通信的问题
- 求提供<<Developing C# Windows Software>>书的源码?
- 为什么我的MSDN不能够被F1唤出来啊?怎么解决?
- 哪位仁兄有Wrox出版的关于C#中进程还有正则表达式的书的电子版﹖
- 公有变量如何在C#中定义和属性如何使用,请各位指教,在线等待......
- 如何在程序中把一个控件放在其他控件的前面?
- 字体报警 出了点错误!
- 问一些关于EntityFramework的基本操作,请有相关经验的朋友帮忙
public delegate string ReturnValue(string strvalue);string sReturn(string strvalue)
{
return strvalue;
}protected void Button1_Click(object sender, EventArgs e)
{
ReturnValue re = sReturn;
string a = re("hello");
}
Button3.Click+=Button3_Click;
Private void Button3_Click(object sender,System.EventArgs e)
{
anonymousDelegate=delegate(string x){TextBox1.Text = x;return "Hello"};
TextBox3.Text = anonymousDelegate.Invoke(TextBox2.Text);
}
public delegate Property anonymousDelegate;
this.button3.Click += new System.EventHandler(this.button3_Click);
这句话
public Delegate anonymousDelegate { get; set; } private void button3_Click(object sender, EventArgs e)
{
this.anonymousDelegate = new Func<String, String>((x) =>
{
this.textBox1.Text = x;
return "Hello";
});
this.textBox3.Text = (string)this.anonymousDelegate.DynamicInvoke(textBox2.Text); }
textbox1.text=textbox2.text
textbox3.text=“Hello"
不就可以了么?
TextBox1.Text = x
End Sub
Public Property anonymousDelegate As [Delegate]
anonymousDelegate = Sub(x)
TextBox1.Text = x
End Sub
变成了:
public Delegate anonymousDelegate { get; set; } anonymousDelegate = x => { TextBox1.Text = x; };可是代码不好用!
vb.net可以直接把匿名方法赋值给委托,c#不行,要new一个匿名委托,将匿名方法作为参数 anonymousDelegate = new Action<String>((x) =>
{
this.textBox1.Text = x;
});
public Delegate anonymousDelegate { get; set; }
anonymousDelegate = x => { TextBox1.Text = x; };
private void button3_Click(object sender, EventArgs e)
{
anonymousDelegate = x =>
{
textBox1.Text = x;
return "Hello";
};
textBox3.Text = anonymousDelegate(textBox2.Text);
}
Public Property anonymousDelegate As [Delegate]
public Func<string, string> anonymousDelegate { get; set; }他的委托类型是Delegate,你改成Func<string, string>,这样不行的吧,这个属性可是公开的,而且还可能是Action<String>类型的。