Is there a way to have something like:
string day = "Sunday";
int num = getDayOfWeek(day); //returns 0
I understand we could something like, and I wanted the reverse:
int num = 0;
//returns "Sunday"
return System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.DayNames[(int)num];
The easiest way would probably be to implement a dictionary that does what I am asking, but I wonder if there is something in C#
DateTime
functions that already does so for me.
EDIT:
As Jon Skeet pointed out, it would be ideal that the answer supported different cultures days (e.g. "Sunday" in English, "Segunda" in Portuguese...)
var inx = Array.FindIndex(CultureInfo.CurrentCulture.DateTimeFormat.DayNames, x=>x=="Sunday");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With