Channel 9 Interview: LINQ Language Deep Dive with Visual Studio 2008

Channel 9 Interview: LINQ Language Deep Dive with Visual Studio 2008

  • Comments 11

Ever wonder what really happens when you write a simple LINQ query?

Dim query = From row In db.Customers _
            Where row.Country = "Canada" _
            Select row

A lot of new language features went into the compilers in Visual Studio 2008 to make even this simple LINQ query work.

In this interview I sit down with Jonathan Aneja, a Program Manager on the Visual Basic Compiler team, who dives deep into these features like Type Inference, Anonymous Types, Lambda Expressions, Expressions Trees, and more. He explains what's actually happening behind the scenes and all the work the compiler is doing for you when you write a LINQ query.

My head almost explodes at the end but I learned a lot of important concepts so check it out:

LINQ Language Deep Dive with Visual Studio 2008

image

Enjoy!

Leave a Comment
  • Please add 8 and 7 and type the answer here:
  • Post
  • Is he the same Jonathan with lots of blue shirts? :)

  • LOL. It used to be grey shirts.

    http://blogs.msdn.com/vbteam/archive/2008/07/23/channel-9-interview-look-who-s-working-on-visual-basic-beth-massi.aspx

    I think Jonathan has finally expanded his wardrobe to two colors ;-)

  • very thanks, in this vedio i have learn lot of the thing about linq query

  • I'd also like to acquire and share this well done video with my coleagues.  We often share our ideas, thoughts, and info during brown bag lunche sessions.

    Thanks,

    James

    jas-list@ipns.com

  • Thx a lot,

    it's really valuable

  • Very informing, like it.

    Did get a little distracted by Jonathan saying 'Right' every 5 seconds, right? ;-)

  • I have seen lots of videos for VB.net by Beth, but now I can put a face to the voice...very nice!

  • <p>

    Thanks for the video. The part where you discuss the use of nullables with the inline IF operator reminded me of something strange that I bumped up against on a recent project. I created a simple console app below to demonstrate the problem.

    </p>

    <pre>

       Sub Main()

           Dim x As Integer?

           Dim a = 1

           x = If(a > 0, Nothing, 2)

           Console.WriteLine("Has value? " & x.HasValue)

           If x.HasValue Then

               Console.WriteLine("x=" & x.Value.ToString)

           End If

           Console.ReadKey()

       End Sub

    </pre>

    <p>

    Contrary to what one would expect, x.HasValue evaluates to True and x=0. Why?  Expanding the inline IF to a multi-line IF-THEN-END results in the desired behavior, i.e. x is null.

    </p>

  • Hey Antony,

    The key thing to realize is that Nothing in VB doesn't mean null, it means "default value for type" (i.e. it's the equivalent of C#'s default(T) operator).  When nothing is assigned to a reference type, it's default value is null.  When it's assigned to an integer, the default value is zero.  When assigned to a nullable integer, the value is null (and .HasValue would return false).

    The type of Nothing is inferred from its context, and in your example above the ternary operator is passed 3 arguments: a > 0 (type is boolean), Nothing (no type), and 2 (Integer).  I'm simplifying what actually happens here, but basically the compiler runs it's "dominant type algorithm" and treats the Nothing literal as if its type were Integer, in which case you get 0 which is its default value.

    Now try this code instead:

           Dim x As Integer?

           Dim z As Integer? = 2

           Dim a = 1

           x = If(a > 0, Nothing, z)

    Here the ternary operator gets "Nothing" (no type) and "z" (type is *Nullable* Integer) - and so now the dominant type is Nullable(Of Integer) and Nothing is assigned to that.  Now you'll see that x.HasValue is False.

    Lucian Wischik (Spec Lead for VB) has a good blog entry that touches on this a bit:

    http://blogs.msdn.com/lucian/archive/2008/11/05/my-dog-has-no-type.aspx

    Hope that helps,

    Jonathan

  • Jonathan,

    Thanks for the reply. It explained my quandary perfectly.

  • No sirve para nada est blog es una estupides no ayuda

Page 1 of 1 (11 items)