There is a List <string> lst
How to check if lst [1] exists?
if (lst != null && lst.Count > 1 && lst[1] != null) { // код }
lst[1]
not necessarily necessary: it is not clear that there is "exists" in the vehicle. Check lst != null
is harmful, because it does not distinguish the normal situation (the list is empty) from the non-fulfillment of the contract (lst == null). I would write this: if (lst == null) throw new ArgumentException ("appropriate description"); bool hasAtIndex1 = lst. Count> 1; - VladDSource: https://ru.stackoverflow.com/questions/203504/
All Articles