Как вернуться из нескольких классов c # - PullRequest
0 голосов
/ 06 ноября 2018

Я не уверен, как произнести название и искал лучшее, что мог, но на самом деле все еще не уверен, как с этим справиться.

Мне нужно создать возврат, который выглядит следующим образом:

[ { «Имя»: «Первый | Последний», «Id»: 1, «Разрешено»: правда, "date": "datestring", "EndTime": "11:00 AM", «Время»: «10:00» «Настройки»: [ { "id": 1, "name": "TestName", "maxValue": 100 }

Мой код, очевидно, я не могу сделать новые настройки внутри этого, так как я могу добавить этот бит в возвращение? Или я совершенно не прав?

    public Information[] PMI(string Id)  
    {
        return new Information[]
        {
            new Information
            {
                Name = "First|Last",
                NameId = "1",
                Allowed = true,
                date = "Feb 1, 2018",
                EndTime = "1:00 PM",
                DateTime = "09:00"
            },
            new Settings
            {
                id = 1,
                name = "TestName",
                maxValue = "1000"
            }
        };
    }

public class Information
{
    public string Name { get; set; }
    public string Id { get; set; }
    public bool Allowed { get; set; }
    public string date { get; set; }
    public string EndTime { get; set; }
    public string DateTime { get; set; }

}

public class Settings
{
    public string id { get; set; }
    public string name { get; set; }
    public string maxValue { get; set; }
}

1 Ответ

0 голосов
/ 06 ноября 2018

Это будет делать то, что вам нужно:

   public Information[] PMI(string Id)  
{
    return new Information[]
    {
        new Information
        {
            Name = "First|Last",
            NameId = "1",
            Allowed = true,
            date = "Feb 1, 2018",
            EndTime = "1:00 PM",
            DateTime = "09:00"
            Settings = new Settings
            {
                id = 1,
                name = "TestName",
                maxValue = "1000"
            }
        },

    };
}

public class Information
{
    public string Name { get; set; }
    public string Id { get; set; }
    public bool Allowed { get; set; }
    public string date { get; set; }
    public string EndTime { get; set; }
    public string DateTime { get; set; }
    public Settings Settings {get; set;}
}

public class Settings
{
    public string id { get; set; }
    public string name { get; set; }
    public string maxValue { get; set; }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...