Sharing the goodness…
Beth Massi is a Senior Program Manager on the Visual Studio team at Microsoft and a community champion for .NET developers. Learn more about Beth.
More videos »
Ever wonder what really happens when you write a simple LINQ query?
Dim query = From row In db.Customers _
Where row.Country = "Canada" _
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
Is he the same Jonathan with lots of blue shirts? :)
LOL. It used to be grey shirts.
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.
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!
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.
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)
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.
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 z As Integer? = 2
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:
Hope that helps,
Thanks for the reply. It explained my quandary perfectly.
No sirve para nada est blog es una estupides no ayuda