C# - 拉姆达语法上循环DataGridView.Rows [英] C# - Lambda syntax for looping over DataGridView.Rows

查看:737
本文介绍了C# - 拉姆达语法上循环DataGridView.Rows的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是遍历一个DataGridView的每一个DataGridViewRow在C#中正确的lambda语法?作为一个例子让我们说的功能,使该行。可见=虚假的基础上,在单元格某值[0]。

What is the correct lambda syntax in C# for looping over each DataGridViewRow of a DataGridView? And as an example lets say the function makes the row .Visible = false based on some value in the Cells[0].

推荐答案

那么,有对枚举没有内置的ForEach 扩展方法。我不知道一个简单的的foreach 循环可能不是更简单吗?这是小事写的,虽然...

Well, there is no inbuilt ForEach extension method on enumerable. I wonder if a simple foreach loop might not be easier? It is trivial to write, though...

目前一推,也许你可以有效地使用其中,这里:

At a push, maybe you could usefully use Where here:

        foreach (var row in dataGridView.Rows.Cast<DataGridViewRow>()
            .Where(row => (string)row.Cells[0].Value == "abc"))
        {
            row.Visible = false;
        }

但就个人而言,我只是用一个简单的循环:

But personally, I'd just use a simple loop:

        foreach (DataGridViewRow row in dataGridView.Rows)
        {
            if((string)row.Cells[0].Value == "abc")
            {
                row.Visible = false;
            }
        }

这篇关于C# - 拉姆达语法上循环DataGridView.Rows的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