VB 2010 – List Initializer

I’ve been using VB.NET for about a year now (I was exclusively a C# developer before that) and one thing that always annoyed me was not being able to initialize my lists at the time that I declared them, the way I could in C#.  They added this functionality in VB 10, so this is how you do it:

Dim customers As New List(Of String) From {"Tom", "Bob", "John", "Lisa"}

About esteban

Esteban is the Founder and Chief Technologist at Nebbia Technology, an ALM consulting and Azure-powered technology company. He is a software developer with a passion for ALM, TFS, Azure, and software development best practices. Esteban is a Microsoft Visual Studio ALM MVP and ALM Ranger, Pluralsight author, and the president of ONETUG (Orlando .NET User Group).

2 thoughts on “Building dynamic where logic in LINQ

  1. Anonymous

    Hi There – Can you let me know what myType refers to?

    Thanx

    marcus.leedham@yaoo.co.uk

  2. Esteban Garcia

    Hello Marcus,
    In this case, myType would be whatever LINQ to SQL type you the predicate is acting on . So if you have a table called Product that you want to apply the dymanic logic to, that line would read:
    Dim predicate = PredicateBuilder.False(Of Product)()

    I hope that helps!


Leave a Reply

Your email address will not be published. Required fields are marked *

Are you human? *