-
What is boxing and unboxing in C#? Answer: Boxing is the process of converting a value type (e.g., int, float) to a reference type (e.g., object) so that it can be stored on the heap. Unboxing is the process of converting a reference type (e.g., object) back to a value type. It involves extracting the value from the boxed object.
-
What is Managed or Unmanaged Code? Managed code in C# runs within a managed environment like the Common Language Runtime (CLR), providing automatic memory management and security features. Unmanaged code, however, operates outside of such environments, directly interacting with system resources and requiring manual memory management.
-
What is the difference between a struct and a class in C#? Class and struct are both user-defined data types but have some major differences: Struct The struct is a value type in C# and inherits from System.Value Type. Struct is usually used for smaller amounts of data. Struct can’t be inherited from other types. A structure can't be abstract.