【问题标题】:what does out in **out string [][] teams** meanout in **out string [][] teams** 是什么意思
【发布时间】:2021-08-03 15:12:21
【问题描述】:

out在多维参数中是什么意思,如果可以写一个例如,我将非常感激

public string GetTeamsInfo(out string[][] teams)
{
    ...
}

【问题讨论】:

标签: c# asp.net .net c#-6.0


【解决方案1】:

out 表示参数是 {out}put 参数

与默认输入参数相反(注意:输入参数与使用in修饰符的参数不同,它是一个仅输入参数,并有自己的要求)

这意味着它在函数的开头没有值,您需要分配一个以将其传递回调用代码

https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/out-parameter-modifier

public string GetTeamsInfo(out string[][] teams)
{
    teams = new string[3][4];
    return "test";
}

string[][] teams;
//here teams is null
string text = GetTeamsInfo(out teams);
//here teams is a array of string[]

【讨论】:

  • in不是默认的,默认是传值的
  • 输入为默认方向,in关键字表示'readonly by reference',
  • 我意识到这就是你的意思,但这并不是很明显。也许澄清
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-20
  • 1970-01-01
  • 2012-11-27
  • 2011-07-26
  • 1970-01-01
  • 2023-03-12
相关资源
最近更新 更多