Delegate w/ Lambda
-
-
What is the C# equivalent to the following VB.NET code?
Delegate Sub SetStatus(ByVal Text As String)
Private Sub SetStatusStrip(ByVal Text As String)
Dim d As New SetStatus(Sub()
' Do some work.
End Sub)
Me.Invoke(d, New Object() {Text})
End SubThis seems homeworky but since you could just whip it through an autotranslater anyway, here you go:
delegate void SetStatus(string text);
private void SetStatusStrip(string text){
Invoke(text => {
// do some work
}, new object[] { text } );
}I think that's right. Invoke is a bit sniffy sometimes, you might need to cast the lambda, but I don't think so. Although it seems like the VB method you're generating for the delegate doesn't actually use a parameter so there's no reason you need to use that delegate for the inner method.
-
This seems homeworky but since you could just whip it through an autotranslater anyway, here you go:
delegate void SetStatus(string text);
private void SetStatusStrip(string text){
Invoke(text => {
// do some work
}, new object[] { text } );
}I think that's right. Invoke is a bit sniffy sometimes, you might need to cast the lambda, but I don't think so. Although it seems like the VB method you're generating for the delegate doesn't actually use a parameter so there's no reason you need to use that delegate for the inner method.
-
This seems homeworky but since you could just whip it through an autotranslater anyway, here you go:
delegate void SetStatus(string text);
private void SetStatusStrip(string text){
Invoke(text => {
// do some work
}, new object[] { text } );
}I think that's right. Invoke is a bit sniffy sometimes, you might need to cast the lambda, but I don't think so. Although it seems like the VB method you're generating for the delegate doesn't actually use a parameter so there's no reason you need to use that delegate for the inner method.
I assure you it's not homework. I've been programming (promoted from drafting) for about three years. I started in VB.Net and am now trying to convert to C#. That doesn't seem to work. How can I cast a lambda expression? Thanks for the auto translate idea. I ran the code through a couple and none seem to work. Thanks for your help.
-
What is the C# equivalent to the following VB.NET code?
Delegate Sub SetStatus(ByVal Text As String)
Private Sub SetStatusStrip(ByVal Text As String)
Dim d As New SetStatus(Sub()
' Do some work.
End Sub)
Me.Invoke(d, New Object() {Text})
End Subinternal delegate void SetStatus(string Text);
private void SetStatusStrip(string Text)
{
SetStatus d = new SetStatus(() => {
// Do some work.
});
this.Invoke(d, new object[] {Text});
}David Anton Convert between VB, C#, C++, & Java www.tangiblesoftwaresolutions.com Instant C# - VB to C# Converter Instant VB - C# to VB Converter
-
internal delegate void SetStatus(string Text);
private void SetStatusStrip(string Text)
{
SetStatus d = new SetStatus(() => {
// Do some work.
});
this.Invoke(d, new object[] {Text});
}David Anton Convert between VB, C#, C++, & Java www.tangiblesoftwaresolutions.com Instant C# - VB to C# Converter Instant VB - C# to VB Converter