Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 494
  • Last Modified:

check to see if var is initialized in c#

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
jrspano
Asked:
jrspano
1 Solution
 
rtenhoveCommented:
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
 
naveenkohliCommented:
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
 
jrspanoAuthor Commented:
thanks that worked.  don't know why I didn't do that to start with???
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now