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

Getting type information at runtime 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 get the type of the variable number.

C Sharp (C#)
int number = 5;
Type typeInfo = number.[1];
Drag options to blanks, or click blank then click option'
AGetType()
Btypeof()
CGetType
DTypeOf
Attempts:
3 left
💡 Hint
Common Mistakes
Using typeof() on an instance instead of a type.
Forgetting the parentheses after GetType.
2fill in blank
medium

Complete the code to print the name of the type of text.

C Sharp (C#)
string text = "hello";
Console.WriteLine(text.[1].Name);
Drag options to blanks, or click blank then click option'
AGetType
Btypeof()
CGetType()
DTypeName()
Attempts:
3 left
💡 Hint
Common Mistakes
Using GetType without parentheses.
Trying to use typeof() on a variable instead of a type.
3fill in blank
hard

Fix the error in the code to get the type of obj and print its full name.

C Sharp (C#)
object obj = 10;
Type t = [1];
Console.WriteLine(t.FullName);
Drag options to blanks, or click blank then click option'
Aobj.GetType()
BGetType(obj)
Ctypeof(obj)
Dobj.Type()
Attempts:
3 left
💡 Hint
Common Mistakes
Using typeof with a variable instead of a type.
Trying to call a non-existent method Type().
4fill in blank
hard

Fill both blanks to create a dictionary with words as keys and their lengths as values, but only include words longer than 3 characters.

C Sharp (C#)
var words = new List<string> { "cat", "house", "tree", "a" };
var lengths = words.ToDictionary(word => word, word => word.[1])
    .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 < instead of > in the filter.
Using Count instead of Length for string length.
5fill in blank
hard

Fill all three blanks to create a dictionary with uppercase keys and values only for entries where the value is greater than 10.

C Sharp (C#)
var data = new Dictionary<string, int> { {"a", 5}, {"b", 15}, {"c", 20} };
var result = data.Where(kv => kv.Value [1] 10)
    .ToDictionary(kv => kv.Key.[2](), kv => kv.[3]);
Drag options to blanks, or click blank then click option'
A<
B>
CValue
DToUpper
Attempts:
3 left
💡 Hint
Common Mistakes
Using < instead of > in the filter.
Using Key instead of Value for dictionary values.