devxlogo

.NET

Enumerate All the Values in an Enum

See an easy way to enumerate all the values. public enum WorkTypes{Remote = 0,Office = 1,Exempted = 2}foreach (WorkTypes workType in Enum.GetValues(typeof(WorkTypes)))Console.WriteLine(workType);

Return Response Codes from ASP.NET Action Result Using StatusCodes Enum

The Microsoft.AspNetCore.Http.StatusCodes?enum has many response codes. Please see below for an example to return one of the values from the enum: [HttpGet]public IActionResult CustomStatusCode (){ //code”return StatusCode(Microsoft.AspNetCore.Http.StatusCodes.Status405MethodNotAllowed);}

Quickly Tell Team Something About Code

Visual Studio allows you to communicate with fellow developers about a piece of code. It lets you add a compiler directive “warning” to your code, which shows up in the

Cast an Int Value to an Enum Value in C#

Oftentimes, the input is an integer that has to be converted to the appropriate enum value. All we have to do is cast the integer value as below: EnumName e

Quick C# Experiments with Interactive Window

We often create console applications to write test code or to do quick experiments in Visual Studio because they are lightweight when compared to Windows/Web applications. Visual Studio 2015 provides

Displaying Date Time with Reference to Time

There are lot of .NET helper assemblies that help you represent datetime in more readable formats, such as yesterday, 5 minutes ago, and so on. One of the libraries that

How to Kill a Long-Running Process

You can use HttpResponse’s IsClientConnected property to figure out if the connection is still alive. Based on the value, you can kill a long-running process if the client is not