我想要一个函数,在其中输入一个数组,因此我需要另一个数组和一个整数值。这可能吗?
Example:
private int[] FunctionName (int[] InputArray)
{
//some function made here
int intResult = xxxxx
int[] array = xxxxx
return intResult; //but here i need also to pass the new array!
}
EDIT:
我需要的是以下内容(已更新);
我有一个函数,作为输入不需要任何东西,但在内部生成两个项目 - 数组+整数。我需要退回这两件物品吗?
您还能告诉我如何使用这些物品吗?
如何做到这一点?
您有几个选择(按照我的偏好顺序):
创建一个类并返回:
class MyResult
{
public int[] Array { get; set; }
public int Integer { get; set; }
}
...
private MyResult FunctionName(int[] inputArray)
{
return new MyResult { Array = ..., Integer = ... };
}
您可以使用内置类型,这基本上使自定义类的定义变得更容易:
private Tuple<int[], int> FunctionName(int[] inputArray)
{
return Tuple.Create( ..., ... );
}
您可以使用out
范围:
private int[] FunctionName(int[] inputArray, out int integerResult)
{
integerResult = 123;
return new int[] { ... };
}
(显然函数名称和属性等只是示例......我假设您会选择更有意义的名称)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)