Accessibility inconsistency c #

3

I have the following class that marks me error in the second word Address of the virtual method:

public class Profesor {
        public Profesor() {
        }
        public Profesor(int id, string nombre, string ape1, string ape2) {
            this.id = id;
            this.nombre = nombre;
            this.ape1 = ape1;
            this.ape2 = ape2;
        }
        private int id;
        public virtual int Id {
            get { return id; }
            set { id = value; }
        }
        private String nombre;
        public virtual string Nombre {
            get { return nombre; }
            set { nombre = value; }
        }
        private String ape1;
        public virtual string Ape1 {
            get { return ape1; }
            set { ape1 = value; }
        }
        private String ape2;
        public virtual string Ape2 {
            get { return ape2; }
            set { ape2 = value; }
        }
        private Direccion direccion;
        public virtual Direccion Direccion {
            get { return direccion; }
            set { direccion = value; }
        }

    }

The error says Accessibility inconsistency: The 'Address' property type is less accessible than the 'Teacher.Direction' property. How can I fix it? This is the Address class:

class Direccion {
        public Direccion() {
        }
        public Direccion(int id,String calle, int numero,String poblacion, String provincia) {
            this.id = id;
            this.calle = calle;
            this.numero = numero;
            this.poblacion = poblacion;
            this.provincia = provincia;
        }
        private int id;
        public virtual int Id {
            get { return id; }
            set { id = value; }
        }
        private String calle;
        public virtual String Calle {
            get { return calle; }
            set { calle = value; }
        }
        private int numero;
        public virtual int Numero {
            get { return numero; }
            set { numero = value; }
        }
        private String poblacion;
        public virtual String Poblacion {
            get { return poblacion; }
            set { poblacion = value; }
        }
        private String provincia;
        public virtual String Provincia {
            get { return provincia; }
            set { provincia =value; }
        }
    }
    
asked by abrahamhs 18.11.2016 в 01:09
source

2 answers

3

Try doing public class Direccion

public class Direccion { ....

    
answered by 18.11.2016 / 02:10
source
3

In c# there are these access levels ( internal , private , protected or public ) and are inferred depending on the context, in the case that they are not specified, in case of the classes that they are created directly under a namespace, by default they are internal, which means that they will only be accessible by the classes of the same assembly, this is the case of Direccion , but Profesor is a public class, which indicates that can be used by any assembly, by declaring the property Direccion public you are indicating that it can be accessed by any assembly but the type is not.

In this site you will find more details of the access levels.

    
answered by 18.11.2016 в 04:19