0

Hey i've tried all the online code converters but none of them work on this. Can someone please explain to me how to transform this sniped it to vb.net?

yahoo.OnBuddyAddYouRequest += delegate(object sender, string buddy, string requestMessage, ref bool bAccept)
{
    object[] inVar = { sender, buddy, requestMessage,bAccept };
    this.Invoke(new OnBuddyAddYouRequestYahooEventHandler(OnBuddyAddYouRequest), inVar);
    bAccept = (bool)inVar[3];
};
2
  • While I know why you probably need it converted, I thought I would mention that all this effort is moot anyway since both code snippets evidently end up as MSIL :D Commented Jan 27, 2011 at 21:27
  • what does that mean? i'm confused Commented Jan 27, 2011 at 23:14

1 Answer 1

2

Change the inner code to a separate method:

private void buddyAddYouRequest(object sender, string buddy,
        string requestMessage, ref bool bAccept)
{
    object[] inVar = { sender, buddy, requestMessage, bAccept };
    this.Invoke(new OnBuddyAddYouRequestYahooEventHandler(OnBuddyAddYouRequest), inVar);
    bAccept = (bool)inVar[3];
}

and then change the line you quoted into this:

yahoo.OnBuddyAddYouRequest += buddyAddYouRequest;

Then you can run this through a code converter to convert it to VB.NET.

However, I should point out that the code makes no sense. It seems to invoke an existing method, OnBuddyAddYouRequest, but in an unnecessarily roundabout way. I realise that the author may be trying to overcome multi-threading issues; in that case, you can write it much more simply (and type-safe) like this:

private void buddyAddYouRequest(object sender, string buddy,
        string requestMessage, ref bool bAccept)
{
    bool bAcceptCopy = bAccept;
    this.Invoke(new Action(() => OnBuddyAddYouRequest(sender, buddy,
                                 requestMessage, ref bAcceptCopy)));
    bAccept = bAcceptCopy;
}

// ...

yahoo.OnBuddyAddYouRequest += buddyAddYouRequest;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.