首页 > 解决方案 > 对于应该具有If条件的数组的for循环c#

问题描述

我必须使用 for 循环迭代一个数组以找到其中包含特定单词并将其添加到列表框 String[] result= ["vicky","vinay@","google@","hello"]

For (l=0 ; l<= result.length; l++)
{
     If(result[l].contains("@")
    {
    Listbox.items.add(result[l]);
     }
}

这是做什么的,它只获得第一个发现的价值,我没有获得第二个价值?

标签: c#asp.net.netfor-loop

解决方案


您的数据需要一个排序列。让我假设你有一个。

首先添加新列:

alter table t add column id int;

注意: 对于可以id是. 然后:null

with toupdate as (
      select t.*,
             row_number() over (partition by col1 order by <ordering col>) as seqnum
      from t
     )
update toupdate
    set id = (case when col1 = 1 then seqnum end);

严格来说,你不需要在 时更新值col1 = 0,因为默认值为NULL。但是,如果你想要一个不同的值,我会省略where col1 = 1.


推荐阅读