Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite5f510a

Browse files
authored
Added section on Out and Ref parameters (#19)
1 parentc700391 commite5f510a

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

‎.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22
_site/
33
.sass-cache/
44
.jekyll-metadata
5+
6+
# Visual Studio cache/options directory
7+
.vs/

‎README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,33 @@ someobject.SomeGenericMethod[int](10)
255255
someobject.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

260287
Delegates defined in managed code can be implemented in Python.
@@ -274,6 +301,9 @@ d = AssemblyLoadEventHandler(my_handler)
274301
AppDomain.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+
277307
Multicast delegates can be implemented by adding more callable objects to
278308
a delegate instance:
279309

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp