Process-oriented, object-oriented in-depth understanding 1

Source: Internet
Author: User

Process-oriented, object-oriented in-depth understanding 1

First, let's take a look at several exercises.

The first question does not need to be object-oriented.

Exchange the values of two variables. (If ref is used, use the method to pass two int parameters .)

Int num1 = 5; int num2 = 6;

PassProgramExchange num1 = 6, num2 = 5;

 

Figure 1. First calculation question

 

Figure 2. method 2 of Question 1 (no third variable is used)

Here is a shortcut: (CTRL + K + C comments, CTRL + K + u uncomment)

 

Question 2: Implement using methods (Note: What are the parameters and return values of methods ?) :

Calculate the maximum value of two numbers (pass two int type parameters ). Extended: (calculate the maximum number of three, Params)

 

 

Figure 3. If-else Solution

 

 

Figure 4. Three element expression solution for question 2nd and the differences between Ctrl + F5 and F5

 

 

Question 3: Calculate the sum of all the odd numbers between 1 and.

 

Figure 5. Calculate the sum of odd values

 

Question 4: find Fat Man, {200,120, 90,180,110}, and find the fattest person. (the maximum value is an array of int type .) The max () method of the array cannot be called.

 

 

Figure 6. Find the fattest person

 

Question 5: C # converts Chinese characters in the time format in uppercase, for example:"2011Year 6Month 4Day"To"June 4, 2011". (Refer to the tip: Use the string as a char array to determine if it is 2 → '2', 0 → '0', 1 → '1 '...). For the time being, questions such as day 10, day 13, and day 23 are not considered.

 

 

Figure 7. Time Format Conversion in uppercase

Question 6: Create a person class with attributes: name, gender, and age. Method: sayhi (). Create an employee class that inherits the person class, extends the property salary, and overwrites the sayhi method.

The following illustration is not fully written.CodeBut focuses on introducing some important and in-depth knowledge in the class.

 

Figure 8. in-depth understanding of the attributes in the class and the roles of values and return in the attributes during calling

In the above section, we used a concise article to review the object-oriented and process-oriented knowledge. Hope to help you.

 

C #Source codeCompilation process

 

Author's recentArticleList:
C # basic tutorial (free of charge, the best gift for code lovers. Note: The authors share their carefully organized basic C # tutorials without any commercial purposes.
I hope to share my experiences with more code lovers. Please give me more advice !!!)
Winform Basics Winform Basics
Commonly used controls in winform
Process-oriented Comparison of three cycles
Method (I) in C)
Our common Array
Object-oriented Thought Change
C # super-class and easy-to-use classes
The use of destructor and namespaces in C #
C # super-class and easy-to-use strings
How to quickly process strings in C #
Value Type, reference type, and others
Arraylist and hashtable
Arraylist and hashtable
File Management
Polymorphism
Section on other issues in C #
GDI + The GDI + code I have collected over the years
The GDI + Code 2 I collected over the years
HTML Overview HTML language that you cannot ignore
You can't ignore HTML 2.
HTML language 3 that you cannot ignore

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.