当前位置:网站首页>The use of three parameters of ref, out, and Params in Unity3D
The use of three parameters of ref, out, and Params in Unity3D
2022-08-05 06:32:00 【IT apprentice.】
ref
作用:
将一个变量传入一个函数中进行"处理","处理"完成后,再将"处理"后的值带出函数.
语法:
Both formal and actual parameters must be added when usedref关键字.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Test: MonoBehaviour {
void Start () {
int a = 1;
int b = 2;
refTest(ref a, b);
Debug.Log("a:" + a + " " + "b:" + b);
}
private void refTest(ref int num1,int num2)
{
num1 = 5;
num2 = 10;
}
void Update () {
}
}
输出:
out
作用:
一个函数中如果返回多个不同类型的值,就需要用到out参数.
语法:
It is not necessary to assign values to variables outside the function,But inside the function must assign a value to the function.And both formal parameters and actual parameters should be addedout关键字.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Test : MonoBehaviour
{
void Start()
{
int b;
outTest(out b);
Debug.Log("b:" + b);
}
private void outTest(out int num1)
{
num1 = 5;
}
void Update()
{
}
}
输出:
注意:
outThe real assignment of the modified parameter is inside the function,Assignment outside is useless,具体如下:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Test : MonoBehaviour
{
void Start()
{
int b;
b = 10;
outTest(out b);
Debug.Log("b:" + b);
}
private void outTest(out int num1)
{
num1 = 5;
}
void Update()
{
}
}
输出
Params
可变参数params(数组参数)Allows us to dynamically pass in a different number of parameters.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Test : MonoBehaviour
{
public void Getdd(params int[] pp)
{
foreach (var p in pp)
{
print(p);
}
}
void Start()
{
Getdd(1, 2, 3);
}
void Update()
{
}
}
输出:
边栏推荐
- 磁盘管理与文件系统
- RAID磁盘阵列
- static routing
- input detailed file upload
- What impact does CIPU have on the cloud computing industry?
- Difference between link and @improt
- Technology Sharing Miscellaneous Technologies
- In-depth Zabbix user guide - from the green boy
- What?CDN cache acceleration only works for accelerating static content?
- 初识网页与浏览器
猜你喜欢

Chengyun Technology was invited to attend the 2022 Alibaba Cloud Partner Conference and won the "Gathering Strength and Going Far" Award

深度 Zabbix 使用指南——来自惨绿少年

Passing parameters in multiple threads

DisabledDate date picker datePicker
time complexity and space complexity

Introduction to Network Layer Protocols

IP packet format (ICMP protocol and ARP protocol)

入职前,没想到他们玩的这么花

input详解之文件上传

Teach you simple steps to achieve industrial raspberries pie properly installed RS232 USB drive
随机推荐
In-depth Zabbix user guide - from the green boy
By solving these three problems, the operation and maintenance efficiency will exceed 90% of the hospital
King power volume LinkSLA, realize operations engineer is happy fishing
Detailed explanation of ten solutions across domains (summary)
Does flink cdc currently support Gauss database sources?
This is indeed the best article on microservice architecture I have read!
spark source code - task submission process - 3-ApplicationMaster
Mina断线重连
Spark source code - task submission process - 6-sparkContext initialization
Transformer interprets and predicts instance records in detail
逻辑卷创建
网络层协议介绍
[问题已处理]-虚拟机报错contains a file system with errors check forced
Transport layer protocol (TCP 3-way handshake)
LinkSLA insists that users come first and creates a sustainable operation and maintenance service plan
错误类型:反射。ReflectionException:无法设置属性“xxx”的“类”xxx”与价值“xxx”
Seven Ways to Center a Box Horizontally and Vertically
Programmers should understand I/O this way
What impact does CIPU have on the cloud computing industry?
浏览器存储WebStorage