Add Item from a DataTable to a HashSet Variable

Hi all,
I have seen that to add item to the string, we would use this syntax:

hashSetVariable = New HashSet(Of T) From { item }
but i also see that syntax:
listVariable = New List(Of T)(
From row In dataTableVariable.AsEnumerable()
Select row.Field(Of T)(“ColumnName”)
)
I thought it woule be:, without from {}
listVariable = New List(Of T) from {(
From row In dataTableVariable.AsEnumerable()
Select row.Field(Of T)(“ColumnName”)
)}
but why it is in this format
so, can I just write this (an element not from a datatable)
hashSetVariable = New HashSet(Of T)(“item1”,“item2”)

Thanks for helping me out

maybe you are looking for this?
grafik

new HashSet(Of String)(new String(){item1, item2})

we would write:
listVariable =
(
From row In dataTableVariable.AsEnumerable()
Select v = row.Field(Of T)(“ColumnName”)
).toList

keep in mind:
T - the Datatype e.g String, int32
Field(Of T) can fail when values are not within the expected datatype, a more solid approach is to take care and handle it with conversion directly within the LINQ

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.