当前位置:网站首页>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()
{
}
}
输出:
边栏推荐
- Passing parameters in multiple threads
- Proprietary host CDH
- RAID磁盘阵列
- Browser Storage for H5
- VRRP overview and experiment
- selenium模块的操作之拉钩
- Does flink cdc currently support Gauss database sources?
- Collection of error records (write down when you encounter them)
- Will intelligent operation and maintenance replace manual operation and maintenance?
- wc、grep、tar、vi/vim
猜你喜欢

Mina断线重连

Transport layer protocol (TCP 3-way handshake)

el-progress实现进度条颜色不同

NIO works is analysed
![[问题已处理]-虚拟机报错contains a file system with errors check forced](/img/07/1222a44dd52b359bf7873e6f3b7ebf.png)
[问题已处理]-虚拟机报错contains a file system with errors check forced

markdown editor template

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

Configuration of routers and static routes

VLAN介绍与实验
![[问题已处理]-jenkins流水线checkout超时](/img/3d/c14276d2b5ce18fc3d1288abb059c0.png)
[问题已处理]-jenkins流水线checkout超时
随机推荐
路由器和静态路由的配置
云计算基础-学习笔记
Operation and maintenance engineer, come and pick up the wool
sql server duplicate values are counted after
用户和用户组管理、文件权限管理
disabledDate 日期选择器 datePicker
Teach you simple steps to achieve industrial raspberries pie properly installed RS232 USB drive
Media query, rem mobile terminal adaptation
BIO,NIO,AIO实践学习笔记(便于理解理论)
磁盘管理与文件系统
From "dual card dual standby" to "dual communication", vivo took the lead in promoting the implementation of the DSDA architecture
ALC实验
flink cdc 目前支持Gauss数据库源吗
Mina断线重连
干货!教您使用工业树莓派结合CODESYS配置EtherCAT主站
What?CDN cache acceleration only works for accelerating static content?
product learning materials
[问题已处理]-虚拟机报错contains a file system with errors check forced
解决这三大问题,运维效率将超90%的医院
spark operator - map vs mapPartitions operator