我有幾個關於創建對象(2個值)以及如何「調用」的問題。執行2次計算的C#對象(2個數字)
初始化對象有:
Tweetal t1, t2, t3, t4, t5, t6;
t1 = new Tweetal(); //a: 0 , b = 0
t2 = new Tweetal(-2); //a: -2, b = -2
t3 = new Tweetal(5, 17); //a: 5, b = 17
t4 = new Tweetal(t3); //a:5, b = 17
Console.Write("t1 = " + t1);
Console.Write("\tt2 = " + t2);
Console.Write("\tt3 = " + t3);
Console.Write("\tt4 = " + t4);
Console.WriteLine("\n");
t1 = t1.Som(t2);
t4 = t2.Som(t2);
//......
現在的兩件事情,我想用這個對象做所走的SUM和SUMNumber: 總:t4 = t2.sum(t3);
(這將導致T4:一:3( -2 + 5),b:15(-2 + 17) SumNumber:t1 = t3.sum(8)
(這將導致t1:a:13,b:25)
Sum - >參數,例如t3,t2等。 。SumNumber - >參數7,5,...或2個數字(5,7)...
接下來是我的目標代碼(在一個單獨的類),但究竟如何做我執行我的呼喚了例如T2等簡單相加計算...
public class Tweetal: Object
{
private int a;
private int b;
public Tweetal()
{
//???
//Sum(...,...)
}
public Tweetal(int a)
{
//???
//Sum(...,...)
}
public Tweetal(int a, int b)
{
//???
}
public Tweetal(Tweetal //....) // to call upton the object if i request t1, t2, t3,... insteed of a direct number value)
{
// ????
}
public void Sum(int aValue, int bValue)
{
//a = ???
//b = ???
//Sum(...,...)
}
public void SumNumber(int aValue, int bValue)
{
}
public override string ToString()
{
return string.Format("({0}, {1})", a, b);
}/*ToString*/
}
讓我只是注意每個人'tweetal'是荷蘭語'對'。 – Joren 2010-04-03 13:49:06