Home c# check if list contains an existing element (not null)
Reply: 0

c# check if list contains an existing element (not null)

user5917
1#
user5917 Published in September 21, 2018, 8:02 am

Is there some equivalent to myTestList.Count that will only count not-nullable fields?

For example I want to do certain things when I know that between some null elements is one existing element.

This is the behaviour I want, but can this be achieved also with pre-existing functions?

if(myList.Count > 0){
    for(int i = 0; i < myList.Count; i++){
        if(myList[i] != null){
            DoSomething();
            break;
        }
    }
}
share|improve this question
  • So you have myList[0] = null, myList[1] = something, myList[2] = null? How do you have a not null in between nulls or did I completely misread this? – gilliduck Feb 12 at 16:15
  • err yes the thing is in unity you can assign elements to fields in the inspector that come after a null element. – Mc Midas Feb 12 at 16:19

2 Answers 2

active oldest votes
up vote 3 down vote accepted
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.330807 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO