Concepts
Boxing and Unboxing
Both Boxing and Unboxing are used for converting the type.
Boxing | Unboxing |
---|---|
The process of converting from value type to reference (object) type is called Boxing. | The process of converting from reference (object) type to value type in called Unboxing. |
Boxing is an implicit conversion. | Unboxing is an explicit conversion. |
Covariance and Contravariance
Covariance preserves assignment compatibility and contravariance reverses it.
Parse and TryParse
Parse() | TryParse() |
---|---|
returns the converted number | returns a |
if the string is not in a valid format, | if the string is not in a valid format, |
|
Stateful and Stateless Methods
Stateful Methods | Stateless Methods |
---|---|
Stateful methods are also known as instance methods. | Stateless methods are knowns as static methods. |
When calling a stateful method, you need to create an instance of the class and access the method on the object. | When calling a stateless method, you don't need to create a new instance of its class first. |
Example:
In this example, we created the instance of the class(object) so that the method can access the state of the application. | Example:
In this example, this method performs its function and finishes without impacting the state of the application in any way. |
Last updated