How Can You Access A Private Method Of A Class?

user image

Muskan Anand

2 years ago

Use .Net Reflection. Using reflection we can invoke private methods too. Example: Car car = new Car(); Type type = car.GetType(); MethodInfo methodInfo = type.GetMethod("ShiftGearUp", BindingFlags.NonPublic | BindingFlags.Instance); methodInfo.Invoke(car, null);  Pre: Create a class Car with private method "ShiftGearUp"

Recent Doubts

Close [x]