C# – inheritance of private members in c#

asp.netcinheritanceprivate

Are private members inherited when inheriting the class in c#?
I have read some topic related to this, somebody telling that private members are inherited but cannot access the private members, somebody telling that it is not inherited when inheriting the class. Please explain the concept. if it is inheriting can any body give an explanation?

thanks

Best Answer

If I understand your question correctly then you're not concerned about the accessibility you are only concerned about private members are inherited or not

Answer is yes, all private members are inherited but you cant access them without reflection.

public class Base
{
    private int value = 5;

    public int GetValue()
    {
        return value;
    }
}

public class Inherited : Base
{
    public void PrintValue()
    {
        Console.WriteLine(GetValue());
    }
}

static void Main()
{
    new Inherited().PrintValue();//prints 5
}