Re: C# Language Proposal for 'out' Parameters
From: Daniel O'Connell [C# MVP] (onyxkirx_at_--NOSPAM--comcast.net)
Date: 04/10/04
- Next message: William Ryan eMVP: "Re: DataBase doesn't AcceptChange"
- Previous message: pnp: "Circular References! Big Problem!"
- In reply to: C# Learner: "C# Language Proposal for 'out' Parameters"
- Next in thread: C# Learner: "Re: C# Language Proposal for 'out' Parameters"
- Reply: C# Learner: "Re: C# Language Proposal for 'out' Parameters"
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 10 Apr 2004 15:01:37 -0500
>
> (a) Method bodies can benefit from one less statement for each time this
> technique is used, promoting readability.
>
> (b) C# becomes more consistent since returning values using both the
> traditional way, and using 'out' parameters, is uniform. Again,
> this promotes readability.
>
> Example:
>
> // traditional way
> static void Main()
> {
> int i = GetANumber();
> DoSomethingWith(i);
> }
>
> // using an 'out' parameter, with the aforementioned syntax
> static void Main()
> {
> if (TryGetANumber(out int i)) {
> DoSomethingWith(i);
> }
> }
>
>
>
>
>
> End
> ---
>
> Comments?
>
The primary problem I have with this is in all othercases I can think of, a
variable declared within a () is scoped to the underlying block(method
parameters, for (int x) { //x is only valid here }, using (IDisposable x)
{ //x is only valid here }. By allowing declarations within a method call,
you remove that partciular consistence of the language.
> Regards,
> C. S. Learner
- Next message: William Ryan eMVP: "Re: DataBase doesn't AcceptChange"
- Previous message: pnp: "Circular References! Big Problem!"
- In reply to: C# Learner: "C# Language Proposal for 'out' Parameters"
- Next in thread: C# Learner: "Re: C# Language Proposal for 'out' Parameters"
- Reply: C# Learner: "Re: C# Language Proposal for 'out' Parameters"
- Messages sorted by: [ date ] [ thread ]