Q:

What is the difference between value types and reference types?

0

What is the difference between value types and reference types?

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Answer:

# Struct Class
1. They are stored on stack. They are stored on heap.
2. Memory is allocated at compile time. Memory is allocated at runtime.
3. The value type is popped on its own from the stack when they go out of scope. Required garbage collector to free memory.
4. Value type contains actual value. Reference type contains reference to a value.
5. Cannot contain null values. However, this can be achieved by nullable types. Can contain null values.
e.g. int, float, char, Bool, short. Class, Interface, String, Object, Delegate, Array.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Top 100 C# interview questions and answers 2022

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
How do you get the size of value type?... >>
<< What are reference types in C#?...