X

C# tip property with different accessibility scopes

dotnet C#

In C# you can have property with different scope (property accessors). Properties in C# can be marked as public, private, protected, internal, or protected internal.

Example:


public int MyProperty { get; private set; }
public string Name { get; protected set;}
public int Age { get { return _age; } } // no set but still valid
private string Fullname { get; set; } //both are private only class can access it
internal string LName { get; set; } //only code in same assembly can access
protected internal string FName { get; set; } //only code that inherit and in same assembly
virtual string PersonName { get; set; } //use override keyword in derived class
static int Count { get; set; } // avaiable to caller at any time
Categories: .NET C#
Taswar Bhatti:
Related Post