473,396 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Anonymous Method syntax issue

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
fi****@sd-il.com
Jan 26 '06 #1
3 1229
Joel Finkel <Jo********@discussions.microsoft.com> wrote:
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; };
}

}

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 26 '06 #2
> 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
fi****@sd-il.com


I can't get the event to fire though.
Jan 26 '06 #3
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.

"chris martin" wrote:
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
fi****@sd-il.com


I can't get the event to fire though.

Jan 26 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: Doug Holton | last post by:
Is there any metaclass trick or something similar to allow anonymous code blocks? I'd like to be able to let users do something like this fictitious example: b = Button() b.OnClick =: print...
0
by: Carlos Ribeiro | last post by:
I thought about this problem over the weekend, after long hours of hacking some metaclasses to allow me to express some real case data structures as Python classes. I think that this is something...
31
by: Chris S. | last post by:
Is there a purpose for using trailing and leading double underscores for built-in method names? My impression was that underscores are supposed to imply some sort of pseudo-privatization, but would...
76
by: Nick Coghlan | last post by:
GvR has commented that he want to get rid of the lambda keyword for Python 3.0. Getting rid of lambda seems like a worthy goal, but I'd prefer to see it dropped in favour of a different syntax,...
0
by: Cordell Lawrence | last post by:
Okay guys, We are wondering if this is a bug in Framework 2.0.40607 and looking for some clarification on the issue. Take a look at the folowing code. public delegate bool BoundryTest(int...
2
by: Marcos Stefanakopolus | last post by:
In C# is there any way to use the concept of delegates to have multiple implementations of a particular block of code, so that you can choose between them without the overhead of possibly expensive...
3
by: anonymous | last post by:
I believe I ran into an interesting way to create memory leaks in C# 2.0 using anymous delegates. Here is a sample of the code in question. private void Handle_Event(object sender, EventArgs e)...
7
by: moondaddy | last post by:
I'm reading the book Wrox-Professional C# 2005 and it's trying to demonstrate an anonymous method in an event handler. I would not do this in a real app, but am trying to understand how this...
4
by: Frankie | last post by:
I have just gotten up to speed on what anonymous methods are (syntax, capabilities, etc), and how they can be used with /called via delegates. What I am wondering is... 1. Are they only/mostly...
0
by: Peter Duniho | last post by:
On Mon, 01 Sep 2008 16:14:10 -0700, Blip <blip@krumpli.comwrote: Briefly, an anonymous method is exactly that: a method without a name. When you use the "delegate" keyword to declare an...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.