Try the following. You will see that C# actually passes the out param value
into the function! As has been said, this is because it is a C# feature, not
a CLR/CLS feature.


--- VB.Net ---

Imports System.Runtime.InteropServices

Public Class TestServer
    ' Fool C# into thinking this is an out only param
    Public Shared Sub DoStuff(<Out()> ByRef x As Integer)
        Console.WriteLine("Out param is {0}", x)
    End Sub
End Class

--- C# ---

using System;

namespace ThunderMain.Test {
        class TestClient {
                static void Main(string[] args) {
                        int y=42;
                        TestServer.DoStuff(out y);
                        Console.ReadLine();
                }
        }
}

----------


> -----Original Message-----
> From: Moderated discussion of advanced .NET topics.
> [mailto:[EMAIL PROTECTED]]On Behalf Of Steven Lyons
> Sent: 18 November 2002 21:11
> To: [EMAIL PROTECTED]
> Subject: Re: [ADVANCED-DOTNET] VB's ByVal/ByRef vs. C#'s ref/out
>
>
> VB.Net doesn't include an "out" equivilent in the language but
> supposedly you can use the <Out> attribute to write methods with "out"
> parameters.
>
> Sub OutDemo(<Out> ByRef num As Integer)
>
> Calling methods should work the same way. I haven't tried it but this is
> the way I hear it's done.
>
> "out" parameters don't make it CLS non-compliant but FXCop doesn't seem
> to like them:
> http://www.gotdotnet.com/team/libraries/FxCopRules/DesignRules.aspx
>
> Hope that works for you,
> Steve
>
>
>
> Shawn A. Van Ness wrote:
> > Is it just me or do these two pairs not match up very nicely?
> >
> > Is there really no equivalent of C#'s "out" keyword, in VB.NET?
> >
> > Are methods with "out" parameters non-CLSCompliant?
> >
> > (I searched the archives, and found some early confusion from
> Ted Pattison and Don Box on this matter, but no clear resolution.)
> >
> > Cheers,
> > -Shawn
> > http://www.arithex.com/
> >
> > You can read messages from the Advanced DOTNET archive,
> unsubscribe from Advanced DOTNET, or
> > subscribe to other DevelopMentor lists at http://discuss.develop.com.
> > .
> >
>
> You can read messages from the Advanced DOTNET archive,
> unsubscribe from Advanced DOTNET, or
> subscribe to other DevelopMentor lists at http://discuss.develop.com.
>

You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced 
DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to