How to Access Protected Method and/or Class from Other Class in C# | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

How to Access Protected Method and/or Class from Other Class in C#

Just for example, let's say I have something like this protected class A{ protected void x() { //some code } } Then how to call the void x() outside from the class A? I've tried to do something like this sealed class B : A{ static void Main(){ A n = new A(); n.x(); } } But it's not working. Please help me with this

2nd May 2018, 1:03 PM
Keanu Taufan
Keanu Taufan - avatar
1 Answer
+ 2
in non-static method in class B you can access x() like that: this.x().
2nd May 2018, 6:31 PM
Дмитрий Я
Дмитрий Я - avatar