Maha

Maha

  • NA
  • 0
  • 326.4k

Object data type

Jul 13 2013 11:16 AM
Object is a generic data type and every class you create in C# derives from a single class named System.Object.

When you have object data type instead of Employee data type program is not executing. Please explain the reason. Problem is highlighted.

using System;

public class CreateEmployee
{
public static void Main(string[] args)
{
Employee myAssistant = new Employee();

myAssistant.SetId(345);

Display(myAssistant);

Console.ReadKey();
}
static void Display(object num)
{
Console.WriteLine("ID # is {0}", num.GetId());
}
}

internal class Employee : Object
{
private int idNumber;

public int GetId()
{
return idNumber;
}
public void SetId(int id)
{
idNumber = id;
}
}
// ID # is 345


Answers (4)