2

How can I convert below code to vb.net?

I can not convert select new { c.CustomerID, OrderCount = c.Orders.Count() };

public void Linq76()
{
    List<Customer> customers = GetCustomerList();

    var orderCounts =
        from c in customers
        select new { c.CustomerID, OrderCount = c.Orders.Count() };

    ObjectDumper.Write(orderCounts);
}

2 Answers 2

4

With this tool.

Public Sub Linq76()
    Dim customers As List(Of Customer) = GetCustomerList()

    Dim orderCounts = From c In customers New With { _
        c.CustomerID, _
        Key .OrderCount = c.Orders.Count() _
    }

    ObjectDumper.Write(orderCounts)
End Sub

MSDN:Anonymous Types (Visual Basic)

Sign up to request clarification or add additional context in comments.

1 Comment

This doesn't work. Tried converting comboBox1.DropDownWidth = comboBox1.Items.Cast<string>().Max(x => TextRenderer.MeasureText(x, comboBox1.Font).Width); - just kept processing - no result.
3

That's C#'s anonymous classes. VB has support for that too. See this example.

For basic info on using LINQ in VB: try this resource.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.