Questions tagged [icloneable]

Questions regarding .NET ICloneable Interface

.NET ICloneable Interface

Supports cloning, which creates a new instance of a class with the same value as an existing instance.

Docs: https://msdn.microsoft.com/en-us/library/system.icloneable%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396

Famous question: Proper way to implement ICloneable

47 questions
1
vote
2 answers

C# stack overflow

I am trying to find out why I am getting a stack overflow exception. I am creating a simple card game for a school assignment and when I clone the cards to return them I get the stack overflow exception. So I got this card class: public class Card :…
Patrick
  • 1,763
  • 5
  • 18
  • 16
0
votes
0 answers

Object remains linked to an array element until object is copied to different element of the array

I have a class to hold test data. I have a main form that puts data into an instance of the test data class. I have another form with a 2D array of data class objects. The main form copies its test data object to an element of the array in the…
russ
  • 65
  • 7
0
votes
2 answers

How to copy List by value and not by reference?

I'm attempting to copy a List but have so far only managed to copy the reference. Can anyone offer a way to do this without creating the original MapIcon object again. I now understand why the methods i've…
AlexS
  • 510
  • 2
  • 7
  • 23
0
votes
1 answer

How can I implement a Clone method on an abstract class without using MemberwiseClone?

I have an abstract base class defined like this: public abstract class BaseItem: INotifyPropertyChanged, ICloneable { // Various Properties... public event public event PropertyChangedEventHandler PropertyChanged; public object…
oaky_afterbirth
  • 125
  • 3
  • 15
0
votes
2 answers

Problem with making a deepcopy using IClonable interface in C#

I'm having a trouble of making a deep copy of an object. I need to make a deep copy of Graph class object. This is my Graph class and Edge class from which Graph is using objects. class Graph : ICloneable { private List edges; …
virouz98
  • 96
  • 8
0
votes
1 answer

vb .net swallow ICloneable implementation

I know there's tons of question on the matter. But I couldn't, for the life of me, make any sense of the answers or use them in my example. I am newish in vb .net and I can't really implement general examples to my specific one. What I have is…
Monochromatic
  • 172
  • 13
0
votes
0 answers

What's the purpose of Clone?

I'm new to C# and working on existing project. I found this clone in all the Data classes, can someone tell me why is it necessary to do this? Any known issues if i don't use clone? Thanks in advance! public class PreviewRequestDetails : ICloneable …
Wreeecks
  • 2,186
  • 1
  • 33
  • 53
0
votes
1 answer

Passing ICloneable Class throws Proxy error

I have a PhoneRecord that is passed to an EditWindow so that a user is able to edit the record. On each PhoneRecord there is a type of CostCode. On the EditWindow I clone a record to break the reference to the SelectedRecord so that in case the user…
CBreeze
  • 2,925
  • 4
  • 38
  • 93
0
votes
3 answers

Looking for Clone() implementation with derived return Type

I am sure this must be a duplicate, but I can't find the answer: If I have two classes: public class BASE { public BASE() {}; public abstract BASE clone(); } public class CHILD : BASE { public CHILD() : base() {} public override…
Philipp
  • 499
  • 5
  • 17
0
votes
2 answers

Cloning an array of objects which implement ICloneable

public class MyStuff : ICloneable { public int A {get;set;} public int B {get;set;} public object Clone() { MyStuff Copy = (MyStuff)MemberwiseClone(); return Copy; } } Now lets assume i have an array of…
CathalMF
  • 9,705
  • 6
  • 70
  • 106
0
votes
1 answer

C# Clone a specialized TreeNode containing another Object of type Object

I have been searching for a simple solution for a cloning of an object containing other objects. public class TPFTestCaseTreeNode: TreeNode, ICloneable { public Object Obj; public TPFTestCaseTreeNode(string Title, Object O) { //…
satyadev
  • 1
  • 4
0
votes
1 answer

C# class, subclases, IClonable, IDisposable

I am working in C# some exercises and I don't understand the big picture. If these should implement in Java I wodn't have problems. But I am new in C# so I mixed up things and I don't know how te structure should look like. I read some explanasions…
0
votes
2 answers

Implementing a custom clone/copy capability: abstract or interface?

As I've learned that it is not advised to implement ICloneable (due to the fact that it does not differentiate between Deep Copy or Shallow Copy), I'm trying to determine whether I should implement it as an abstract or an interface. I feel that my…
Arclight
  • 493
  • 4
  • 18
0
votes
2 answers

Create copy of Object

I need to clone object (class, not struct) in .net 4.5 (c#). I found two ways: Implement ICloneable Interface Create own clone mechanism like this famous SO answer I like fist way - it's easier, but I also found Not Implpement ICloneable…
jimpanzer
  • 3,470
  • 4
  • 44
  • 84
0
votes
2 answers

Should I Implement ICloneable?

I have written some codes and found that two classes (namely Fish and Mammal below) have a same pattern so I decided to sum up with generics. The problem is, I need copy a constructor from the base class part. Also, this can't be fixed using new()…
Jeffrey Goines
  • 935
  • 1
  • 11
  • 30