+ 2
How to check several strings with operator ||(or)
I have several strings and I need to check for null with operator ||. For example: if (!String.IsNullOrEmpty(string1) || !String.IsNullOrEmpty(string2) || !String.IsNullOrEmpty(string3) || !String.IsNullOrEmpty(string4) || !String.IsNullOrEmpty(string5) || ...) { //something } Is there a more flexible way to do this?
4 Respuestas
+ 3
Zakaria, it looks like a workaround. Have you got any idea? Is there some functions? It will be better without loops.
+ 2
Brains thanks, but it's not that.
1. My strings have different names.
2. If I have some variables for iteration into my statement. For example:
{ b++;
My_int++; }
And after looping It will be increased several times instead of one time.
b = 10 instead of b=1
+ 1
for(int i=0;i<strings.length;i++){
if(!String.isNullorEmpty(strings[i])){
//do stuff }
}
All strings should be in an array
+ 1
according to NG brains answer .
you can do this .
for(int i=0;i<strings.length;i++){
if(!String.isNullorEmpty(strings[i])){
//do stuff
break;
}
}
All strings should be in an array