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

How does a class function without creating it.

Hi Newbee here to C# I have a simple questions...

In a Hello world example how does the class object Hello exist with out
creating it? I come from object pascal where everything object is created
then used. In object pascal you can call a method a "class" and it means you
can call it by the name of the class and the function name with out creating
it like "Hello.Main()" is that true for key word "static"?

Also what if I have more than one class that has "Main"?
Can I tell the system what "Main" to use (not via comand line)?
class Hello
{
static void Main( )
{
// Use the system console object
System.Console.WriteLine("Hello World");
}
}

Davinci
Nov 16 '05 #1
6 1746
Davinci,

Yes, static is the same thing in this scenario.

As for the name of the Main method to use, the only option there is to
use the command line compiler, using the /main flag to indicate the type
that has the Main method on it to use as the entry point.

I believe that the option to set this in the IDE exists in VS.NET 2005
though.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
"Davinci_Jeremie" <Da*************@discussions.microsoft.com> wrote in
message news:4B**********************************@microsof t.com...
Hi Newbee here to C# I have a simple questions...

In a Hello world example how does the class object Hello exist with out
creating it? I come from object pascal where everything object is created
then used. In object pascal you can call a method a "class" and it means
you
can call it by the name of the class and the function name with out
creating
it like "Hello.Main()" is that true for key word "static"?

Also what if I have more than one class that has "Main"?
Can I tell the system what "Main" to use (not via comand line)?
class Hello
{
static void Main( )
{
// Use the system console object
System.Console.WriteLine("Hello World");
}
}

Davinci

Nov 16 '05 #2
Davinci_Jeremie <Da*************@discussions.microsoft.com> wrote:
Hi Newbee here to C# I have a simple questions...

In a Hello world example how does the class object Hello exist with out
creating it? I come from object pascal where everything object is created
then used. In object pascal you can call a method a "class" and it means you
can call it by the name of the class and the function name with out creating
it like "Hello.Main()" is that true for key word "static"?
"static" means "in the context of the type rather than any one specific
instance of the type". You can use static methods/properties/fields
without ever creating an instance.
Also what if I have more than one class that has "Main"?
Can I tell the system what "Main" to use (not via comand line)?


Yes - there's a property (Startup Object or something similar, IIRC) in
one of the build settings for the project.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #3
I'm not up on my Pascal, but I believe that the OP is confusing the
"class" keyword with the class itself.

You don't call a method a "class". You call it a "class method",
meaning that it is associated with the class as a whole rather than
with every instance of that class individually. The keyword "static" in
C# has the same meaning.

Nov 16 '05 #4
Davinci_Jeremie wrote:
Hi Newbee here to C# I have a simple questions...

In a Hello world example how does the class object Hello exist with out
creating it? I come from object pascal where everything object is created
then used. In object pascal you can call a method a "class" and it means you
can call it by the name of the class and the function name with out creating
it like "Hello.Main()" is that true for key word "static"?

Static methods work as you suspect. Main is a static method, which means
that the class defining it does not have to be instantiated before
calling the method. Main and it's overload gets special treating by the
compiler, which marks it as .entrypoint.
Also what if I have more than one class that has "Main"?
Can I tell the system what "Main" to use (not via comand line)?


You have to use the command line argument /main:<class-name> to specify
to csc.ece which of the classes Main method to call at application
startup. You can also specify the 'Startup Object' attribute on the
property page for your property in Visual Studio.

Regards,
Joakim
Nov 16 '05 #5
Nicholas Paldino [.NET/C# MVP] <mv*@spam.guard.caspershouse.com> wrote:
Yes, static is the same thing in this scenario.

As for the name of the Main method to use, the only option there is to
use the command line compiler, using the /main flag to indicate the type
that has the Main method on it to use as the entry point.


It's in VS.NET 2003, too - at least in C#.

The option is in project properties, General | Startup Object.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #6
Thank you that answered my questions.

Thanks to everyone that responed to my post.

Davinci
Nov 16 '05 #7

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

Similar topics

13
by: Emmanuel | last post by:
Hi, I run across this problem, and couldn't find any solution (python 2.2.2) : Code : =========== from __future__ import generators >>> class titi:
5
by: me | last post by:
I have a Class Library that contains a Form and several helper classes. A thread gets created that performs processing of data behind the scenes and the Form never gets displayed (it is for debug...
3
by: Pierre Rouleau | last post by:
The std::exception class defined in the Standard C++ <exception> header specifies that the constructors could throw any exception becuase they do not have a throw() specification. Why is that? ...
9
by: baumann | last post by:
hi all, to implement a singleton class, one has define a static function in the singleton class, class A{ public: static A* getInstance() { static A a; return &a;
5
by: kuvpatel | last post by:
Hi I want to refer a class called LogEvent, and use one of its methods called WriteMessage without actually having to create an instance of Logevent. I have tried using the word sealed with...
0
by: me | last post by:
I have a Class Library that contains a Form and several helper classes. A thread gets created that performs processing of data behind the scenes and the Form never gets displayed (it is for debug...
4
by: D | last post by:
I was reviewing these vb.net classes which deal with user logins, logouts, cookies etc etc. I noticed that in the Page_Load function of a user control the code calls into another library like so...
22
by: ypjofficial | last post by:
Is there any possibility of invoking the member functions of a class without creating an object (or even a pointer to ) of that class. eg. #include <iostream.h> class test { public: void...
3
by: Lakshmank85 | last post by:
Hi, i have a c++ class, class XYZ { public: void Function1 ( MyStruct * myStruct ); // member variables, etc }
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.