-2

I mean, I want to create a new object in base of a exitisng obejct, this is my code, and will be useful like a example:

PictureBox Pic = new PíctureBox();
Pic.Image = Properties.Resources.Theme;
Pic Pic2 = new Pic();
  • Short answer NO. Why you need to do something like this? – Salah Akbari Apr 28 '18 at 19:42
  • To create/duplicate a high number of "Pics" – Sebastián García Apr 28 '18 at 19:46
  • You can use `Array` or `List` and initialize all of them with what you want. – Salah Akbari Apr 28 '18 at 19:47
  • This is called Cloning an object. The PictureBox doesn't implement the [IClonable interface](https://msdn.microsoft.com/en-us/library/system.icloneable%28v=vs.110%29.aspx). And consider also that there are many discussions if this feature is a good or bad practice See [deep cloning vs shallow cloning](https://stackoverflow.com/questions/184710/what-is-the-difference-between-a-deep-copy-and-a-shallow-copy) – Steve Apr 28 '18 at 19:54
  • If you used a collection, you could use something like `Enumerable.Range(new PictureBox { Image = Properties.Resources.Theme }, 10).ToArray()` to get 10 duplicates – Camilo Terevinto Apr 28 '18 at 20:43

1 Answers1

-2

Think that's what you want:

PictureBox Pic = new PíctureBox();
Pic.Image = Properties.Resources.Theme;
PictureBox Pic2 = new PictureBox(Pic);

Just make a constructor to pass all the attributes to the new instance.