Quantcast
Viewing all articles
Browse latest Browse all 12583

Inheritance - Inconsistent Accessibility field type

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace AssignmentQ2
{
    public partial class Form1 : Form
    {
        List<Advisor> advisorList;                          //call  List<Advisor> at class level
        List<Students> students = new List<Students>();      //call List<Students> at class level

        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            advisorList = Advisor.Load();
            if (advisorList == null)
            {
                advisorList = new List<Advisor>();
            }
        }

        private void addAdvisorButton_Click(object sender, EventArgs e)
        {
            Advisor a;

            frmAddAdvisor formAdd = new frmAddAdvisor();

            formAdd.ShowDialog();
            a = formAdd.newAdvisor;

            if (a != null)
            {
                advisorList.Add(a);
            }
        }

        private void viewAdvisorbutton_Click(object sender, EventArgs e)
        {
            frmViewAdvisor formAdvisor = new frmViewAdvisor();

            formAdvisor.listAdvisors = advisorList;
            formAdvisor.ShowDialog();



        }

        private void saveButton_Click(object sender, EventArgs e)
        {
            Advisor.Save(advisorList);
        }

        private void addStudentButton_Click(object sender, EventArgs e)
        {
            frmAddStudents s = new frmAddStudents();

            s.listAdvisor = advisorList;
            s.ShowDialog();
            students.Add(s.student);
        }

        private void viewStudentButton_Click(object sender, EventArgs e)
        {
            frmViewStudents s = new frmViewStudents();

            s.listAdvisors = advisorList;
            s.student = students;

            s.ShowDialog();
        }
    }
}







//this is  another form 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace AssignmentQ2
{
    public partial class frmAddAdvisor : Form
    {
        public Advisor newAdvisor;   //call Advisor at class level class and declare newAdvisor as variable

        public frmAddAdvisor()
        {
            InitializeComponent();
        }

        private void cancelButton_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void addButton_Click(object sender, EventArgs e)
        {
            //calling Advisor class and using overload constructor to execute
            newAdvisor = new Advisor(advisorFirstNameTextBox.Text, advisorLastNameTextBox.Text, departmentTextBox.Text);

            newAdvisor = new Advisor();

            newAdvisor.FirstName = advisorFirstNameTextBox.Text;

            this.Close();
        }
        
        
    }
}



//Advisor Class

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace AssignmentQ2
{
    class Advisor
    {
        //field
        private string _firstName;
        private string _lastName;
        private string _department;
        private Students _students;   //assigne Students class as variable

        //default constructor
        public Advisor()
        {
            _firstName = "";
            _lastName = "";
            _department = "";
        }

        //overload constructor
        public Advisor(string fn, string ln, string dep)
        {
            _firstName = fn;
            _lastName = ln;
            _department = dep;
        }

        //another constructor???
        public Advisor(string fn)
        {
            _firstName = fn;
        }

        //property for Students
        public Students _Students
        {
            get { return _students; }
            set { _students = value; }
        }

        //property FirstName
        public string FirstName
        {
            get { return _firstName; }
            set { _firstName = value; }
        }

        //property LastName
        public string LastName
        {
            get { return _lastName; }
            set { _lastName = value; }
        }

        //property department
        public string Department
        {
            get { return _department; }
            set { _department = value; }
        }


        //Save method for advisor list
        public static void Save (List<Advisor> listAdvisors)
        {
            AdvisorList.save(listAdvisors);   //use AdvisorList class and save method to execute this part
        }

        //Load list
        public static List<Advisor> Load()
        {
            return AdvisorList.Load(); //use the AdvisorList class and load method to execute
        }

        //get information
        public string GetInfo()
        {
            return "First Name: " + _firstName + ", Last Name: " + _lastName + ", Department: " + _department;
        }

        
    }
}


It says that my new Advisor (from form AddAdvisor) is inconsisten accessbility field type.

I have other form that also holds the same error on Class variables.

Can someone have an idea how to fix this?


Viewing all articles
Browse latest Browse all 12583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>