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("Hell o World");
}
}
Davinci 6 1769
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.co m
"Davinci_Jeremi e" <Da************ *@discussions.m icrosoft.com> wrote in
message news:4B******** *************** ***********@mic rosoft.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("Hell o World"); } }
Davinci
Davinci_Jeremie <Da************ *@discussions.m icrosoft.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.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
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.
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
Nicholas Paldino [.NET/C# MVP] <mv*@spam.guard .caspershouse.c om> 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.co m> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Thank you that answered my questions.
Thanks to everyone that responed to my post.
Davinci This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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:
|
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 puposes only and is not
normally visable to the user.) The Thread function is actually in the Form
class.
Now.. What I am seeing is that when I create an instance of this Class
Library's Form, which starts the worker thread, it seems to hose up...
|
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? Is this because there could be an exception thrown when
the code creates a std::exception? I would assume that is not the case.
However, if I want to create a new exception class, derived from
std::exception (say MyException) then how can I...
|
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;
|
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 the class and this works but I would
also like to know of other ways to do this.
Also are there any performance implacations of using sealed?
| |
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 puposes only and is not
normally visable to the user.) The Thread function is actually in the Form
class.
Now.. What I am seeing is that when I create an instance of this Class
Library's Form, which starts the worker thread, it seems to hose up...
|
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
Call AnotherClassLibrary.AnotherClass.UserLogin(userId)
I do not understand how this code can call this function without first
creating an instance of the AnotherClass.
|
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 fun()
{
|
by: Lakshmank85 |
last post by:
Hi,
i have a c++ class,
class XYZ
{
public:
void Function1 ( MyStruct * myStruct );
// member variables, etc
}
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |