A aaa Feb 17, 2005 #1 I know in VB we had IsObject ut how do I check an object to see if it exists in sharp (without bombing the if)?
I know in VB we had IsObject ut how do I check an object to see if it exists in sharp (without bombing the if)?
J Jon Skeet [C# MVP] Feb 17, 2005 #2 aaa said: I know in VB we had IsObject ut how do I check an object to see if it exists in sharp (without bombing the if)? Click to expand... Test the expression for null: if (x==null) { .... }
aaa said: I know in VB we had IsObject ut how do I check an object to see if it exists in sharp (without bombing the if)? Click to expand... Test the expression for null: if (x==null) { .... }
M MuZZy Feb 17, 2005 #3 aaa said: I know in VB we had IsObject ut how do I check an object to see if it exists in sharp (without bombing the if)? Click to expand... If an object variable doesn't reference a live object, it wll always be = null. So if you want to use construct similar to vb, define a func: bool IsObject(object ob) { return ob != null; } or just check inline using if ob == null
aaa said: I know in VB we had IsObject ut how do I check an object to see if it exists in sharp (without bombing the if)? Click to expand... If an object variable doesn't reference a live object, it wll always be = null. So if you want to use construct similar to vb, define a func: bool IsObject(object ob) { return ob != null; } or just check inline using if ob == null