Jesper Jesper - 8 months ago 63
C# Question

Getting fields from superclass

I have the following abstract class:

abstract class Customer
private string address { get; set; }
private int phone { get; set; }

public Customer(string address, int phone)
this.address = address; = phone;

Then i have the following class that inherits from the customer class:

class Private : Customer

private string name { get; set; }
private int age { get; set; }
private string sex { get; set; }

public Private(string name, int age, string sex, string address, int phone) : base(address, phone)
{ = name;
this.age = age; = sex;

My question is: How do I access the phone and address fields on my Private class?


Use the protected modifier instead of private for everything that can be accessed by inherited classes.

From the docs:

A protected member is accessible within its class and by derived class instances.