c# Argument is 'value' while parameter is declared as 'out'
时间: 2023-12-12 15:03:13 浏览: 295
InvalidArgument-The argument is invalid(解决方案).md
When a parameter is declared as `out` in C#, it means that the method is expected to assign a value to that parameter. Therefore, when calling the method, you cannot pass a variable as the argument. Instead, you must pass the variable by reference using the `ref` keyword.
Here's an example:
```csharp
void MyMethod(out int result) {
result = 42;
}
int myVar;
MyMethod(out myVar);
// myVar now has a value of 42
```
In the above example, `MyMethod` takes an `out` parameter named `result`. When calling the method, we pass `myVar` by reference using the `out` keyword. After the method is called, `myVar` now has a value of 42.
阅读全文