Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I try to Covert the List<> value to Enum but i'm Failed.
C#
List<string> lstDays = new List<string> { "Monday", "Tuesday ", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" };


Need Enum like

C#
enum lstDays 
	{
		Monday,
		Tuesday,
		Wednesday,
		Thursday,
		Friday,
		Saturday,
		Sunday
	}


Please can help?

What I have tried:

i don't have any idea.i cann't able to Convert.
Posted
Updated 29-Jul-20 22:11pm
v2
Comments
[no name] 29-Jul-20 3:11am    
F-ES Sitecore 29-Jul-20 6:17am    
That's not possible. You would be better explaining why you want to do this, ie what problem you're trying to solve, and someone might have an alternative solution.

AFAIK you cannot do that. You might keep the list and use it or you have to hand-code the enum.
 
Share this answer
 
Comments
Maciej Los 30-Jul-20 5:00am    
5ed!
CPallini 30-Jul-20 5:04am    
Thank you!
You can't change ENum's during Runtime - they are allways created with your development-system (during Designtime).
In fact they are contants.
But you could go the other way round : you can make strings from defined ENum's ...
 
Share this answer
 
Comments
Maciej Los 30-Jul-20 4:12am    
5ed!
Ralf Meier 30-Jul-20 4:37am    
Thank you Maciej ... :)
There is an Enum 'DayOfWeek in the 'System namespace:
Type dayType = typeof(DayOfWeek);

string[] dayNames = Enum.GetNames(dayType); // => ["Sunday" ... "Saturday"]

string sunday = Enum.GetName(dayType, 0); // => "Sunday"
 
Share this answer
 
Comments
Maciej Los 30-Jul-20 4:12am    
5ed!
BillWoodruff 30-Jul-20 5:21am    
Thank you, Maciej

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900