Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 如何将ListItemCollection转换为(对象的)列表_Asp.net_Vb.net - Fatal编程技术网

Asp.net 如何将ListItemCollection转换为(对象的)列表

Asp.net 如何将ListItemCollection转换为(对象的)列表,asp.net,vb.net,Asp.net,Vb.net,我定义了一个类,比如 Public Class MyClass Public Type1 As Integer Public Type2 As float End Class 如何将ListItemCollection转换为(MyClass的)列表 使用Linq: Dim selectedItems As List(Of [MyClass]) = ListItemCollectionInstance.Items.Cast(Of [MyClass])().Where(Function(itm

我定义了一个类,比如

Public Class MyClass
 Public Type1 As Integer
 Public Type2 As float
End Class
如何将ListItemCollection转换为(MyClass的)列表

使用Linq:

Dim selectedItems As List(Of [MyClass]) = ListItemCollectionInstance.Items.Cast(Of [MyClass])().Where(Function(itm) itm.Selected = True).ToList()

VB.NET中的
MyClass
是关键字,而
float
类型是通过
Single
别名(System.Single)表示的

我已经用样本数据构建了集合

Dim cl作为新的ListItemCollection
cl.Add(新列表项(“1”、“1.2”))
cl.Add(新列表项(“2”、“2.3”))
cl.Add(新列表项(“3”、“3.4”))
Dim lst=从cl中的ele选择新_
项目与
{
.Type1=Integer.Parse(ele.Text),
.Type2=Single.Parse(ele.Value)
}
对于lst中作为项目的每个ele
响应。写入(“
”和ele.Type1&“&ele.Type2) 下一个
@user1460625&AVD:看看标签,asp.net说…@Quandary,标签是在AVD的评论之后添加的。
Dim selectedItems As List(Of [MyClass]) = ListItemCollectionInstance.Items.Cast(Of [MyClass])().Where(Function(itm) itm.Selected = True).ToList()
Public Class Item
   Public Type1 As Integer
   Public Type2 As Single
End Class
Dim cl As New ListItemCollection
cl.Add(New ListItem("1", "1.2"))
cl.Add(New ListItem("2", "2.3"))
cl.Add(New ListItem("3", "3.4"))

Dim lst = From ele In cl Select New  _
                    Item With
                     {
                         .Type1 = Integer.Parse(ele.Text),
                         .Type2 = Single.Parse(ele.Value)
                     }

For Each ele As Item In lst
    Response.Write("<br/>  " & ele.Type1 & " " & ele.Type2)
Next