Simple Use of Tuple
You can easily return more than one value from method without using out
or ref
parameters.
public Tuple<int, int> SplitPoints(string point) { string[] pointList = point.Split(','); int x = Convert.ToInt32(pointList[0]); int y = Convert.ToInt32(pointList[1]); return Tuple.Create<int, int>(x, y); }
SplitPoints
method split the points and returns x
and y
points in tuple
.
Tuple<int,int> points = SplitPoints("12,14"); string msg = string.Format("X: {0}, Y: {1}", points.Item1, points.Item2); MessageBox.Show(msg);
You can get the returned values from exposed properties Item1
, Item2
, etc. by Tuple
object. Item properties of Tuple
object are readonly. You can not change the value of the property.