void vs. System::Void

  • Thread starter Thread starter Marcus Kwok
  • Start date Start date
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.
 
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
 
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)).
 
Back
Top