Category: C#

Assign value to enum in c#

You can assign the integer value to enum by casting it to the respective enum type. For example , In the below sample program , you can assign the value 10 to enum by casting the value to the Designation type.

How to Use the Null Coalescing Operator (??) in C# ?

There are times when you simply want to check if the value is null and perform some steps based on the condition . The Null Coalescing Operator (??) can help you achieve this. How to Use the Null Coalescing Operator (??) in C# ? Below is a sample code that uses Null Coalescing Operator (??) in C# to find if the vaklue is null ….

How to get the total number of items in a Enum in C# ?

If you want to get the total number of items that is defined in an enum using C# , you can use the Enum.GetNames static method combined with the Length property. How to get the total number of items in a Enum in C# ? Here’s a code sample demonstrating how to do it. This would display 3 in the console.