If I did something like this:
public int Foo
{
get
{
return GetFoo() + 5;
int GetFoo() => 3;
}
}
It will actually compile, which makes me wonder if this would be a good or bad practice.
Now, clearly this particular example can be refactored into: public int Foo => 8;
, but other cases might have a few local methods and doing stuff in it's main get
portion.
Keeping in mind the fact that C# actually moves GetFoo
outside of property or method it is in whenever the code is compiled, this should have just about the exact same performance as a property calling a normal method.
However, If one feels the need to use local functions in a property, is that a sign that the property is doing too much work and should be a method instead?