using System;
class MyBaseClass
{
public static string CompanyName = "My Company";
public int age;
public string name;
}
class MyDerivedClass : MyBaseClass
{
float xx = 10;
static void Main()
{
// Creates an instance of MyDerivedClass and assign values to its fields.
MyDerivedClass m1 = new MyDerivedClass();
// Performs a shallow copy of m1 and assign it to m2.
MyDerivedClass m2 = (MyDerivedClass)m1.MemberwiseClone();
m1.age = 42;
m1.name = "Sam";
m1.xx = 20;
// Please use debug as well as break point to see the contents of m1 and m2. (using "Add Watch")
Console.WriteLine("");
}
}
class MyBaseClass
{
public static string CompanyName = "My Company";
public int age;
public string name;
}
class MyDerivedClass : MyBaseClass
{
float xx = 10;
static void Main()
{
// Creates an instance of MyDerivedClass and assign values to its fields.
MyDerivedClass m1 = new MyDerivedClass();
// Performs a shallow copy of m1 and assign it to m2.
MyDerivedClass m2 = (MyDerivedClass)m1.MemberwiseClone();
m1.age = 42;
m1.name = "Sam";
m1.xx = 20;
// Please use debug as well as break point to see the contents of m1 and m2. (using "Add Watch")
Console.WriteLine("");
}
}
浙公网安备 33010602011771号