When are two enums equal in C#?

前端 未结 7 1737
栀梦
栀梦 2020-12-31 22:39

I have created two enums and I know they are not the same but still I think it makes sense they would be equal since their string represent

7条回答
  •  孤城傲影
    2020-12-31 23:31

    If you want them to match, cast them to int

    Assert.AreEqual((int)enumA.one,(int)enumB.one);
    

    would pass because they are both the first listed. If you wanted them to match because they both say "one" then you need to use reflection.

提交回复
热议问题