Re: ref vs. out: same at runtime, same/different at compiler time?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Scott M. <s-mar@xxxxxxxxxxxxx> wrote:
1. you can't have
two methods that differ only in ref/out (presumably because they are
treated the same at run time),

No, at run time they are processed by the CLR according to different rules.

Could you point out those different rules in the CLI spec? I don't
believe there's any difference.

2, ref/out specifically are handled differently in
terms of when they need to be ininitialized, which is caught at
compile time.

Not quite. The reason they are treated the same at compile time is that
thier method signatures are the same and this is why you can't overload
them.

They're not treated the same. Changing "out" for "ref" or vice versa
changes the rules as to what you can and can't do.

--
Jon Skeet - <skeet@xxxxxxxxx>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
.



Relevant Pages

  • Re: Framework runtime environment
    ... How much briefer than 'Yes' do you want? ... > You mean every process have its own CLR. ... Jon Skeet - http://www.pobox.com/~skeet Blog:http://www.msmvps.com/jon.skeet ... If replying to the group, please do not mail me too ...
    (microsoft.public.dotnet.framework)
  • Re: type of expression in C# 2.0?
    ... determined at compile time. ... Jon Skeet - ... If replying to the group, please do not mail me too ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: SQL Statement in C#
    ... A literal string is a string that is known at compile time. ... Jon Skeet - ... If replying to the group, please do not mail me too ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: How to make template function for array??
    ... Generics in the CLR are resolved at runtime and hence can be used with dynamic type generation. ... i think this is for DotNet only. ... Ralph was referring to generics such as C++'s templates which are a compile time only thing. ...
    (microsoft.public.vb.general.discussion)
  • Re: Conditional Compilation dependent on .net-Version
    ... If you need to get the CLR version during run time, ... Beer is part of the life. ... which enables the correct code at COMPILE TIME (it is not possible ...
    (microsoft.public.dotnet.languages.csharp)