CS301_02_01 – Local Type Inference (var keyword)

In this video we’ll talk about local type inference, also known as implicitly typed local variables. This introduces the var keyword to C# 3.0, and it is used basically as an easy way to create a variable without having to know the type. When we work with LINQ, many times it may not be very clear what a given linq query is returning, and so the var keyword allows us to say “we don’t really care what it is, let C# figure it out.” Now, Microsoft suggests that you use the var keyword to make development easier. Some authors I’ve read insist that you should use it as a temporary measure until you can figure out the exact return type … one technique would be to set a break point and use the debugging tools to figure out what the actual type is. Whichever you decide is up to you, but the one thing to keep in mind is that the var keyword only works for the local scope. You can’t return or reference a variable created with var outside of the scope of a local method.

« Previous LessonC# 301 – C# 3.0 Language EnhancementsNext Lesson »

This ship has sailed …

This webpage describes one video of hundreds hosted on this website. HOWEVER …

This video has been removed from our collection.

Read why I decided to keep old pages like this around. Or better yet, visit the home page … its the best place to get started.

About this video:

Duration: 12 Minutes, 48 Seconds
Recorded Using: Visual Studio 2008 (all versions)


10 Year Anniversary Sale - 30% Off - ENDING SOON!!!    Learn more ...