C# Tutorial
Different ways for giving value to the variable are,
System.Console class provides Read, ReadLine and ReadKey methods to read user inputs.
System.Console.ReadLine();
This C# program uses Console.ReadLine method to read the string value and assigns to string text variable.
/* This C# program for user input Also added single and multiline comments. */ using System; // System is a namespace public class InteractiveInput { // Main method which starts the program execution. public static void Main() { Console.Write("Enter text: "); string text = Console.ReadLine(); // Prints welcome text Console.WriteLine("Text : " + text); // Waits till any key press Console.ReadKey(); } }
Output:
C:> csc InteractiveInput.cs C:> InteractiveInput Enter text: Welcome to codingpointer.com to learn C# Text : Welcome to codingpointer.com to learn C#
This C# program reads multiple user inputs and prints the user inputs.
/* This C# program Using alias for System namespace classes Also added single and multiline comments. */ using System; // System is a namespace public class InteractiveInput { // Main method which starts the program execution. public static void Main() { Console.Write("Enter text1: "); string text1 = Console.ReadLine(); Console.Write("Enter text2: "); string text2 = Console.ReadLine(); // Prints text1 Console.WriteLine("Text1 : " + text1); // Prints text2 Console.WriteLine("Text2 : " + text2); // Waits till any key press Console.ReadKey(); } }
Output:
C:> csc InteractiveInput.cs C:> InteractiveInput Enter text1: welcome to codingpointer.com Enter text2: testing interactive input program Text1 : welcome to codingpointer.com Text2 : testing interactive input program
Privacy Policy | Copyright2020 - All Rights Reserved. | Contact us | Report website issues in Github | Facebook page | Google+ page