Beispiel #1
0
        static void Main(string[] args)
        {
            // Creates an instance of clsShallow and assign values to its fields.
            clsShallow objshallow = new clsShallow();
            objshallow.Age = 25;
            objshallow.EmployeeName = "Ahmed Eid";

            // add the ref value to the objshallow
            clsRefSalary clsref = new clsRefSalary(1000);
            objshallow.EmpSalary = clsref;

            // Performs a shallow copy of m1 and assign it to m2.
            clsShallow m2 = objshallow.CreateShallowCopy(objshallow);

            // then modify the clsref salary value to be 2000
            clsref.Salary = 2000;
            m2.EmployeeName = "unos baghaii";
            m2.Age = 100;

            // so the m1 object salary value become 2000
            int EmpSalary = objshallow.EmpSalary.Salary;

            Console.ReadLine();
        }
Beispiel #2
0
 public clsShallow CreateShallowCopy(clsShallow inputcls)
 {
     return (clsShallow)inputcls.MemberwiseClone();
 }