473,406 Members | 2,467 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,406 software developers and data experts.

Coding Nothing in C#

I have the following code in VB that needs to be done in C#
Dim o As New Company.Common.QueueItem

o.OrderID = 123456789

o.QueueItemType = Company.Common.QueueItemType.StockOrder

Dim oDispatch As New Company.Queuing.CompanyDispatchQueue(Nothing)

oDispatch.Dispatch(o, True)

I have created the following code in C#, but I am getting a Null Exception
when running it:

queue=new Company.Common.QueueItem();

queue.OrderID=123456789;

queue.QueueItemType=Company.Common.QueueItemType.R efill;

dispatch=new Company.Queuing.CompanyDispatchQueue(null);

dispatch.Dispatch(queue,true);

The definition of Nothing in VB is: Represents the default value of any data
type

Whereas Null in C# is: The null keyword is a literal that represents a null
reference, one that does not refer to any object

What can I use in subtitute of Nothing in C# in this instance?
Nov 27 '06 #1
7 17130
Hi,
What can I use in subtitute of Nothing in C# in this instance?
"Nothing" and "null" are semantically equivalent for reference types and
will produce the same CIL. For value types, null in C# cannot be used but
Nothing in VB.NET will provide the default value, AFAIK.

Assuming that the exception is being thrown on the line that calls the
CompanyDispatchQueue constructor, the argument is a reference type, and that
the exception is an ArgumentNullException being thrown because of the "null"
argument that you have supplied, then I must assume that the VB.NET code
will fail as well.

--
Dave Sexton

"Eric Stott" <er*******@nospam.nospamwrote in message
news:uc**************@TK2MSFTNGP04.phx.gbl...
>I have the following code in VB that needs to be done in C#
Dim o As New Company.Common.QueueItem

o.OrderID = 123456789

o.QueueItemType = Company.Common.QueueItemType.StockOrder

Dim oDispatch As New Company.Queuing.CompanyDispatchQueue(Nothing)

oDispatch.Dispatch(o, True)

I have created the following code in C#, but I am getting a Null Exception
when running it:

queue=new Company.Common.QueueItem();

queue.OrderID=123456789;

queue.QueueItemType=Company.Common.QueueItemType.R efill;

dispatch=new Company.Queuing.CompanyDispatchQueue(null);

dispatch.Dispatch(queue,true);

The definition of Nothing in VB is: Represents the default value of any
data type

Whereas Null in C# is: The null keyword is a literal that represents a
null reference, one that does not refer to any object

What can I use in subtitute of Nothing in C# in this instance?


Nov 27 '06 #2
Since I don't have access to the underlying code, this is the argument:
Company.Queuing.CompanyDispatchQueue(System.Compon entModel.ISyncronizeInvoke
HostForm)

and Nothing works in the case of VB.

So you are saying that Null should work in this case?

"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
Hi,
>What can I use in subtitute of Nothing in C# in this instance?

"Nothing" and "null" are semantically equivalent for reference types and
will produce the same CIL. For value types, null in C# cannot be used but
Nothing in VB.NET will provide the default value, AFAIK.

Assuming that the exception is being thrown on the line that calls the
CompanyDispatchQueue constructor, the argument is a reference type, and
that the exception is an ArgumentNullException being thrown because of the
"null" argument that you have supplied, then I must assume that the VB.NET
code will fail as well.

--
Dave Sexton

"Eric Stott" <er*******@nospam.nospamwrote in message
news:uc**************@TK2MSFTNGP04.phx.gbl...
>>I have the following code in VB that needs to be done in C#
Dim o As New Company.Common.QueueItem

o.OrderID = 123456789

o.QueueItemType = Company.Common.QueueItemType.StockOrder

Dim oDispatch As New Company.Queuing.CompanyDispatchQueue(Nothing)

oDispatch.Dispatch(o, True)

I have created the following code in C#, but I am getting a Null
Exception when running it:

queue=new Company.Common.QueueItem();

queue.OrderID=123456789;

queue.QueueItemType=Company.Common.QueueItemType. Refill;

dispatch=new Company.Queuing.CompanyDispatchQueue(null);

dispatch.Dispatch(queue,true);

The definition of Nothing in VB is: Represents the default value of any
data type

Whereas Null in C# is: The null keyword is a literal that represents a
null reference, one that does not refer to any object

What can I use in subtitute of Nothing in C# in this instance?



Nov 27 '06 #3
Since I don't have access to the underlying code, this is the
argument:
Company.Queuing.CompanyDispatchQueue(System.Compon entModel.ISyncronize
Invoke HostForm)

and Nothing works in the case of VB.

So you are saying that Null should work in this case?
yes

Best Regards,
Dustin Campbell
Developer Express Inc.
Nov 27 '06 #4
Hi,
and Nothing works in the case of VB.

