People is a dictionary, usingPeople clonedPeople=new People(MyContent.val);will not give your a deeply cloned object, you probably should do (what is the MyContent stuff??)People clonedPeople=new People(MyContent.val);foreach (DictionaryEntry de in this)
{
     clonedPeople.Add(de.Key, de.Value);
}return clonedPeople;

解决方案 »

  1.   

    to思归:
    我在我的code中加了你的代码后,调试出错:
    J:\learnvc#\my\chap11\people\people.cs(99): 与“people.People.Add(string, people.Person)”最匹配的重载方法具有一些无效参数
    J:\learnvc#\my\chap11\people\people.cs(99): 参数“1”(参数1为de.Key) : 无法从“object”转换为“string”
    J:\learnvc#\my\chap11\people\people.cs(99): 参数“2”(参数2为de.Value) : 无法从“object”转换为“people.Person”MyContent是我仿照书上的写法写的,我不知道这儿该如何实现深度复制,试着写的......
      

  2.   

    foreach (DictionaryEntry de in this)
    {
         clonedPeople.Add((String)de.Key, (Person)de.Value);
    }
      

  3.   

    谢思归,我刚在msdn 2003和.net framework SDK 1.1里面用深度复制做关键字搜索,居然没有找到一个相关主题,晕死,这是为什么,难道深度复制在c#里是一个无关紧要的method?
      

  4.   

    for 深度复制, you are talking about cloning object instances, that is not a preferred way in .NET, but seeAn insight into cloning objects in .NET
    http://www.codeproject.com/dotnet/Clone.aspBase class for cloning an object in C#
    http://www.codeproject.com/csharp/cloneimpl_class.asp