What is wrong with this code-snippet?
class Program
{
static void Main(string[] args)
{
var obj = new { Name = "A", Price = 3.003 };
obj.Name = "asdasd";
obj.Price = 11.00;
Console.WriteLine("Name = {0}
Price = {1}", obj.Name, obj.Price);
Console.ReadLine();
}
}
I am getting the following errors:
Error 5 Property or indexer 'AnonymousType#1.Name' cannot be assigned to -- it is read only .....CS_30_features.AnonymousTypesProgram.cs 65 13 CS_30_features.AnonymousTypes
Error 6 Property or indexer 'AnonymousType#1.Price' cannot be assigned to -- it is read only .....CS_30_features.AnonymousTypesProgram.cs 66 13 CS_30_features.AnonymousTypes
How to re-set values into an anonymous type object?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…