Difference between out and [Out]

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have been doing a lot of PInvoke calls using signatures published on
www.pinvoke.net. I notice that where out parameters are involved, sometimes
the signature uses 'out' and sometimes '[Out]'. I have discovered that using
the wrong one causes nasty things to happen, but I can't work out what the
difference is, and when one should be used and when the other (luckily I have
not yet had to work out my own signatures for PInvoke calls, but I may have
to one day)
 
I have been doing a lot of PInvoke calls using signatures published on
www.pinvoke.net. I notice that where out parameters are involved, sometimes
the signature uses 'out' and sometimes '[Out]'. I have discovered that using
the wrong one causes nasty things to happen, but I can't work out what the
difference is, and when one should be used and when the other (luckily I have
not yet had to work out my own signatures for PInvoke calls, but I may have
to one day)

out is equivalent to using [Out] ref.

Both ref and out change the way the parameter is passed (by reference
ratehr than by value).


Mattias
 
Thanks. I understand out and ref. Can you explain what [Out] actually is,
syntactically?
--
Dave


Mattias Sjögren said:
I have been doing a lot of PInvoke calls using signatures published on
www.pinvoke.net. I notice that where out parameters are involved, sometimes
the signature uses 'out' and sometimes '[Out]'. I have discovered that using
the wrong one causes nasty things to happen, but I can't work out what the
difference is, and when one should be used and when the other (luckily I have
not yet had to work out my own signatures for PInvoke calls, but I may have
to one day)

out is equivalent to using [Out] ref.

Both ref and out change the way the parameter is passed (by reference
ratehr than by value).


Mattias
 
Thanks. I understand out and ref. Can you explain what [Out] actually is,
syntactically?

It's an attribute - OutAttribute, to be specific.

Jon
 
Doh! Of course it is. Sorry. Attributes are one aspect of the C# language
I've never really got my head round, I must read up on them more carefully.
Thanks for the quick response.
--
Dave


Jon Skeet said:
Thanks. I understand out and ref. Can you explain what [Out] actually is,
syntactically?

It's an attribute - OutAttribute, to be specific.

Jon
 

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

Back
Top