C#: Interacting with command-line
October 24, 2007 – 5:27 pmThe command-line interaction is a basic element of c#, it allows a program to accept input from a user. Typically, it works
like this: prompt user for input, they enter information, and program takes action.
// Declare Namespace
using System;// Start "Program" Class
class InteractiveWelcome
{
// begins program execution.
public static void Main()
{
// Write to console and ready to receive input
Console.Write("What is your favorite site?: ");
Console.Write("Your favorite site is, {0}! ", Console.ReadLine());
Console.WriteLine("Welcome to C#, stay tuned on Splitzer.net!");
}
}
Result/Explaination:
The first line writes the “What is your favorite site?”, which is written using Console.Write() , the second line doesnt actually
get any input, but it evoluates from the first line. Third line, just basiclly writes the output from line two and three.If you havent noticed, “//”, two forward slash refers to commenting out the line.
Therefore, the output is:
>What is your favorite site? <type your fav site> [Enter Key]
>Hello, <your fav site>! Welcome to C#, stay tuned on Splitzer.net!
Tags: c#, command-line