Articles → CSHARP → Call Private Method Of The Class Using Delegates In C#
Call Private Method Of The Class Using Delegates In C#
Create A Class With A Private Method
public class MyClass {
private void Display() {
Console.WriteLine("Private Display Method");
}
}
Add Delegate
public class MyClass {
public MyClass() {
DelegateProp = new MyDelegate(Display);
}
public delegate void MyDelegate();
private void Display() {
Console.WriteLine("Private Display Method");
}
public MyDelegate DelegateProp {
get;
set;
}
}
Call Delegate
MyClass cls = new MyClass();
cls.DelegateProp();
Output