S
S
sivabur2015-10-12 19:26:06
Java
sivabur, 2015-10-12 19:26:06

How to check many variables for null?

Perhaps there is some kind of function that if at least one null element returned false
Or if there is at least one element in the array, it did a coexisting check.
Interested in how to do this in C # and Java.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
Z
Zelimkhan Beltoev, 2015-10-12
@sivabur

In principle, you can do the check yourself:

bool Check<T>(params T[] values)
        {
            return values.All(val => val != null);
        }

G
GavriKos, 2015-10-12
@GavriKos

Where are the variables? In a class, in an array, in a struct?

R
ruboss, 2015-10-12
@ruboss

Alternatively, you can grab it already during execution -

try{
         //your code here 
}
catch(NullPointerException e)
{
         e.printStackTrace();
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question