Recall & Review
beginner
What is the purpose of getting type information at runtime in C#?
It helps you find out what kind of object you have while the program is running. This is useful when you don't know the type in advance and want to make decisions based on the object's type.
Click to reveal answer
beginner
Which C# keyword or method returns the runtime type of an object?
The
GetType() method returns the exact type of an object at runtime.Click to reveal answer
intermediate
How do you compare the runtime type of an object to a known type in C#?
Use
obj.GetType() == typeof(SomeType) to check if the object's runtime type matches SomeType.Click to reveal answer
intermediate
What is the difference between
GetType() and typeof() in C#?GetType() is called on an object instance to get its runtime type. typeof() is used with a type name to get the Type object representing that type at compile time.Click to reveal answer
beginner
How can you get the name of an object's type at runtime?
Call
obj.GetType().Name to get the simple name of the object's type as a string.Click to reveal answer
Which method do you use to get the runtime type of an object in C#?
✗ Incorrect
GetType() is called on an object instance to get its runtime type.What does
typeof(int) return in C#?✗ Incorrect
typeof(int) returns the Type object representing the int type at compile time.How do you check if an object is exactly of type string at runtime?
✗ Incorrect
Use
obj.GetType() == typeof(string) to check exact type equality.Which property gives you the simple name of a type in C#?
✗ Incorrect
Type.Name returns the simple name of the type as a string.If you want to get the full namespace and name of a type, which property do you use?
✗ Incorrect
Type.FullName returns the full namespace and type name.Explain how to get and compare the runtime type of an object in C#.
Think about how you find out an object's type and then check if it matches a known type.
You got /4 concepts.
Describe the difference between GetType() and typeof() in C#.
One works on objects, the other works on type names.
You got /4 concepts.