check array value exists
-
i have a function which returns a string array. the array may or may not have value. how to check if the array has any value. In the below code how to check in if codition. i want to keep the looping option as last. I would like to check in 1 line statement. I tried indexof, contain and exits option but all of them are for checking a specific value in array and not to check the whole array if it has any value presence. below is the sample code. main() { string[]victory=war(); if(victory as any value except null) then { } else { } } public string[] war() { step 1..... return some string array }
-
i have a function which returns a string array. the array may or may not have value. how to check if the array has any value. In the below code how to check in if codition. i want to keep the looping option as last. I would like to check in 1 line statement. I tried indexof, contain and exits option but all of them are for checking a specific value in array and not to check the whole array if it has any value presence. below is the sample code. main() { string[]victory=war(); if(victory as any value except null) then { } else { } } public string[] war() { step 1..... return some string array }
-
i have a function which returns a string array. the array may or may not have value. how to check if the array has any value. In the below code how to check in if codition. i want to keep the looping option as last. I would like to check in 1 line statement. I tried indexof, contain and exits option but all of them are for checking a specific value in array and not to check the whole array if it has any value presence. below is the sample code. main() { string[]victory=war(); if(victory as any value except null) then { } else { } } public string[] war() { step 1..... return some string array }
Try:
if (victory != null && victory.Length > 0)
{
...
}You looking for sympathy? You'll find it in the dictionary, between sympathomimetic and sympatric (Page 1788, if it helps)
-
Use
array.Any()
. It's an extension method to
IEnumerable<>
if(array.Any(a => a!=null) ){
// there's a non-null object here
}http://msdn.microsoft.com/en-us/library/vstudio/bb337697(v=vs.100).aspx[^]
its working. cheers J.