Solved

check to see if var is initialized in c#

Posted on 2002-04-12
3
468 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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

Title # Comments Views Activity
Writing a parser for java language 4 91
How to copy an image file into clipboard C/C++? 1 217
thread-safe code in c++ 2 120
Coding for the first time 9 62
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…
This article will show you some of the more useful Standard Template Library (STL) algorithms through the use of working examples.  You will learn about how these algorithms fit into the STL architecture, how they work with STL containers, and why t…
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.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

762 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