当前位置:网站首页>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()
{
}
}
输出:
边栏推荐
- Billions of IT operations in the market, the product by strength to speak
- 初识网页与浏览器
- 网络层协议介绍
- input detailed file upload
- Quick question and quick answer - FAQ of Tencent Cloud Server
- 产品学习资料
- User and user group management, file permission management
- IP address and subnet division
- DisabledDate date picker datePicker
- DevOps流程demo(实操记录)
猜你喜欢

VRRP概述及实验

Mongodb query analyzer parsing

Into the pre-service, thought they play so flowers

错误类型:反射。ReflectionException:无法设置属性“xxx”的“类”xxx”与价值“xxx”
![[问题已处理]-虚拟机报错contains a file system with errors check forced](/img/07/1222a44dd52b359bf7873e6f3b7ebf.png)
[问题已处理]-虚拟机报错contains a file system with errors check forced

路由器和静态路由的配置

Mina的长连接和短连接

Take you in-depth understanding of cookies

Vim tutorial: vimtutor

LinkSLA坚持用户第一,打造可持续的运维服务方案
随机推荐
IP packet format (ICMP protocol and ARP protocol)
Complete mysql offline installation in 5 minutes
产品学习资料
In-depth Zabbix user guide - from the green boy
Does flink cdc currently support Gauss database sources?
RAID disk array
Programmers should understand I/O this way
Quick question and quick answer - FAQ of Tencent Cloud Server
time complexity and space complexity
DevOps-了解学习
This is indeed the best article on microservice architecture I have read!
Proprietary host CDH
增长:IT运维发展趋势报告
H5 的浏览器存储
逻辑卷创建
By solving these three problems, the operation and maintenance efficiency will exceed 90% of the hospital
What are some things that you only know when you do operation and maintenance?
带你深入了解Cookie
618, you may be able to wake up a little bit
错误类型:反射。ReflectionException:无法设置属性“xxx”的“类”xxx”与价值“xxx”