我定义了一个类
Public Class MyClass
Public Type1 As Integer
Public Type2 As float
End Class
如何将 ListItemCollection 转换为(MyClass 的)列表?
最佳答案
MyClass
是关键字,VB.NET 中的 float
类型通过 Single
别名 (System.Single) 表示
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
关于asp.net - 如何将 ListItemCollection 转换为 List(of object),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11667431/