请问一个方法如何返回多个返回值?如果对一个数组进行多下标赋值?

kills 2003-02-18 10:40:52
我想同时返回一个string和一个string[]
public string string[] UserCheck(){};
这样好象不行?!比如下面四句能不能用一句实现?!并且不固定有几个下标~
UserBasicData[0]=ReadUserBasicData.GetString(0);
UserBasicData[1]=ReadUserBasicData.GetString(1);
UserBasicData[2]=ReadUserBasicData.GetString(2);
UserBasicData[3]=ReadUserBasicData.GetString(3);
...全文
122 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
MEELON 2003-02-28
  • 打赏
  • 举报
回复
好好看看关于函数定义的书
在函数定义中除了一般的
public int func(string strPara)
{
...
}

还有
public int func(ref string strPara)
{
...
}

public int func(out string strPara)
{
...
}
两种,这两种就是使用引用传递来一个函数输出多个值的。
kills 2003-02-28
  • 打赏
  • 举报
回复
小鸟大哥,你给的好象是获取参数啊?我要的是输出……
lbx1979 2003-02-18
  • 打赏
  • 举报
回复
use ref or out keyword in ur fuction args
poetc 2003-02-18
  • 打赏
  • 举报
回复
ref
and
out
fidudidu 2003-02-18
  • 打赏
  • 举报
回复
就是用out就可以了

kills 2003-02-18
  • 打赏
  • 举报
回复
我说的是OUT不是IN啊
snla 2003-02-18
  • 打赏
  • 举报
回复
public void (ref string s, ref string[] f)
public string (ref string[] f)
public string[](ref string f)

传递到 ref 参数的参数必须最先初始化。将此方法与 out 参数相比,后者的参数在传递到 out 参数之前不必显式初始化。

示例:
static public void FillArray(out int[] myArray)
{
// Initialize the array:
myArray = new int[5] {1, 2, 3, 4, 5};
}
maddogdog 2003-02-18
  • 打赏
  • 举报
回复
out
maotin 2003-02-18
  • 打赏
  • 举报
回复
for( int i = 0; i< string[].length, i++ )
{
UserBasicData[i]=ReadUserBasicData.GetString(i);
}
maotin 2003-02-18
  • 打赏
  • 举报
回复
public object[] UserCheck(){};
or public string[] UserCheck(){};
string就当成string[]里的一个值
snla 2003-02-18
  • 打赏
  • 举报
回复
你看看我给你例子,不就是out嘛!
把out或者ref去掉才是iN呢

111,125

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