请问如何在自定义函数中返回两个值? 请问如何在自定义函数中返回两个值,一个是int型,一个是 List<string>型。C#是否有结构体,能否通过结构体实现,请给出示范代码,谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 class YourClass{int Num;List<string> Items}private YourClass Foo(){YourClass yc = new YourClass();yc.Num = 0;yc.Items = new List<string>();yc.Items.Add("abc");return yc;} http://msdn.microsoft.com/zh-cn/library/dd268536.aspx return list<string>out int 请问我这种情况使用返回类的方式好,还是使用out关键字的方式好? int fun(out List<string> outlist){asdfasdfasdfoutlist=new List<string>();return 5;} 第一种:private List<T> Get(out int){}第二种:struct Test<T>{ int A {get;set;} List<T> List {get;set;}}private Test<T> Get(){} List<string> strlist = new List<string>();private int Foo(ref List<string> strlist){int result=0;...........return result;} C# 函数只有一个返回值,可以使用 out 参数达到相同的效果 你要是有很多返回值的话,可以参考楼上各路大神的思路,两个返回值为什么要搞这么复杂呢?很明显是KeyValuePair最省事啊,而且我估计你这两个值之间八成是有关联的,以Int为键很方便,这也是很常见的业务模型,我自己也经常用到这种结构。循环调用的话,还能直接就压进Dictionary,多省事。 用C#的Serial.Port 向手机发送AT指令 datalist怎么找header中的控件 Socket发送对象 怎么排列xml .net 机试题目证集 菜鸟请高手指教!! [散分]--公司要招聘,请各位帮俺想几道面试题吧,谢谢! !!!!还是没有解觉图象的问题???? 用delphi给C#的webservice发一段中文字符串,服务器收到一堆乱码,如何解决?? C#如何记录行号与文件? 如何使用C#调用内嵌资源 bat 从ftp的一个文件夹(不包含子文件夹)中下载出后缀为.txt的所有文件,
class YourClass
{
int Num;
List<string> Items
}
private YourClass Foo()
{
YourClass yc = new YourClass();
yc.Num = 0;
yc.Items = new List<string>();
yc.Items.Add("abc");
return yc;
}
out int
请问我这种情况使用返回类的方式好,还是使用out关键字的方式好?
{
asdfasdfasdf
outlist=new List<string>();
return 5;
}
{}
第二种:struct Test<T>
{
int A {get;set;}
List<T> List {get;set;}
}
private Test<T> Get()
{}
private int Foo(ref List<string> strlist)
{
int result=0;
...........
return result;
}