是否可以采用现有类型并使用其他属性从中创建匿名类型?例如(在VB中) Public Class Person Public Name As String Public Age As IntegerEnd ClassDim p As New Person With {.Name = "James", .Age = 100}Dim n = New With {.
Public Class Person Public Name As String Public Age As Integer End Class Dim p As New Person With {.Name = "James", .Age = 100} Dim n = New With {.ShoeSize = 10}
我想要的是克隆p的所有属性然后添加一个新属性(ShoeSize)的第二个对象(n).
这可能吗?
非常感谢
詹姆士
在C#中没有语法可以做到这一点.你必须自己构建匿名类型,包含所有属性.