Tag: class
How to Call Other Constructors within the Same Class in C# ?
There are times when you want to avoid duplicating code and want to reuse them when working on multiple constructors . If you want to call other constructors from a constructor within the same class , you need to use the this keyword . How to Call Other Constructors within the Same Class in C# ? Below is a sample code snippet that demonstrates how…
How to Get the Name of the Anonymous class(type) in C# ?
Below is a sample code snippet which gets the name of the anonymous class . In the below example , the Name and the ID property is set which is anonymous where the type is not specified. When trying to find out the type of the anonymous type , you will get the type as shown in the screenshot below. How to Get the Name…
What is the difference between struct and class in C# ?
Below are some differences between struct and class in C# classes are reference types where as struct are value types. Null value cannot be assigned to the Struct because it is a non-nullable value type . Whereas the object of a class can be assigned a null value. Classes support inheritance but the struct doesn’t. struct cannot have destructor but a class can have. struct…
How to Prevent the Class from Inheriting in C# ?
You can use the keyword “sealed” in C# to prevent the user from inheriting the class. Below is a class that is marked as sealed and is not inheritable. How to Prevent the Class from Inheriting in C# ?