当前位置:网站首页>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()
{
}
}
输出:
边栏推荐
- Browser Storage for H5
- Complete mysql offline installation in 5 minutes
- 智能运维会取代人工运维吗?
- Spark source code-task submission process-6.2-sparkContext initialization-TaskScheduler task scheduler
- What is Alibaba Cloud Express Beauty Station?
- RAID磁盘阵列
- Mina disconnects and reconnects
- What are some things that you only know when you do operation and maintenance?
- 带你深入了解Cookie
- 程序员应该这样理解I/O
猜你喜欢

By solving these three problems, the operation and maintenance efficiency will exceed 90% of the hospital

多线程之传递参数

Network wiring and digital-to-system conversion

Transformer详细解读与预测实例记录

sql server 重复值在后面计数

el-autocomplete use

Autoware--Beike Tianhui rfans lidar uses the camera & lidar joint calibration file to verify the fusion effect of point cloud images

错误类型:反射。ReflectionException:无法设置属性“xxx”的“类”xxx”与价值“xxx”

What's the point of monitoring the involution of the system?

NAT experiment
随机推荐
Technology Sharing Miscellaneous Technologies
One-arm routing experiment and three-layer switch experiment
Media query, rem mobile terminal adaptation
监控系统的内卷,有什么讲究?
大小屏适配
Mina的长连接和短连接
系统基础-学习笔记(一些命令记录)
Spark source code - task submission process - 6-sparkContext initialization
Programmers should understand I/O this way
D46_Force applied to rigid body
May I ask how to read the binlog of the two tables of hologres through flink sql, and then how to join?
The problem come from line screening process
Small example of regular expression--remove spaces in the middle and on both sides of the string
King power volume LinkSLA, realize operations engineer is happy fishing
七种让盒子水平垂直居中的方法
网络层协议介绍
[ingress]-ingress exposes services using tcp port
el-progress implements different colors of the progress bar
From "dual card dual standby" to "dual communication", vivo took the lead in promoting the implementation of the DSDA architecture
vim教程:vimtutor