有多种方法:
1)用途:
public KeyValuePair<int, int> Location(int p_1, int p_2, int p_3, int p_4)
{
return new KeyValuePair<int,int>(p_2 - p_1, p_4-p_3);
}
或者
static Tuple<int, int> Location(int p_1, int p_2, int p_3, int p_4)
{
return new Tuple<int, int>(p_2 - p_1, p_4-p_3);
}
2)使用自定义类,如Point
public class Point
{
public int XLocation { get; set; }
public int YLocation { get; set; }
}
public static Point Location(int p_1, int p_2, int p_3, int p_4)
{
return new Point
{
XLocation = p_2 - p_1;
YLocation = p_4 - p_3;
}
}
3)使用out
关键字:
public static int Location(int p_1, int p_2, int p_3, int p_4, out int XLocation, out int YLocation)
{
XLocation = p_2 - p_1;
YLocation = p_4 - p_3;
}
以下是这些方法的比较:multiple-return-values。
最快的方式(最佳性能)是:
public KeyValuePair<int, int> Location(int p_1, int p_2, int p_3, int p_4)
{
return new KeyValuePair<int,int>(p_2 - p_1, p_4-p_3);
}