C# value and reference types, nullable types, strings, control flow, methods, arrays and the .NET type system.
39 cards · basic cards · AI-written, checked twice. Edit anything.
- What is a value type in C#?
Show answer
A type whose instances are stored directly on the stack and contain their actual data.
- Where are value types stored in memory?
Show answer
On the stack.
- What is boxing in C#?
Show answer
Converting a value type to an object reference type, allocating it on the heap.
- What is unboxing in C#?
Show answer
Extracting a value type from a boxed object, converting it back to its value form.
- What does struct keyword declare?
Show answer
A value type that can contain methods, properties, and fields.
- What is the main difference between struct and class?
Show answer
Struct is a value type (stack), class is a reference type (heap).
- Name three built-in value types in C#.
Show answer
int, double, bool (or byte, decimal, char, long, etc.)
- Do value type fields have default values?
Show answer
Yes, all fields are initialized to their default value (0, false, etc.) automatically.
- What is a reference type in C#?
Show answer
A type whose instances store a reference to data on the heap, not the data itself.
- Where are reference types stored in memory?
Show answer
On the heap, with a reference stored on the stack.
- What does class keyword declare?
Show answer
A reference type that can contain methods, properties, fields, and other members.
- What is the difference between passing by value and by reference?
Show answer
By value: a copy is passed; by reference: the original variable is passed and changes reflect outside.
- What does the new keyword do?
Show answer
Allocates memory on the heap and calls a constructor for a reference type.
- What is null in C#?
Show answer
A special value indicating a reference type variable does not point to any object.
- What is the syntax for a nullable type?
Show answer
Type followed by a question mark, e.g. int?, double?, string?