Anonymous Method syntax issue

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Folks,

Sorry to take up bandwidth, but for the life of me I cannot see the syntax
error in this code:

Timer myTimer = new Timer();
myTimer.Tick += delegate {
stopWaiting = true;
};

The compiler error indicates that the parser is exepcting a "}" at the "."
in the second line. This is the first error in the source file.

By the way, the same error is thrown if I use either of these two variations:

myTimer.Tick += delegate() {
stopWaiting = true;
};

myTimer.Tick += delegate(object sender, EventArgs e) {
stopWaiting = true;
};

Thanks in advance for your assistance.

/Joel Finkel
(e-mail address removed)
 
Joel Finkel said:
Sorry to take up bandwidth, but for the life of me I cannot see the syntax
error in this code:

Timer myTimer = new Timer();
myTimer.Tick += delegate {
stopWaiting = true;
};

The compiler error indicates that the parser is exepcting a "}" at the "."
in the second line. This is the first error in the source file.

Are you absolutely sure you're using the C# 2.0 compiler? This code
compiles fine on my box with 2.0, but gives the same kind of error
you're talking about if I try to compile it with 1.1...

using System;
using System.Windows.Forms;

public class Test
{
static Timer myTimer;

static bool stopWaiting;

static void Main()
{
myTimer = new Timer();

myTimer.Tick += delegate(object sender, EventArgs e)
{
stopWaiting = true;
};

myTimer.Tick += delegate { stopWaiting = true; };
}

}
 
Folks,
Sorry to take up bandwidth, but for the life of me I cannot see the
syntax error in this code:

Timer myTimer = new Timer();
myTimer.Tick += delegate {
stopWaiting = true;
};

Compiles over here.
The compiler error indicates that the parser is exepcting a "}" at the
"." in the second line. This is the first error in the source file.

By the way, the same error is thrown if I use either of these two
variations:

myTimer.Tick += delegate() {
stopWaiting = true;
};

Won't compile.
myTimer.Tick += delegate(object sender, EventArgs e) {
stopWaiting = true;
};
Thanks in advance for your assistance.

Compiles fine.
/Joel Finkel
(e-mail address removed)

I can't get the event to fire though
 
I have not a clue what the problem is. I brought the code into an existing
project and it compiles fine. Somehow, there must have been some crud in the
editor.

Hmmm...I guess that means I DO have a clue what the problem is; but I'm not
going to pursue it further.

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top