Solved

check to see if var is initialized in c#

Posted on 2002-04-12
3
465 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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 be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

791 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