Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set value of Base class variable?

This may be a very stupid question and it's making feel like my brain has gone...but I cannot fathom how to set a protected or public variable from a Base class.

I have an Enum that is used in the Base class, but must be set in the Inheriting class. The Inheriting class is very little to no code so I SPECIFICALLY want to do this outside of a Method.

An example of what I want:

public class MyBase {
    protected myEnum;
}

public class MyClass : MyBase {
    myEnum = SomeValue;
}

If I set myEnum as a property with get/set, I can override it...but then I end up with many more lines of code.
If I override Page_Load I can access this.myEnum but again, I want to access it outside of a method as it is the only code in the Inheriting class.

Am I missing something completely obvious here?

like image 951
James P. Wright Avatar asked Sep 05 '26 04:09

James P. Wright


1 Answers

You need to create a constructor.
You cannot execute code outside a method.

like image 69
SLaks Avatar answered Sep 07 '26 18:09

SLaks



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!