Hierarchy Employee/Manager from a List - c#

I have three classes.I want to get the hierarchy of employees for a selected employee.
public class Employees
{
public int empId{ get; set; }
public string empName { get; set; }
public Employees(int id, string name)
{
empId= id;
empName = name;
}
}
public class EmployeeManager
{
public int empmgr_id { get; set; }
public int emp_id { get; set; }
public int mgr_id{ get; set; }
public EmployeeManager(int emid, int eid, int mid)
{
empmgr_id = emid;
emp_id = eid;
mgr_id= mid;
}
}
public static class EmpMgrData
{
public static IEnumerable<Employees> EmpList()
{
var lstEmp = new List<Employees>();
lstEmp .Add(new Employees(1,"Emp 1"));
lstEmp .Add(new Employees(2,"Emp 2"));
lstEmp .Add(new Employees(3,"Emp 3"));
lstEmp .Add(new Employees(4,"Emp 4"));
lstEmp .Add(new Employees(5,"Emp 5"));
lstEmp .Add(new Employees(6,"Emp 6"));
lstEmp .Add(new Employees(7,"Emp 7"));
lstEmp .Add(new Employees(8,"Emp 8"));
lstEmp .Add(new Employees(9,"Emp 9"));
lstEmp .Add(new Employees(10,"Emp 10"));
lstEmp .Add(new Employees(11,"Emp 11"));
lstEmp .Add(new Employees(12,"Emp 12"));
lstEmp .Add(new Employees(13,"Emp 13"));
lstEmp .Add(new Employees(14,"Emp 14"));
lstEmp .Add(new Employees(15,"Emp 15"));
lstEmp .Add(new Employees(16,"Emp 16"));
lstEmp .Add(new Employees(17,"Emp 17"));
lstEmp .Add(new Employees(18,"Emp 18"));
lstEmp .Add(new Employees(19,"Emp 19"));
lstEmp .Add(new Employees(20,"Emp 20"));
return lstEmp ;
}
public static IEnumerable<EmployeeManager> EmpMgrList()
{
var lstEmpMgr = new List<EmployeeManager>
{
new EmployeeManager(1,18,19),
new EmployeeManager(2,17,20),
new EmployeeManager(3,19,17),
new EmployeeManager(4,14,15),
new EmployeeManager(5,13,15),
new EmployeeManager(6,12,13),
new EmployeeManager(7,9,13),
new EmployeeManager(8,10,13),
new EmployeeManager(9,11,13),
new EmployeeManager(10,6,5),
new EmployeeManager(11,7,5),
new EmployeeManager(12,8,5),
new EmployeeManager(13,5,4),
new EmployeeManager(14,4,20),
new EmployeeManager(15,2,4),
new EmployeeManager(16,1,3),
new EmployeeManager(17,3,20)
};
return lstEmpMgr ;
}
}
private void Form1_Load(object sender, EventArgs e)
{
//Displaying list of persons in the combo box
var empList = EmpMgrData.EmpList();
comboBox1.DataSource = empList;
comboBox1.DisplayMember = "empName";
comboBox1.ValueMember = "empId";
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(comboBox1.DisplayMember))
{
listBox1.DataSource = null;
listBox1.Items.Clear();
var personKey = ((Employees)comboBox1.SelectedItem).empId;
var personname = ((Employees)comboBox1.SelectedItem).empName;
List<EmployeeManager> hierarchyDownEmployees = null;
List<Employees> hierarchyDownEmployeesName = null;
hierarchyDownEmployees = EmpMgrData.EmpMgrList().ToList();
//Using an Extension method to get the hierarchy of employees for the selected person.First we find all the direct employees of selected person and using the extension method, we will find the hierarchy
List<int> hEmployees = new List<int>(hierarchyDownEmployees.GetHierarchyEmployees(personKey));
for (int i = 0; i < hEmployees.Count; i++)
{
hEmployees.AddRange(hierarchyDownEmployees.GetHierarchyEmployees(hEmployees[i]).Except(hEmployees));
}
//Finding the EmpName of the hierarchy employees
hierarchyDownEmployeesName = EmpMgrData.EmpList().Where(n => hEmployees.Any(s => s == n.empId)).ToList();
//Displaying the Hierarchy Employee Names of selected person to the list box
if (hierarchyDownEmployeesName != null && hierarchyDownEmployeesName.Count() > 0)
{
label2.Text = "All Employees under " + comboBox1.Text + " are: " + string.Join(", ", hEmployees);
listBox1.DataSource = hierarchyDownEmployeesName;
listBox1.DisplayMember = "empName";
listBox1.ValueMember = "empId";
listBox1.SelectedIndex = -1;
}
}
}
}
public static class Hierarchy
{
//Extension method to get the Employee Hierarchy of the selected person
public static IEnumerable<int> GetHierarchyEmployees(this IEnumerable<EmployeeManager> employees, int empID)
{
return from emp in employees
where emp.mgr_id == empID
select emp.emp_id ;
}
}
When I select a person in the ComboBox, I want to Show the list of employees in the hierarchy ('down'), based on the employee/manager relationships, all the way to the bottom people that have no employees reporting to them.My code retrieves all the employees under the selected person, but not in the hierarchical order.(When I find the employee name from the EmpList)
Example:
Emp 20
>>Emp 3
>>>>Emp 1
>>Emp 4
>>>>Emp 5
>>>>>>>>Emp 6
>>>>>>>>Emp 7
>>>>>>>>Emp 8
>>>>Emp 2
>>Emp 17
>>>>Emp 19
>>>>Emp 18
Thanks for any help!

