你能将如下C#代码转成VB.NET吗?
private void button1_Click(object sender, EventArgs e){
//int i = 1;
SetTimeout(3000, delegate { MessageBox .Show("SetTimeout 3000."); });
}
public static void SetTimeout(double interval, Action<System.Timers.ElapsedEventArgs> action)
{
System.Timers.Timer timer = new System.Timers.Timer(interval);
timer.Elapsed += delegate(object sender, System.Timers.ElapsedEventArgs e)
{
timer.Enabled = false;
action(e);
};
timer.Enabled = true;
}
public static void SetInterval(double interval, Action<System.Timers.ElapsedEventArgs> action)
{
System.Timers.Timer timer = new System.Timers.Timer(interval);
timer.Elapsed += delegate(object sender, System.Timers.ElapsedEventArgs e)
{
action(e);
};
timer.Enabled = true;
}
==================================
主要是在调用的时候:SetTimeout(3000, delegate { MessageBox .Show("SetTimeout 3000."); });
-----
在vb.net里面SetTimeout的delegate 如何实现直接转入? --------------------编程问答-------------------- C# to VB.net
Private Sub button1_Click(sender As Object, e As EventArgs)--------------------编程问答-------------------- --------------------编程问答--------------------
'int i = 1;
SetTimeout(3000, Function() Do
MessageBox.Show("SetTimeout 3000.")
End Function)
End Sub
Public Shared Sub SetTimeout(interval As Double, action As Action(Of System.Timers.ElapsedEventArgs))
Dim timer As New System.Timers.Timer(interval)
AddHandler timer.Elapsed, Function(sender As Object, e As System.Timers.ElapsedEventArgs) Do
timer.Enabled = False
action(e)
End Function
timer.Enabled = True
End Sub
Public Shared Sub SetInterval(interval As Double, action As Action(Of System.Timers.ElapsedEventArgs))
Dim timer As New System.Timers.Timer(interval)
timer.Elapsed += Function(sender As Object, e As System.Timers.ElapsedEventArgs) Do
action(e)
End Function
timer.Enabled = True
End Sub
--------------------编程问答-------------------- Reflector.net 写C# 的反编译成 VB 的即可; --------------------编程问答-------------------- 以上都是用使用Reflector.net 反编译成 VB 的吧,我也试过这样转,可是这些代码是有“语法错误”的。 --------------------编程问答-------------------- http://www.developerfusion.com/tools/convert/csharp-to-vb/ --------------------编程问答-------------------- 里面用到匿名委托,在vb.net下是不支持的
Private Sub button1_Click(ByVal sender As Object, ByVal e As EventArgs)
Form1.SetTimeout(3000, Function
MessageBox.Show("SetTimeout 3000.")
End Function)
End Sub
Public Shared Sub SetInterval(ByVal interval As Double, ByVal action As Action(Of ElapsedEventArgs))
Dim timer As New Timer(interval)
AddHandler timer.Elapsed, Function (ByVal sender As Object, ByVal e As ElapsedEventArgs)
action.Invoke(e)
End Function
timer.Enabled = True
End Sub
Public Shared Sub SetTimeout(ByVal interval As Double, ByVal action As Action(Of ElapsedEventArgs))
Dim timer As New Timer(interval)
AddHandler timer.Elapsed, Function (ByVal sender As Object, ByVal e As ElapsedEventArgs)
timer.Enabled = False
action.Invoke(e)
End Function
timer.Enabled = True
End Sub
补充:.NET技术 , VB.NET