加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c# – 解决“不包含’OfType’的定义”错误消息?

发布时间:2020-12-15 04:29:15 所属栏目:百科 来源:网络整理
导读:这是我的代码并出现未知错误: private void dataGridView1_CellValueChanged(object sender,DataGridViewCellEventArgs e){ for (int i = 0; i dataGridView1.Rows.Count; ++i) { object a = dataGridView1.Rows[i].Cells["price"].Value; object b = dataG
这是我的代码并出现未知错误:
private void dataGridView1_CellValueChanged(object sender,DataGridViewCellEventArgs e)
{
        for (int i = 0; i < dataGridView1.Rows.Count; ++i)
        {

            object a = dataGridView1.Rows[i].Cells["price"].Value;
            object b = dataGridView1.Rows[i].Cells["tedad"].Value;
            double aNumber = 0;
            double bNumber = 0;
            if (a != null)
                aNumber = Double.Parse(a.ToString());
            if (b != null)
                bNumber = Double.Parse(b.ToString());
            dataGridView1.Rows[i].Cells["total"].Value = aNumber * bNumber;
            dataGridView1.RefreshEdit();
        }
        decimal sum = dataGridView1.Rows.OfType<DataGridViewRow>()
           .Sum(row => Convert.ToDecimal(row.Cells["total"].Value));
        txtDate.Text  = sum.ToString();

像OfType()这样的错误:

‘System.Windows.Forms.DataGridViewRowCollection’ does not contain a definition for ‘OfType’ and no extension method ‘OfType’ accepting a first argument of type ‘System.Windows.Forms.DataGridViewRowCollection’ WindowsFormsApplication1test

解决方法

确保你有:
using System.Linq;

Enumerable.OfType Method

>命名空间:System.Linq>程序集:System.Core(在System.Core.dll中)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读