Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Check for existence of an object?

Reply
Thread Tools

Check for existence of an object?

 
 
CK
Guest
Posts: n/a
 
      03-21-2006
How can I check for the exisitence of an object in C#/Asp.net?
I have a routine that initailizes form values based on a loaded up object,
however if the object hasn't been created I get an Object reference not set
to an instance of an object. Is there a function I can use to see if the
object exists before trying to use it properties?

Thanks for any advice,
Chris




 
Reply With Quote
 
 
 
 
Kevin Spencer
Guest
Posts: n/a
 
      03-21-2006
if (objectName != null) ...

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Show me your certification without works,
and I'll show my certification
*by* my works.

"CK" <(E-Mail Removed)> wrote in message
news:uQXTf.3712$(E-Mail Removed) t...
> How can I check for the exisitence of an object in C#/Asp.net?
> I have a routine that initailizes form values based on a loaded up object,
> however if the object hasn't been created I get an Object reference not
> set to an instance of an object. Is there a function I can use to see if
> the object exists before trying to use it properties?
>
> Thanks for any advice,
> Chris
>
>
>
>



 
Reply With Quote
 
 
 
 
Paul E Collins
Guest
Posts: n/a
 
      03-21-2006
"CK" <(E-Mail Removed)> wrote:

> How can I check for the exisitence of an object in
> C#/Asp.net? [...] if the object hasn't been created
> I get an Object reference not set to an instance of
> an object.


Usually, supposing your object is called "o", you'd just test (o ==
null).

Eq.


 
Reply With Quote
 
CK
Guest
Posts: n/a
 
      03-21-2006
Thanks Guys. I am an idiot but I did figure it out.
I am used to VB. They had an IsNull, IsNothing, and IsObject functions.


"Paul E Collins" <(E-Mail Removed)> wrote in message
news:dvpk0i$d2t$(E-Mail Removed)-infra.bt.com...
> "CK" <(E-Mail Removed)> wrote:
>
>> How can I check for the exisitence of an object in
>> C#/Asp.net? [...] if the object hasn't been created
>> I get an Object reference not set to an instance of
>> an object.

>
> Usually, supposing your object is called "o", you'd just test (o == null).
>
> Eq.
>
>



 
Reply With Quote
 
Lars-Inge Tønnessen \(VJ# MVP\)
Guest
Posts: n/a
 
      03-21-2006

if ( YourObject == null ) return; // Object does not exists. Jump out of
function.
// Statemens if the object exists...


or

if ( YourObject != null )
{
// The object exists, do statemenst.
}

Regards,
Lars-Inge Tønnessen


 
Reply With Quote
 
Lars-Inge Tønnessen \(VJ# MVP\)
Guest
Posts: n/a
 
      03-21-2006
> I am used to VB.

if not YourObject is Nothing Then
// Do VB.NET statements... Your object exists...
End If


Regards,
Lars-Inge Tønnessen


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Check process existence nkammah@yahoo.fr Java 3 04-17-2006 09:28 AM
Check for existence of a tag Tassilo J. Klein XML 9 08-23-2004 01:09 AM
Is it possible to check the existence of a URL in asp.net? TaeHo Yoo ASP .Net 3 10-20-2003 09:14 PM
Is it possible to check the existence of a URL in asp.net? Leon ASP .Net 1 10-17-2003 11:43 PM
XSLT: check existence of a variable Thomas Scheffler XML 0 09-17-2003 10:01 AM



Advertisments