is it a good idea to create an enum for the key names of session values?

后端 未结 7 2196
失恋的感觉
失恋的感觉 2021-02-14 22:45

instead of doing

 session(\"myvar1\") = something
 session(\"myvar2\") = something
 session(\"myvar3\") = something
 session(\"myvar4\") = something
7条回答
  •  有刺的猬
    2021-02-14 23:02

    How about:-

    public static class  SessionVar
    {
      public static readonly string myVar1 = "myVar1";
      public static readonly string myVar2 = "myVar2";
      public static readonly string myVar3 = "myVar3";
      public static readonly string myVar4 = "myVar4";
    }
    

    This allows you to use:-

    session(SessionVar.myVar1) = something;
    

提交回复
热议问题