0

So I have a list(panelList) that I created and I inserted 10 Panel controls (which are already created on the aspx design page).. However, when I try and check if panelList[0] is the same panel as Panel1(which is the first panel I added in panelList), I get returned FALSE... any idea why? Here is my code


 static List<Panel> panelList = new List<Panel>();
 protected void Page_Load(object sender, EventArgs e)
 {
 if (!IsPostBack) 
        {
            panelList.Add(Panel1);
            panelList.Add(Panel2);
            panelList.Add(Panel3);
            panelList.Add(Panel4);
            panelList.Add(Panel5);
            panelList.Add(Panel6);
            panelList.Add(Panel7);
            panelList.Add(Panel8);
            panelList.Add(Panel9);
            panelList.Add(Panel10);
         } 
  }  

   protected void AddQuestionButton_Click(object sender, EventArgs e)
      {    
       Debug.WriteLine(panelList[0].Equals(Panel1));
      // here i get returned false in the debug output
      }

1 Answers1

1

You should consider How to compare 2 object in c#, There are some ways to achieve this

  1. Implement IEquatable<T>
  2. Serialize both objects then compare them as string result

BTW, this link is helpful for you.

Nguyễn Văn Phong
  • 13,506
  • 17
  • 39
  • 56