当前位置:网站首页>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()
{
}
}
输出:
边栏推荐
- Dry!Teach you to use industrial raspberries pie combining CODESYS configuration EtherCAT master station
- From "dual card dual standby" to "dual communication", vivo took the lead in promoting the implementation of the DSDA architecture
- js dynamically get screen width and height
- flink cdc 目前支持Gauss数据库源吗
- What are some things that you only know when you do operation and maintenance?
- D46_Force applied to rigid body
- The idea of commonly used shortcut key
- wc、grep、tar、vi/vim
- 错误类型:反射。ReflectionException:无法设置属性“xxx”的“类”xxx”与价值“xxx”
- [ingress]-ingress exposes services using tcp port
猜你喜欢

BIO,NIO,AIO实践学习笔记(便于理解理论)

Transformer interprets and predicts instance records in detail

One-arm routing experiment and three-layer switch experiment

transport layer protocol

从“双卡双待“到”双通“,vivo率先推动DSDA架构落地

config.js相关配置汇总

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

From "dual card dual standby" to "dual communication", vivo took the lead in promoting the implementation of the DSDA architecture

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

What are some things that you only know when you do operation and maintenance?
随机推荐
spark operator - map vs mapPartitions operator
Small example of regular expression--validate email address
Advantages of overseas servers
VLAN is introduced with the experiment
网络层协议介绍
Mina的长连接和短连接
产品学习资料
markdown editor template
wc, grep, tar, vi/vim
Operation and maintenance engineer, come and pick up the wool
Detailed explanation of ten solutions across domains (summary)
Proprietary host CDH
spark source code - task submission process - 3-ApplicationMaster
disabledDate 日期选择器 datePicker
flink cdc 目前支持Gauss数据库源吗
ALC实验
LeetCode中常用语言的一些基本方法记录
Mina disconnects and reconnects
原生JS带你了解数组方法实现及使用
Network wiring and digital-to-system conversion