Re: please help me understand ref and out
From: Bruce Wood (brucewood_at_canada.com)
Date: 12/08/04
- Next message: Bradley1234: "Re: Doing I/O to the Printer port and legacy IO space in C# ?"
- Previous message: Bruce Wood: "Re: Overloading properties?"
- In reply to: Bradley1234: "Re: please help me understand ref and out"
- Next in thread: Jon Skeet [C# MVP]: "Re: please help me understand ref and out"
- Messages sorted by: [ date ] [ thread ]
Date: 8 Dec 2004 12:36:54 -0800
"out" is a more specific form of "ref". By giving the compiler more
information you allow it to make more checks for you. By designating a
parameter as "out" you are telling the compiler, "I guarantee that when
this method returns, this argument will have been set to a value by the
method."
The compiler then does the necessary static checking to ensure that
your method is living up to its contract.
"ref" is more vague: it states that the method may or may not choose to
assign a (new) value to the variable.
You should use "out" whenever your design calls for multiple return
values from a method, because you then get "free" code correctness
checking. It is much less often that you need "ref". If you just use
"ref" all over the place the compiler won't care, but then you give up
the opportunity to find bugs at compile time rather than at run time.
- Next message: Bradley1234: "Re: Doing I/O to the Printer port and legacy IO space in C# ?"
- Previous message: Bruce Wood: "Re: Overloading properties?"
- In reply to: Bradley1234: "Re: please help me understand ref and out"
- Next in thread: Jon Skeet [C# MVP]: "Re: please help me understand ref and out"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|