我有一个像这样的列表:
如何检查此列表中是否存在值? listaProduktow是一个列表
Private Function PobierzProduktyKategorii(ByVal nazwaSklepu As String, ByVal idSklepKategorie As Integer) As List(Of Object)
Dim sql As String = "SELECT Id_sklep_kategorie, Id_rodzic FROM SKLEP_KATEGORIE WHERE Usunieto = 0 AND Id_rodzic = @IdSklepKategorie ORDER BY Kolejnosc ASC"
Dim produkty As List(Of Object) = New List(Of Object)
Polacz(nazwaSklepu)
Dim sqlCommand As New MySqlCommand
With sqlCommand
.Connection = connection
.CommandText = sql
.Parameters.AddWithValue("@IdSklepKategorie", idSklepKategorie)
End With
Try
Using dr As MySqlDataReader = sqlCommand.ExecuteReader()
If dr.HasRows Then
While dr.Read
produkty.Add(PobierzProduktyKategorii(nazwaSklepu, dr("Id_sklep_kategorie")))
End While
Else
Rozlacz()
Polacz(nazwaSklepu)
Dim sql2 As String = "SELECT Id_produkty FROM PRODUKTY WHERE Blokada = 0 AND Usunieto = 0 AND Id_sklep_kategorie = @IdSklepKategorie"
Dim sqlCommand2 As New MySqlCommand
With sqlCommand2
.Connection = connection
.CommandText = sql2
.Parameters.AddWithValue("@IdSklepKategorie", idSklepKategorie)
End With
Using dr2 As MySqlDataReader = sqlCommand2.ExecuteReader()
While dr2.Read
produkty.Add(dr2("Id_produkty"))
End While
End Using
End If
End Using
Catch ex As MySqlException
Logi.LogInfo(ex)
Catch ex As Exception
Logi.LogInfo(ex)
Finally
Rozlacz()
End Try
Return produkty
End Function
Produkty也是一个List,您可以在代码顶部看到。我通过这样做来递归地添加值:produkty.add(myFunction()),并且这个函数返回一个Object数组,这就是为什么。
答案 0 :(得分:2)
您可以使用(ls file* | select -Expand Basename) -join ' - '
和Enumerable.Cast<uint>
:
Enumerable.Contains
所以你改用VB.NET。您还有一个多维数组的uint[,] array2D = new uint[,] { { 1, 2 }, { 3, 4 }, { 5, 6 }, { 7, 8 } };
uint value = 6;
bool valueExists = array2D.Cast<uint>().Contains(value); // true
instread。
您应使用List(Of List(Of Object))
而不是Object
,而不是Int32
而不是dr2.GetInt32("Id_produkty")
。然后你得到一个dr2("Id_produkty")
:
List(Of List(Of Int32))
现在,您可以使用Private Function PobierzProduktyKategorii(ByVal nazwaSklepu As String, ByVal idSklepKategorie As Integer) As List(Of List(Of Int32))
Dim produkty As New List(Of List(Of Int32))
' .... '
Using dr2 As MySqlDataReader = sqlCommand2.ExecuteReader()
While dr2.Read
produkty.Add(dr2.GetInt32("Id_produkty"))
End While
End Using
' ... '
If dr.HasRows Then
While dr.Read
produkty.Add(PobierzProduktyKategorii(nazwaSklepu, dr("Id_sklep_kategorie")))
End While
Else
' ... '
Dim subList As New List(Of Int32)
Using dr2 As MySqlDataReader = sqlCommand2.ExecuteReader()
While dr2.Read
subList.Add(dr2.GetInt32("Id_produkty"))
End While
End Using
produkty.Add(subList) ' a single list added '
End If
' ... '
return produkty
End Function
+ SelectMany
Contains