❔ Making properties accessible by both static and non-static methods
I had to make a static duplicate of a property, because I wanted it to be accessible by both non-static and static methods:
readonly string[] NoteNames = { "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B" };
static readonly string[] NoteNamesStatic = { "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B" };
Is there a better way of doing this, or do I always need to define it twice?3 Replies
Just make it static. Instances can still access it within the same class or from outside using the class name
Thanks, that seems to work
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.