.NET Enumeration allows comma in the last field

后端 未结 5 1528
后悔当初
后悔当初 2020-11-27 06:13

Why is this .NET enumeration allowed to have a comma in the last field?
Does this have any special meaning?

[FlagsAttribute]
public enum DependencyProper         


        
5条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-27 06:48

    I know that it is an old topic but, another approach that would make sense for this issue is for code versioning systems.

    Consider the following example:

    //version 1
    var myArray = {
        "item 1",
        "item 2"
    };
    //version 2
    var myArray = {
        "item 1",
        "item 2", //will be considered a change, it may be considered an erroneous approach
        "item 3"
    }
    

    Now consider this approach:

    //version 1
    var myArray = {
        "item 1",
        "item 2",
    };
    //version 2
    var myArray = {
        "item 1",
        "item 2", //will not be considered a change, it may be considered an erroneous approach too, but, means that the code wasn't changed intrinsically
        "item 3",
    };
    

    Anyhow, both approaches may be considered incorrect or correct depending on the situation. I particularly prefer the second approach that makes much more sense when dealing with code versioning systems.

    Anyway hope this helps.

提交回复
热议问题