I create a new instance of ProductionWorker
called worker
which itself is a derived class of Employee
. Anyway both class's and their properties are protected. According to my HW they have to be. Well I thought using auto properties let me around that. But its still saying I don't have access?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Employee_Form
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
this.Close();
}
private void button2_Click(object sender, EventArgs e)
{
ProductionWorker worker = new ProductionWorker(textBox1.Text,
Convert.ToInt32(textBox2.Text),
Convert.ToInt32(textBox3.Text),
Convert.ToDouble(textBox4.Text));
textBox5.Text = $"Name: {worker.Name}\n Number: {worker.Number}\n Shift Number: {worker.ShiftNum}\n Hourly Pay Rate: {worker.PayRate}";
/*OnActivated the line above I can't access the worker props and I get a red squiggly'*/
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Employee_Form
{
class ProductionWorker : Employee
{
protected string Name { get; set; }
protected int Number { get; set; }
protected int ShiftNum { get; set; }
protected double PayRate { get; set; }
public ProductionWorker(string Name, int Number, int shiftNum, double payRate) : base (Name, Number)
{
this.ShiftNum = shiftNum;
this.PayRate = payRate;
}
/*public string showData()
{
}*/
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Employee_Form
{
class Employee
{
protected string Name { get; set; }
protected int Number { get; set; }
public Employee(string name, int number)
{
this.Name = name;
this.Number = number;
}
}
}