如何为列表类型类变量赋值?

时间:2014-08-21 04:11:28

标签: c#

我正在开发一个模块来在谷歌日历中创建事件所以我想制作json文件,但请告诉我有关以下问题的信息。 如何为EmailAddress类的电子邮件赋予价值? 我的视图模型类是:

public class CreateJson
    {
        public EventTime end { get; set; }
        public EventTime start { get; set; }
        public string summary { get; set; }
        public List<EmailAddress> attendees { get; set; }
    }

    public class EventTime
    {
        public string dateTime { get; set; }
        public string timeZone { get; set; }
    }

    public class EmailAddress
    {
        public string email { get; set; }
    }


My Controller Class:
 CreateJson objCreateJson = new CreateJson()
            {
                summary = summary,
                end = new EventTime()
                {
                    dateTime =endtime,
                    timeZone = "America/Los_Angeles"
                },
                start = new EventTime()
                {
                    dateTime = starttime,
                    timeZone = "America/Los_Angeles"
                },
                attendees =
                {
                   ???????
                }
            };

我如何为EmailAddress Class的电子邮件赋予价值?

1 个答案:

答案 0 :(得分:2)

使用collection initializer语法:

attendees = new List<EmailAddress>()
{
    new EmailAddress(...),
    new EmailAddress(...),
    new EmailAddress(...),
    ...
}