new Tuple<T1, T2, T3, T4, T5, T6, T7, T8>(T1, T2, T3, T4, T5, T6, T7, T8):建立1至8個項目的Tuple物件。
Tuple.Create<T1, T2, T3, T4, T5, T6, T7, T8>(T1, T2, T3, T4, T5, T6, T7, T8):建立1至8個項目的Tuple物件。
Tuple.Item1、Tuple.Item2.....Tuple.Item8:取得Tuple物件之項目內容。
public static void Main(string[] args)
{
Tuple obj = Cale(5, 6);
Console.WriteLine(obj.Item1);
Console.WriteLine(obj.Item2);
Console.WriteLine(obj.Item3);
Console.WriteLine(obj.Item4);
Console.WriteLine(obj.Item5);
Console.ReadKey();
}
//最多可傳遞8個結果
public static Tuple<int, int, int, double, string> Cale(int x, int y)
{
int add = x + y;
int sub = x - y;
int multip = x * y;
double division = Convert.ToDouble(x) / Convert.ToDouble(y);
string show = string.Format("x={0:f2}, y={1:f2}", x, y);
return Tuple.Create<int, int, int, double, string>(add, sub, multip, division, show);
}
//傳遞超過8個結果之寫法
public static Tuple<int, int, int, int, int, int, int, Tuple<int, int>> Cale()
{
return new Tuple<int, int, int, int, int, int, int, Tuple<int, int>>(1, 2, 3, 4, 5, 6, 7, new Tuple(8, 9));
}
沒有留言:
張貼留言