Skilled in SEO, content writing, and digital marketing. Completed several years of working in many organizations including multinational companies. I love to learn new things in life that keep me motivated.
In C#, you can convert an enum value to its string representation using the
ToString() method. If you want to convert a list of enum values to their string representations, you can use methods like
Select from LINQ. Here's how you can do it:
using System;
using System.Collections.Generic;
using System.Linq;
public enum DaysOfWeek
{
Sunday,
Monday,
Tuesday,
Wednesday,
Thursday,
Friday,
Saturday
}
class Program
{
static void Main()
{
List<DaysOfWeek> daysList = new List<DaysOfWeek>
{
DaysOfWeek.Monday,
DaysOfWeek.Wednesday,
DaysOfWeek.Friday
};
List<string> daysAsStringList = daysList.Select(d => d.ToString()).ToList();
Console.WriteLine("Enum values as strings:");
foreach (var dayString in daysAsStringList)
{
Console.WriteLine(dayString);
}
}
}
Liked By
Write Answer
How to convert enum to string for a list in C#?
Join MindStick Community
You have need login or register for voting of answers or question.
Aryan Kumar
27-Sep-2023In C#, you can convert an enum value to its string representation using the ToString() method. If you want to convert a list of enum values to their string representations, you can use methods like Select from LINQ. Here's how you can do it: