如何传出FOR循环的值? public string liB() { string a; for (int i = 0; i < listBox1.Items.Count; i++) { a = i.ToString(); } return a; }请问如何能返回A的值??? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public IEnumerable<string> Lib() { for (int i = 0; i < listBox1.Items.Count; i++) { yield return i.ToString(); } } 就是现在提示return返回的是空值,我想返回listBox1的最后一项 public string liB() { if(listBox1.Items.Count == 0) { return ""; } return listBox1.Items[listBox1.Items.Count-1].Text; //要返回Text还是Value自己选 如果是返回listBox1.Items[最后一项].ToString()的话返回的是Object。什么的吧? } 看得出来,LZ没有C语言的基础,导致一个简单的程序逻辑都没有想清 return (listBox1.Items.Count - 1).ToString() 直接取listBox1.Items.Count不就ok了,还循环什么 你只需要最后一项不需要循环。 return (listBox1.Items.Count - 1).ToString(); public string liB() { string a=""; for (int i = 0; i < listBox1.Items.Count; i++) { a = i.ToString(); ; } return a; } return listBox1.Items[listBox1.Items.Count - 1].ToString(); public string liB() { string a=""; for (int i = 0; i < listBox1.Items.Count; i++) { a = listBox1.Items[i].ToString();// i.ToString(); } return a; } 要返回最后一项 应该不用循环就取得到 listBox1.Items[listBox1.Items.Count-1].Text 试试看 return listBox1.Items[listBox1.Items.Count - 1].ToString();或public string liB() { string a=""; for (int i = 0; i < listBox1.Items.Count; i++) { a = listBox1.Items[i].ToString();// i.ToString(); } return a; } ~return listBox1.Items[listBox1.Items.Count - 1].ToString(); C# Marshal ushort[] 到IntPtr.急,急,急! 用SQL SERVER命令修改字符集 c# 结构体问题 求助! 请教Delphi中如何实现像.NET DatSET一样的离线操作 关闭SqlConnection对象出错 批量下载一批网页。。如果使用多线程进行下载。。由于每个网页的下载完成时间不同。。如果判断所有网页下载完成。。 这该怎么办?我刚接触c#+sqlserver2005 关于windows service 类和接口是什么关系 请问如何将图片对象Image转换为Byte[]?下面的方法有什么区别? 小弟是新手啊,求SUM的取值与代码问题,在线等,高手帮忙啊
public IEnumerable<string> Lib()
{
for (int i = 0; i < listBox1.Items.Count; i++)
{
yield return i.ToString();
}
}
{
if(listBox1.Items.Count == 0)
{
return "";
}
return listBox1.Items[listBox1.Items.Count-1].Text; //要返回Text还是Value自己选 如果是返回listBox1.Items[最后一项].ToString()的话返回的是Object。什么的吧? }
public string liB()
{
string a="";
for (int i = 0; i < listBox1.Items.Count; i++)
{
a = i.ToString(); ;
}
return a;
}
{
string a="";
for (int i = 0; i < listBox1.Items.Count; i++)
{
a = listBox1.Items[i].ToString();// i.ToString();
}
return a;
}
或public string liB()
{
string a="";
for (int i = 0; i < listBox1.Items.Count; i++)
{
a = listBox1.Items[i].ToString();// i.ToString();
}
return a;
}
return listBox1.Items[listBox1.Items.Count - 1].ToString();