So you are saying that Null should work in this case?
From your response I take it that my assumptions were all accurate, so
unless the context in which the code is executed makes a difference, then
yes.

You can verify whether the constructor is throwing the ArgumentNullException
because of the null reference you are supplying by taking a peek at the
source code in Reflector:

"Lutz Roeder's Programming .NET" (first item in list is Reflector)
http://www.aisto.com/roeder/dotnet/

--
Dave Sexton

"Eric Stott" <er*******@nospam.nospamwrote in message
news:OD**************@TK2MSFTNGP03.phx.gbl...
Since I don't have access to the underlying code, this is the argument:
Company.Queuing.CompanyDispatchQueue(System.Compon entModel.ISyncronizeInvoke
HostForm)

and Nothing works in the case of VB.

So you are saying that Null should work in this case?

"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>Hi,
>>What can I use in subtitute of Nothing in C# in this instance?

"Nothing" and "null" are semantically equivalent for reference types and
will produce the same CIL. For value types, null in C# cannot be used
but Nothing in VB.NET will provide the default value, AFAIK.

Assuming that the exception is being thrown on the line that calls the
CompanyDispatchQueue constructor, the argument is a reference type, and
that the exception is an ArgumentNullException being thrown because of
the "null" argument that you have supplied, then I must assume that the
VB.NET code will fail as well.

--
Dave Sexton

"Eric Stott" <er*******@nospam.nospamwrote in message
news:uc**************@TK2MSFTNGP04.phx.gbl...
>>>I have the following code in VB that needs to be done in C#
Dim o As New Company.Common.QueueItem

o.OrderID = 123456789

o.QueueItemType = Company.Common.QueueItemType.StockOrder

Dim oDispatch As New Company.Queuing.CompanyDispatchQueue(Nothing)

oDispatch.Dispatch(o, True)

I have created the following code in C#, but I am getting a Null
Exception when running it:

queue=new Company.Common.QueueItem();

queue.OrderID=123456789;

queue.QueueItemType=Company.Common.QueueItemType .Refill;

dispatch=new Company.Queuing.CompanyDispatchQueue(null);

dispatch.Dispatch(queue,true);

The definition of Nothing in VB is: Represents the default value of any
data type

Whereas Null in C# is: The null keyword is a literal that represents a
null reference, one that does not refer to any object

What can I use in subtitute of Nothing in C# in this instance?




Nov 27 '06 #5
'Nothing' in VB is a strange beast - it is the equivalent of the C# 'null'
plus more.
If the parameter of the method is a value type, then 'Nothing' gets compiled
to be the default or freshly-constructed value type instance. If the value
type of the parameter is 'foo', then you can pass "new foo()" to get the same
result as the VB code.
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
Instant C++: C#/VB to C++ converter
Instant Python: VB to Python converter
"Eric Stott" wrote:
I have the following code in VB that needs to be done in C#
Dim o As New Company.Common.QueueItem

o.OrderID = 123456789

o.QueueItemType = Company.Common.QueueItemType.StockOrder

Dim oDispatch As New Company.Queuing.CompanyDispatchQueue(Nothing)

oDispatch.Dispatch(o, True)

I have created the following code in C#, but I am getting a Null Exception
when running it:

queue=new Company.Common.QueueItem();

queue.OrderID=123456789;

queue.QueueItemType=Company.Common.QueueItemType.R efill;

dispatch=new Company.Queuing.CompanyDispatchQueue(null);

dispatch.Dispatch(queue,true);

The definition of Nothing in VB is: Represents the default value of any data
type

Whereas Null in C# is: The null keyword is a literal that represents a null
reference, one that does not refer to any object

What can I use in subtitute of Nothing in C# in this instance?
Nov 27 '06 #6
Hi Eric,

null will work, but Null wont. Remember: C# is case sensitive.
If null doesn't work, because the parameter is of a value-type, you will get
a compiler error. So if it compiles, yes it works.
If it really is a value-type, and you don't know the default value of that
type "new TypeName()" will work, because this gives the default value of the
type.

"Eric Stott" <er*******@nospam.nospamschrieb im Newsbeitrag
news:OD**************@TK2MSFTNGP03.phx.gbl...
Since I don't have access to the underlying code, this is the argument:
Company.Queuing.CompanyDispatchQueue(System.Compon entModel.ISyncronizeInvoke
HostForm)

and Nothing works in the case of VB.

So you are saying that Null should work in this case?

"Dave Sexton" <dave@jwa[remove.this]online.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
>Hi,
>>What can I use in subtitute of Nothing in C# in this instance?

"Nothing" and "null" are semantically equivalent for reference types and
will produce the same CIL. For value types, null in C# cannot be used
but Nothing in VB.NET will provide the default value, AFAIK.

