How do I iterate through a List inside a class?

OgrePyknic

New member
Joined
Sep 23, 2024
Messages
1
Programming Experience
Beginner
I am pulling weather data from a Web API call which returns JSON which populates the following class:
C#:
public class WeatherResponse
{
    public string queryCost { get; set; }
    public string latitude { get; set; }
    public string longitude { get; set; }
    public string resolvedAddress { get; set; }
    public string address { get; set; }
    public string timezone { get; set; }
    public string tzoffset { get; set; }
    public List<DayInfo> days { get; set; }

}
There is a List inside it: DayInfo with the daily info for a number of days (see below).
C#:
public class DayInfo
{
    public string datetime { get; set; }
    public string tempmax { get; set; }
    public string tempmin { get; set; }

    // etc..
}
How do I iterate through this list in the WeatherResponse object. eg: with a foreach.
Basically I need to insert the data for each day into an MS SQL table.
Thanks.
 
You would iterate over it the same way you iterate over any other list. Having a list reference as a local variable is the same as having a list reference that is a member of class or struct.

Is the real issue about how to structure the data in your database? Have you found yourself in your first encounter with the problem of stumbled of object-relational impedance mismatch?
 
Back
Top Bottom