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

String comparison and equality in C Sharp (C#) - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to check if two strings are equal using the == operator.

C Sharp (C#)
string a = "hello";
string b = "hello";
bool areEqual = a [1] b;
Drag options to blanks, or click blank then click option'
A==
B!=
C=
DEquals
Attempts:
3 left
💡 Hint
Common Mistakes
Using = instead of == causes assignment, not comparison.
Using != checks for inequality, not equality.
2fill in blank
medium

Complete the code to compare two strings ignoring case using String.Equals method.

C Sharp (C#)
string a = "Hello";
string b = "hello";
bool areEqual = String.Equals(a, b, [1]);
Drag options to blanks, or click blank then click option'
AStringComparison.CurrentCultureIgnoreCase
BStringComparison.Ordinal
CStringComparison.CurrentCulture
DStringComparison.OrdinalIgnoreCase
Attempts:
3 left
💡 Hint
Common Mistakes
Using Ordinal instead of OrdinalIgnoreCase causes case-sensitive comparison.
Using CurrentCulture may depend on system culture settings.
3fill in blank
hard

Fix the error in the code to correctly compare two strings for equality using the Equals method.

C Sharp (C#)
string a = "test";
string b = "test";
bool areEqual = a.Equals([1]);
Drag options to blanks, or click blank then click option'
Ab
B"b"
Ca
DEquals
Attempts:
3 left
💡 Hint
Common Mistakes
Passing a string literal "b" instead of variable b.
Calling Equals without any argument causes error.
4fill in blank
hard

Fill both blanks to create a dictionary that maps strings to their lengths, but only include strings with length greater than 3.

C Sharp (C#)
var words = new List<string> { "apple", "bat", "carrot", "dog" };
var lengths = words.ToDictionary(word => word, word => word.[1]);
var filtered = lengths.Where(kv => kv.Value [2] 3).ToDictionary(kv => kv.Key, kv => kv.Value);
Drag options to blanks, or click blank then click option'
ALength
B<
C>
DCount
Attempts:
3 left
💡 Hint
Common Mistakes
Using Count instead of Length for string length.
Using < 3 instead of > 3 for filtering.
5fill in blank
hard

Fill all three blanks to create a dictionary with uppercase keys and values only for strings that start with 'a'.

C Sharp (C#)
var words = new List<string> { "apple", "banana", "apricot", "cherry" };
var result = words.Where(word => word.[1]("a")).ToDictionary(word => word.[2](), word => word.[3]());
Drag options to blanks, or click blank then click option'
AStartsWith
BToUpper
DContains
Attempts:
3 left
💡 Hint
Common Mistakes
Using Contains instead of StartsWith for filtering.
Not converting keys or values to uppercase.