473,396 Members | 1,886 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Check for existence of an object?

CK
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


Mar 21 '06 #1
5 956
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" <c_**********@hotmail.com> wrote in message
news:uQ*****************@newssvr27.news.prodigy.ne 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

Mar 21 '06 #2
"CK" <c_**********@hotmail.com> 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.
Mar 21 '06 #3
CK
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" <fi******************@CL4.org> wrote in message
news:dv**********@nwrdmz03.dmz.ncs.ea.ibs-infra.bt.com...
"CK" <c_**********@hotmail.com> 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.

Mar 21 '06 #4

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
Mar 21 '06 #5
> 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
Mar 21 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Nicolas Fleury | last post by:
Hi everyone, I'm wondering what is the easiest/cleanest way to look for existence of available methods/members. For example, in parsing a xml file, created objects can define a setXmlFilename...
6
by: McKirahan | last post by:
Is this a very good browser check? <html> <head> <title>wB.htm</title> <script type="text/javascript"> var adBtype = "??"; function wB() { if (document.getElementById && !document.all) {...
25
by: pamelafluente | last post by:
Hi Guys, I have the following HTML code which is doing a GET to a page, say MyUrl.aspx : <body> <form name="form1" method="get" action="MyUrl.aspx" id="form1"> <input type="hidden"...
10
by: Dieter Pelz | last post by:
Hallo, what is the best way to check the installation of mfc80 and vcrt sidebyside assemblies? Best Regards, Dieter Pelz
2
by: DesCF | last post by:
I have a textbox and a combobox on a toolstrip. The user enters either an ID in the textbox or selects a name from the combobox. When the user selects a name from the combobox the textbox is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.