I have been tasked with parsing out xml and json data into an application. I am trying to create a properties class that encompasses all the data I will be collecting.
Here is my issue/question
I have created a class with the variables for the weather data, temp, wind, uv index, etc. I have created the days as well. I can access the days individually but not as a whole. For example.
Monday m = new Monday();
m.TempHiF = "65";
What I want to do is this.
WDay d = new WDay();
d.Monday.TempHiF = "65"
d.Tuesday.TempHiF = "67";
And so on. I am pretty new to C# and I am not even sure what to google. I have been racking my brain for a week and come up with limited success. I am open to other suggestions on storing the data as well.
All you have to do is make WDay have properties for all the days:
public class WDay
{
public Day Monday {get;set;}
...
Then have the Day class have a TempHiF property, and so on:
public class Day
{
public string TempHif {get;set;}
...
}
Make sure WDay's constructor initializes all its Day properties with new instances to avoid null reference exceptions.
class Week {
public Day Sunday{get;set;}
public Day Monday{get;set;}
// etc...
}
class Day {
// Define day-bound properties here
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With