Can I assign a null value to an anonymous type property?

I have the following in WebAPI that is converted to a JSON string and sent to the client:

return Ok(new
    {
        Answer = "xxx",
        Text = question.Text,
        Answers = question.Answers.Select((a, i) => new
        {
            AnswerId = a.AnswerId,
            AnswerUId = i + 1,
            Text = a.Text
        })
    });

Now I realize that I would like to assign the value null to Answer. However this gives me a message saying

cannot assign <null> to anonymous type property. 

Is there a way I can do this without having to define a class just so I can assign the null?

Jon Skeet
people
quotationmark

Absolutely - you just need to cast the null value to the right type so that the compiler knows which type you want for that property. For example:

return Ok(new {
    Answer = (string) null,
    Text = ...,
    ...
});

people

See more on this question at Stackoverflow