for (int r = 2; r < 100; r++)
{
List<int> dq = new List<int>(3);
for (int c = 2; c <= 4; c++)
{
dq.Add(ListGrid.Cell(r, c).IntegerValue);
}
dq.Distinct();//去除重复元素 if (dq.Count == 2) //判断剩下的元素个数是否是2个
}
请问,错在哪里?如何统计元素个数
解决方案 »
- c# 用了picturebox-paint重绘事件之后
- 文件大小和空间的关系
- 自动释放问题
- VS2008怎么创建不了解决方案了呢?
- 数据库错误,各位帮忙看看
- 请问C++写的DLL中Void*参数,C#如何调用?
- silverlight mvvm开发中,当点击Button按钮(传值),然后打开一个新页面
- DataGrid有个问题,有关CurrentCellChanged事件
- HttpWebRequest.GetResponse的问题。远程服务器返回错误: (407) 需要代理身份验证。
- 请问C#写数据库访问DLL组件能否使用.Config文件保存连接字符串?
- 关于一个线程的问题
- 一个有关WEBBROWSER弹出错误提示的问题
=》
dq=dq.Distinct().ToList();//去除重复元素
if (dq.count == 2) 是否正确呢?
<ExtensionAttribute> _
Public Shared Function Distinct(Of TSource) ( _
source As IEnumerable(Of TSource) _
) As IEnumerable(Of TSource)
<ExtensionAttribute> _
Public Shared Function Distinct(Of TSource) ( _
source As IEnumerable(Of TSource) _
) As IEnumerable(Of TSource)
哪里在搞笑?已经指出来了,并且你的写法有问题 要ToList一下,类型对应
{
List<int> dq = new List<int>(3);
for (int c = 2; c <= 4; c++)
{
dq.Add(ListGrid.Cell(r, c).IntegerValue);
}
dq.Distinct().ToList();
if (dq.Count() == 2)
{
ListGrid.Cell(r, 15).Text = "0";
}
}
没有效果,没能在制定位置 填入 0
IEnumerable<int> distinctdq = dq.Distinct();
if (dq.Count() == 2) //判断剩下的元素个数是否是2个
这样就好了嘛,反正Distinct结果又不需要。
而不是dq.Distinct().ToList();
这样可能,永远进不了判断dq.Distinct().ToList();这和你上面的没什么区别,只是调用了一个方法,对下面没有任何影响你要重新赋值才行
{
List<int> dq = new List<int>(3);
for (int c = 2; c <= 4; c++)
{
dq.Add(ListGrid.Cell(r, c).IntegerValue);
}
dq = dq.Distinct().ToList();
if (dq.Count() == 2)
{
ListGrid.Cell(r, 15).Text = "0";
}
}
为何分开写,就不行呢?
dq.distinct();
dq.count() == 2
string test_a = "ssss";
test_a.ToUpper();
//那么此时你认为test_a是大写还是小写呢?