0
0
C Sharp (C#)programming~15 mins

Console.ReadLine for input in C Sharp (C#) - Mini Project: Build & Apply

Choose your learning style9 modes available
Using Console.ReadLine to Get User Input
📖 Scenario: You are creating a simple program that asks a user for their name and age. Then, it will greet the user and tell them their age next year.
🎯 Goal: Build a program that reads user input from the console using Console.ReadLine(), converts the age to a number, and prints a greeting message with the age next year.
📋 What You'll Learn
Use Console.ReadLine() to get user input
Store the user name in a variable called userName
Store the user age in a variable called userAge
Convert the age input from string to integer
Print a greeting message with the user name and age next year
💡 Why This Matters
🌍 Real World
Getting user input from the console is common in simple command-line tools and learning programs.
💼 Career
Understanding how to read input and convert data types is essential for building interactive applications and processing user data.
Progress0 / 4 steps
1
Create variables for user name and age input
Create two string variables called userName and userAge and set both to empty strings.
C Sharp (C#)
Need a hint?

Use string type and set variables to empty quotes "".

2
Read user input using Console.ReadLine()
Use Console.ReadLine() to read the user name into userName and the user age into userAge.
C Sharp (C#)
Need a hint?

Assign Console.ReadLine() to each variable to get input from the user.

3
Convert age input to integer
Create an integer variable called age and convert userAge to an integer using int.Parse(userAge).
C Sharp (C#)
Need a hint?

Use int.Parse() to convert the string to an integer.

4
Print greeting with age next year
Print a message using Console.WriteLine that says: "Hello, {userName}! Next year, you will be {age + 1} years old." Use string interpolation with $"...".
C Sharp (C#)
Need a hint?

Use Console.WriteLine with $"..." to insert variables inside the string.