So I think a better approach would be to modify the extension method a bit:
public static IEnumerable<int> GetEmployees(this EmployeeManager mgr, int mgrID)
{
return EmpMgrData.EmpMgrList()
.Where(mgr => mgr.mgr_id = mgrID)
.Select(mgr => mgr.emp_id);
}
and then modify the EmployeeManager class to get its own employees:
public class EmployeeManager
{
public int empmgr_id { get; set; }
public int emp_id { get; set; }
public int mgr_id{ get; set; }
public IEnumerable<int> Employees
{
get
{
return this.GetEmployees(emp_id);
}
}
public EmployeeManager(int emid, int eid, int mid)
{
empmgr_id = emid;
emp_id = eid;
mgr_id= mid;
}
}
and then finally, when a person is selected, you just go get that EmployeeManager. It now has all of its own employees, and its employees have all of their own employees. That code might look like this:
var rootManager = EmpMgrData.EmpMgrList()
.FirstOrDefault(mgr => mgr.emp_id = personKey);

Related

Search in an ArrayList C#

class EmployeeDAL
{
private ArrayList _employees;
public EmployeeDAL()
{
_employees = new ArrayList();
_employees.Add(new Employee { EmployeeID = 1, EmployeeName = "Ram", Salary = 50000 });
_employees.Add(new Employee { EmployeeID = 2, EmployeeName = "Sahaym", Salary = 40000 });
_employees.Add(new Employee { EmployeeID = 3, EmployeeName = "Gopi", Salary = 55000 });
_employees.Add(new Employee { EmployeeID = 4, EmployeeName = "Prakash", Salary = 45000 });
_employees.Add(new Employee { EmployeeID = 5, EmployeeName = "Dheeraj", Salary = 60000 });
_employees.Add(new Employee { EmployeeID = 6, EmployeeName = "Shibhu", Salary = 50000 });
}
public bool DeleteEmployee(int id)
{
if (_employees.Contains(id))
{
_employees.Remove(id);
return true;
}
else
return false;
}
}
I want to delete an employee with specific id using DeleteEmployee(id) method. How can I do this in ArrayList ?
Hi as an answer to your question you can use the code below :
public bool DeleteEmployee(int id)
{
var employees = _employees.Cast<Employee>()
.Where(e => e.EmployeeID == id)
.Distinct();
if (employees.Count() == 0)
return false;
else
foreach (var employee in employees.ToList())
_employees.Remove(employee);
return true;
}
But in my opinion, if it's possible, you should use another type of collection like a List, it could be easier to handle than an ArrayList.
Forgive the crudeness of my code. But, sample of using a List follows:
using System;
using System.Collections.Generic;
using Gtk;
public partial class MainWindow : Gtk.Window
{
public class Employee
{
public int EmployID;
public string EmployeeName;
public int Salary;
public Employee(int v1, string v2, int v3)
{
this.EmployID = v1;
this.EmployeeName = v2;
this.Salary = v3;
}
}
public class Employees
{
public List<Employee> employees = null;
public bool Delete(int inID)
{
Employee buffer = employees.Find(x => x.EmployID == inID);
if (buffer != null)
{
employees.Remove(buffer);
return true;
}
return false;
}
}
public Employees Listof = new Employees();
public MainWindow() : base(Gtk.WindowType.Toplevel)
{
Build();
Listof.employees = new List<Employee>()
{
new Employee(1, "Ram", 50000),
new Employee(2, "Sahaym", 40000),
new Employee(3, "Gopi", 55000),
new Employee(4, "Prakash", 45000),
new Employee(5, "Dheeraj", 60000),
new Employee(6, "Shibhu", 50000)
};
label1.Text = "Employee Count: " + Listof.employees.Count.ToString();
}
protected void OnDeleteEvent(object sender, DeleteEventArgs a)
{
Application.Quit();
a.RetVal = true;
}
protected void OnButton3Pressed(object sender, EventArgs e)
{
label1.Text = $"Deleted Employee 3 successful : {Listof.Delete(3)}" +
" Employee Count: " + Listof.employees.Count.ToString();
}

comparing two lists excluding a particular column in c#

Consider an entity named Employee which contains id,age and name as properties
I have two lists containing the Employee details
I have to compare the two lists excluding the id column
Please help with your suggestions
This will yield all the entries that are the same in both lists, ignoring the Id Property of your Employee:
var employees1 = new List<Employee>
{
new Employee(1, "Thomas", 12),
new Employee(2, "Alex", 24),
new Employee(3, "Tobias", 13),
new Employee(4, "Joshua", 12),
new Employee(5, "Thomas", 24)
};
var employees2 = new List<Employee>
{
new Employee(1, "Thomas", 12),
new Employee(2, "Yu", 24),
new Employee(3, "Max", 13),
new Employee(4, "Joshua", 30),
new Employee(5, "Maico", 13)
};
var duplicates = employees1.Intersect(employees2, new EmployeeComparer());
class EmployeeComparer : IEqualityComparer<Employee>
{
public bool Equals(Employee employee1, Employee employee2)
{
if (Object.ReferenceEquals(employee1, null) || Object.ReferenceEquals(employee2, null) ||
Object.ReferenceEquals(employee1, employee2)) return false;
return employee1.Name == employee2.Name && employee1.Age == employee2.Age;
}
public int GetHashCode(Employee employee)
{
return 0;
}
}
class Employee
{
public Employee(int id, string name, int age)
{
Id = id;
Name = name;
Age = age;
}
public int Id { get; set; }
public string Name { get; set; }
public int Age { get; set; }
}
As the post is tagged with LINQ I have used that in my answer.
static void Main(string[] args)
{
var list1 = new List<Person>();
var list2 = new List<Person>();
list1.Add(new Person(1, "james", "moon"));
list1.Add(new Person(1, "bob", "bar"));
list1.Add(new Person(1, "tim", "lane"));
list1.Add(new Person(1, "fizz", "sea"));
list2.Add(new Person(1, "buzz", "space"));
list2.Add(new Person(1, "james", "moon"));
var result = findDuplicates(list1, list2);
}
public static List<Person> findDuplicates(List<Person> l1, List<Person> l2)
{
return l1.Where(p => l2.Any(z => z.FName == p.FName && z.Addre == p.Addre)).ToList();
}
Person Class
public class Person
{
private int id;
private string fName;
private string addre;
public string Addre
{
get { return addre; }
set { addre = value; }
}
public string FName
{
get { return fName; }
set { fName = value; }
}
public int ID
{
get { return id; }
set { id = value; }
}
public Person(int i, string f, string a)
{
ID = i;
FName = f;
Addre = a;
}
}
Assuming Employee class:
class Employee
{
public int id { get; set; }
public int age { get; set; }
public string name { get; set; }
}
You can simply use Intersect :
var list1 = new List<Employee> {
new Employee{ id=2 , age=23, name="Hari"},
new Employee{ id=3 , age=10, name="Joe"},
new Employee{ id=4 , age=29, name="Daniel"},
};
var list2 = new List<Employee> {
new Employee{ id=1 , age=23, name="Hari"},
new Employee{ id=5 , age=10, name="Joe"},
new Employee{ id=6 , age=29, name="Daniel"},
};
var intersect = list1.Select(e => new { e.age, e.name }).Intersect(list2.Select(e => new { e.age, e.name })).ToList();

Creating Org Structure from An Employee Class

I have the following class:
public class Employee
{
public int EmployeeID { get; set; }
public string EmployeeName { get; set; }
public string EmployeeLastname { get; set; }
public int ManagerID { get; set; }
public Employee Manager { get; set; }
public string Department { get; set; }
}
And the following objects:
Employee emp1 = new Employee();
emp1.Department = "C Level";
emp1.EmployeeID = 1;
emp1.EmployeeLastname = "Smith";
emp1.EmployeeName = "Joe";
Employee emp2 = new Employee();
emp2.Department = "B Level";
emp2.EmployeeID = 2;
emp2.EmployeeLastname = "Smith";
emp2.EmployeeName = "John";
emp2.ManagerID = 1;
Employee emp3 = new Employee();
emp3.Department = "A Level";
emp3.EmployeeID = 3;
emp3.EmployeeLastname = "Mallari";
emp3.EmployeeName = "Lem";
emp3.ManagerID = 2;
I need to create a method which needs an employee id and returns a single Employee object which contains the org structure. So for example if I search for employee 1 it returns me the following:
Employee
EmployeeID: 1
EmployeeName: Joe
EmployeeLastName: Smith
Department: C Level
ManagerID: null
Manager: null
But for example if I search for Employee ID 3 it will return me the following:
Employee
EmployeeID: 3
EmployeeName: Lem
EmployeeName: Mallari
Department: A Level
ManagerID: 2
Manager:
EmployeeID: 2
EmployeeName: John
EmployeeLastname: Smith
Department: B Level
ManagerID: 1
Manager:
EmployeeID: 1
EmployeeName: Joe
EmployeeLasname: Smith
Department: C Level
ManagerID: null
Manager: null
I was able to create a method already which gets the details of the manager given an ID and link that manager to the employee originally searched. I just can't think of a way to continuously search for a manager and updating the property of an object an be able to create the structure I need.
One solution would be to use recursion to reconstruct the object graph. Downside is that you would need all employees in memory.
public class EmployeeSearcher
{
private IEnumerable<Employee> _employees;
public EmployeeSearcher(IEnumerable<Employee> employees) => _employees = employees;
public Employee Search(int id)
{
var employee = _employees.SingleOrDefault(e => e.EmployeeID == id);
if (employee == null) throw new Exception($"Employee not found: {id}");
FindManagerRecursive(employee);
return employee;
}
private void FindManagerRecursive(Employee employee)
{
if (!employee.ManagerID.HasValue) return;
var manager = _employees.SingleOrDefault(e => e.EmployeeID == employee.ManagerID.Value);
if (manager == null) throw new Exception("Manager not found: {employee.ManagerID}");
employee.Manager = manager;
FindManagerRecursive(manager);
}
}
Usage:
var searcher = new EmployeeSearcher(new List<Employee> { emp1, emp2, emp3});
var result = searcher.Search(3);
Your requirement is already in C#.
var employee3 = emps.FirstOrDefault(x => x.EmployeeID == 3);
Your employee3 contains already all the information of the managers.
var manager = employee3?.Manager?.Manager;
Have a look at below at any point you will know who all are the employees and who is the manager and then with your employee object you can traverse upwards or downwards.
class Program
{
static List<Employee> lstEmployee = new List<Employee>();
static void Main(string[] args)
{
Employee emp1 = new Employee();
emp1.Department = "C Level";
emp1.EmployeeID = 1;
emp1.EmployeeLastname = "Smith";
emp1.EmployeeName = "Joe";
lstEmployee.Add(emp1);
Employee emp2 = new Employee();
emp2.Department = "B Level";
emp2.EmployeeID = 2;
emp2.EmployeeLastname = "Smith";
emp2.EmployeeName = "John";
emp2.ManagerID = 1;
lstEmployee.Add(emp2);
Employee emp3 = new Employee();
emp3.Department = "A Level";
emp3.EmployeeID = 3;
emp3.EmployeeLastname = "Mallari";
emp3.EmployeeName = "Lem";
emp3.ManagerID = 2;
lstEmployee.Add(emp3);
Console.ReadLine();
}
public class Employee
{
public int EmployeeID { get; set; }
public string EmployeeName { get; set; }
public string EmployeeLastname { get; set; }
public int ManagerID { get; set; }
public Employee Manager
{
get
{
return (from a in lstEmployee where a.EmployeeID == ManagerID select a).FirstOrDefault();
}
}
public List<Employee> Reportees
{
get
{
return (from a in lstEmployee where a.ManagerID == EmployeeID select a).ToList();
}
}
public string Department { get; set; }
}
}

Linq : Comparing 1 Child Collection to (Aggregated) ChildCollection(s)

I have a Linq question: (DotNet Framework 4.0)
I have the following classes:
public class Employee
{
public Guid? EmployeeUUID { get; set; }
public string SSN { get; set; }
}
public class JobTitle
{
public Guid? JobTitleSurrogateKey { get; set; }
public string JobTitleName { get; set; }
}
public class EmployeeToJobTitleMatchLink
{
public EmployeeToJobTitleMatchLink()
{
this.TheJobTitle = new JobTitle() { JobTitleSurrogateKey = Guid.NewGuid(), JobTitleName = "SomeJobTitle:" + Guid.NewGuid().ToString("N") };
}
public Guid LinkSurrogateKey { get; set; }
/* Related Objects */
public Employee TheEmployee { get; set; }
public JobTitle TheJobTitle { get; set; }
}
public class Organization
{
public Organization()
{
this.Links = new List<EmployeeToJobTitleMatchLink>();
}
public int OrganizationSurrogateKey { get; set; }
public ICollection<EmployeeToJobTitleMatchLink> Links { get; set; }
}
In my code below, I can compare 2 child-collections and get the results I need (in "matches1".
Here I am using the "SSN" string property to compare and find the overlaps. And the Console.Write for matches1 works as I expect.
What I don't know how to do is compare the first child collection (org10) to all the children in (allOtherOrgsExceptOrg10 (all the Organizations and all the Links of these Organizations )
The commented out code shows kinda what I'm trying to do, one of my many feeble attempts today.
But basically, match2 would be populated with all the SSN overlaps...but comparing org10 with allOtherOrgsExceptOrg10, all their "Links", and their Employee.SSN's.
org10 overlaps with org20 with "AAA", so match2 would contain "AAA". and org10 overlaps with org30 with "BBB" so match2 would contain "BBB".
Organization org10 = new Organization();
org10.OrganizationSurrogateKey = 10;
Employee e11 = new Employee() { SSN = "AAA", EmployeeUUID = new Guid("AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA") };
EmployeeToJobTitleMatchLink link11 = new EmployeeToJobTitleMatchLink();
link11.TheEmployee = e11;
org10.Links.Add(link11);
Employee e12 = new Employee() { SSN = "BBB", EmployeeUUID = new Guid("BBBBBBBB-BBBB-BBBB-BBBB-BBBBBBBBBBBB") };
EmployeeToJobTitleMatchLink link12 = new EmployeeToJobTitleMatchLink();
link12.TheEmployee = e12;
org10.Links.Add(link12);
Organization org20 = new Organization();
org20.OrganizationSurrogateKey = 20;
Employee e21 = new Employee() { SSN = "AAA", EmployeeUUID = new Guid("AAAAAAAA-AAAA-AAAA-AAAA-AAAAAAAAAAAA") };
EmployeeToJobTitleMatchLink link21 = new EmployeeToJobTitleMatchLink();
link21.TheEmployee = e21;
org20.Links.Add(link21);
Employee e22 = new Employee() { SSN = "CCC", EmployeeUUID = new Guid("CCCCCCCC-CCCC-CCCC-CCCC-CCCCCCCCCCCC") };
EmployeeToJobTitleMatchLink link22 = new EmployeeToJobTitleMatchLink();
link22.TheEmployee = e22;
org20.Links.Add(link22);
Organization org30 = new Organization();
org30.OrganizationSurrogateKey = 30;
Employee e31 = new Employee() { SSN = "BBB", EmployeeUUID = new Guid("BBBBBBBB-BBBB-BBBB-BBBB-BBBBBBBBBBBB") };
EmployeeToJobTitleMatchLink link31 = new EmployeeToJobTitleMatchLink();
link31.TheEmployee = e31;
org30.Links.Add(link31);
Employee e32 = new Employee();
e32.SSN = "ZZZ";
EmployeeToJobTitleMatchLink link32 = new EmployeeToJobTitleMatchLink();
link32.TheEmployee = e32;
org30.Links.Add(link32);
IList<Organization> allOtherOrgsExceptOrg10 = new List<Organization>();
/* Note, I did not add org10 here */
allOtherOrgsExceptOrg10.Add(org20);
allOtherOrgsExceptOrg10.Add(org30);
IEnumerable<EmployeeToJobTitleMatchLink> matches1 =
org10.Links.Where(org10Link => org20.Links.Any(org20Link => org20Link.TheEmployee.SSN.Equals(org10Link.TheEmployee.SSN, StringComparison.OrdinalIgnoreCase)));
IEnumerable<EmployeeToJobTitleMatchLink> matches2 = null;
//org10.Links.Where(org10Link => ( allOtherOrgs.Where ( anyOtherOrg => anyOtherOrg.Links.Any(dbSideChild => dbSideChild.TheEmployee.SSN == org10Link.TheEmployee.SSN)) );
if (null != matches1)
{
foreach (EmployeeToJobTitleMatchLink link in matches1)
{
Console.WriteLine(string.Format("matches1, SSN = {0}", link.TheEmployee.SSN));
}
}
if (null != matches2)
{
foreach (EmployeeToJobTitleMatchLink link in matches2)
{
Console.WriteLine(string.Format("matches2, SSN = {0}", link.TheEmployee.SSN));
}
}
matches2 =
allOtherOrgsExceptOrg10.SelectMany(x => x.Links)
.Where(x => org10.Links.Select(o => o.TheEmployee.SSN).Contains(x.TheEmployee.SSN));
You can use the SelectMany on the allOther collection to select all Links over all org's. Then check if any SSN is inside the org10 List.
See: http://msdn.microsoft.com/en-us/library/system.linq.enumerable.selectmany(v=vs.100).aspx
You can use SelectMany to flatten out the collection and then use it just like you have for matches1
IEnumerable<EmployeeToJobTitleMatchLink> matches2 =
org10.Links.Where(
org10Link =>
allOtherOrgsExceptOrg10.SelectMany(allOtherOrgs => allOtherOrgs.Links).Any(
anyOtherLink =>
anyOtherLink.TheEmployee.SSN.Equals(org10Link.TheEmployee.SSN, StringComparison.OrdinalIgnoreCase)));
The SelectMany will make it seem like one IEnumerable instead of and IEnumerable of an IEnumerable.

Question about Auto-Implemented Properties C#

I have this code:
void Main()
{
List<Employee> employeeList;
employeeList = new List<Employee>
{
{new Employee("000001", "DELA CRUZ, JUAN T.")},
{new Employee("000002", "GOMEZ, MAR B.")},
{new Employee("000003", "RIVERA, ERWIN J.")}
};
employeeList.Dump();
}
public class Employee
{
public string EmployeeNo { get; set; }
public string Name { get; set; }
public Employee(string employeeNo, string name)
{
this.EmployeeNo = employeeNo;
this.Name = name;
}
}
How should I make a new instance of Employee class using the properties only and add that instance to the employeeList (I mean not using the class constructor of employee)?
I already made a solution but it's too lengthy. How should I shorten it?
void Main()
{
List<Employee> employeeList;
#region - I want to shorten these lengthy codes.
Employee employee1 = new Employee();
employee1.EmployeeNo = "000001";
employee1.Name = "DELA CRUZ, JUAN T.";
Employee employee2 = new Employee();
employee2.EmployeeNo = "000002";
employee2.Name = "GOMEZ, MAR B.";
// other employees...
#endregion
employeeList = new List<Employee>
{
employee1,
employee2
};
employeeList.Dump();
}
public class Employee
{
public string EmployeeNo { get; set; }
public string Name { get; set; }
}
You could do this
var list = new List<Employee>
{
new Employee {EmployeeNo = "000001", Name = "Peter Pan"},
new Employee {EmployeeNo = "000002", Name = "King Kong"}
};
of this
public class EmployeeList : List<Employee>
{
public void Add(string no, string name)
{
this.Add(new Employee(no, name));
}
}
var list = new EmployeeList
{
{ "000001", "Peter Pan" },
{ "000002", "King Kong"}
};
You could do something like that
var employee1 = New Employee() { EmployeeNo = "000001", Name = "DELA CRUZ, JUAN T." };
How about this?
void Main()
{
var employeeList = new List<Employee> {
new Employee { EmployeeNo = "000001", Name = "DELA CRUZ, JUAN T." },
new Employee { EmployeeNo = "000002", Name = "GOMEZ, MAR B." }
};
employeeList.Dump();
}
public class Employee
{
public string EmployeeNo { get; set; }
public string Name { get; set; }
}

Categories

Resources