I encountered a problem when coding where I wanted to convert a string to an enum last night, First, I generated a long list of switch and case statements to handle this problem. But it is very awkward, so I tried to find a simple way to do it, finally I got it.
    Sample code as below :

     enum NodeType { RootNode, CorpNode, CentralNode, DepartmentNode }

     public class OrganizeNode
     {
         public static NodeType getNodeType(string strNodeName)
         {
              NodeType nodeType;
              nodeType = (NodeType) NodeType.Parse(typeof(NodeType), strNodeName, true);
              return nodeType;
         }
     }

相关文章:

  • 2022-02-28
  • 2022-12-23
  • 2022-01-30
  • 2022-02-15
  • 2021-08-09
  • 2022-12-23
  • 2022-02-14
  • 2022-12-23
猜你喜欢
  • 2021-09-14
  • 2022-01-15
  • 2021-11-01
  • 2021-09-26
  • 2022-02-08
  • 2021-06-05
相关资源
相似解决方案