[ VB.NET Tips] to create an anonymous type list


When calling some web APIs, you often need to send or receive some data, and you may need to create some classes when constructing JSON.
Many of these classes are used only when calling related methods, so anonymous type is a good choice. If you want to transfer some table structure data, you need to create a list.
Anonymous type to create a list or use a brain. Go straight to the code.

'anonymous type case
    Dim sample = New With {
                            .Name = "Teng",
                            Key. Sex = "male",'key keyword defines a read-only anonymous type member
                            .Address = New Object(),
                            . run = function (byref x As Integer) As Integer 'defines anonymous methods                                     
                                        Return x + 10
                                    End Function

    'create anonymous type
    Dim obj = New With {
                        .PartNo = "20010C01",
                        .Qty = 200

    'create an empty list based on this anonymous type
    Dim objList = CreateEmptyList(obj)

    Add anonymous type to 'list'
    Add anonymous type to 'list'
    objList.Add(New With {.PartNo = "20010C02", .Qty = 300})
    Add anonymous type to 'list'
    objList.Add(New With {.PartNo = "20010D01", .Qty = 200})

    'create an empty list
    Public Function CreateEmptyList(Of T)(ByVal obj As T) As List(Of T)

        Dim NewList As New List(Of T)

        Return NewList

    End Function

Recommended Today

Java work for two years, even mybatis plug-in mechanism are not understand, then you work dangerous!

Configuration and use of plug in Configure the plugin node in mybatis-config.xml configuration file, such as a custom log plug-in loginterceptor and an open source paging plug-in pageinterceptor <plugins> <plugin interceptor=”com.crx.plugindemo.LogInterceptor”></plugin> <plugin interceptor=”com.github.pagehelper.PageInterceptor”> <property name=”helperDialect” value=”oracle” /> </plugin> </plugins> How plug-ins work With the help of the responsibility chain mode, a series of filters are […]