void vs. System::Void

M

Marcus Kwok

Is there a difference between using the C++ keyword "void" and using
"System::Void" when specifying parameters and return types? Is there a
preference when choosing between the two? In the code I'm working on,
the original author uses both, and I don't understand if there is a
specific reason to choose one over the other in certain situations.
 
B

Brandon Bray [MSFT]

Marcus said:
Is there a difference between using the C++ keyword "void" and using
"System::Void" when specifying parameters and return types? Is there a
preference when choosing between the two? In the code I'm working on,
the original author uses both, and I don't understand if there is a
specific reason to choose one over the other in certain situations.

Hey Marcus!
Both 'void' and 'System::Void' do exactly the same thing. You can
substitute one for the other in all situations (even to access static
methods of the System::Void class like "void::ReferenceEquals(a,b);").

Brandon
 
M

Marcus Kwok

Brandon Bray said:
Hey Marcus!
Both 'void' and 'System::Void' do exactly the same thing.

Hi Brandon,
Thanks for your response. Based on this, I will go ahead and change
them all to just plain "void" for consistency.
You can
substitute one for the other in all situations (even to access static
methods of the System::Void class like "void::ReferenceEquals(a,b);").

Now that just looks bizarre to me :) In that situation (calling static
methods of the System::Void class), I would use the
System::Void::ReferenceEquals(a, b); form, but for specifying return
types, I prefer the standard "void", and for empty parameter lists, I
prefer to leave the parameter list empty (like func() instead of
func(void)).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top