Guilio
You can also check by using the == operator.
For example:
using System;
class nullcheck
{
private static Foo f;
[STAThread]
static void Main(string[] args)
{
// f = new Foo();
if (f == null)
Console.WriteLine("Foo is not initialized!!!");
else
Console.WriteLine("Foo is initialized.");
return;
}
}
class Foo
{
public int x = -1;
public Foo()
{
x = 5;
}
}
Cheers,
Christian T. [MSFT]
Visual Studio Update Team
- Please do not reply to this email directly. This email is for newsgroup
purposes only.
================================================== =======================
This posting is provided "AS IS" with no warranties, and confers no
rights. Use of included script samples are subject to the terms specified
at
http://www.microsoft.com/info/cpyright.htm
Note: For the benefit of the community-at-large, all responses to this
message are best directed to the newsgroup/thread from which
they originated.
================================================== =======================
--------------------
Date: Wed, 12 Nov 2003 22:28:51 +0100
From: Giulio Mastrosanti <gi****@cantoberon.it>
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.4)
Gecko/20030624 Netscape/7.1 (ax)X-Accept-Language: en-us, en
MIME-Version: 1.0
Subject: check if object is null
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
Message-ID: <uL**************@TK2MSFTNGP11.phx.gbl>
Newsgroups: microsoft.public.dotnet.general
NNTP-Posting-Host: 217.220.125.116
Lines: 1
Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP11.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.general:115445
X-Tomcat-NG: microsoft.public.dotnet.general
How can I check if a declared object in not initialized yet with a new
command?
is catching the exception while accessing it the only way?
thanx