c# - 对 Object[] 数组列表的 LINQ 查询

标签 c# linq

我有一个对象数组列表 (List),我将把它传递给 DLL 函数以应用 PDF 控件。每个对象的第一个索引应该标识控件将是什么。我想知道是否有某种方法可以查询我的对象列表以获取每个标识对象的计数并将其转换为 int?这是我正在尝试做的一个例子......

        List<Object[]> controlsList = new List<Object[]>();

        //Textfield = 1
        //Checkbox = 2
        Object[] control1 = new Object[] { 1, 1, 1, 75, 75, "txtField1", 1, 8, 10};
        Object[] control2 = new Object[] { 1, 1, 1, 144, 144, "txtField2", 1, 10, 15};
        Object[] control3 = new Object[] { 2, 1, 1, 50, 50, "checkYESNOy", 1, "Yes", "grpYesNo"};
        Object[] control4 = new Object[] { 2, 1, 1, 50, 50, "checkYESNOn", 1, "No", "grpYesNo" };
        Object[] control5 = new Object[] { 2, 1, 1, 50, 50, "checkDirectionN", 1, "North", "grpDirection" };
        Object[] control6 = new Object[] { 2, 1, 1, 50, 50, "checkDirectionS", 1, "South", "grpDirection" };
        Object[] control7 = new Object[] { 2, 1, 1, 50, 50, "checkDirectionW", 1, "West", "grpDirection" };
        Object[] control8 = new Object[] { 2, 1, 1, 50, 50, "checkDirectionE", 1, "East", "grpDirection" };


        controlsList.Add(control1);
        controlsList.Add(control2);
        controlsList.Add(control3);
        controlsList.Add(control4);
        controlsList.Add(control5);
        controlsList.Add(control6);
        controlsList.Add(control7);
        controlsList.Add(control8);

        //Some LINQ code to get back a count of all the textfields(1) and all the checkboxes(2)

最佳答案

int textBoxCount = controlsList.Count(o => (int)o[0] == 1);
int checkBoxCount = controlsList.Count(o => (int)o[0] == 2);

关于c# - 对 Object[] 数组列表的 LINQ 查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3462491/

相关文章:

c# - X86 浏览器(cefsharp)无法在某些 X64 计算机上运行

c# - NHibernate - 如何审计实体的所有领域?

c# - 如何在 C# 的 TreeView 中显示选定节点的显示值?

c# - 为多个 XmlReader.Read() 用法重置 StreamReader

c# - 我如何使用 Reactive Extensions 将 IObservable<T>.Throttle() 与其他一些事件源结​​合起来?

vb.net - 如何在 VB.NET 中使用 "Into"LINQ 表达式?

c# - 为什么我的 GZipStream 不可写?

c# - 将 IEnumerable<T> 转换为用户类型的更好方法

c# - 仅查询重复项的列表

c# - linq to sql 中的奇怪行为在不过滤的情况下返回所有行