C# - Part 5 - Getting User's Input Using Console - Tutorial For Beginners
In this video we have discussed below topics: Time Stamps 00:00 Intro 00:29 Demo Console.ReadLine() method 07:44 Console.Write() method 09:04 Console.ReadKey() method 10:46 Comment/Uncomment code in Visual Studio 11:37 C# is case-sensitive WriteLine() Purpose: Displays a line of text to the console window and then adds a new line character (like pressing the Enter key). This means anything you write afterward will appear on the next line. Example: If you use WriteLine("Hello World!"), the console will display "Hello World!" and then move the cursor down to start a new line. Write() Purpose: Displays text to the console window but does not add a new line character. Anything you write after it will continue on the same line. Example: If you use Write("Hello "), and then follow it up with Write("World!"), the console will display "Hello World!" all on a single line. ReadKey() Purpose: Pauses the program and waits for the user to press a single key on the keyboard. It captures that keypress but doesn't display it on the console. Example: Often used when you want a user to confirm something with a keypress before the program continues (e.g., "Press any key to continue...") ReadLine() Purpose: Reads a line of text input from the user (everything they type until they press Enter). The program then captures this entire line of text as a string. Example: Used to get information from the user like their name, address, or other text-based input. In Visual Studio, you have two main ways to comment and uncomment code: Using keyboard shortcuts: Comment: Use Ctrl + K, then Ctrl + C. This adds the comment symbol (//) to the beginning of each selected line, effectively commenting it out. Uncomment: Use Ctrl + K, then Ctrl + U. This removes the comment symbols from the beginning of each selected line, effectively uncommenting it. Bonus Tip: You can also use the mouse to right-click on the selected lines and choose Comment Lines or Uncomment Lines from the context menu. C# is case-sensitive - This means that the uppercase and lowercase letters are considered distinct. As a result, the following are all treated differently: Variable names: age and Age are considered different variables. Keywords: if, else, and for are all keywords and must be written in lowercase. Using If, Else, or For will result in errors. Method names: PrintMessage and printmessage are considered different methods. Being case-sensitive helps to avoid confusion and improves code readability by making it clear when different identifiers are intended. However, it also means you need to be consistent with the capitalization you use throughout your code.
Download
0 formatsNo download links available.