I have a public abstract class employee with a constructor I would like to call from a click event in the form for the project. When trying to call the method I get an error that this type or namespace cannot be found, I also get this error if trying to call it from another class within the same project and name space.
Here is the Employee class I have:
using System;
using andrewWoodsAssignment2;
namespace andrewWoodsAssignment2
{
abstract class Employee
{
string employeeFirstName;
string employeeLastName;
string employeeNumber;
string employeeAddress;
public Employee(string first, string last, string number, string address)
{
employeeFirstName = first;
employeeLastName = last;
employeeNumber = number;
employeeAddress = address;
}
public override string ToString()
{
return "";
}
}
}
Here is my form I am trying to call the instructor in:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Text;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using andrewWoodsAssignment2;
namespace andrewWoodsAssignment2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
Employee e1 = new Employee("f", "f", "f", "f");
}
}
}
The line in the button1_click is the one causing the error, I have tried checking namespaces, and class names
Here is another class that inherits the employee class which also can't call the constructor or even seem to recognize the inheritance:
using System;
using andrewWoodsAssignment2;
namespace andrewWoodsAssignment2
{
public class ShiftSupervisor : Employee
{
double annualSalary;
double annualBonus;
int minimumHoursTraining;
int trainingHoursAttended;
public ShiftSupervisor(double annualSalary, double annualBonus, int minimumHoursTraining,
int trainingHoursAttended)
{
this.annualSalary = annualSalary;
this.annualBonus = annualBonus;
this.minimumHoursTraining = minimumHoursTraining;
this.trainingHoursAttended = trainingHoursAttended;
}
public override string ToString()
{
return "";
}
}
}
What could be causing this? Here is a screenshot of my files in visual studio
The files listed under "Solution Items" are not part of your project. Move them into your project using drag n drop.
You will still get compiler errors because of other issues with your code, but the visibility issue will be solved.