How to set value for property of an anonymous object?

后端 未结 8 914
心在旅途
心在旅途 2020-12-05 17:44

this is my code for example:

var output = new
{
    NetSessionId = string.Empty
};

foreach (var property in output.GetType().GetProperties())
{
    property         


        
8条回答
  •  被撕碎了的回忆
    2020-12-05 18:18

    Anonymous type properties are read only and they cannot be set.

    Anonymous types provide a convenient way to encapsulate a set of read-only properties into a single object without having to explicitly define a type first. The type name is generated by the compiler and is not available at the source code level. The type of each property is inferred by the compiler.

    Anonymous Types (C# Programming Guide)

提交回复
热议问题