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

String comparison and equality in C Sharp (C#) - Mini Project: Build & Apply

Choose your learning style9 modes available
String comparison and equality
📖 Scenario: Imagine you are creating a simple program that checks if a user's input matches a secret password. This is a common task in many applications like login screens or secret codes.
🎯 Goal: You will build a program that stores a secret password, takes a user input as a string, compares the input with the secret password using string equality, and then prints whether the input matches or not.
📋 What You'll Learn
Create a string variable called secretPassword with the exact value "OpenSesame".
Create a string variable called userInput with the exact value "opensesame".
Use a boolean variable called isMatch to store the result of comparing userInput and secretPassword using string.Equals with case sensitivity.
Print "Passwords match!" if isMatch is true, otherwise print "Passwords do not match.".
💡 Why This Matters
🌍 Real World
Checking if a user input matches a stored password or code is a common task in login systems, games, and secure applications.
💼 Career
Understanding string comparison is essential for software developers working on authentication, data validation, and user input handling.
Progress0 / 4 steps
1
Create the secret password and user input strings
Create a string variable called secretPassword and set it to "OpenSesame". Then create a string variable called userInput and set it to "opensesame".
C Sharp (C#)
Need a hint?

Use string type and assign the exact text values with double quotes.

2
Add a boolean variable to compare the strings
Create a boolean variable called isMatch and set it to the result of string.Equals(userInput, secretPassword) to compare the two strings with case sensitivity.
C Sharp (C#)
Need a hint?

Use string.Equals method to compare strings exactly.

3
Use an if statement to print the comparison result
Write an if statement that checks if isMatch is true. If yes, print "Passwords match!". Otherwise, print "Passwords do not match.".
C Sharp (C#)
Need a hint?

Use if and else blocks with System.Console.WriteLine to print messages.

4
Run the program to see the output
Run the program and observe the output printed on the screen.
C Sharp (C#)
Need a hint?

The output should say Passwords do not match. because the cases are different.