Cast integer to enum in C#

Enum values can be converted to integral values and vice versa using type casts. For example: using System; public class Program { public enum ProgrammingLanguages { CSharp, PHP, Python, Java, Go, Javascript } public static…

ASP.NET Core | Making a request synchronously

using (var netClient = new System.Net.Http.HttpClient()) { var response = netClient.GetAsync(“”).Result; if (response.IsSuccessStatusCode) { var responseContent = response.Content; string responseAsString = responseContent.ReadAsStringAsync().Result; Console.WriteLine(responseAsString); } }

C# | Cast an int to enum

using System; public class Program { public static void Main() { var e0 = (Food)Enum.ToObject(typeof(Food), 0); Console.WriteLine(e0); // or simply var e2 = (Food)2; Console.WriteLine(e2); } public enum Food { Pizza, Pasta, Tofu } }