3
Answers

Object reference not set to an instance of an object.

Sai Kumar

Sai Kumar

6y
1.2k
1
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;
namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
employee[] e1 = new employee[4];
e1[0] = new employee();
e1[1] = new parttimemeployee();
e1[2] = new fulltimeemployee();
foreach (employee e in e1)
{
e.add();
}
Console.ReadLine();
}
}
}
class employee
{
public string firstname="sai";
public string lastname="kumar";
public virtual void add()
{
Console.WriteLine("Base class method called");
}
}
class fulltimeemployee : employee
{
public new void add()
{
Console.WriteLine(firstname+lastname);
}
}
class parttimemeployee : employee
{
public override void add()
{
Console.WriteLine("partime employee called");
}
}
 
after executing above code i am getting object reference not set to an instance of an object. Please help sir im begineer
Answers (3)