Skip to content

simple typo #50333

Description

@ffishstix

Type of issue

Typo

Description

in this code snipit:

namespace Example1
{
    class BaseClass
    {
        protected int myValue = 123;
    }

    class DerivedClass : BaseClass
    {
        static void Main()
        {
            var baseObject = new BaseClass();
            var derivedObject = new DerivedClass();

            // Error CS1540, because myValue can only be accessed through
            // the derived class type, not through the base class type.
            // baseObject.myValue = 10;

            // OK, because this class derives from BaseClass.
            derivedObject.myValue = 10;
        }
    }
}

the comments are meant to explain why you couldn't grab the value from the baseObject however that line of code doesn't exist

could quickly add baseObject.myValue = 10;

Page URL

https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/protected

Content source URL

https://github.com/dotnet/docs/blob/main/docs/csharp/language-reference/keywords/protected.md

Document Version Independent Id

ca4b8d67-d015-e47d-01bf-06be8c938e4d

Platform Id

8ac23fc2-a2ac-6154-97b4-9dcf8f23cab2

Article author

@BillWagner

Metadata

  • ID: 17ee29ae-d0ae-9f8e-545d-15b72901be7d
  • PlatformId: 8ac23fc2-a2ac-6154-97b4-9dcf8f23cab2
  • Service: dotnet-csharp
  • Sub-service: lang-reference

Related Issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions