Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6138669
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:53:43+00:00 2026-05-23T17:53:43+00:00

i go through a code sample where i have seen a different way to

  • 0

i go through a code sample where i have seen a different way to create a instance.

so code here

public interface IEmployee
{
    System.Int32? EmployeeID { get; set; }
    System.String FirstName { get; set; }
    System.String LastName { get; set; }
    System.DateTime DateOfBirth { get; set; }
    System.Int32? DepartmentID { get; set; }
    System.String FullName();
    System.Single Salary();
}

public class Employee : IEmployee
{
    #region Properties

    public System.Int32? EmployeeID { get; set; }
    public System.String FirstName { get; set; }
    public System.String LastName { get; set; }
    public System.DateTime DateOfBirth { get; set; }
    public System.Int32? DepartmentID { get; set; }

    #endregion

    public Employee(
        System.Int32? employeeid
        , System.String firstname
        , System.String lastname
        , System.DateTime bDay
        , System.Int32? departmentID
    )
    {
        this.EmployeeID = employeeid;
        this.FirstName = firstname;
        this.LastName = lastname;
        this.DateOfBirth = bDay;
        this.DepartmentID = departmentID;
    }

    public Employee() { }

    public System.String FullName()
    {
        System.String s = FirstName + " " + LastName;
        return s;
    }

    public System.Single Salary()
    {
        System.Single i = 10000.12f;
        return i;
    }
}

    private List<IEmployee> myList =  new List<IEmployee> { new Employee(1, "John", "Smith", new DateTime(1990, 4, 1), 1), 
            new Employee(2, "Gustavo", "Achong", new DateTime(1980, 8, 1), 1), 
            new Employee(3, "Maxwell", "Becker", new DateTime(1966, 12, 24), 2), 
            new Employee(4, "Catherine", "Johnston", new DateTime(1977, 4, 12), 2), 
            new Employee(5, "Payton", "Castellucio", new DateTime(1959, 4, 21), 3), 
            new Employee(6, "Pamela", "Lee", new DateTime(1978, 9, 16), 4) };

so i just want to know why code should create instance of list with IEmployee why not Employee.

here we can code like

private List<Employee> myList =  new List<Employee> { new Employee(1, "John", "Smith", new DateTime(1990, 4, 1), 1), 
        new Employee(2, "Gustavo", "Achong", new DateTime(1980, 8, 1), 1), 
        new Employee(3, "Maxwell", "Becker", new DateTime(1966, 12, 24), 2), 
        new Employee(4, "Catherine", "Johnston", new DateTime(1977, 4, 12), 2), 
        new Employee(5, "Payton", "Castellucio", new DateTime(1959, 4, 21), 3), 
        new Employee(6, "Pamela", "Lee", new DateTime(1978, 9, 16), 4) };

it also works….they why should one use IEmployee.
why coder is using IEmployee instead of Employee so there must be some specific objective. so i just need to know the objective for using IEmployee.
i am looking for good explanation. please guide me. thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T17:53:44+00:00Added an answer on May 23, 2026 at 5:53 pm

    You said you want some code. I’ll show you some (slightly different for sake of answer).

    Suppose you have

    public interface IPlanet {
        string Name {get;}
    }
    

    And then specialize that interface many times:

    public class Mars    : IPlanet { public string Name { get { return "Mars";   } } }
    public class Venus   : IPlanet { public string Name { get { return "Venus";  } } }
    public class Jupiter : IPlanet { public string Name { get { return "Jupiter";} } }
    public class Earth   : IPlanet { public string Name { get { return "Earth";  } } }
    

    Then you can do:

    List<IPlanet> solarsystem = new List<IPlanet> {
        new Mars(),
        new Venus(),
        new Jupiter(),
        new Earth(),
    };
    

    And because they share the same interface, you can do:

    foreach (var planet in solarsystem) {
        Console.WriteWrite (planet.Name);
    }
    

    So, in some sense, interfaces help you to manage heterogeneous objects in a homogeneous way. This is also one (of many) sort of generic, re-usable programming (don’t look at the wikipedia site, which equates generic programming with templates and generics).

    Note that a List implements the IList-interface, so you can generalise even more:

    IList<IPlanet> solarsystem = new List<IPlanet> {
        new Mars(),
        new Venus(),
        new Jupiter(),
        new Earth(),
    };
    

    For whether you should or not, see List<T> or IList<T> .

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have downloaded sample code from Apple Center.I also have gone through following question:
Just going through the sample Scala code on Scala website, but encountered an annoying
I recently read through Code Complete, and it recommends that I create a project
I have been looking through code for the last 3 days, and the original
I have used the smtp class to send emails through code. Can I use
Hi I need to create a query in MSAccess 2003 through code (a.k.a. VB)
I want to create a Dynamic aspx Page in current solution through code-behind..forexample i
I'm fairly new to programming and from learning I have seen different ways of
Sometime when looking through code, I see many methods specify an annotation: @SuppressWarnings(unchecked) What
I am populating a UITableViewController's UITableView through code only. At the bottom of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.