asp.net - 如何将 ListItemCollection 转换为 List(of object)

标签 asp.net vb.net

我定义了一个类

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/

相关文章:

c# - 在 ASP.NET 中将文件从 Web 服务传递到客户端

vb.net - Visual Basic UDPClient 服务器/客户端模型?

c# - 为什么我不能在没有 runat=server 的情况下绑定(bind)可见的控件?

c# - Android 虚拟设备加载速度非常慢

javascript - 在 asp TreeView 控件中更改文件夹图标

vb.net - 更改数据 GridView 行中单个单元格的样式

.net - 如何设置日期从和到月份的开始和结束日期?

c# - 将匿名类型转换为 IList

ASP.net Web 窗体,在编译时出现 aspx/view 错误?

vb.net - Windows 脚本宿主对象模型的 Interop.IWshRuntimeLibrary.dll 引用与可执行文件相同的目录