C# object (2 numbers) performing 2 calculations

Posted by Chris on Stack Overflow See other posts from Stack Overflow or by Chris
Published on 2010-04-03T13:37:22Z Indexed on 2010/04/03 13:43 UTC
Read the original article Hit count: 196

Filed under:

I have a couple questions about creating a object (2 values) and how to "call" it.

Initializing the object with:

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);
//......

Now the 2 things i want to do with this object are taking the SUM and the SUMNumber: Sum: t4 = t2.sum(t3); (this would result in t4: a:3 (-2+5), b: 15(-2+17) SumNumber: t1 = t3.sum(8) (this would result in t1: a:13 , b:25)

Next is my code for the object (in a separate class), but how exactly do i perform the simple sum calculation when i call up for example t2 etc...

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*/
}

© Stack Overflow or respective owner

Related posts about c#