C#枚举与string类型相互比较

public enum ChatTemplateFunctionType
{
  tt,
  aaaaa,
}

Enum.Parse(typeof(enum), string),来进行比较;

public void XXX(string strType)
{
  if (!string.IsNullOrEmpty(strType))
  {
    switch (Enum.Parse(typeof(ChatTemplateFunctionType), strType))
    {
      case ChatTemplateFunctionType.tt:
      break;
    }
  }
}

完毕!!!!!

posted @ 2022-02-24 17:55  匆匆,不惑之年  阅读(239)  评论(0)    收藏  举报