在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
如果要产生新的一个对象,内容和老的对象一致,可以通过下面方法实现(使用 MemberwiseClone 复制类):
using System;
class MyBaseClass { public static string CompanyName = "My Company"; public int age; public string name; } class MyDerivedClass: MyBaseClass { static void Main() { // Creates an instance of MyDerivedClass and assign values to its fields. MyDerivedClass m1 = new MyDerivedClass(); m1.age = 42; m1.name = "Sam"; // Performs a shallow copy of m1 and assign it to m2. MyDerivedClass m2 = (MyDerivedClass) m1.MemberwiseClone(); } } |
请发表评论