Solved

check to see if var is initialized in c#

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
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…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.

706 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now