我有一个枚举为: -如何转换一个枚举列表和替换“_”与“”(空格)
public enum EnumType
{
Type1_Template,
Type2_Folders,
Type3_Template,
Type1_Folders,
}
现在,在我的控制,我想
- 枚举列表和
- 用空格替换下划线。
所以对于: - 获取枚举的名单上有
return new Models.DTOObject()
{
ID = model.id,
Name = model.Name,
Description = model.Description,
//Type is the property where i want the List<Enum> and replace the underscore with space
Type = Enum.GetValues(typeof(EnumType)).Cast<EnumType>().ToList()
};
但现在,我想这样的事情(可能听起来不可思议,虽然): -
return new Models.Customers()
{
ID = model.id,
Name = model.Name,
Description = model.Description,
//Type is the property where i want the List<Enum> and replace the underscore with space
Type = Enum.GetValues(typeof(EnumType)).Cast<EnumType>().ToList().Select(e => new
{
Value = e,
Text = e.ToString().Replace("_", " ")
})
};
但抛出语法错误(';'缺失)。尽管这只是一种尝试。请让我知道我该如何实现它。
“但抛出语法错误”不是一个明确的错误描述。 *什么*错误? – 2013-02-26 07:37:48