C#: Accept a string from keyboard and print it
Write a program in C# Sharp to input a string and print it.
Sample Solution:-
C# Sharp Code:
using System;
// Define the Exercise1 class
public class Exercise1
{
// Main method - entry point of the program
public static void Main()
{
string str; // Declare a variable to store the input string
// Prompt the user to enter a string
Console.Write("\n\nAccept a string from the keyboard:\n");
Console.Write("-----------------------------------\n");
// Request user input for a string
Console.Write("Input the string: ");
str = Console.ReadLine(); // Read the user input
// Display the entered string back to the user
Console.Write("The string you entered is: {0}\n", str);
}
}
Sample Output:
Accept a string from keyboard : ----------------------------------- Input the string : w3resource is very easy tutorial. The string you entered is : w3resource is very easy tutorial.
Flowchart:
C# Sharp Code Editor:
Contribute your code and comments through Disqus.
Previous: C# Sharp String Exercise.
Next: Write a program in C# Sharp to find the length of a string without using library function.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics