0

I have come across some syntax I've never seen before; can someone explain the syntax of line 2 in the following code, specifically the =] bits?

//decide what to do with the response we get back from the bridge
client.UploadStringCompleted += (o, args) =] Dispatcher.BeginInvoke(() =]
{
    try
    {
        ResponseTextBox.Text = args.Result;
    }
    catch (Exception ex)
    {
        ResponseTextBox.Text = ex.Message;
    }
});

Unfortunately, web searches don't seem to parse =], which is frustrating my attempts to find an explanation!

TylerH
  • 20,799
  • 66
  • 75
  • 101
danabnormal
  • 462
  • 2
  • 8

1 Answers1

10

A cursory search for the text in the comment in the given code listing leads to this Channel 9 article. There are two occurrences of this statement, one of which presents the same lambda expressions with the correct syntax =>:

//decide what to do with the response we get back from the bridge
client.UploadStringCompleted += (o, args) => Dispatcher.BeginInvoke(() =>
{
    try
    {
        ResponseTextBox.Text = args.Result;
    }
    catch (Exception ex)
    {
        ResponseTextBox.Text = ex.Message;
    }

});

It becomes abundantly clear, therefore, that what you're looking at is a typo on part of the author of said article.

AFAIK, there is no legal C# construct that consists of the characters =], in that order, even accounting for whitespace. In your particular example it's most definitely a syntax error.

BoltClock
  • 700,868
  • 160
  • 1,392
  • 1,356
  • Thank you very much. No wonder I was confused! – danabnormal Oct 09 '15 at 14:13
  • 2
    @BoltClock: Should this not be closed as offtopic/typo then? I ask because you seem to be a mod and would have expected you to do that rather than put in an answer... – Chris Oct 09 '15 at 14:13
  • 4
    @Chris: I was wondering the same thing tbh. The difference here is that the typo comes from an external source outside of the author's control; it is not a mistake made by the author in composing their question. – BoltClock Oct 09 '15 at 14:14
  • @BoltClock: so is the current close reason incorrect? – Tim Schmelter Oct 09 '15 at 14:17
  • @Tim Schmelter: IMO, yes. I generally only apply this close reason to questions stemming from a mistake made by the asker (and even then, only if it's unlikely to help future readers, as stated in the description). But that's just my opinion and my own interpretation of the close reason. – BoltClock Oct 09 '15 at 14:18
  • @Grant Winney: The latter. – BoltClock Oct 09 '15 at 14:22
  • 2
    Also, feel free to take this to meta; I'd like to see what the community at large thinks of this. – BoltClock Oct 09 '15 at 14:24
  • Despite the discussion this has caused I've marked the above as an accepted answer on the off chance this helps someone else. Thanks all. – danabnormal Oct 09 '15 at 14:24
  • 2
    I'm not fussed enough to take this to Meta (especially given it is closed now so I don't think any more needs to be done). My personal view on the off topic/typo is that if the root cause is a typo then the question is kind of meaningless. So in this case asking "what does =] mean in c#" is a meaningless question since that syntax doesn't exist in c#. And there are plenty of questions probably asking what does => mean already so once the typo is recognised I don't feel it adds much. That having been said I am certainly happy with it having an accepted answer while it is here. :) – Chris Oct 09 '15 at 14:34
  • 2
    @Chris: Agreed - in retrospect, it would have been trivial to find out if this really was legal syntax simply by trying to run it. – BoltClock Oct 09 '15 at 14:37