forum

Home / DeveloperSection / Forums / How to do this in c#?

How to do this in c#?

Pravesh Singh 1935 09-Dec-2014

I have a List of MyClass and in the main page I have 10 controls which will display the information about that list of Items. What I want is to check the count of the items in the List and then make the excess controls invisible. Now I'm using this code but is there an easier way of doing this?

 

 if (myList.Count > 0)
 {
      Control1.MyClassInfo = myList[0];
      if (myList.Count > 1)
      {
           Control2.MyClassInfo = myList[1];
           if (myList.Count > 2)
           {
                // and like that till 10
           }
           else
           {
                Control3.Visible = false;
                Control4.Visible = false;
                // till 10
           }
       }
       else
       {
           Control2.Visible = false;
           Control3.Visible = false;
           // till 10
       }
  }
  else
  {
       Control1.Visible = false;
       Control2.Visible = false;
       Control3.Visible = false;
       // and then till 10
  }


.net c# 
Updated on 10-Dec-2014

Can you answer this question?


Answer

2 Answers

Liked By