-
Package
- Access modifier
- public can access all objects
- private access to the object itself inside the object
- prorected only class object can access the object and its subclasses
- internal set of objects of the same program can be accessed
- protected internal access limited current type self-contained assembly or derived classes
- Access modifier
-
method
- 调用方法 <Access Specifier> <Return Type> <Method Name> (Parameter List)
- Access Specifier: access modifier, the decision variables or method visibility to another class
- Return Type: return type, a method can return a value
- Method Name: Method names are case insensitive, not the same as the other identifiers to other classes declared
- Parameter List: the list of parameters
- Recursive method
- A method can be called that calls itself recursively
- Recursive three elements
- When changing ends
- Recursive need Zuosa
- You need to return the value of the recursive return value ah
- Recursive three elements
- A method can be called that calls itself recursively
- Passing parameters
- The value of the parameter
- Reference parameters, use the keyword ref, call way: ref Type Parameter
- Output parameters (can return multiple values) using the keyword out, call way: out Type Parameter
- Output parameters are not assigned, when the method returns a value, the output mode is particularly useful when there is no need to initialize worth from a parameter
- 调用方法 <Access Specifier> <Return Type> <Method Name> (Parameter List)
-
Nullable type (Nullable)
- ? : One question mark for int, double, bool, etc. can not be assigned directly assigned null null data type, meaning that the data type is nullable type
- Null merge operator (??)
- Null type of the operands to merge operator operand is implicit type conversion may be a blank (empty or not) of the value types
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace RectanglePack { class Rectangle { protected internal double m_length; protected internal double m_width; double GetArea() { return m_length * m_width; } public void Display() { Console.WriteLine("长度: {0}", m_length); Console.WriteLine("宽度: {0}", m_width); Console.WriteLine("面积: {0}", GetArea()); } } }; namespace StudentCShrap { class MainClassTest { static void Main(string[] args) { double? num1 = null; double? num2 = 3.1415926; double num3; num3 = num1 ?? 6.34; //如果num1 为null时 num3 = 5.34,否则等于num1 Console.WriteLine(num3); //6.34 num3 = num2 ?? 3.14; Console.WriteLine(num3); // 3.1415926 Console.ReadKey(); } } } 输出: 6.34 3.1415926
- Null type of the operands to merge operator operand is implicit type conversion may be a blank (empty or not) of the value types
The method of encapsulation and
Guess you like
Origin blog.csdn.net/Ellis1993/article/details/105309687
Recommended
Ranking