Wednesday 27 July 2016

C Sharp Copy Constructure Tutorial

C# Copy Constructure Program

class test
    {
        String nm1, nm2;
        public test(string nm1, string nm2)
        {
            this.nm1 = nm1;
            this.nm2 = nm2;
        }
        public test(test ob) //Copy C
onstruction  and it's always takes an object of related class
        {
            nm1 = ob.nm1;
            nm2 = ob.nm2;
        }
        public void show()
        {
            Console.WriteLine("\nString1\t{0}\nString2\t{1}\n", nm1, nm2);
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            test ob1 = new test("Sunday", "Monaday");
            test ob2 = ob1;
            test ob3 = new test(ob2);
            ob1.show();
            ob2.show();
            ob3.show();
        }
    }
Next Topic

No comments:

Post a Comment