title: C# - Variable values changes after it's executed
body: <p>Can someone help me with this code?</p>
  
  <p>EDIT: <strong>Path is 2 points that form the last straight last line.</strong></p>
  
  <p>Basically I want to draw BLUE the last <code>profundidadePinca</code> {0 to profundidadePinca} if the path is bigger than it's value and the rest <code>TubeConfig.OutsideColor</code> . Otherwise if it's smaller than <code>profundidadePinca</code> just draw it <code>TubeConfig.OutsideColor</code>;</p>
  
  <p>PROBLEM: It's drawing Blue on top of the <code>TubeConfig.OutsideColor</code></p>
  
  <p><a href="https://i.stack.imgur.com/6GWn0.png" rel="nofollow noreferrer">Image of my 3D view</a></p>
  
  <pre><code> Point3DCollection remaining = new Point3DCollection();
  
          TubeVisual3D tubeRemain = new TubeVisual3D();
          tubeRemain.Path = new Point3DCollection(finalPointsTube.ToList().GetRange(remain.idxStart, remain.idxEnd - remain.idxStart + 1));
          if (profundidadePinca &lt; (tubeRemain.Path[1].X - tubeRemain.Path[0].X))
          {
              remaining = tubeRemain.Path;              
              tubeRemain.Path[1] = new Point3D(profundidadePinca, tubeRemain.Path[1].Y, tubeRemain.Path[1].Z);
          }
          tubeRemain.Diameter = TubeConfig.Diameter;
          tubeRemain.IsPathClosed = false;
          tubeRemain.IsSectionClosed = false;
          tubeRemain.Fill = new SolidColorBrush(TubeConfig.OutsideColor);
          tubeRemain.Material = new DiffuseMaterial(new SolidColorBrush((Color)ColorConverter.ConvertFromString("#1b74c2")));
          Group.Children.Add(tubeRemain);
  
          if (profundidadePinca &lt; (remaining[1].X - remaining[0].X))
          {
          TubeVisual3D tubeRemainClamp = new TubeVisual3D();
  
          var tubeEnding = finalPointsTube[remain.idxEnd].X;
          tubeRemainClamp.Path = new Point3DCollection(finalPointsTube.ToList().GetRange(remain.idxStart, remain.idxEnd - remain.idxStart + 1));
  
          tubeRemainClamp.Path[0] = new Point3D(profundidadePinca, tubeRemainClamp.Path[0].Y, tubeRemainClamp.Path[0].Z);
  
          tubeRemainClamp.Diameter = TubeConfig.Diameter;
          tubeRemainClamp.IsPathClosed = false;
          tubeRemainClamp.IsSectionClosed = false;
          tubeRemainClamp.Fill = new SolidColorBrush(TubeConfig.OutsideColor);
          tubeRemainClamp.Material = new DiffuseMaterial(new SolidColorBrush(TubeConfig.OutsideColor));
          Group.Children.Add(tubeRemainClamp);
      }
  </code></pre>
  
  <p>One other thing I dont get:</p>
  
  <pre><code> remaining = tubeRemain.Path;              
   tubeRemain.Path[1] = new Point3D(profundidadePinca, tubeRemain.Path[1].Y, tubeRemain.Path[1].Z);
  </code></pre>
  
  <p>I'm trying to save <code>tubeRemain.Path</code> before changing it's value. It works but <code>remaining</code> <strong>changes value when the second line is executed. What the hell?</strong></p>