shanmuga raja shanmuga raja - 9 days ago 5
C# Question

What is the best practice to name the second instance of a class when the first instance is still in scope?

What is the best practice to name the second instance of a class? For example, for a class named Employee I create the first instance named as employee. What would be the best name for the second instance of the Employee class when the first instance is still in scope?

Answer

Typically the answer is that you don't create a second Employee variable. If you are dealing with two employees, use a collection like:

An array:

Employee[] employees = new Employee[2];

Or a List:

List<Employee> employees = new List<Employee>();

If you aren't in a situation where you are just dealing with a group of employees than name the variable what it represents in the context of the code, like any other variable (searchEmployee, newEmployee, employeeToBeFired, etc.).