C# Object Oriented Programming

Associate
Joined
31 Dec 2002
Posts
458
Hi,

I have just started to dive into learning OOP with C#. Getting to grips with creating Classes, Constructors, Properties and Methods etc.

However I could do with a nudge conceptually. Say you had an application using employee objects how would you keep track of multiple employees. Also how would you retrieve specific instances of an employee and make changes? would you save the state of an object to a database? and then retrieve it from there? or would you also use collections such as an arraylist?

Say the user creates a user account and enters their details how would the application instantiate an Employee object dynamically? without explicitly declaring it in the application?

Sorry for all the questions but OOP is a bit of a leap!!!!

Cheers.
 
Associate
OP
Joined
31 Dec 2002
Posts
458
Hi thanks for the quick replies, appreciate it. I am using .NET and Visual Studio 2013 through VMWARE Fusion. I have an iMac and have also been playing with Xamarin and Java.
 
Associate
OP
Joined
31 Dec 2002
Posts
458
One thing that baffles me is how would you get all of an Employee objects associated properties. Say you had name, age, job role, age for each employee. Would you need to keep track of the list index number for each employee and then work with that?
 
Associate
OP
Joined
31 Dec 2002
Posts
458
So going back to make changes to a hypothetical employee named Joe Bloggs that is stored in index 0 of the employeeList list would be something like:

Code:
if (employeeList[0].name == "Joe Bloggs")
{
employeeList[0].jobrole = "Department manager";
employeeList[0].salary = "45000";
employeeList[0].leave = "35";
employeeList[0].appraisal = "Excellent";

}
 
Associate
OP
Joined
31 Dec 2002
Posts
458
Hi sorry have not heard of MVVM, will take a look. Just been reading about Entity Framework, it looks really interesting. Regarding you mentioning selecting the employee from the list first before making changes, how would you do this? i.e. instantiating that specific instance again? would it be something like:

Code:
Employee retrievedEmployee;
retrievedEmployee = employeeList[0];
retrievedEmployee.salary = int.Parse(txtSalary.Text);

What I do not understand is if the list had a datatype of Employee objects how would you grab an object from it, or would you have to recreate as above?
 
Last edited:
Associate
OP
Joined
31 Dec 2002
Posts
458
I see now, you changed the reference with emp2 pointing to the emp object. So any changes made to either emp or emp2 would update the same object. I think !!!!
 
Back
Top Bottom