Click here to Skip to main content
12,555,711 members (49,618 online)
Rate this:
Please Sign up or sign in to vote.
See more: C#
Hey I have an array of class:
Empty = new EmptyPage[100];
for (int i = 0; i < 100; i++)
    Empty[i] = null;

If I do: if(Empty[0]==null) ==> always returns false;

What is the best way to check if an object is not defined or it is null?
Posted 25-Dec-12 2:35am
Zoltán Zörgő 25-Dec-12 8:49am
But it should work like this. What's the rest of the code?
missak boyajian 25-Dec-12 12:38pm
Thanks. There was something wrong in the code.
GeekBond 25-Dec-12 8:58am
What is 'Empty'?
Oleksandr Kulchytskyi 25-Dec-12 9:02am
I don't believe you!! if(Empty[0]==null) must work!!!
Oleksandr Kulchytskyi 25-Dec-12 9:03am
Empty = new EmptyPage[100];??? Provide community with full list of code!!!
rizwan muhammed khan gouri 22-Jan-13 8:51am
Hello paste Your Complete code ??????????/
missak boyajian 22-Jan-13 14:54pm
Hey it was working. The problem was elsewhere.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Your code looks ok.

To check for null you can always look at the null coalese operator[^].
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

apply If Else
Sergey Alexandrovich Kryukov 25-Dec-12 15:40pm
I cannot believe that someone else will be able to suggest such gibberish.
The answer is: someObject == null. I'm really sorry, Dheerendra, but the vote is 1...
By the way, in general case, ReferencesEqual should be used, as equality can be overridden.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.161021.1 | Last Updated 21 Jan 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100