Click here to Skip to main content
15,917,481 members
Home / Discussions / C#
   

C#

 
QuestionCopy an instance Pin
sjembek31-Jul-06 4:30
sjembek31-Jul-06 4:30 
AnswerRe: Copy an instance Pin
Dustin Metzgar31-Jul-06 4:44
Dustin Metzgar31-Jul-06 4:44 
GeneralRe: Copy an instance Pin
sjembek31-Jul-06 5:50
sjembek31-Jul-06 5:50 
GeneralRe: Copy an instance Pin
Dustin Metzgar31-Jul-06 6:25
Dustin Metzgar31-Jul-06 6:25 
GeneralRe: Copy an instance Pin
sjembek31-Jul-06 6:42
sjembek31-Jul-06 6:42 
AnswerRe: Copy an instance Pin
A.A.31-Jul-06 4:45
A.A.31-Jul-06 4:45 
GeneralRe: Copy an instance Pin
sjembek31-Jul-06 5:35
sjembek31-Jul-06 5:35 
AnswerRe: Copy an instance Pin
LongRange.Shooter31-Jul-06 5:12
LongRange.Shooter31-Jul-06 5:12 
You could do the following:

Make the following changes to your class:

public class MyClass : ICloneable
{
   public MyClass(){}
   public MyClass(object newInstance)
   {
       if ( !(newInstance is MyClass) ) throw new Exception...
       MyClass instance = (MyClass)newInstance;
       // set all properties to the values in the passed instance
   }
   public object Clone
   {
      return (object)this;
   {
}

Then in your code you would do as follows:
...
MyClass newObject = new MyClass(oldObject.Clone());

Unfortunately, there is no ICloneable<t> and object is all you can pass.
AnswerRe: Copy an instance Pin
Judah Gabriel Himango31-Jul-06 5:29
sponsorJudah Gabriel Himango31-Jul-06 5:29 
GeneralRe: Copy an instance Pin
sjembek31-Jul-06 5:52
sjembek31-Jul-06 5:52 
GeneralRe: Copy an instance Pin
sjembek31-Jul-06 6:43
sjembek31-Jul-06 6:43 
AnswerRe: Copy an instance Pin
Libor Tinka31-Jul-06 12:44
Libor Tinka31-Jul-06 12:44 
QuestionRichtext box Ctrl + I Pin
AB777131-Jul-06 3:32
AB777131-Jul-06 3:32 
AnswerRe: Richtext box Ctrl + I Pin
LongRange.Shooter31-Jul-06 4:59
LongRange.Shooter31-Jul-06 4:59 
GeneralRe: Richtext box Ctrl + I Pin
AB777131-Jul-06 17:54
AB777131-Jul-06 17:54 
GeneralRe: Richtext box Ctrl + I Pin
LongRange.Shooter1-Aug-06 8:48
LongRange.Shooter1-Aug-06 8:48 
GeneralRe: Richtext box Ctrl + I Pin
AB77711-Aug-06 18:31
AB77711-Aug-06 18:31 
GeneralRe: Richtext box Ctrl + I Pin
LongRange.Shooter2-Aug-06 12:35
LongRange.Shooter2-Aug-06 12:35 
GeneralRe: Richtext box Ctrl + I Pin
AB77712-Aug-06 17:53
AB77712-Aug-06 17:53 
QuestionProduct Registration and Keys Pin
saamirp31-Jul-06 2:48
saamirp31-Jul-06 2:48 
AnswerRe: Product Registration and Keys Pin
gnjunge31-Jul-06 3:03
gnjunge31-Jul-06 3:03 
AnswerRe: Product Registration and Keys Pin
AB777131-Jul-06 3:20
AB777131-Jul-06 3:20 
GeneralRe: Product Registration and Keys Pin
gnjunge31-Jul-06 4:18
gnjunge31-Jul-06 4:18 
GeneralRe: Product Registration and Keys Pin
AB777131-Jul-06 4:26
AB777131-Jul-06 4:26 
AnswerRe: Product Registration and Keys Pin
Ennis Ray Lynch, Jr.31-Jul-06 4:33
Ennis Ray Lynch, Jr.31-Jul-06 4:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.