472,340 Members | 1,944 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,340 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 1668
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 >>>...
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...
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...
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() {...
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...
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...
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...
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....
3
by: Lakshmank85 | last post by:
Hi, i have a c++ class, class XYZ { public: void Function1 ( MyStruct * myStruct ); // member variables, etc }
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
0
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
by: Arjunsri | last post by:
I have a Redshift database that I need to use as an import data source. I have configured the DSN connection using the server, port, database, and...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...

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.