title: why there are duplicate values in list of circles in c#?
body: <p>I'm writing dijkstra algorithm ,i created a class called circle that it has property </p>
  
  <pre><code>public List&lt;Circle&gt; Circles = new List&lt;Circle&gt;();
  </code></pre>
  
  <p>but it values are duplicate it values initialize with each MouseDoubleClick . for example : properties values Name,Location and selected are duplicate.
  in event <code>pictureBox1_MouseDoubleClick</code> i save all of properties related to circle but As I said values are duplicate.i mean is this line <code>circle.Circles.Add(circle);</code></p>
  
  <p><a href="https://i.stack.imgur.com/0Nizw.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/0Nizw.png" alt="enter image description here"></a></p>
  
  <pre><code>public class Circle
  {
      public List&lt;Circle&gt; Circles = new List&lt;Circle&gt;();
      public List&lt;Rectangle&gt; CircleShape = new List&lt;Rectangle&gt;();
      public string Name { get; set; }
      public Size size = new Size(25, 25);
      public Color normalFillColor = Color.White;
      public Color selectedFillColor = Color.Red;
      public Color borderColor = Color.Gray;
      public int borderWith = 2;
      // public int Diameter { get; set; }
  
      public Point Location { get; set; }
      public bool Selected { get; set; }
  
      public Rectangle Bounds
      {
          get
          {
              return new Rectangle(Location, size);
          }
      }
  
      public void HitTest(Point p)
      {
          //var result = false;
          for (int i = 0; i &lt; CircleShape.Count; i++)
          {
              using (var path = new GraphicsPath())
              {
                  path.AddEllipse(CircleShape[i]);
                  if (path.IsVisible(p))
                  {
                      Circles[i].Selected = true;
                  }
              }
          }
      }
  
      private Font font = new Font("Tahoma", 8, FontStyle.Bold);
  
      public void Draw(Graphics g)
      {
          for (int i = 0; i &lt; CircleShape.Count; i++)
          {
              using (var brush = new SolidBrush(Circles[i].Selected ? selectedFillColor : normalFillColor))
                  g.FillEllipse(brush, CircleShape[i]);
              using (var pen = new Pen(borderColor, 2))
                  g.DrawEllipse(pen, CircleShape[i]);
              TextRenderer.DrawText(g, i.ToString(), font,
                  CircleShape[i], Color.Black,
                  TextFormatFlags.VerticalCenter | TextFormatFlags.HorizontalCenter);
          }
      }
  }
  
      namespace Dijkstra_s_algorithm
  {
      public partial class Form1 : Form
      {
          private List&lt;Rectangle&gt; Shapes = new List&lt;Rectangle&gt;();
          private Circle circle = new Circle();
          int number = 0;
          public int Count { get { return number; } set { number = value; } }
          public Form1()
          {
              InitializeComponent();
              pictureBox1.Paint += new PaintEventHandler(pic_Paint);
          }
  
          private void pic_Paint(object sender, PaintEventArgs e)
          {
              e.Graphics.SmoothingMode = SmoothingMode.AntiAlias;
              Graphics g = e.Graphics;
              circle.Draw(g);
          }
  
          private void pictureBox1_MouseDoubleClick(object sender, MouseEventArgs e)
          {
  
              if (e.Button == MouseButtons.Left)
              {
                  circle.Name = Count.ToString();
                  Location.Offset(-circle.size.Width / 2, -circle.size.Height / 2);
                  circle.Location = e.Location;
                  circle.CircleShape.Add(new Rectangle(circle.Location, circle.size));
                  pictureBox1.Invalidate();
              }
              circle.Circles.Add(circle);
              Count++;
          }
  
  
  
          private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
          {
              if (ModifierKeys != Keys.Control &amp;&amp; e.Button != MouseButtons.Right)
              {
                  return;
              }
              else
              {
  
                  circle.HitTest(e.Location);
  
              }
  
              pictureBox1.Invalidate();
          }
      }
  }
  </code></pre>