Define enums within a method in C#?

前端 未结 5 1986
囚心锁ツ
囚心锁ツ 2020-12-18 17:50

I have mainly a C++ background and I am learning C#. So, I need some help with C# idioms and style.

I am trying to write, in C#, a small text-file parsing method i

5条回答
  •  星月不相逢
    2020-12-18 18:26

    I know this is old, so this is mainly for folks looking for ideas.

    The closest I can think of to creating an 'enum' type, clean structure as required, within a method is to use a dictionary.

    var stateOpt = new Dictionary() { { "stHeader", 0 }, { "stBody", 1 }, { "stFooter", 2 } };
    var state = stateOpt["stBody"];
    

    You can then do what you need in your condition...

    if (state == stateOpt["stHeader"] && input == ".endheader")
    {
      state = stateOpt["stBody"];
    }
    

提交回复
热议问题