📝 What is Boxing and Unboxing?
Boxing and Unboxing both are used for type conversion but have some difference:
🔸 Boxing is the process of converting a value type data type to the object or to any interface data type which is implemented by this value type. When the CLR boxes a value means when CLR is converting a value type to Object Type, it wraps the value inside a System.Object and stores it on the heap area in application domain.
🔸 Unboxing is also a process which is used to extract the value type from the object or any implemented interface type. Boxing may be done implicitly, but unboxing have to be explicit by code.
The concept of boxing and unboxing underlines the C# unified view of the type system in which a value of any type can be treated as an object.
#post
Boxing and Unboxing both are used for type conversion but have some difference:
🔸 Boxing is the process of converting a value type data type to the object or to any interface data type which is implemented by this value type. When the CLR boxes a value means when CLR is converting a value type to Object Type, it wraps the value inside a System.Object and stores it on the heap area in application domain.
🔸 Unboxing is also a process which is used to extract the value type from the object or any implemented interface type. Boxing may be done implicitly, but unboxing have to be explicit by code.
The concept of boxing and unboxing underlines the C# unified view of the type system in which a value of any type can be treated as an object.
#post
📝 What is the difference between string and StringBuilder?
🔸 It's an immutable object that hold string value.
🔸 Performance wise string is slow because its' create a new instance to override or change the previous value.
🔸 String belongs to System namespace.
🔸 StringBuilder is a mutable object.
🔸 Performance wise StringBuilder is very fast because it will use same instance of StringBuilder object to perform any operation like insert value in existing string.
🔸 StringBuilder belongs to System.Text.Stringbuilder namespace.
#post
String
:🔸 It's an immutable object that hold string value.
🔸 Performance wise string is slow because its' create a new instance to override or change the previous value.
🔸 String belongs to System namespace.
StringBuilder
:🔸 StringBuilder is a mutable object.
🔸 Performance wise StringBuilder is very fast because it will use same instance of StringBuilder object to perform any operation like insert value in existing string.
🔸 StringBuilder belongs to System.Text.Stringbuilder namespace.
#post
📝 What is deep or shallow copy concept in C#?
🔸 Shallow Copy is about copying an object's value type fields into the target object and the object's reference types are copied as references into the target object but not the referenced object itself. It copies the types bit by bit. The result is that both instances are cloned and the original will refer to the same object.
🔸 Deep Copy is used to make a complete deep copy of the internal reference types, for this we need to configure the object returned by
In other words a deep copy occurs when an object is copied along with the objects to which it refers.
#post
🔸 Shallow Copy is about copying an object's value type fields into the target object and the object's reference types are copied as references into the target object but not the referenced object itself. It copies the types bit by bit. The result is that both instances are cloned and the original will refer to the same object.
🔸 Deep Copy is used to make a complete deep copy of the internal reference types, for this we need to configure the object returned by
MemberwiseClone()
.In other words a deep copy occurs when an object is copied along with the objects to which it refers.
#post