Methods inside enum in C#

后端 未结 6 1335
离开以前
离开以前 2020-12-04 10:21

In Java, it\'s possible to have methods inside an enum.

Is there such possibility in C# or is it just a string collection and that\'s it?

I tried to override

6条回答
  •  借酒劲吻你
    2020-12-04 11:11

    C# Does not allow use of methods in enumerators as it is not a class based principle, but rather an 2 dimensional array with a string and value.

    Use of classes is highly discouraged by Microsoft in this case, use (data)struct(ures) instead; The STRUCT is intended as a light class for data and its handlers and can handle functions just fine. C# and its compiler don't have the tracking and efficiency capabilities as one knows from JAVA, where the more times a certain class / method is used the faster it runs and its use becomes 'anticipated'. C# simply doesn't have that, so to differentiate, use STRUCT instead of CLASS.

提交回复
热议问题