© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
21 replies
jouri

❔ if you use a string command in an if command, can you make it case insensitive

so i'm really new to this, and decide to venture a bit away from the tutorial and I want to make it work.

So what I have currently is just a basic
Console.Write("Enter your name:");
                string name = Console.ReadLine();
Console.Write("Enter your name:");
                string name = Console.ReadLine();

etc.

but I'm stuck at a part where I did
Console.Write("Hello " + *name *+ " you are " + *age* + ". is this correct:");
                string *correct* = Console.ReadLine();

                if (*correct *== "YES")
                {
                    Console.WriteLine("Great :D");
                    Console.ReadLine();
                    return;
                }
                if (*correct *== "NO")
                {
                    Console.Write("Do you want to try again?");
Console.Write("Hello " + *name *+ " you are " + *age* + ". is this correct:");
                string *correct* = Console.ReadLine();

                if (*correct *== "YES")
                {
                    Console.WriteLine("Great :D");
                    Console.ReadLine();
                    return;
                }
                if (*correct *== "NO")
                {
                    Console.Write("Do you want to try again?");


The code works, but it's case and space sensitive, which makes it really annoying to answer the question. Is there a fix for this?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Binding case-insensitive query parameter to string enum in .NET 9 Minimal API
C#CC# / help
13mo ago
Can't use | operator in case?
C#CC# / help
2y ago
Check if a string contains a word in an array
C#CC# / help
4y ago
✅ use one string if a condition is true, else use another string
C#CC# / help
3y ago