Many a time, you would wonder how to return a pair of objects (not necessarily just 2, but 3,4,5) from a a function and simply creating a new Class to hold together those objects does not make sense / justifiable.
In such cases, you can make use the Tuple Class in C#, which is versatile class for the same purpose.
public (int diameter, double circumference, double area) GetCircleMetaData(int radius) {
const double PI = 3.1415; var diameter = radius * 2; var circumference = PI * diameter; var area = PI * radius * radius; return (diameter, circumference, area); }
var (d, c, a) = GetCircleMetaData(9);
No comments:
Post a Comment