Re: Control.Invoke and ref parameter
- From: jetan@xxxxxxxxxxxxxxxxxxxx ("Jeffrey Tan[MSFT]")
- Date: Tue, 27 Jun 2006 02:53:25 GMT
Hi George,
In addition to Barry's reply, I still want to add some comment to your 2
questions:
Based on the C# language reference, "ref" is a method parameter keyword,
which is only used in the parameter decoration.
1. without "ref" or "out", the object array *contents* are not modified.
2. with "ref" or "out", the object array * contents" are modified.
The key point is where the keyword applies: does it apply to the object
array itself or to the elements in the array?
If you are marking the object array with "ref", it means that the array
*contents* will remain the normal behavior, which we do not care, but the
array itself may point to another array after invoking the method, please
refer to the guide below:
"Passing Arrays Using ref and out (C# Programming Guide) "
http://msdn2.microsoft.com/en-us/library/szasx730.aspx
If you are marking the elements in the array with "ref", it means the array
remains the same, but the element itself may be *modified* after invoking.
Your problem demonstrates this scenario.
Actually, your scenario is somewhat specific, which I also can not find a
definite sample or document regarding the syntax passing to
Control.Invoke.(anyway, with the help of the community, you finally got the
answer). In this scenario, I think we have to try with the existing C#
document to find out the correct syntax.
1. Based on "ref" document, "An argument passed to a ref parameter must
first be initialized.", so we should initialize the object array outside of
the method first.
2. Marking "ref" in front of the object array element is invalid(because
"ref" is only valid in method parameter), so we have no option of marking
the "ref" keyword.
With these 2 constraints, the code snippet Barry provided should be the
only valid syntax.
Hope this comment makes sense to you. If you have any concern, please feel
free to tell me. Thanks.
Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
.
- References:
- Re: Control.Invoke and ref parameter
- From: Barry Kelly
- Re: Control.Invoke and ref parameter
- From: Barry Kelly
- Re: Control.Invoke and ref parameter
- From: George
- Re: Control.Invoke and ref parameter
- Prev by Date: Re: DataGrid Edit field
- Next by Date: How can I get web browser content by using .NET framework 2.0 ?
- Previous by thread: Re: Control.Invoke and ref parameter
- Next by thread: Re: Control.Invoke and ref parameter
- Index(es):
Relevant Pages
|