473,473 Members | 2,145 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

So simple question for C# user ??

Dear all,

Until now I was programing for more that 6 years using VB.net simply because
I come from that word and used to. Now I need to switch to C# simply because
my customer want its project in that language. So now I am fighting with so
simple thing like raising a simple event as follow, and have a complie error,
with no damn idea what this compiler want.

The code is as follow

------>

namespace ConsoleApplication1
{
public delegate void dg_Startup();

class Program
{

public event dg_Startup StartupComplete;

static void Main(string[] args)
{
Console.WriteLine("Initiliastion");
Console.Write("completetd...");
StartupComplete;
Console.ReadLine;
}

}

}
<-------

The two last line of my main are highligtied with error saying :

Error 1 Only assignment, call, increment, decrement, and new object
expressions can be used as a statement D:\Users\Serge\Documents\Visual Studio
2005\Projects\WindowsService1\ConsoleApplication1\ Program.cs 18 10 ConsoleApplication1

Error 2 An object reference is required for the nonstatic field, method, or
property
'ConsoleApplication1.Program.StartupComplete' D:\Users\Serge\Documents\Visual
Studio
2005\Projects\WindowsService1\ConsoleApplication1\ Program.cs 18 10 ConsoleApplication1

Thnaksa for help
serge
Apr 30 '07 #1
4 4626
Calderara,
Try something like this:

class Program
{

static void Main(string[] args)

{

MyClass mc = new MyClass();

mc.StartupComplete += new MyClass.dg_Startup(mc_StartupComplete);

mc.Start();

}

static void mc_StartupComplete()

{

Console.WriteLine("Startup Complete");

}

}
....
....
....

public class MyClass
{

public delegate void dg_Startup();

public event dg_Startup StartupComplete;

public void Start()

{

if (StartupComplete != null)

StartupComplete();

}

}

....

--
Page Brooks
www.explosivedog.com
"calderara" <ca*******@discussions.microsoft.comwrote in message
news:D5**********************************@microsof t.com...
Dear all,

Until now I was programing for more that 6 years using VB.net simply
because
I come from that word and used to. Now I need to switch to C# simply
because
my customer want its project in that language. So now I am fighting with
so
simple thing like raising a simple event as follow, and have a complie
error,
with no damn idea what this compiler want.

The code is as follow

------>

namespace ConsoleApplication1
{
public delegate void dg_Startup();

class Program
{

public event dg_Startup StartupComplete;

static void Main(string[] args)
{
Console.WriteLine("Initiliastion");
Console.Write("completetd...");
StartupComplete;
Console.ReadLine;
}

}

}
<-------

The two last line of my main are highligtied with error saying :

Error 1 Only assignment, call, increment, decrement, and new object
expressions can be used as a statement D:\Users\Serge\Documents\Visual
Studio
2005\Projects\WindowsService1\ConsoleApplication1\ Program.cs 18 10
ConsoleApplication1

Error 2 An object reference is required for the nonstatic field, method,
or
property
'ConsoleApplication1.Program.StartupComplete'
D:\Users\Serge\Documents\Visual
Studio
2005\Projects\WindowsService1\ConsoleApplication1\ Program.cs 18 10
ConsoleApplication1

Thnaksa for help
serge

Apr 30 '07 #2
hi thanks for your reply...
Could you explain a bit...

What i understand here is that you need to create a new class to raise an
event that you have decared on an other one ?

I am just writeing a test console application on witch I have delcare a
delegate for that event then during the main function, which is in a way the
initliasation oart I just need to raise it at that time !!
Juts for this we need to creat an extra class ?

regards
serge

"Page Brooks" wrote:
Calderara,
Try something like this:

class Program
{

static void Main(string[] args)

{

MyClass mc = new MyClass();

mc.StartupComplete += new MyClass.dg_Startup(mc_StartupComplete);

mc.Start();

}

static void mc_StartupComplete()

{

Console.WriteLine("Startup Complete");

}

}
....
....
....

public class MyClass
{

public delegate void dg_Startup();

public event dg_Startup StartupComplete;

public void Start()

{

if (StartupComplete != null)

StartupComplete();

}

}

....

--
Page Brooks
www.explosivedog.com
"calderara" <ca*******@discussions.microsoft.comwrote in message
news:D5**********************************@microsof t.com...
Dear all,

Until now I was programing for more that 6 years using VB.net simply
because
I come from that word and used to. Now I need to switch to C# simply
because
my customer want its project in that language. So now I am fighting with
so
simple thing like raising a simple event as follow, and have a complie
error,
with no damn idea what this compiler want.

The code is as follow

------>

namespace ConsoleApplication1
{
public delegate void dg_Startup();

class Program
{

public event dg_Startup StartupComplete;

static void Main(string[] args)
{
Console.WriteLine("Initiliastion");
Console.Write("completetd...");
StartupComplete;
Console.ReadLine;
}

}

}
<-------

The two last line of my main are highligtied with error saying :

Error 1 Only assignment, call, increment, decrement, and new object
expressions can be used as a statement D:\Users\Serge\Documents\Visual
Studio
2005\Projects\WindowsService1\ConsoleApplication1\ Program.cs 18 10
ConsoleApplication1

Error 2 An object reference is required for the nonstatic field, method,
or
property
'ConsoleApplication1.Program.StartupComplete'
D:\Users\Serge\Documents\Visual
Studio
2005\Projects\WindowsService1\ConsoleApplication1\ Program.cs 18 10
ConsoleApplication1

Thnaksa for help
serge


Apr 30 '07 #3
IN fact I simply want to creat a class which raise an event.
Then from an other assembly I will register to that event and catch it.

So in my test, the smal console app should only raise the event for others
which are register to it..

???
serge

"Page Brooks" wrote:
Calderara,
Try something like this:

class Program
{

static void Main(string[] args)

{

MyClass mc = new MyClass();

mc.StartupComplete += new MyClass.dg_Startup(mc_StartupComplete);

mc.Start();

}

static void mc_StartupComplete()

{

Console.WriteLine("Startup Complete");

}

}
....
....
....

public class MyClass
{

public delegate void dg_Startup();

public event dg_Startup StartupComplete;

public void Start()

{

if (StartupComplete != null)

StartupComplete();

}

}

....

--
Page Brooks
www.explosivedog.com
"calderara" <ca*******@discussions.microsoft.comwrote in message
news:D5**********************************@microsof t.com...
Dear all,

Until now I was programing for more that 6 years using VB.net simply
because
I come from that word and used to. Now I need to switch to C# simply
because
my customer want its project in that language. So now I am fighting with
so
simple thing like raising a simple event as follow, and have a complie
error,
with no damn idea what this compiler want.

The code is as follow

------>

namespace ConsoleApplication1
{
public delegate void dg_Startup();

class Program
{

public event dg_Startup StartupComplete;

static void Main(string[] args)
{
Console.WriteLine("Initiliastion");
Console.Write("completetd...");
StartupComplete;
Console.ReadLine;
}

}

}
<-------

The two last line of my main are highligtied with error saying :

Error 1 Only assignment, call, increment, decrement, and new object
expressions can be used as a statement D:\Users\Serge\Documents\Visual
Studio
2005\Projects\WindowsService1\ConsoleApplication1\ Program.cs 18 10
ConsoleApplication1

Error 2 An object reference is required for the nonstatic field, method,
or
property
'ConsoleApplication1.Program.StartupComplete'
D:\Users\Serge\Documents\Visual
Studio
2005\Projects\WindowsService1\ConsoleApplication1\ Program.cs 18 10
ConsoleApplication1

Thnaksa for help
serge


Apr 30 '07 #4
calderara <ca*******@discussions.microsoft.comwrote:
Until now I was programing for more that 6 years using VB.net simply because
I come from that word and used to. Now I need to switch to C# simply because
my customer want its project in that language. So now I am fighting with so
simple thing like raising a simple event as follow, and have a complie error,
with no damn idea what this compiler want.
Brackets, that's all, and a using statement at the start -

using System;

....
StartupComplete();
Console.ReadLine();

After that, you've just got two more issues:
1) You're accessing StartupComplete from within a static method, but
it's an *instance* event (and therefore an instance field has been
created)

2) StartupComplete(); will throw a NullReferenceException if nothing
has subscribed to it.

--
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
Apr 30 '07 #5

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

Similar topics

3
by: Ryno Rijnsburger | last post by:
I am busy packaging our product as a standard Setup project in VS.NET that uses a bunch of merge modules (basically, a merge module for every key infrastructure component in our system). Part...
7
by: jmac | last post by:
Greetings fellow programmers, I have created a C program that has a few bugs and would like to get some help with working them out. Here is a list of the problems that I am experiencing: -...
2
by: Hazzard | last post by:
I just realized that the code I inherited is using all asp.net server controls (ie. webform controls) and when I try to update textboxes on the client side, I lose the new value of the textbox when...
5
by: Stephanie_Stowe | last post by:
Hi. I am trying to get used to AS.NET. I have been doing ASP classic for years, and am now in a position to do ASP.NET. I am in the stumbling around until I get my bearings phase. I hope you will...
10
by: serge calderara | last post by:
Dear all, I need to build a web application which will contains articles (long or short) I was wondering on what is the correct way to retrive those article on web page. In orther words, when...
10
by: Andrew | last post by:
Sorry about this but I'm new to ADO.NET (finally coming from simple ADO, bless it) and I'm trying to create a simple three tier program. Ie, User interface Layer / Business object layer / Database...
1
by: c_beginner | last post by:
yes, this is my how work question. Since I am lack in getting an assistance with my lab work I put this in this advance group. Sorry for the trouble I am making. Write a program to calculate the...
1
by: Bl00dFox | last post by:
Hi I am making a simple program to calculate interest. At the beginning when the user has to pick 1 or 2 (to select simple or compound interest respectively), if the user enters a letter (eg, a)...
4
by: RN1 | last post by:
An ASPX page, named LinkButton.aspx, has a single LinkButton & nothing else. The code is very simple: <form runat="server"> <asp:LinkButton ID="lnk" PostBackUrl="Page1.aspx" Text="CLICK"...
3
maxx233
by: maxx233 | last post by:
Hello, I'm developing a simple program to control a video switcher we have via RS232. All the backend control stuff is figured out just fine, the interface is what's giving me problems! I'm...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.