[Out] vs out keywords!

G

Guest

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.
 
M

mikeb

Chua said:
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.
 
M

Mattias Sjögren

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
 

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