Forum guidelines
  • Home
  • »
  • C# Language
  • »
  • C# Adding a Class To List changes all data previously added
AuthorQuestion
C# Adding a Class To List changes all data previously added
Posted By peter uss on 13 Dec 2012
 

C# Adding a Class To A List Of Classes changes all data in previously added Classes.
The new class is added to the list as expected.
But data in every class that has been previously added changes to match the newly added class.

tCardInfo2.Add(new TCardInfoClass(cardType.ToString(),strReqID, true));

public static List<TCardInfoClass> tCardInfo2 = new List<TCardInfoClass>();

public class TCardInfoClass // dragon
    {
       static private string arrayID;
       static private string reqId;
       static private bool visible = false;

      public TCardInfoClass(string ArrayID, string ReqID, bool Visible)
      {
  
     arrayID = ArrayID;
        
reqId = ReqID;
        
visible = Visible;
      
}

    }


AuthorReply
Re: C# Adding a Class To List changes all data previously added
Posted By peter uss on 13 Dec 2012  
       private string arrayID;
       private string reqId;
       private bool visible = false;
Removed static works OK now.
Thanks

Download Free E-books

SPONSORED BY

JetBrains ReSharper Ultimate
.NET code analysis, refactorings, navigation, unit testing, code coverage and profiling in Visual Studio, a bonus for C++ devs, bundled at 50% off.