C # Encapsulation and Class properties classroom on-machine exercises

Source: Internet
Author: User

Properties of encapsulation and classes classroom on-machine Exercise
Classroom task One: definition and use of the field
Time: 12 minutes
Required:
Creates a field in car class and displays information for each field in the button's Click event.
Step:
? 1. Create a project of a form type Carsystem
? 2, create car class cars, this class contains the fields: car name, price, manufacturers
? 3, write a button click event, use the MessageBox.Show method to display these field information
? 4, create a form, enter the car name, price, manufacturer, and store it in the corresponding field in the Car object
? 5, Test the class, try the price of 1 billion yuan will be wrong? Does this price accord with the common sense of life?
Classroom Task Two: definition and use of properties
    time: 10 minutes
Requirements:
Creates an attribute for the Price field in the previous car class car, with a rule of a price greater than 20,000 and less than 50 million.
   Step:
1, create a property for the price field of the car class, the rule is that the price is greater than 20,000 and less than 50 million
2, test the class, the attempt price is 1 billion yuan error?
Classroom Task Three: Declaration and use of methods
Time: 12 minutes
Requirements:
  in front of car cars, use the method showcarinfo to display information for each field.
    Step:
1, write a method showcarinfo in the class car, and messagebox.show the information of each field in the method, no return value is required.
2, add a button, call Showcarinfo display information in its Click event,
3, test the method is correct
  4, [supplemental] Another method ShowCarInfo2, return the field information to be displayed. (done)
Classroom Task Four: Writing construction methods for classes
Time: 12 minutes
Requirements:
  Create a constructor for car cars and initialize each field with the values in the form text box.
    steps:
1, create a constructor for car cars, and initialize each field with the values in the form text box.
2, add a button to create a car object in its Click event, initialize the fields, and then call Showcarinfo to display the information.
3. The test initialization data is correct.

Properties for C # encapsulation and classes classroom on-machine exercises

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.