jeudi 16 juillet 2020

c# generic if statement

I have 4 lists. some of them filled with data and some of them empty. i want to make a if statement which will consider only the lists which has elements, if a list empty, i dont want to see it in if condition.


            List<int> list1 = new List<int> {1,2,3 };
            List<string> list2 = new List<string>();
            List<string> list3 = new List<string> { "cc", "cc", "cc" };
            List<string> list4 = new List<string> { "dd", "dd", "dd" };
             

            if (list1.Contains(1) && list2.Contains("bb") && list3.Contains("cc") && list4.Contains("dd"))
            {
                MessageBox.Show("condition okey");
            }

as you see in the code example, the list2 is empty, and i dont want to include it inside the if statement. i fill these lists from Database. and i dont know, which one will be empty.

how can i write a generic if statement. thank you.

Aucun commentaire:

Enregistrer un commentaire