最傻的方法也是最有效果的方法。
string[] column = i.Split(new char[] { ','});
int i = 0;
foreach (string j in column)
{
if (i == 1) frist = j;
if (i == 2) second = j;
i++;
string cell = j;
}循环次数不就是column.Length吗?
string[] column = i.Split(new char[] { ','});
int i = 0;
foreach (string j in column)
{
if (i == 1) frist = j;
if (i == 2) second = j;
i++;
string cell = j;
}循环次数不就是column.Length吗?
解决方案 »
- 怎么实现在同一个datagridview里面行的上下拖拽(DragDrop),请指教?!
- 关于listview的一个问题
- C#编写windows服务应用程序,出现的奇怪问题。高分求解
- 对抽象工厂的一些理解,不知道对否?
- blog 中 Calendar控件问题
- 如何写ethernet报头?
- C#解码方法
- DateTime的问题?
- 怪问题:当做调试的时候,系统报“无法调试,计算机调试管理器服务被禁用”高手救急啊
- 如何用C#访问令一台服务器(192.168.0.21)上的mysql数据库test中的salary表(数据库用默认监听端口)
- 急~~socket下载网页
- c#如何调试呢??逐步调式时 为什么不能进入.net类库呢??
if (i == 1) second = j;
first = column[1]
second = column[2]
count = column.Length;
string second = "";//取第二个字符
string[] column = i.Split(new char[] { ','});
int i = 0;
foreach (string j in column)
{
if (i == 0) frist = j;
if (i == 1) second = j;
i++;
string cell = j;
}
用控制循环次数就用for
string second = "";
string[] column = i.Split(new char[] { ','});
int i = 0;
foreach (string j in column)
{
if (i == 0) frist = j;
if (i == 1) second = j;
i++;
string cell = j;
}
string second = "";
string[] column = i.Split(new char[] { ','});
int i = 0;
foreach (string j in column)
{
if (i == 0) frist = j;
if (i == 1) second = j;
i++;
string cell = j;
}
不然就用FOREACH
你要知道有多少个值
直接取得数组长度就可以了 column.length
还有
如果去第一和第二个值的话
string strFirst = column.length > 0 ? column[0] : "";
string strSecond = column.length > 1 ? column[1] : "";
if (column.Length>0)
{
first=column[0];
if (column.Length>1)
{
second=column[1];
}
}