call a protected property on an instance of a class in csharp

To call a protected property on an instance of a class in c#, you can create a public method within the class that returns the value of the protected property. For example:

main.cs
public class MyClass
{
    protected string myProtectedProperty = "Hello World!";
    
    public string GetMyProtectedProperty()
    {
        return myProtectedProperty;
    }
}
180 chars
10 lines

Then, you can create an instance of MyClass and call the GetMyProtectedProperty method to retrieve the value of the protected property.

main.cs
MyClass myInstance = new MyClass();
string myProtectedPropertyValue = myInstance.GetMyProtectedProperty();
107 chars
3 lines

This will return the value "Hello World!" from the protected property myProtectedProperty.

gistlibby LogSnag