C # struct traps in languages

Source: Internet
Author: User

Suppose we want to write a salary management program for a university. First, it indicates the Employee's Employee class (Employee. cs ):

01: namespace Skyiv. ben02: {03: class Employee04: {05: public string Department {get; private set;} 06: public string Name {get; private set;} 07: public decimal Salary {get; set;} 08: 09: public Employee (string department, string name, decimal salary) 10: {11: Department = department; 12: Name = name; 13: Salary = salary; 14:} 15: 16: public override string ToString () 17: {18: return string. format ("{0} {1} Salary: {2: N2}", Department, Name, Salary); 19:} 20:} 21 :}

Next, the Department class (Department. cs) of each Department in the school ):

01: namespace Skyiv. ben02: {03: class Department04: {05: public string Name {get; private set;} 06: public int Count {get; private set;} 07: public decimal TotalSalary {get; private set;} 08: 09: public Department (string name) 10: {11: Name = name; 12:} 13: 14: public void Add (Employee) 15: {16: Count ++; 17: TotalSalary + = employee. salary; 18 :}19: 20: public override string ToString () 21: {22: return string. format ("{0} Total number of students: {1} total salary: {2: N2}", Name, Count, TotalSalary); 23:} 24:} 25 :}

Finally, the main Program. cs:

01: using System; 02: using System. collections. generic; 03: 04: namespace Skyiv. ben05: {06: class Program07: {08: static void Main () 09: {10: new Program (). run (); 11 :}12: 13: void Run () 14: {15: var employees = InitializeEmployees (); 16: SalaryRaise (employees); 17: statistic (employees); 18:} 19: 20: List <Employee> InitializeEmployees () 21: {22: var employees = new List <Employee> (); 23: employees. add (new Employee ("", "", 72767.58 m); 24: employees. add (new Employee (
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.