<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Local Variable Type Inference</title><link>http://blogs.msdn.com/ericwhite/pages/Local-Variable-Type-Inference.aspx</link><description>[Table of Contents] [Next Topic] Local variable type inference is a feature in C# 3.0 where you can use the var keyword instead of explicitly specifying the type of a variable. The C# 3.0 compiler makes the type of the variable match the type of the right</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Local Variable Type Inference</title><link>http://blogs.msdn.com/ericwhite/pages/Local-Variable-Type-Inference.aspx#2463325</link><pubDate>Mon, 07 May 2007 16:46:39 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2463325</guid><dc:creator>rogerj</dc:creator><description>&lt;p&gt;You didn't mention that VB 9.0 has local variable type inference with the Dim keyword and Option Infer On|Off.&lt;/p&gt;
&lt;p&gt;C# myopia?&lt;/p&gt;
&lt;p&gt;--rj&lt;/p&gt;
</description></item><item><title>re: Local Variable Type Inference</title><link>http://blogs.msdn.com/ericwhite/pages/Local-Variable-Type-Inference.aspx#3924603</link><pubDate>Wed, 18 Jul 2007 00:39:18 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:3924603</guid><dc:creator>Arnaud Weil</dc:creator><description>&lt;p&gt;I see a lot of writing about the fact that var is an inferred type, not a variant. Which should mean it's safe to use, right?&lt;/p&gt;
&lt;p&gt;Well, I don't agree and still fear &amp;quot;var&amp;quot; for clean programming. Why? Because we avoid the &amp;quot;variable type&amp;quot; effect of a variant, but it the compiler INFERS the type, then it may infer something different from the developer. For instance:&lt;/p&gt;
&lt;p&gt;var d = 1.0;&lt;/p&gt;
&lt;p&gt;could declare d as a Decimal instead of a Double.&lt;/p&gt;
&lt;p&gt;Now, I have to admin that var is extremely useful for LINQ. I'd just don't rely on it for my business code...&lt;/p&gt;
</description></item><item><title>re: Local Variable Type Inference</title><link>http://blogs.msdn.com/ericwhite/pages/Local-Variable-Type-Inference.aspx#6718838</link><pubDate>Mon, 10 Dec 2007 06:13:08 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6718838</guid><dc:creator>Ryan Cromwell</dc:creator><description>&lt;p&gt;How is Arnaud's comment addressed? &amp;nbsp;Resolving to Int versus Long could have some severe consequences.&lt;/p&gt;
</description></item><item><title>re: Local Variable Type Inference</title><link>http://blogs.msdn.com/ericwhite/pages/Local-Variable-Type-Inference.aspx#6726528</link><pubDate>Mon, 10 Dec 2007 22:09:36 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6726528</guid><dc:creator>EricWhite</dc:creator><description>&lt;p&gt;One point that I would make regarding local variable type inference: it is for local variables only. For instance, you can't declare the signature of a method using type inference. Regarding the above example:&lt;/p&gt;
&lt;p&gt;var d = 1.0;&lt;/p&gt;
&lt;p&gt;In that case, type inference uses the rules that the C# compiler uses to determine types of literals, so the type is double, I believe.&lt;/p&gt;
&lt;p&gt;In general, after many months of using it, I reserve type inference for two cases:&lt;/p&gt;
&lt;p&gt;- where declaring a variable that is an anonymous type (or collection of them). In this case, there is no other option.&lt;/p&gt;
&lt;p&gt;- where declaring a parameterized type, and it is a fair amount of typing to explicitly declare the type, yet the typing doesn't add any readability to the code, for example:&lt;/p&gt;
&lt;p&gt;var z = new List&amp;lt;string&amp;gt;();&lt;/p&gt;
</description></item></channel></rss>