Solved

check to see if var is initialized in c#

Posted on 2002-04-12
3
458 Views
Last Modified: 2006-11-17
I didn't see a C# category, so I'll ask here.
If I have a variable in c# as an xmldocument, I want to know if it has been initialized or not with a constructor.  in the debug window it is set to nothing until it is initialized.  How do you check for that in code?
0
Comment
Question by:jrspano
3 Comments
 

Expert Comment

by:rtenhove
ID: 6938123
You'd probably do better in the Java forum, since C# is more closely related to Java than C/C++.

At a guess, I'd say you want something like:

if (var == null)
{
    // ... whatever.
}
else
{
    // safe to use var.
}
0
 
LVL 23

Accepted Solution

by:
naveenkohli earned 50 total points
ID: 6938148
every variable that is of type class, is initialized to null unless you explictly initialize it caling new. XmlDocument object will also be null. so as rtenhove said... check if it == null or not.
0
 
LVL 3

Author Comment

by:jrspano
ID: 6951335
thanks that worked.  don't know why I didn't do that to start with???
0

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question