I created a class call Sales with a Amount get/set:
class Sales
{
public static string Amount { get; set; }
}
Then I called from other class, out of a function scope:
class Test
{
Sales.Amount = "10";
public static VoidSales()
{
.....
}
}
I get the following error:
'Fun.Sales.Amount' is a 'property' but is used like a 'type'
But When I use in a function, it is correct.
Thank you.
You can't place these type of assignment statements inside the open class context. You can only make these type of assignments inside a method. The only assignments that can be done in the class context are initializations of class level fields.
If this assignment needs to be made when the class is instantiated, then it should be done in the constructor.
I may not be able to explain it well. But a get/set property is actually sort of equivalent to a method. Having said that, I believe you can't call a method outside of a function right?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With