如何订购以匿名类型返回的数据?

时间:2014-07-21 04:44:23

标签: c#

我有这段代码:

         return Ok(new
            {
                Answer = (string) null,
                Text = question.Text,
                Answers = question.Answers.Select((a, i) => new
                {
                    AnswerId = a.AnswerId,
                    AnswerUId = i + 1,
                    Correct = (bool?) null,
                    Response = (bool?) null,
                    Text = a.Text
                })
            });

如何订购AnswerId返回的答案?

1 个答案:

答案 0 :(得分:3)

添加

.OrderBy( z => z.AnswerId)
紧接在Select语句之后