简体   繁体   English

从整数列表中删除所有负整数

[英]remove all negative integers from a list of integer

I need to remove all the negative values from a list of integers. 我需要从整数列表中删除所有负值。

Dim cells As List(Of Integer) = GridView1.GetSelectedRows().ToList()

cells returns a list of rows getting from the devexpress grid view. cells返回从devexpress网格视图获取的行的列表。 But the filter/group option will return negative integers... How can I either remove those negative values from cells or prevent them from getting in to cells? 但是filter / group选项将返回负整数...我该如何从单元格中删除这些负值或阻止它们进入单元格?

You can use this code : 您可以使用以下代码:

    Dim NumberOfElements As Integer = cells.Count - 1
    Dim i As Integer = 0
    While i <= NumberOfElements
        If cells(i) < 0 Then
            cells.RemoveAt(i)
            NumberOfElements = NumberOfElements - 1
        Else
            i = i + 1
        End If
    End While
  Dim postiveCells As List(Of Integer) = cells.[Where](Function(x) x > 0).ToList() 

我想我找到了一种在vb.net中放置where子句的方法谢谢您的提示

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

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