As I'm learning c# I would appreciate some professional advice about structs and classes. As classes are reference types and stored on the heap, while structs are value types and stored on the stack.
What I understand is that structs are typically used for smaller data types for performance reasons.
Given with what I have read, would the following code be a struct or a class.
public struct DisplayWeatherAstronomy
{
public string SunRise { get; internal set; }
public string SunSet { get; internal set; }
public string MoonRise { get; internal set; }
public string MoonSet { get; internal set; }
}
/***Extra code***/
Going off two replies, I've added some extra code.
public IEnumerable<DisplayWeatherAstronomy> WeatherAstronomy(string id)
{
var doc = WeatherXml.XmlData(id);
var displayAstronomy = (from wd in doc.Descendants("astronomy")
select new DisplayWeatherAstronomy
{
SunRise = (string)wd.Element("sunrise") ?? string.Empty,
SunSet = (string)wd.Element("sunset") ?? string.Empty
});
return displayAstronomy;
}