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

Object type as universal base in C Sharp (C#) - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is the object type in C#?
The object type is the universal base type in C#. Every type, whether value or reference, directly or indirectly inherits from object.
Click to reveal answer
beginner
Can a variable of type object hold any data type in C#?
Yes, a variable of type object can hold any data type because all types derive from object. This allows storing any value or reference type in an object variable.
Click to reveal answer
intermediate
What happens when you assign a value type to an object variable?
The value type is 'boxed' — it is wrapped inside an object on the heap so it can be treated as a reference type.
Click to reveal answer
intermediate
How do you get the original value back from an object variable holding a value type?
You perform 'unboxing' by casting the object back to the original value type.
Click to reveal answer
beginner
Why is object useful as a universal base type?
Because it allows writing flexible code that can work with any data type, enabling polymorphism and generic programming.
Click to reveal answer
Which type is the universal base type for all types in C#?
Adynamic
Bint
Cstring
Dobject
What is boxing in C#?
AConverting a reference type to a value type
BWrapping a value type inside an object
CCasting an object to a string
DConverting a string to an int
How do you retrieve the original value type from an object variable?
ABy calling ToString()
BBy boxing
CBy unboxing (casting)
DBy using var keyword
Can an object variable hold a string value?
AYes, because string is a reference type derived from object
BOnly if explicitly cast
CNo, only value types
DNo, string is a separate type
Why might you use object as a variable type?
ATo allow storing any type of data
BTo restrict the variable to integers only
CTo improve performance
DTo avoid casting
Explain how the object type acts as a universal base type in C# and what happens when you assign a value type to an object variable.
Think about how value types are wrapped when assigned to object.
You got /3 concepts.
    Describe the difference between boxing and unboxing in C# with examples.
    Boxing and unboxing are about converting between value types and object.
    You got /3 concepts.