如何修复数据收集中数据行的后期绑定,其中数据行变量定义在范围内

问题描述

我正在为我的公司将 VB 转换为 C#.Net。为了更轻松地做到这一点,我选择了严格开启。我正在尝试解决以下代码的后期绑定问题。 Row 被编译器认为是一个 OBJECT。我从来没有以这种方式编写代码(别人的工作)。这是代码

        Dim items As List(Of Contact) = ContactsTable.GetChanges.DataTabletoList(Of Contact)
    'Dim row As DaTarow = nothing
    Dim modifiedRows As DaTarowCollection = From row In ContactsTable.Rows
                       Where row.RowState = DaTarowState.Modified Or row.RowState = DaTarowState.Added

解决方法

无法修改现有代码。下一个最佳选择是使用“For each”循环重新编码。

        Dim modifiedRows As DataRowCollection = Nothing
    For each row As DataRow In ContactsTable.Rows
        If row.RowState = DataRowState.Modified Or row.RowState = DataRowState.Added Then
            modifiedRows.Add(row)
        End If
    Next