tailieunhanh - Microsoft Visual C# 2010 Step by Step (P16 - the end)

Tham khảo sách 'microsoft visual c# 2010 step by step (p16 - the end)', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | 720 Appendix Example IronPython The following example shows a Python script called . This class contains four items A class called Customer. This class contains three fields which contain the ID name and telephone number for a customer. The constructor initializes these fields with values passed in as parameters. The_str__ method formats the data in the class as a string so that it can be output. A class called CustomerDB. This class contains a dictionary called customerDatabase. The storeCustomer method adds a customer to this dictionary and the getCustomer method retrieves a customer when given the customer ID. The_str__ method iterates through the customers in the dictionary and formats them as a string. For simplicity none of these methods include any form of error checking. A function called GetNewCustomer. This is a factory method that constructs a Customer object using the parameters passed in and then returns this object. A function called GetCustomerDB. This is another factory method that constructs a CustomerDB object and returns it. class Customer definit_ self id name telephone id name telephone defstr__ self return ID 0 tName 1 tTelephone 2 class CustomerDB def_init__ self def storeCustomer self customer customer def getCustomer self id return id def_str__ self list Customers n for id cust in list 0 cust n return list Appendix 721 def GetNewCustomer id name telephone return Customer id name telephone def GetCustomerDB return CustomerDB The following code example shows a simple C console application that tests these items. You can find this application in the Microsoft Press Visual CSharp Step By Step Appendix PythonInteroperability folder under your Documents folder. It references the IronPython assemblies