Skip to content

C# Adding a Class To List changes all data previously added

peter uss

Asked Dec 13, 2012, 10:24 AM EST1 answer
Share
LinkedInX
 

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.

C#
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;
      }
    }

1 Answer

Know the answer? Post it. Somebody with the same question will find it here.

  • 0
           private string arrayID;
           private string reqId;
           private bool visible = false;
    Removed static works OK now.
    Thanks
    0