locked
based on month name how to add the list for sample detail RRS feed

  • Question

  • User306227 posted

    based on month name how to add the list for sample detail .this is my code .

    Listsample;

    public class SampleModel { public string MonthName { get; set; } public List detail {get; set ;} }

    public class SampleDetail { public string HeaderTitle { get; set; } public string Description { get; set; } public string Date { get; set; } public string Day { get; set; } public string Time { get; set; } }

    here i m adding value to the samplemodel but how to add for sampledeatils sample = new List { new SampleModel { MonthName = "MARCH 2020",detail{ } },

                new SampleModel { MonthName = "FEBRUARY 2020"},
                new SampleModel { MonthName = "JANUARY 2020" },
    
            };
    
    Friday, April 24, 2020 11:52 AM

Answers

  • User369979 posted

    Change the detail property to:

    public List<SampleDetail> detail { get; set; }
    

    And then initialize:

    List<SampleDetail> list = new List<SampleDetail>();
    //list.Add(new SampleDetail { });
    new SampleModel { MonthName = "MARCH 2020", detail = list };
    
    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Sunday, April 26, 2020 5:31 AM