C#-in,ref,out

 

 

 

 

 Figure on the line

See:

 

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

 

public class Test : MonoBehaviour
{
  // Start is called before the first frame update
  void Start()
  {
    int a = 0, b = 1;

 


    Sum2 (REF A, B);
    Debug.Log (string.Format ( "REF need to be evaluated when passed, and this value can be modified after being passed, returns the results {0} =", A));
    Sum3 (C var OUT, B);
    Debug.Log (string.Format ( "OUT corresponds to the function return value, this parameter must be assigned only when the internal processing function must have the equivalent of a non-void return value returned result = {0 } ", C));
  }

 

  // 1. In parameter that is unable to compile this because in almost declared variables and readonly, read-only, can not be modified
  // public void Suml (in A int, int B)
  // {
    // = A + b;

  //}

 

  //2. ref型参数
  public void Sum2(ref int a, int b)
  {
    a += b;
  }
  //3. out型参数
  public void Sum3(out int a, int b)
  {
    a = b + 2;
  }
}

 

Guess you like

Origin www.cnblogs.com/fairy-blonde/p/12011949.html