new to sql server

I am relatively new to c#. My experience so far has been with console apps. I have recently learned that the user input from the keyboard for a console app is of the datatype string. I am trying to figure out the significance of the word string in the following code. I am guessing that it is due to the fact that the keyboard input is a string datatype. I am also guessing that this is telling the compiler the type that will be passed is string.

static void Main(string[] args)

Can anyone confirm or correct me on this.....................................................thanks



Re: Visual C# Language static void Main(string[] args).........question

Manju Sandhu

Hi,

If this exe is run from command prompt then All parameter seperated by space are passed as arguments to Main method

Let your exe name is test.ext

C:\> test.exe My Parameters Are This

then args contain

args[0] = My

args[1]=Parameters

args[2]=Are

args[3]=This

It is considered that all parameters passed to main is type of string only.

Yes your reson is right.

Regards,

Manju Sandhu





Re: Visual C# Language static void Main(string[] args).........question

:)Eric Han

there are many kinds of Main

static void Main() // no arguments

static void Main(string [] args)

static int Main()
{
return 0;
}



also you can write more than two main methods in one project.
but you must set only one entrypoint to let the complier know which one is the right entrypoint.





Re: Visual C# Language static void Main(string[] args).........question

Navaneeth

Hi,

new to sql server wrote:

the keyboard for a console app is of the datatype string


Not only for console app, for all values from keyboard will be string. Then we can cast it to any datatype of our choice. Main method can be overloaded. But it can be parametrless or it has to accept string array.

new to sql server wrote:

I am also guessing that this is telling the compiler the type that will be passed is string.


YES





Re: Visual C# Language static void Main(string[] args).........question

Florian Reischl

Hi

It is also possible to use the arguments at any other location outside the main without remember the arguments in a own variable:

Code Block

static void Main(string[] args)

{

Console.WriteLine("Main");

foreach (string arg in args)

{

Console.WriteLine(arg);

}

OtherLocation();

}

static void OtherLocation()

{

Console.WriteLine("Other Location:");

// ATTENTION: The first argument is your application location

foreach (string arg in System.Environment.GetCommandLineArgs())

{

Console.WriteLine(arg);

}

}

Regards

Flo