Monday, 13 July 2015

[.]Dot Net Programs

/*... WRITE A PROGRAM that will work like copy constructor of c++....*/


using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication14
{
    class Student
    {
        int rollno;
        string name;

        public void SetData(int r, string n)
        {
            rollno = r;
            name = n;
        }
        public void ShowData()
        {
            Console.WriteLine(rollno + " " + name);
        }
    }
   class Demo
    {
        static void Main(string[] args)
        {
            Student s = new Student();
            s.SetData(1, "Gabriel");
            s.ShowData();
            Student t = s;// t will point to s
            t.ShowData();
            t.SetData(2, "Rohinton");// s will also be changed                            
t.ShowData();
s.ShowData();
            Console.ReadLine();
        }
    }
}