Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Delegate w/ Lambda

Delegate w/ Lambda

Scheduled Pinned Locked Moved C#
csharpquestionlinqfunctional
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Herrwolf1
    wrote on last edited by
    #1

    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 Sub

    B D 2 Replies Last reply
    0
    • H Herrwolf1

      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 Sub

      B Offline
      B Offline
      BobJanova
      wrote on last edited by
      #2

      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.

      L H 2 Replies Last reply
      0
      • B BobJanova

        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.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Doesn't sound like homework to me; I don't know any schools that mix VB/C#, but I do know that managers "insist" on keeping their codebase in a single language :)

        Bastard Programmer from Hell :suss: if you can't read my code, try converting it here[^]

        1 Reply Last reply
        0
        • B BobJanova

          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.

          H Offline
          H Offline
          Herrwolf1
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • H Herrwolf1

            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 Sub

            D Offline
            D Offline
            Dave Doknjas
            wrote on last edited by
            #5

            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

            H 1 Reply Last reply
            0
            • D Dave Doknjas

              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

              H Offline
              H Offline
              Herrwolf1
              wrote on last edited by
              #6

              Thank you sir. The following is what I ended up using and it works great.

              SetStatus d = new SetStatus( (string myText) =>
              {
              // Do some work
              });
              this.Invoke(d, new object[] { _text });

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups