Algorithme T
Member
- Joined
- Sep 26, 2022
- Messages
- 15
- Programming Experience
- Beginner
Hello,
I am trying to get a Person, Teacher,Student Crud done .
I initially worked with Person, Teacher,Student abstract classes (every thing was working perfectly well) then i decided to use those abstract classes as models and created 3 other classes which are Services such as PersonService , TeacherService ....
I am getting an error of "Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object." each time i am trying to use a method which are now found in the Services classes
<
/>
I am trying to get a Person, Teacher,Student Crud done .
I initially worked with Person, Teacher,Student abstract classes (every thing was working perfectly well) then i decided to use those abstract classes as models and created 3 other classes which are Services such as PersonService , TeacherService ....
I am getting an error of "Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object." each time i am trying to use a method which are now found in the Services classes
<
My AddPerson Function:
PersonService? p = null;
Person? pChange = null;
switch (type)
{
case "student":
if (lastName != null && id != null)
{
pChange = new Student(lastName, firstName, dateOfBirth, id);
try
{
p.Add(pChange);
}
catch(Exception ex)
{
Console.WriteLine("Success ");
}
}
break;
case "teacher":
int salary;
try
{
salary = Convert.ToInt32(Console.ReadLine());
}
catch (Exception ex)
{
salary = 0;
}
if (lastName != null)
{
pChange = new Teacher(lastName, firstName, dateOfBirth, hireDate, salary);
p.Add(pChange);
}