The method of encapsulation and

  1. Package

    1. Access modifier
      1. public can access all objects
      2. private access to the object itself inside the object
      3. prorected only class object can access the object and its subclasses
      4. internal set of objects of the same program can be accessed
      5. protected internal access limited current type self-contained assembly or derived classes
  2. method

    1. 调用方法 <Access Specifier> <Return Type> <Method Name> (Parameter List)
      1. Access Specifier: access modifier, the decision variables or method visibility to another class
      2. Return Type: return type, a method can return a value
      3. Method Name: Method names are case insensitive, not the same as the other identifiers to other classes declared
      4. Parameter List: the list of parameters
    2. Recursive method
      1. A method can be called that calls itself recursively
        1. Recursive three elements
          1.  When changing ends
          2. Recursive need Zuosa
          3. You need to return the value of the recursive return value ah
    3. Passing parameters
      1. The value of the parameter
      2. Reference parameters, use the keyword ref, call way: ref Type Parameter 
      3. Output parameters (can return multiple values) using the keyword out, call way: out Type Parameter
        1. 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
  3. Nullable type (Nullable)

    1.  ? : 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 
    2.  Null merge operator (??)
      1. 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
        
        

         

Published 24 original articles · won praise 5 · Views 3207

Guess you like

Origin blog.csdn.net/Ellis1993/article/details/105309687