简体   繁体   English

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

[英]How to fix late binding for datarow in datacollection where datarow variable defined in range

I'm in the process of converting VB to C#.Net for my company.我正在为我的公司将 VB 转换为 C#.Net。 In order to do this more easily, I have option strict ON.为了更容易地做到这一点,我有选项严格打开。 I am trying to resolve a late binding on the following code.我正在尝试解决以下代码的后期绑定。 Row is considered an OBJECT by the compiler.被编译器视为 OBJECT。 I've never written code in this fashion (someone else's work).我从来没有以这种方式编写过代码(其他人的工作)。 Here is the code.这是代码。

        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

There was no way to modify the existing code.无法修改现有代码。 The next best option was to recode it using a "For each" loop.下一个最佳选择是使用“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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM