473,387 Members | 1,465 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,387 software developers and data experts.

probably a very simple question

I have two files:

public class Tester
{
public static void Main()
{
Program begin = new Program();
begin.StartCalculator();
}
}

AND

public class Program
{
public void StartCalculator()
{
System.Console.WriteLine("Hello world");
}
}

This works, but when I change the body of Main() to simply:

StartCalculator();

and make the StartCalculator() method static, I get:

The name 'StartCalculator' does not exist in the current context

What does that mean, and why must I call the method on an object for the
program to run?
Nov 17 '05 #1
3 934
Hi,

You just need to tell it what class contains the StartCalculator method.

....
public static void Main()
{
Program.StartCalculator();
}

With just StartCalculator(), the compiler was searching for the method in the
Tester class.

Best regards,

Rodger

Achieve Planner - Keep track of your projects/tasks and schedule them in the
calendar
<http://www.effexis.com/achieve/planner.htm>

Sequence Diagram Editor - Draw sequence diagrams faster
<http://www.SequenceDiagramEditor.com>

John Salerno wrote:
I have two files:

public class Tester
{
public static void Main()
{
Program begin = new Program();
begin.StartCalculator();
}
}

AND

public class Program
{
public void StartCalculator()
{
System.Console.WriteLine("Hello world");
}
}

This works, but when I change the body of Main() to simply:

StartCalculator();

and make the StartCalculator() method static, I get:

The name 'StartCalculator' does not exist in the current context

What does that mean, and why must I call the method on an object for the
program to run?

Nov 17 '05 #2
Rodger Constandse wrote:
Hi,

You just need to tell it what class contains the StartCalculator method.

...
public static void Main()
{
Program.StartCalculator();
}

With just StartCalculator(), the compiler was searching for the method in the
Tester class.

Best regards,

Rodger

Achieve Planner - Keep track of your projects/tasks and schedule them in the
calendar
<http://www.effexis.com/achieve/planner.htm>

Sequence Diagram Editor - Draw sequence diagrams faster
<http://www.SequenceDiagramEditor.com>

John Salerno wrote:
I have two files:

public class Tester
{
public static void Main()
{
Program begin = new Program();
begin.StartCalculator();
}
}

AND

public class Program
{
public void StartCalculator()
{
System.Console.WriteLine("Hello world");
}
}

This works, but when I change the body of Main() to simply:

StartCalculator();

and make the StartCalculator() method static, I get:

The name 'StartCalculator' does not exist in the current context

What does that mean, and why must I call the method on an object for the
program to run?


Ack, so simple! Thanks!

Is there a preferred way to do this? (static or instance?)
Nov 17 '05 #3
Hi,

It depends on what you are trying to accomplish.

There is nothing wrong with calling a static method from Main and letting it be
the one initializing your app.

Best regards,

Rodger

Achieve Planner - Keep track of your projects/tasks and schedule them in the
calendar
<http://www.effexis.com/achieve/planner.htm>

Sequence Diagram Editor - Draw sequence diagrams faster
<http://www.SequenceDiagramEditor.com>


Ack, so simple! Thanks!

Is there a preferred way to do this? (static or instance?)

Nov 17 '05 #4

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

Similar topics

0
by: Gene Ellis | last post by:
Very simple question. If I have the XML file below: <?xml version="1.0" encoding="ISO-8859-1"?> <?xml-stylesheet type="text/xsl" href="newspage.xsl"?> <newspage> <content>Click here for blah...
3
by: MatGyver | last post by:
I've gotten this far: When a field is left blank, I have a message box popping up that says "You must enter a name." This is the code that used: Private Sub Entered_By_Exit(Cancel As Integer)...
16
by: lovecreatesbeauty | last post by:
`Writing C code is very simple', one guy related to my work said. I'm not sure whether he is an expert or not. What he said about C programming like this can't convince me. I think there should be...
30
by: Brian Elmegaard | last post by:
Hi, I am struggling to understand how to really appreciate object orientation. I guess these are FAQ's but I have not been able to find the answers. Maybe my problem is that my style and...
3
by: Rangy | last post by:
Hi, I've decided to take the plunge and move from tables to a pure css layout. I still "think" in tables when I do my layouts and I was wondering the following: I have a simple, standard two...
2
by: dave | last post by:
Hi, I have searched for the answer for this error message without success. I have seen the question many times though:) I create an ASP.NET project (VS 2005, C#), and use a very simple .mdf...
1
by: Raycaster | last post by:
I'm 3/4 finished 2 simple VB apps for a upcoming silent auction being held at my children's school. Very Simple - This is what it does: 1st app allows input and builds a text database Unit...
4
by: maria | last post by:
I only use C++ with Visual Studio 6.0 for string manipulations in thousands of HTML pages on my website. Many times, the output files of many of my C++ programs contain a spanish question mark (¿)...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...

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.