How to enumerate an enum

后端 未结 29 2306
深忆病人
深忆病人 2020-11-22 01:14

How can you enumerate an enum in C#?

E.g. the following code does not compile:

public enum Suit
{         


        
29条回答
  •  离开以前
    2020-11-22 01:30

    Here is a working example of creating select options for a DDL:

    var resman = ViewModelResources.TimeFrame.ResourceManager;
    
    ViewBag.TimeFrames = from MapOverlayTimeFrames timeFrame
          in Enum.GetValues(typeof(MapOverlayTimeFrames))
          select new SelectListItem
          {
             Value = timeFrame.ToString(),
             Text = resman.GetString(timeFrame.ToString()) ?? timeFrame.ToString()
          };
    

提交回复
热议问题