I’m pretty new in OOP but have to develop a big project… Just for imagination, below 2 examples which returns same.
Which one is (more) correct, hmm or cleaner? The Property or the method?
In real I have to return complex datasets from joined tables… I avoid copy the complet query which returns the dataset. Thats why it’s just an empty here in this example.
Thanks.
public class House
{
public static DataSet Windows
{
// just for imaging
get
{
DataSet ds = new DataSet(); // Here would be my data set from sql which returns a windows collection.
return ds;
}
set
{
Windows = value;
}
}
public static DataSet GetWindows()
{
DataSet ds = new DataSet(); // Gets same right?
return ds;
}
}
Properties in C# are converted to get/set methods, so technically they are equivalent. However, the framework guidelines recommend that properties should be used for ‘simple’ operations like field access. Therefore, in your example I’d use the GetWindows method approach since it hints to consumers that it could be a long-running call.