Wednesday, 14 August 2013

How to Pass and returns objects via function in C#.Net


class Person
    {
        public int a, b;

        public Person(int x,int y)
        {
            a = x;
             b=y;
        }
        public Person() { }
        public static Person sum(Person pp, Person hh)
        {
            int x = pp.a + hh.a;
            int y = pp.b + hh.b;

            Person temp = new Person();
            temp.a = x;
            temp.b = y;
            return temp;
      //return "a="+a+"b="+b;
        }
         
    }


class A
{
static void Main(String []st)
 {

   Person pp = new Person(34, 60);
            Person hh = new Person(2, 5);

           Person ans = Person.sum(pp, hh);
           MessageBox.Show("a="+ans.a + "b=" + ans.b);
       

}
}


0 comments:

Post a Comment