Challenge - 5 Problems
String Comparison Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
β Predict Output
intermediate2:00remaining
What is the output of this string equality check?
Consider the following C# code snippet. What will be printed to the console?
C Sharp (C#)
string a = "Hello"; string b = "hello"; Console.WriteLine(a == b);
Attempts:
2 left
π‘ Hint
Remember that string equality with == is case-sensitive by default.
β Incorrect
The == operator compares strings with case sensitivity, so "Hello" and "hello" are not equal.
β Predict Output
intermediate2:00remaining
What does this code print when comparing strings ignoring case?
What will be the output of this C# code?
C Sharp (C#)
string a = "Test"; string b = "test"; bool result = string.Equals(a, b, StringComparison.OrdinalIgnoreCase); Console.WriteLine(result);
Attempts:
2 left
π‘ Hint
Check the StringComparison option used in string.Equals.
β Incorrect
Using StringComparison.OrdinalIgnoreCase makes the comparison ignore case differences, so the strings are equal.
β Predict Output
advanced2:00remaining
What is the output of this string reference comparison?
Analyze the following C# code and determine what it prints.
C Sharp (C#)
string s1 = "hello"; string s2 = new string(new char[] {'h','e','l','l','o'}); Console.WriteLine(object.ReferenceEquals(s1, s2));
Attempts:
2 left
π‘ Hint
ReferenceEquals checks if both variables point to the same object in memory.
β Incorrect
s1 and s2 have the same content but are different objects, so ReferenceEquals returns false.
β Predict Output
advanced2:00remaining
What does this code print when comparing strings with Compare method?
What will be the output of this C# code snippet?
C Sharp (C#)
string a = "apple"; string b = "banana"; int result = string.Compare(a, b, StringComparison.Ordinal); Console.WriteLine(result);
Attempts:
2 left
π‘ Hint
Compare returns a negative number if the first string is less than the second.
β Incorrect
"apple" comes before "banana" lexicographically, so Compare returns a negative number.
β Predict Output
expert2:00remaining
What is the output of this culture-sensitive string comparison?
Consider this C# code. What will it print?
C Sharp (C#)
using System.Globalization; System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("de-DE"); string s1 = "straΓe"; string s2 = "strasse"; bool result = string.Equals(s1, s2, StringComparison.CurrentCultureIgnoreCase); Console.WriteLine(result);
Attempts:
2 left
π‘ Hint
In German culture, "Γ" is considered equivalent to "ss" in comparisons.
β Incorrect
Using CurrentCultureIgnoreCase with German culture treats "straΓe" and "strasse" as equal ignoring case.