Are you new to C#? Cool, so am I. Usually when you are new to programming you want to see some code and test it, so this will allow you to do just that. If you have Visual Studio then simply cut and paste the code within Main to a new console project application.
The program below will do three things:
1. Greet the user and ask for name:
2. Take the user's name
3. Display a message using the user's name.
Very simple program that uses 2 output methods, one input method, and variable declartion. Read the comments if you have any questions about what the program is doing. I tried to comment heavy on this simple program.
Hope this was useful to beginners. I will post more later. Enjoy.Code:using System; namespace testProg { ///<summary> /// Test Programming ///</summary> class helloProg { [STAThread] static void Main(string[] args) { //Declare a String variable. Name it userName string userName; Console.Write("Console Asks - Please Enter your Name: "); //Place the user input into the variable userName with //Console.ReadLine() userName = Console.ReadLine(); //Skip a line for nicer formatting Console.WriteLine(""); //On the next line, display the input. //{0} is where the variable value will go. It //is followed by a comma and variable name userName Console.WriteLine("Hello {0}!", userName); Console.WriteLine("Press Enter to Continue"); //The Console.Readline will pause the program until you //press [ENTER]. Then it will exit. Console.ReadLine(); }//end main }//end class }//end namespace



LinkBack URL
About LinkBacks


