C# - How to initialize complex property when creating new object? -


Say I have an employee class and it has a property type department in my GUI, I want to make a new employee And I want to instantiate it. I have a collection through the combo box of objects so that the end users can select one department for each employee

My question is, when I instantiate this employee And I want to define the department at some value, say "finance" which is for the department. Code Property

How can I do this?

I tried, but it does not look like when saved:

  this.Employee = Employee.CreateEmployee ("-1", date time.Now, "active", ...); this. Staff. Department = new department {code = "finance"};  

Any advice would be greatly appreciated.

Generally classes are built with constructors; I.e.

  public square section {string _code = ""; Public Department () {} Public Department (string code) {_code = code; }}  

So when your program creates a new department object, you can do this:

  Department Finance = New Department ("Finance" ); this. Employee employee = Crete employee ("- 1", date time.Now, "active", ...); this. Staff. Department = finance; Edit: You probably want to use an aummeter for it, as you can declare a calculator:  
  public enterprise department { Finance, Technology, Sales} Public Class Employees (Departments Department Department; Public Employee () {} Public Worker (Department Staff Department) (_employeeDepartment = Staff Department;}}  

Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -