Industrial essays _C # connection PLC_ entry _07_ function of _C #

A function common to use

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Function
{
    class staticFunction
    {
        public static void staticFunctionTest()
        {
            Console.WriteLine ( " This is a static function of the type of a class, to test " );
        }
    }
    class Program
    {
        public static void TestFunction()
        {
            Console.WriteLine ( " This is a test function !!! " );
        }

        public static void Main(string[] args)
        {
            // Note that the function can also define variable class include Main (), and may instantiate
             // Program cMyProgram = new new Program ();

            // test the effect of a recursive call Main function  
             // cMyProgram.Main ( "1", "2");   // not

            // If the class member function is defined as static, then with reference to the class name
             // without the need to instantiate an object 
             Program.TestFunction ();

            // static class function calls, static class functions do not need to instantiate the object can be referenced. 
             staticFunction.staticFunctionTest ();

            Console.ReadKey();
        }
    }
}

 

Second, the value of the parameter function

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace argument
{
    class Variable
    {
        public  int iVar = 20 ;
    }

    ///  <Summary> 
    ///   procedure demonstrates the value of the form parameter of the call type
     ///  </ Summary> 
    class Funtion
    { 
        ///  <Summary> 
        ///   define a function that is used to output information
         ///  </ Summary> 
        ///  <param name = "C1"> This parameter accepts an object of type Variable </ param> 
        / //  <param name = "B"> this parameter takes a variable int </ param> 
        public  void Print (variable C1, int B)
        {
            // Since the object is passed, the value of the object member fields, as modified herein, even if the exit function call
             // the value field corresponds to a member of the object will remain the modified value
             // master, because the class object Variable field is defined member 20 is = iVar,
             // after the following operations, becomes 25, when this function exits, a corresponding actual parameter value of the object will also 25 
            c1.iVar + = c1.iVar . 5 ;

            // If not a class object, when the function is exited, the value of the actual parameter passed to the holding function inside the original value 
            B = B + . 5 ;

            Console.WriteLine ( " which is inside in the Function class " );
            Console.WriteLine("v1.iVar = {0} , b = {1}",c1.iVar,b);
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Funtion f1 = new Funtion();
            Variable v1 = new Variable();

            int b=5;

            f1.print(v1, b);

            Console.WriteLine ( " \ n-Main function which is inside " );
             // this place printed value, demonstrates the value of the type parameter is an object, or simply different types 
            Console.WriteLine ( " v1.iVar = {0 }, B = {}. 1 " , v1.iVar, B);

            Console.ReadKey();

        }
    }
}

 

Third, the reference type parameter

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace argument
{
    class Variable
    {
        public  int iVar = 20 ;
    }

    ///  <the Summary> 
    ///   presentation referral process type formal parameter called
     ///  </ the Summary> 
    class Funtion
    {
        ///  <Summary> 
        ///   define a function that is used to output information
         ///  </ Summary> 
        ///  <param name = "C1"> This parameter accepts an object of type Variable </ param> 
        / //  <param name = "B"> this parameter takes a variable int </ param> 
        public  void Print ( REF variable C1, REF  int B)
        {
            // Since the object is passed by reference, so the value of the object's member fields as modified herein, even if the exit function call
             // value corresponding member field of the object will remain the modified value
             // master, because Variable members of the class object definition field 20 is = iVar,
             // after the following operations, becomes 25, when this function exits, a corresponding actual parameter value of the object will also 25 
            c1.iVar + = c1.iVar . 5 ;

            // Because the parameter b is positioned in the form of a reference type, when the function call is passed to the function is a reference to the actual parameter,
             // when the function is exited, the value of the actual parameter values will be modified to perform the following operations after the statement 
            b = b + 5 ;

            Console.WriteLine ( " which is inside in the Function class " );
            Console.WriteLine("v1.iVar = {0} , b = {1}", c1.iVar, b);
        }
    }

    class Program
    {
        static void Main(string[] args)
        {
            Funtion f1 = new Funtion();
            Variable v1 = new Variable();

            int b = 5;

            // Note that, regardless of class type of arguments, or simple type arguments, if defined as
             // ref type, the call, you must add the keyword ref 
            f1.print ( ref v1, ref b);

            Console.WriteLine ( " \ n-Main function which is inside " );
             // place print out the value of the attention value type parameter and a reference differential type parameter ref 
            Console.WriteLine ( " v1.iVar = {0}, B {}. 1 = " , v1.iVar, B);

            Console.ReadKey();

        }
    }
}

 

 

-------------------------------------------------- ------------Dividing line------------------------------------ ---------------------------

1, individual articles are original, welcome to reprint, please retain the source: https: //www.cnblogs.com/volcanol/

2, access to industrial PLC, inverter, HMI, computers, Windows, Linux, embedded enlarge click: Access to information

3. If you think the article is helpful to you can go to the page and a half portion of a reward, or the venue: a reward 

4, or recommend a page in the lower right corner yo! ! !

-------------------------------------------------- ------------Dividing line------------------------------------ ---------------------------

 

Guess you like

Origin www.cnblogs.com/volcanol/p/12416756.html