Reputation: 4560
I want to get a value of Enum.In here i get value as enumVal.ToCharArray()[0].But it's not correct.(When i select Received in dropdownlist then value shows me 88 (R's Char
array value,BUT i want Received's value is 1)
My Code
var LetterTypeList = new List<LetterStatusModel>();
foreach (var item in Enum.GetValues(typeof(LetterStatus)))
{
string enumVal = item.ToString();
LetterTypeList.Add(new LetterStatusModel { LetterStatusCode = enumVal.ToCharArray()[0], LetterStatusName = enumVal });
}
public class LetterStatusModel
{
public int LetterStatusCode { get; set; }
public string LetterStatusName { get; set; }
}
public enum LetterStatus
{
Received = 1,
Issued = 2,
Paused = 3,
Cancel = 4,
}
Upvotes: 0
Views: 53
Reputation: 156978
Instead of taking the name of the value by doing ToString()
, you can cast the value to an int:
int enumValue = (int)item;
Upvotes: 3