【发布时间】:2016-12-17 01:21:29
【问题描述】:
问候。我目前有点卡在Object (int,string)的列表中查找字符串@
我想检查字符串是否已经包含在列表中 - 如果没有添加它。
常规的<List>.Contains() 不起作用,因为我在插入之前初始化了一个新对象。
这是我的代码:
Dim command = New SqlCommand(query, connection)
Dim reader = command.ExecuteReader()
While reader.Read
Dim projID = reader.Item("DB_ID")
Dim projName = reader.Item("Project")
Dim proj = New KMProject(projName, projID)
projList.Add(proj)
End While
reader.Close()
=============================== ProjList having some items already =====================================
query = ...
command = New SqlCommand(query, connection)
reader = command.ExecuteReader()
While reader.Read
Dim projID = reader.Item("DB_ID")
Dim projName = reader.Item("Project")
Dim proj = New KMProject(projName, projID)
===============Below this section im stuck while verifying if this String is already in the List ===================================
For Each p In projList
If projList.Contains() Then
Else
projList.Add(proj)
End If
Next
【问题讨论】:
标签: vb.net list contains basic