1

Why exactly I can't use an AutoProperty as an out parameter?

For example (This gives me an error):

public int HeightValue { get; set; }

//...

private void Parse()
{
    int.TryParse(WidthText.Text, out HeightValue);
    //Intellisense Error: out argument is not classified as a variable
}
Nicke Manarin
  • 3,026
  • 4
  • 37
  • 79

2 Answers2

1

Possibly because properties are in essence methods and you need to give a field to set the value to the out parameter. You can define a backing field for your property and give its value as the out parameter.

See Jon Skeet's answer here:

Passing a property as an 'out' parameter in C#

Community
  • 1
  • 1
Piyush Parashar
  • 866
  • 8
  • 20
0

The method itself needs a variable as the out parameter. It's got to have a storage location it can just write values to. Not a property, not anything it needs to invoke: just a storage location. A property doesn't satisfy that requirement. So there's nothing that can be done by the compiler in the method to allow this.