Unfortunately features like "top level statements" seem to be more important than the ability to pass complex data around and manipulate it as needed without having to create a class for that data. Its a HUGE gap in C# who's omission makes little sense to me. You basically have to use Dictionary<string,object> as this is the only way to do this. But let me ask any C# designers who might encounter this page, which is cleaner and less verbose between these 2 code snippets?
var data = new
{
Username = "My Username",
FullName = "John Smith",
Age = 22,
Salary = 11.5,
IsEmployee = true,
DOB = DateTimeOffset.UtcNow,
};
data.FullName = "Hello worlder";
var data2 = new Dictionary<string, object>
{
["Username"] = "My Username",
["FullName"] = "John Smith",
["Age"] = 22,
["Salary"] = 11.5,
["IsEmployee"] = true,
["DOB"] = DateTimeOffset.UtcNow,
};
data["FullName"] = "john smith";