获取返回值问题

xingn 2011-05-26 05:59:59
如一个方法

public string getinfo(string id , string max, string time)
{}

调用可返回
id
code
text
rows

我怎么获取所返回的4个值
...全文
96 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
ak476565 2011-05-26
  • 打赏
  • 举报
回复

 public IEnumerable getinfo(string id , string max, string time)
{
yield id;
yield code;
yield text;
yield rows;
}
debugbird 2011-05-26
  • 打赏
  • 举报
回复
结构, 学习了!!!
  • 打赏
  • 举报
回复
out,或者定义一个类,返回实例
紫寒尺 2011-05-26
  • 打赏
  • 举报
回复

 public string getinfo(ref string id ,ref string max,ref string time,out rows)
{}


调用:
 public static void GetInfoResult()
{
getinfo(ref string id ,ref string max,ref string time);
}

这样应该可以



ianok 2011-05-26
  • 打赏
  • 举报
回复
用全局变量可以
遥望那些年 2011-05-26
  • 打赏
  • 举报
回复
结构比类更轻巧,呵呵
threenewbee 2011-05-26
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 gpshq 的回复:]
引用 10 楼 caozhy 的回复:
从API调用者的舒适度来说,返回一个结构体是最好的。

C# code
struct GetInfoResult
{
public int id;
public int code;
public string text;
public ICollection<DataRow> rows;
}
public GetInfoResult g……
[/Quote]
当然也可以,但是没必要。
氰客 2011-05-26
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 caozhy 的回复:]
从API调用者的舒适度来说,返回一个结构体是最好的。

C# code
struct GetInfoResult
{
public int id;
public int code;
public string text;
public ICollection<DataRow> rows;
}
public GetInfoResult getinf……
[/Quote]

返回一个类呢、
threenewbee 2011-05-26
  • 打赏
  • 举报
回复
从API调用者的舒适度来说,返回一个结构体是最好的。
struct GetInfoResult
{
public int id;
public int code;
public string text;
public ICollection<DataRow> rows;
}
public GetInfoResult getinfo(string id , string max, string time)
{
...
}
threenewbee 2011-05-26
  • 打赏
  • 举报
回复
从API调用者的舒适度来说,返回一个结构体是最好的。
struct GetInfoResult
{
public int id;
public int code;
public string text;
public ICollection<DataRow> rows;
}
public GetInfoResult getinfo(string id , string max, string time)
{
...
}
令狐苦瓜 2011-05-26
  • 打赏
  • 举报
回复
如果有多条记录,就:public List<string []> getinfo(string id , string max, string time)
{}

令狐苦瓜 2011-05-26
  • 打赏
  • 举报
回复
[Quote=引用楼主 xingn 的回复:]
如一个方法

public string getinfo(string id , string max, string time)
{}

调用可返回
id
code
text
rows

我怎么获取所返回的4个值
[/Quote]
你是要用这个方法将这四个字段返回吗?
那你的方法就别返回string了,返回string[]或者list<string>
aoye6202 2011-05-26
  • 打赏
  • 举报
回复
表达的不明确 请LZ说明白点
zx852046 2011-05-26
  • 打赏
  • 举报
回复
用数组试试
xpcxpy 2011-05-26
  • 打赏
  • 举报
回复
.net4.0还有个什么Tuple
xpcxpy 2011-05-26
  • 打赏
  • 举报
回复
你可以返回一个数组嘛
q107770540 2011-05-26
  • 打赏
  • 举报
回复
code
text
rows
这些是什么东西?
我是来接分的 2011-05-26
  • 打赏
  • 举报
回复
out

110,546

社区成员

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

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

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