By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,797 Members | 1,169 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,797 IT Pros & Developers. It's quick & easy.

[Out] vs out keywords!

P: n/a
Hi there,

I am wondering the difference between [Out] attribute and out keywords. Are
they the same or does it serve any different purposes?

I saw the [Out] and out usage in this code, and i had idea, does it had
differences.

[DllImport("kernel32.dll", SetLastError=true)]
internal static extern Boolean ReadFile(IntPtr hFile, [Out] Byte[] lpBuffer,
UInt32 nNumberOfBytesToRead, out UInt32 nNumberOfBytesRead, IntPtr
lpOverlapped);

Any help please?

Thanks.
--
Regards,
Chua Wen Ching :)
Nov 16 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Chua Wen Ching wrote:
Hi there,

I am wondering the difference between [Out] attribute and out keywords. Are
they the same or does it serve any different purposes?

I saw the [Out] and out usage in this code, and i had idea, does it had
differences.

[DllImport("kernel32.dll", SetLastError=true)]
internal static extern Boolean ReadFile(IntPtr hFile, [Out] Byte[] lpBuffer,
UInt32 nNumberOfBytesToRead, out UInt32 nNumberOfBytesRead, IntPtr
lpOverlapped);


Similar ideas, but for different things.

The [Out] attribute is used by the marshaller to mark a parameter to a
pinvoke or com method as needing to be marshalled only from the callee
to the caller.

The 'out' keyword is used in C# to indicate that a parameter will only
be written to by a method (or at least not read by a method until after
that method initializes it). But since this is used for .NET methods,
the marshaller is not involved.

--
mikeb
Nov 16 '05 #2

P: n/a
I am wondering the difference between [Out] attribute and out keywords. Are
they the same or does it serve any different purposes?


out == [Out] ref

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Nov 16 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.