is order of field important in anonymous types automatic initialization?

前端 未结 3 1603
庸人自扰
庸人自扰 2020-12-10 06:17

I got a scenario to create the anonymous list from the anonymous types, and i achieved that using

    public static List MakeList(T itemOf         


        
3条回答
  •  没有蜡笔的小新
    2020-12-10 06:44

    Yes, the order of fields is significant. Same fields, different order will yield different types.

    From the language specification:

    "Within the same program, two anonymous object initializers that specify a sequence of properties of the same names and compile-time types in the same order will produce instances of the same anonymous type. "

提交回复
热议问题