473,395 Members | 1,756 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Check before calling a method on a potentially null object.

Rather than...

if ( myInstance != null )
{
myInstance.Dispose();
}

maybe something like this...

myInstance?Dispose();

where ? = potentially null operator (question mark is the first symbol that
came to mind)

Just wondering if there's anything like this, going to be anything like
this, or am I being ridiculous.

BTW Please don't post comments about using the IDisposable pattern, this is
just an example.

Glenn
Jul 6 '07 #1
2 5949
Glenn,

No, there is no operator that does this.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Glenn" <gl**********@yahoo.co.ukwrote in message
news:eq**************@TK2MSFTNGP03.phx.gbl...
Rather than...

if ( myInstance != null )
{
myInstance.Dispose();
}

maybe something like this...

myInstance?Dispose();

where ? = potentially null operator (question mark is the first symbol
that came to mind)

Just wondering if there's anything like this, going to be anything like
this, or am I being ridiculous.

BTW Please don't post comments about using the IDisposable pattern, this
is just an example.

Glenn

Jul 6 '07 #2
PS

"Glenn" <gl**********@yahoo.co.ukwrote in message
news:eq**************@TK2MSFTNGP03.phx.gbl...
Rather than...

if ( myInstance != null )
{
myInstance.Dispose();
}

maybe something like this...

myInstance?Dispose();

where ? = potentially null operator (question mark is the first symbol
that came to mind)
One way to avoid null checking is to not create objects that are null in the
first place. You can look into the Null Object pattern to see if it would
fit your situation.

PS
>
Just wondering if there's anything like this, going to be anything like
this, or am I being ridiculous.

BTW Please don't post comments about using the IDisposable pattern, this
is just an example.

Glenn

Jul 7 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Randell D. | last post by:
Folks, I've heard of buffer overflows being used/abused by hackers and believe one method to reduce this from happening is to check the length of my form data before writing it to my MySQL...
2
by: Ken Durden | last post by:
I'm setting up an interface where clients must perform external locking before calling certain commands. I do this to force them to specify the duration the action they performed must persist...
7
by: JJ | last post by:
Hi, I call a class in my windows service app and in that class I access a method that returns an OleDbReader. Now It does have records in the reader when I step through the method but when I...
2
by: Daniel Lidström | last post by:
I'm using a library called fyba. This library reads and writes files in a format called sosi. fyba uses the following code to determine if the calling process has own methods to handle errors,...
6
by: Mirek Endys | last post by:
Hello all, another problem im solving right now. I badly need to get typeof object that called static method in base classe. I did it by parameter in method Load, but i thing there should be...
4
by: Edwin Gomez | last post by:
I'm a C# developer and I'm new to Python. I would like to know if the concept of Asynchronous call-backs exists in Python. Basically what I mean is that I dispatch a thread and when the thread...
30
by: Jess | last post by:
Hello, I tried a program as follows: include<iostream> using namespace std; class A{ public:
1
by: amgupta8 | last post by:
Note: This problem occurred when I updated the JDK from 1.3.1 to 1.4.1 or 1.4.2. Nothing else was changed in the code, other than updating the JDK on the database server (dbm cfg parm jdk_path) and...
15
by: =?Utf-8?B?VG9tIENvcmNvcmFu?= | last post by:
I've been led to believe by several articles, particularly Eric Gunnerson's C# Calling Code Dynamically, that calling a method dynamically through Reflection was much slower than through a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.