Posted by: prankster March 2, 2011
IT -- Solutions Center[Forum]
Login in to Rate this Post:     0       ?        
 Teti ta afai garana bro,
tutorial is below: http://www.csharp-station.com/Tutorials/Lesson01.aspx

Interacting via the Command-Line

Besides command-line input, another way to provide input to a program is via the Console. Typically, it works like this: You prompt the user for some input, they type something in and press the Enter key, and you read their input and take some action. Listing 1-3 shows how to obtain interactive input from the user.

Listing 1-3. Getting Interactive Input: InteractiveWelcome.cs
// Namespace Declaration
using System;

// Program start class
class InteractiveWelcome
{
    // Main begins program execution.
    public static void Main()
    {
        // Write to console/get input
        Console.Write("What is your name?: ");
        Console.Write("Hello, {0}! ", Console.ReadLine());
        Console.WriteLine("Welcome to the C# Station Tutorial!"); 
    }
}

In Listing 1-3, the Main method doesn't have any parameters -- mostly because it isn't necessary this time. Notice also that I prefixed the Main method declaration with the public keyword. The publickeyword means that any class outside of this one can access that class member. For Main, it doesn't matter because your code would never call Main, but as you go through this tutorial, you'll see how you can create classes with members that must be public so they can be used. The default access is private, which means that only members inside of the same class can access it. Keywords such as public and private are referred to as access modifiers. Lesson 19 discusses access modifiers in more depth.

There are three statements inside of Main and the first two are different from the third. They are Console.Write(...) instead of Console.WriteLine(...). The difference is that the Console.Write(...)statement writes to the console and stops on the same line, but the Console.WriteLine(...) goes to the next line after writing to the console.

The first statement simply writes "What is your name?: " to the console.

The second statement doesn't write anything until its arguments are properly evaluated. The first argument after the formatted string is Console.ReadLine().  This causes the program to wait for user input at the console. After the user types input, their name in this case, they must press the Enter key. The return value from this method replaces the "{0}" parameter of the formatted string and is written to the console. This line could have also been written like this:

string name = Console.ReadLine(); 
Console.Write("Hello, {0}! ", name);

The last statement writes to the console as described earlier. Upon execution of the command-line with "InteractiveWelcome", the output will be as follows:

>What is your Name?  <type your name here> [Enter Key]
>Hello, <your name here>!  Welcome to the C# Station Tutorial!


 

Read Full Discussion Thread for this article