Wednesday 27 July 2016

C Sharp Constructure Tutorial

C# Constructure Program 

 class test
    {
        int a, b;
       
        public test(int x,int y)
        {
            a = x;
            b = y;
        }
        public test(int x)
        {
            a = b = x;

        }
        public test()   // Default Constructor
        {
            a = b = 0;
        }
        public void show()
        {
            Console.WriteLine("A={0}\nB={1}\nSum={2}",a,b,a+b);
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            test ob = new test(3, 33);
            ob.show();
            test ob2 = new test(5);
            ob2.show();
            test ob3 = new test();
            ob3.show();
           
           
        }
    }
                                                                         Next Topic

No comments:

Post a Comment