Assuming that the exception is being thrown on the line that calls the
CompanyDispatchQueue constructor, the argument is a reference type, and
that the exception is an ArgumentNullException being thrown because of
the "null" argument that you have supplied, then I must assume that the
VB.NET code will fail as well.

--
Dave Sexton

"Eric Stott" <er*******@nospam.nospamwrote in message
news:uc**************@TK2MSFTNGP04.phx.gbl...
>>>I have the following code in VB that needs to be done in C#
Dim o As New Company.Common.QueueItem

o.OrderID = 123456789

o.QueueItemType = Company.Common.QueueItemType.StockOrder

Dim oDispatch As New Company.Queuing.CompanyDispatchQueue(Nothing)

oDispatch.Dispatch(o, True)

I have created the following code in C#, but I am getting a Null
Exception when running it:

queue=new Company.Common.QueueItem();

queue.OrderID=123456789;

queue.QueueItemType=Company.Common.QueueItemType .Refill;

dispatch=new Company.Queuing.CompanyDispatchQueue(null);

dispatch.Dispatch(queue,true);

The definition of Nothing in VB is: Represents the default value of any
data type

Whereas Null in C# is: The null keyword is a literal that represents a
null reference, one that does not refer to any object

What can I use in subtitute of Nothing in C# in this instance?




Nov 28 '06 #7
Thanks everyone for their input, what I have done is created a function in
VB where I send the OrderId and I call it from C#. It looks like the
underlying code is incorrect, because when I call it from VB, it still gives
me the error that I have been seeing in C#.
Thanks,
Eric
"Eric Stott" <er*******@nospam.nospamwrote in message
news:uc**************@TK2MSFTNGP04.phx.gbl...
>I have the following code in VB that needs to be done in C#
Dim o As New Company.Common.QueueItem

o.OrderID = 123456789

o.QueueItemType = Company.Common.QueueItemType.StockOrder

Dim oDispatch As New Company.Queuing.CompanyDispatchQueue(Nothing)

oDispatch.Dispatch(o, True)

I have created the following code in C#, but I am getting a Null Exception
when running it:

queue=new Company.Common.QueueItem();

queue.OrderID=123456789;

queue.QueueItemType=Company.Common.QueueItemType.R efill;

dispatch=new Company.Queuing.CompanyDispatchQueue(null);

dispatch.Dispatch(queue,true);

The definition of Nothing in VB is: Represents the default value of any
data type

Whereas Null in C# is: The null keyword is a literal that represents a
null reference, one that does not refer to any object

What can I use in subtitute of Nothing in C# in this instance?


Nov 28 '06 #8

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

Similar topics

8
by: s.subbarayan | last post by:
Dear all, In one of our projects in a document about C coding standard it is stated as "Always check a pointer is NULL before calling free. Always set a free'd pointer to NULL to try to protect...
7
by: Ralph Lund | last post by:
Hi. I am starting a new project with C#. I am searching for "good" coding conventions. I know that there are some coding conventions from microsoft, (but they are very extensive and not clear)....
16
by: TT (Tom Tempelaere) | last post by:
Hi Topic 3.21 in <http://www.idesign.net/idesign/download/IDesign%20CSharp%20Coding%20Standard.zip> claims the following "Release build should contain debug symbols I wonder why. Doesn't...
4
by: Josh Golden | last post by:
i lead a small development team (based on some of my posts that might cause some people to choke themselves, but have no fear, i am NOT the lead developer, the people on my team are great - i'm...
3
by: Anusha H via DotNetMonster.com | last post by:
Hello there, I simply need to import a text file into a sql table. Text file is fixed width and i know the column widths. Will anyone give me the exact coding in vb.net by using DTS please. Your...
50
by: Konrad Palczynski | last post by:
I am looking for tool to validate conformity to defined coding standard. I have already found Parasoft's C++ Test, but it is quite expensive. Is there any Open Source alternative? I do not need...
17
by: M.Siler | last post by:
I'm trying to get my head around a conversation I had with a developer the other day. We were talking about Codesmith vs. Hand coding. He's position is Codesmith is for junior to mid level...
7
by: Robert Seacord | last post by:
The CERT/CC has just deployed a new web site dedicated to developing secure coding standards for the C programming language, C++, and eventually other programming language. We have already...
19
by: auratius | last post by:
http://www.auratius.co.za/CSharpCodingStandards.html Complete CSharp Coding Standards 1. Naming Conventions and Styles 2. Coding Practices 3. Project Settings and Project Structure 4....
27
by: dennis1989 | last post by:
Im having problem running the program. Its say i have incorrect syntax at my strsql coding Private Sub ComboBox1_Change() Dim rst As ADODB.Recordset 'Initialize Recordset ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.