@@ -255,6 +255,33 @@ someobject.SomeGenericMethod[int](10)
255255someobject.SomeGenericMethod[str ](" 10" )
256256```
257257
258+ ## Out and Ref parameters
259+
260+ When a managed method has ` out ` or ` ref ` parameters, the arguments appear as
261+ normal arguments in Python, but the return value of the method is modified.
262+ There are 3 cases:
263+
264+ 1 . If the method is ` void ` and has one ` out ` or ` ref ` parameter, the method returns
265+ the value of that parameter to Python. For example, if ` someobject ` has
266+ a managed method with signature ` void SomeMethod1(out arg) ` , it is called like so:
267+ ```
268+ new_arg = someobject.SomeMethod1(arg)
269+ ```
270+ where the value of ` arg ` is ignored, but its type is used for overload resolution.
271+
272+ 2 . If the method is ` void ` and has multiple ` out ` /` ref ` parameters, the method returns
273+ a tuple containing the ` out ` /` ref ` parameter values. For example, if ` someobject ` has
274+ a managed method with signature ` void SomeMethod2(out arg, ref arg2) ` , it is called like so:
275+ ```
276+ new_arg, new_arg2 = someobject.SomeMethod2(arg, arg2)
277+ ```
278+
279+ 3 . Otherwise, the method returns a tuple containing the return value followed by the
280+ ` out ` /` ref ` parameter values. For example:
281+ ```
282+ found, new_value = dictionary.TryGetValue(key, value)
283+ ```
284+
258285## Delegates And Events
259286
260287Delegates defined in managed code can be implemented in Python.
@@ -274,6 +301,9 @@ d = AssemblyLoadEventHandler(my_handler)
274301AppDomain.CurrentDomain.AssemblyLoad += d
275302```
276303
304+ Delegates with ` out ` or ` ref ` parameters can be implemented in Python by
305+ following the convention described in [ Out and Ref parameters] .
306+
277307Multicast delegates can be implemented by adding more callable objects to
278308a delegate instance:
279309
0 commit comments