<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	
	>
<channel>
	<title>
	Comments on: When to Use and Not Use Variable Type var in C#	</title>
	<atom:link href="https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/feed/" rel="self" type="application/rss+xml" />
	<link>https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/</link>
	<description>Complex Software Development - Simplified</description>
	<lastBuildDate>Thu, 31 Aug 2023 22:21:15 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>
		By: Paul Embleton		</title>
		<link>https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-391401</link>

		<dc:creator><![CDATA[Paul Embleton]]></dc:creator>
		<pubDate>Thu, 31 Aug 2023 22:21:15 +0000</pubDate>
		<guid isPermaLink="false">http://intellitect.com/?p=18631#comment-391401</guid>

					<description><![CDATA[I currently avoid var like the plague, for the arguments given. So this changed my mind.

I’m an all but retired programmer learning for fun. I used to prefix everything with the type or some abbreviation. Following the crowd.  But quit the habit when finding I needed to write notes explaining the prefixes. Focussing on plain language descriptive names have been the thing since. And if I can’t think of a clean smelling name then it’s a clue I don’t understand what’s required. Var now looks like an extension of that, and the arguments against rather weak or very specific.]]></description>
			<content:encoded><![CDATA[<p>I currently avoid var like the plague, for the arguments given. So this changed my mind.</p>
<p>I’m an all but retired programmer learning for fun. I used to prefix everything with the type or some abbreviation. Following the crowd.  But quit the habit when finding I needed to write notes explaining the prefixes. Focussing on plain language descriptive names have been the thing since. And if I can’t think of a clean smelling name then it’s a clue I don’t understand what’s required. Var now looks like an extension of that, and the arguments against rather weak or very specific.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Howard		</title>
		<link>https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-391239</link>

		<dc:creator><![CDATA[Howard]]></dc:creator>
		<pubDate>Tue, 08 Aug 2023 22:10:39 +0000</pubDate>
		<guid isPermaLink="false">http://intellitect.com/?p=18631#comment-391239</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-382241&quot;&gt;Jay Patel&lt;/a&gt;.

If you&#039;re on VS, you can find out its type by hovering your mouse over it. Only when viewing the code on Github would you need to figure out the type. But then again, most reviewers only stare at the code on Github.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-382241">Jay Patel</a>.</p>
<p>If you&#8217;re on VS, you can find out its type by hovering your mouse over it. Only when viewing the code on Github would you need to figure out the type. But then again, most reviewers only stare at the code on Github.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Tom		</title>
		<link>https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-390947</link>

		<dc:creator><![CDATA[Tom]]></dc:creator>
		<pubDate>Tue, 27 Jun 2023 20:29:41 +0000</pubDate>
		<guid isPermaLink="false">http://intellitect.com/?p=18631#comment-390947</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-390535&quot;&gt;Chris&lt;/a&gt;.

Indeed you are correct. What surprises me the most is that it&#039;s gone this long without being noticed (or at least mentioned). I&#039;ll take care of that, thanks!]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-390535">Chris</a>.</p>
<p>Indeed you are correct. What surprises me the most is that it&#8217;s gone this long without being noticed (or at least mentioned). I&#8217;ll take care of that, thanks!</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Chris		</title>
		<link>https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-390535</link>

		<dc:creator><![CDATA[Chris]]></dc:creator>
		<pubDate>Mon, 24 Apr 2023 12:17:43 +0000</pubDate>
		<guid isPermaLink="false">http://intellitect.com/?p=18631#comment-390535</guid>

					<description><![CDATA[Prime numbers start with 2, 3, 5, ...

1 is not a prime number]]></description>
			<content:encoded><![CDATA[<p>Prime numbers start with 2, 3, 5, &#8230;</p>
<p>1 is not a prime number</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: RaymondC		</title>
		<link>https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-386747</link>

		<dc:creator><![CDATA[RaymondC]]></dc:creator>
		<pubDate>Fri, 15 Apr 2022 08:11:34 +0000</pubDate>
		<guid isPermaLink="false">http://intellitect.com/?p=18631#comment-386747</guid>

					<description><![CDATA[I prefer

Customer customer = new();

It is short, you can read the type without moose hovering and it is consistent because it works for both class variables and method variables. 

var doesn&#039;t work for class variables.]]></description>
			<content:encoded><![CDATA[<p>I prefer</p>
<p>Customer customer = new();</p>
<p>It is short, you can read the type without moose hovering and it is consistent because it works for both class variables and method variables. </p>
<p>var doesn&#8217;t work for class variables.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Greg		</title>
		<link>https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-385131</link>

		<dc:creator><![CDATA[Greg]]></dc:creator>
		<pubDate>Mon, 19 Apr 2021 21:05:20 +0000</pubDate>
		<guid isPermaLink="false">http://intellitect.com/?p=18631#comment-385131</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-381151&quot;&gt;David Noel&lt;/a&gt;.

Agreed!!!  I&#039;ve been programming since the early 90&#039;s.   I&#039;ve had to come on projects and learn their coding behaviors. 
It is bad enough having to understand explicitly declared variables that are not self-describing.    Now you get this VAR variant and the same programmers will make it worse. 

Many work environments didn&#039;t have coding standards or peer reviews which didn&#039;t help either. 

I don&#039;t use VAR.
And I do get sometimes it isn&#039;t too bad with some self-describing variable names, but I prefer INT, STRING, etc... 

I guess if I used it more, it may not be an issue, but too many new things you have to learn now and expected to know them all in and out for me to change.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-381151">David Noel</a>.</p>
<p>Agreed!!!  I&#8217;ve been programming since the early 90&#8217;s.   I&#8217;ve had to come on projects and learn their coding behaviors.<br />
It is bad enough having to understand explicitly declared variables that are not self-describing.    Now you get this VAR variant and the same programmers will make it worse. </p>
<p>Many work environments didn&#8217;t have coding standards or peer reviews which didn&#8217;t help either. </p>
<p>I don&#8217;t use VAR.<br />
And I do get sometimes it isn&#8217;t too bad with some self-describing variable names, but I prefer INT, STRING, etc&#8230; </p>
<p>I guess if I used it more, it may not be an issue, but too many new things you have to learn now and expected to know them all in and out for me to change.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Andreas Herigstad		</title>
		<link>https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-385125</link>

		<dc:creator><![CDATA[Andreas Herigstad]]></dc:creator>
		<pubDate>Mon, 19 Apr 2021 07:50:39 +0000</pubDate>
		<guid isPermaLink="false">http://intellitect.com/?p=18631#comment-385125</guid>

					<description><![CDATA[I complete agree... but I don&#039;t agree with you&#039;re recommendation of Michael Breenan&#039;s post... He says the strangest things
&quot;The methods you are attempting to call on an object are its object contract, not the type&quot;]]></description>
			<content:encoded><![CDATA[<p>I complete agree&#8230; but I don&#8217;t agree with you&#8217;re recommendation of Michael Breenan&#8217;s post&#8230; He says the strangest things<br />
&#8220;The methods you are attempting to call on an object are its object contract, not the type&#8221;</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Jay Patel		</title>
		<link>https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-382242</link>

		<dc:creator><![CDATA[Jay Patel]]></dc:creator>
		<pubDate>Sat, 12 Sep 2020 21:43:43 +0000</pubDate>
		<guid isPermaLink="false">http://intellitect.com/?p=18631#comment-382242</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-381131&quot;&gt;Brynn&lt;/a&gt;.

Totally agree on this point. Hence I&#039;d rather strongly type and appropriately name variables and use refactoring to rename a variable if needed. Have we forgotten refactoring??

&quot;4. If you change the return value of a function, I want to know everywhere it was used. That var does not give you compile errors means you can miss things and get unexpected behaviour, particularly when marshalling for interop code.&quot;]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-381131">Brynn</a>.</p>
<p>Totally agree on this point. Hence I&#8217;d rather strongly type and appropriately name variables and use refactoring to rename a variable if needed. Have we forgotten refactoring??</p>
<p>&#8220;4. If you change the return value of a function, I want to know everywhere it was used. That var does not give you compile errors means you can miss things and get unexpected behaviour, particularly when marshalling for interop code.&#8221;</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Jay Patel		</title>
		<link>https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-382241</link>

		<dc:creator><![CDATA[Jay Patel]]></dc:creator>
		<pubDate>Sat, 12 Sep 2020 21:42:14 +0000</pubDate>
		<guid isPermaLink="false">http://intellitect.com/?p=18631#comment-382241</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-381227&quot;&gt;Tom Faust&lt;/a&gt;.

Makes sense to use var when type is clear or inferred. isActive can be inferred that it is boolean and not confusing. However, a variable named Status doesn&#039;t infer anything and using var Status can lead to the next developer spending time figuring out if Status is string, enum or an something else.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-381227">Tom Faust</a>.</p>
<p>Makes sense to use var when type is clear or inferred. isActive can be inferred that it is boolean and not confusing. However, a variable named Status doesn&#8217;t infer anything and using var Status can lead to the next developer spending time figuring out if Status is string, enum or an something else.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Tom Faust		</title>
		<link>https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-381643</link>

		<dc:creator><![CDATA[Tom Faust]]></dc:creator>
		<pubDate>Wed, 22 Jul 2020 15:13:54 +0000</pubDate>
		<guid isPermaLink="false">http://intellitect.com/?p=18631#comment-381643</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-381642&quot;&gt;Paul&lt;/a&gt;.

Thank you for reading my blog! I use var when it&#039;s clear and obvious, which is usually the case in small sections of code such as loops and short methods. When in doubt, be clear and give the full declaration.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-381642">Paul</a>.</p>
<p>Thank you for reading my blog! I use var when it&#8217;s clear and obvious, which is usually the case in small sections of code such as loops and short methods. When in doubt, be clear and give the full declaration.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Paul		</title>
		<link>https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-381642</link>

		<dc:creator><![CDATA[Paul]]></dc:creator>
		<pubDate>Wed, 22 Jul 2020 14:21:12 +0000</pubDate>
		<guid isPermaLink="false">http://intellitect.com/?p=18631#comment-381642</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-367175&quot;&gt;Tom Faust&lt;/a&gt;.

This works:
	public static void Main()
	{
		long num = 17;
		num = 9223372036854775800;
		Console.WriteLine(num);
	}

This does not:
	public static void Main()
	{
		var num = 17;
		num = 9223372036854775800;
		Console.WriteLine(num);
	}

It is because the compiler has assumed (because of the missing &#039;L&#039;) that the number will not be used as a long later. 

Adding a type to the variable declaration has cleared up all ambiguity here. Specifying a type is always the clearest approach. As developers we should always make our code as clear as possible.

[This of-course is a very simple example, in practice the situation would be more complex.]]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-367175">Tom Faust</a>.</p>
<p>This works:<br />
	public static void Main()<br />
	{<br />
		long num = 17;<br />
		num = 9223372036854775800;<br />
		Console.WriteLine(num);<br />
	}</p>
<p>This does not:<br />
	public static void Main()<br />
	{<br />
		var num = 17;<br />
		num = 9223372036854775800;<br />
		Console.WriteLine(num);<br />
	}</p>
<p>It is because the compiler has assumed (because of the missing &#8216;L&#8217;) that the number will not be used as a long later. </p>
<p>Adding a type to the variable declaration has cleared up all ambiguity here. Specifying a type is always the clearest approach. As developers we should always make our code as clear as possible.</p>
<p>[This of-course is a very simple example, in practice the situation would be more complex.]</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Tom Faust		</title>
		<link>https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-381227</link>

		<dc:creator><![CDATA[Tom Faust]]></dc:creator>
		<pubDate>Fri, 12 Jun 2020 21:32:24 +0000</pubDate>
		<guid isPermaLink="false">http://intellitect.com/?p=18631#comment-381227</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-381151&quot;&gt;David Noel&lt;/a&gt;.

Thank you for your input. You mentioned TypeScript (which I also prefer to straight JavaScript). Just as with TypeScript, all C# variables are strictly typed (unless one uses object or dynamic). For instance, &lt;em&gt;bool isActive = false;&lt;/em&gt; and &lt;em&gt;var isActive = false;&lt;/em&gt; are functionally identical. Both are strictly typed. But of course, you are welcome to use or not use var however you like and however you feel is best for your team.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-381151">David Noel</a>.</p>
<p>Thank you for your input. You mentioned TypeScript (which I also prefer to straight JavaScript). Just as with TypeScript, all C# variables are strictly typed (unless one uses object or dynamic). For instance, <em>bool isActive = false;</em> and <em>var isActive = false;</em> are functionally identical. Both are strictly typed. But of course, you are welcome to use or not use var however you like and however you feel is best for your team.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: David Noel		</title>
		<link>https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-381151</link>

		<dc:creator><![CDATA[David Noel]]></dc:creator>
		<pubDate>Fri, 05 Jun 2020 03:50:50 +0000</pubDate>
		<guid isPermaLink="false">http://intellitect.com/?p=18631#comment-381151</guid>

					<description><![CDATA[I have been professionally programming since 1997, and leading programming teams for 20 years.  I can tell you that in ANY case where you aren&#039;t absolutely forced to go with a var, it is worth it to spend the effort to strictly declare.  When someone comes behind you to read the code, the curve to learn your code, and the likelihood to make an errant assumption are both greatly reduced with strict typing.  I can tell you this, I love coding JavaScript in TypeScript for this reason.  Untyped variables and code are just way too easy to mess up and introduce random, and sometimes quite capricious, errors.  No one on my team would be allowed to code with variants like that.  The up-front time save of a few keystrokes is definitely not worth it in the long-run.  Also, I think that if you are not sure what the function you are calling, or the object you are constructing is going to return you shouldn&#039;t call it until you have figured it out.  Strict typing ensures the programmer knew exactly what was going to happen when they typed it.  I will say this though: I use vars when I am sandbox coding.  It is faster and often you are totally fine with trial and error there.  But when I am ready to take some code from the sandbox into an actual permanent program, I convert all the vars strict object types.]]></description>
			<content:encoded><![CDATA[<p>I have been professionally programming since 1997, and leading programming teams for 20 years.  I can tell you that in ANY case where you aren&#8217;t absolutely forced to go with a var, it is worth it to spend the effort to strictly declare.  When someone comes behind you to read the code, the curve to learn your code, and the likelihood to make an errant assumption are both greatly reduced with strict typing.  I can tell you this, I love coding JavaScript in TypeScript for this reason.  Untyped variables and code are just way too easy to mess up and introduce random, and sometimes quite capricious, errors.  No one on my team would be allowed to code with variants like that.  The up-front time save of a few keystrokes is definitely not worth it in the long-run.  Also, I think that if you are not sure what the function you are calling, or the object you are constructing is going to return you shouldn&#8217;t call it until you have figured it out.  Strict typing ensures the programmer knew exactly what was going to happen when they typed it.  I will say this though: I use vars when I am sandbox coding.  It is faster and often you are totally fine with trial and error there.  But when I am ready to take some code from the sandbox into an actual permanent program, I convert all the vars strict object types.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Brynn		</title>
		<link>https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-381132</link>

		<dc:creator><![CDATA[Brynn]]></dc:creator>
		<pubDate>Wed, 03 Jun 2020 14:36:30 +0000</pubDate>
		<guid isPermaLink="false">http://intellitect.com/?p=18631#comment-381132</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-381131&quot;&gt;Brynn&lt;/a&gt;.

Also, another annoying aspect of var is when you are doing code reviews.  Since you don&#039;t have access to the IDE while comparing it can be hard to tell exactly what is going on if things aren&#039;t explicitly typed.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-381131">Brynn</a>.</p>
<p>Also, another annoying aspect of var is when you are doing code reviews.  Since you don&#8217;t have access to the IDE while comparing it can be hard to tell exactly what is going on if things aren&#8217;t explicitly typed.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Brynn		</title>
		<link>https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-381131</link>

		<dc:creator><![CDATA[Brynn]]></dc:creator>
		<pubDate>Wed, 03 Jun 2020 13:48:13 +0000</pubDate>
		<guid isPermaLink="false">http://intellitect.com/?p=18631#comment-381131</guid>

					<description><![CDATA[Some issues I have with var:
1. If var represents a class, you can&#039;t F12 on a var to see the class declaration.
2. Even for simple types, something like &quot;var number = 12&quot; is unclear and potentially wasteful.  Using var will make it an int, but depending on its usage, that could be a short, or ushort.  It encourages wasteful programming, or worse, an unexpected overflow.  It&#039;s better to think about what type you really want each variable to be.
3. Code is much more readable with explicit types.
4. If you change the return value of a function, I want to know everywhere it was used.  That var does not give you compile errors means you can miss things and get unexpected behaviour, particularly when marshalling for interop code.  

There is only one instance when I use var, and that is for an anonymous type.]]></description>
			<content:encoded><![CDATA[<p>Some issues I have with var:<br />
1. If var represents a class, you can&#8217;t F12 on a var to see the class declaration.<br />
2. Even for simple types, something like &#8220;var number = 12&#8221; is unclear and potentially wasteful.  Using var will make it an int, but depending on its usage, that could be a short, or ushort.  It encourages wasteful programming, or worse, an unexpected overflow.  It&#8217;s better to think about what type you really want each variable to be.<br />
3. Code is much more readable with explicit types.<br />
4. If you change the return value of a function, I want to know everywhere it was used.  That var does not give you compile errors means you can miss things and get unexpected behaviour, particularly when marshalling for interop code.  </p>
<p>There is only one instance when I use var, and that is for an anonymous type.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Tom Faust		</title>
		<link>https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-381047</link>

		<dc:creator><![CDATA[Tom Faust]]></dc:creator>
		<pubDate>Tue, 26 May 2020 13:42:55 +0000</pubDate>
		<guid isPermaLink="false">http://intellitect.com/?p=18631#comment-381047</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-381033&quot;&gt;JohnKrisfalusci&lt;/a&gt;.

I totally understand old school. I come from a C background. Every C# feature has a place and a reason. Part of the beauty of the language is its flexibility. And you won&#039;t find any flames here.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-381033">JohnKrisfalusci</a>.</p>
<p>I totally understand old school. I come from a C background. Every C# feature has a place and a reason. Part of the beauty of the language is its flexibility. And you won&#8217;t find any flames here.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: JohnKrisfalusci		</title>
		<link>https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-381033</link>

		<dc:creator><![CDATA[JohnKrisfalusci]]></dc:creator>
		<pubDate>Mon, 25 May 2020 04:24:14 +0000</pubDate>
		<guid isPermaLink="false">http://intellitect.com/?p=18631#comment-381033</guid>

					<description><![CDATA[Hi there, great article. But I have to say I&#039;m more of the old school method and everything must be typed out. I am coming from C++ and heck I think auto is evil so this is why... I&#039;m probably gonna get flamed for saying this but that&#039;s how I feel.]]></description>
			<content:encoded><![CDATA[<p>Hi there, great article. But I have to say I&#8217;m more of the old school method and everything must be typed out. I am coming from C++ and heck I think auto is evil so this is why&#8230; I&#8217;m probably gonna get flamed for saying this but that&#8217;s how I feel.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Tom Faust		</title>
		<link>https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-380813</link>

		<dc:creator><![CDATA[Tom Faust]]></dc:creator>
		<pubDate>Wed, 06 May 2020 16:21:58 +0000</pubDate>
		<guid isPermaLink="false">http://intellitect.com/?p=18631#comment-380813</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-380811&quot;&gt;Christiaan Jacobus van Schalkwyk&lt;/a&gt;.

You are always free to use the explicit declaration if you prefer. But that wouldn&#039;t help you know if it contains line items and such. If those potential line items aren&#039;t referenced in your foreach loop then you probably don&#039;t care, but more to the point, the query should not do any more work than necessary if you can control it.

On another note, you say you like to use .ToList() on your query. There are times this makes sense, such as to prevent multiple enumeration. However, consider the possibility that the table from which the active orders are retrieved may contain millions of rows. Doing .ToList() will attempt to read all of that into memory and would likely fail. I&#039;m just saying to be aware of the size of the data set when using it. Processing without the list takes only what is necessary as you need it (possibly with some buffered rows to lessen database access, but not all of them).]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-380811">Christiaan Jacobus van Schalkwyk</a>.</p>
<p>You are always free to use the explicit declaration if you prefer. But that wouldn&#8217;t help you know if it contains line items and such. If those potential line items aren&#8217;t referenced in your foreach loop then you probably don&#8217;t care, but more to the point, the query should not do any more work than necessary if you can control it.</p>
<p>On another note, you say you like to use .ToList() on your query. There are times this makes sense, such as to prevent multiple enumeration. However, consider the possibility that the table from which the active orders are retrieved may contain millions of rows. Doing .ToList() will attempt to read all of that into memory and would likely fail. I&#8217;m just saying to be aware of the size of the data set when using it. Processing without the list takes only what is necessary as you need it (possibly with some buffered rows to lessen database access, but not all of them).</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Christiaan Jacobus van Schalkwyk		</title>
		<link>https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-380811</link>

		<dc:creator><![CDATA[Christiaan Jacobus van Schalkwyk]]></dc:creator>
		<pubDate>Wed, 06 May 2020 12:50:48 +0000</pubDate>
		<guid isPermaLink="false">http://intellitect.com/?p=18631#comment-380811</guid>

					<description><![CDATA[In one line you use it for int and few lines lower you state that you don&#039;t want to use it in an int.

var activeOrders = GetAllOrders().Where(o =&#062; o.Active);
foreach (var activeOrder in activeOrders) { … }

I tend to use the .ToList() function and explicitly declare the active orders, but I definitely would have declared the activeOrder in the for if I didn&#039;t do the first.
I wonder if that is a:
 * table structure of the order headers
 * a specific query structure that only have the id, reference, debtor name and total value in it
 * a structure that has the header and all line items in it
 * a structure that has header, line items and discounts etc.
 * a wrapper class that contains the previous mentioned structure but have some of the header variables as properties.

That is why I like to see an explicit type when something is declared. It just let me know which functions can use that as is, or how it will have to be wrapped to be used.]]></description>
			<content:encoded><![CDATA[<p>In one line you use it for int and few lines lower you state that you don&#8217;t want to use it in an int.</p>
<p>var activeOrders = GetAllOrders().Where(o =&gt; o.Active);<br />
foreach (var activeOrder in activeOrders) { … }</p>
<p>I tend to use the .ToList() function and explicitly declare the active orders, but I definitely would have declared the activeOrder in the for if I didn&#8217;t do the first.<br />
I wonder if that is a:<br />
 * table structure of the order headers<br />
 * a specific query structure that only have the id, reference, debtor name and total value in it<br />
 * a structure that has the header and all line items in it<br />
 * a structure that has header, line items and discounts etc.<br />
 * a wrapper class that contains the previous mentioned structure but have some of the header variables as properties.</p>
<p>That is why I like to see an explicit type when something is declared. It just let me know which functions can use that as is, or how it will have to be wrapped to be used.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Karine		</title>
		<link>https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-380596</link>

		<dc:creator><![CDATA[Karine]]></dc:creator>
		<pubDate>Fri, 17 Apr 2020 14:32:14 +0000</pubDate>
		<guid isPermaLink="false">http://intellitect.com/?p=18631#comment-380596</guid>

					<description><![CDATA[Thank you for your article. It&#039;s very straight to the point.]]></description>
			<content:encoded><![CDATA[<p>Thank you for your article. It&#8217;s very straight to the point.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Tom Scarborough		</title>
		<link>https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-378605</link>

		<dc:creator><![CDATA[Tom Scarborough]]></dc:creator>
		<pubDate>Thu, 14 Nov 2019 18:01:26 +0000</pubDate>
		<guid isPermaLink="false">http://intellitect.com/?p=18631#comment-378605</guid>

					<description><![CDATA[I absolutely agree with your rule of thumb for when not to use &#039;var&#039;.  It&#039;s nice to see that other engineers share the rule of using the type over var when the returned type isn&#039;t clear.  Sure, I can hover over the method in my IDE, but sometimes using the type adds clarity immediately without that additional step.]]></description>
			<content:encoded><![CDATA[<p>I absolutely agree with your rule of thumb for when not to use &#8216;var&#8217;.  It&#8217;s nice to see that other engineers share the rule of using the type over var when the returned type isn&#8217;t clear.  Sure, I can hover over the method in my IDE, but sometimes using the type adds clarity immediately without that additional step.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Tom Faust		</title>
		<link>https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-378487</link>

		<dc:creator><![CDATA[Tom Faust]]></dc:creator>
		<pubDate>Tue, 05 Nov 2019 18:37:04 +0000</pubDate>
		<guid isPermaLink="false">http://intellitect.com/?p=18631#comment-378487</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-378486&quot;&gt;Me&lt;/a&gt;.

Thank you for your comment. This article is indeed my opinion; how I (and my team) like to write code. I don&#039;t know that I&#039;d call it &quot;rules&quot; as much as how we limit verbosity while maintaining clarity in our code. Of course you should do what you feel is best for your project and team.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-378486">Me</a>.</p>
<p>Thank you for your comment. This article is indeed my opinion; how I (and my team) like to write code. I don&#8217;t know that I&#8217;d call it &#8220;rules&#8221; as much as how we limit verbosity while maintaining clarity in our code. Of course you should do what you feel is best for your project and team.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Me		</title>
		<link>https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-378486</link>

		<dc:creator><![CDATA[Me]]></dc:creator>
		<pubDate>Tue, 05 Nov 2019 17:26:45 +0000</pubDate>
		<guid isPermaLink="false">http://intellitect.com/?p=18631#comment-378486</guid>

					<description><![CDATA[The problem with rules like this (use var when this, don&#039;t use var when that), is that it quickly gets sloppy and the lines become blurry. You also waste time trying to comply with yet another rule. At least when everything is typed you know what you have to do and you keep things simple.]]></description>
			<content:encoded><![CDATA[<p>The problem with rules like this (use var when this, don&#8217;t use var when that), is that it quickly gets sloppy and the lines become blurry. You also waste time trying to comply with yet another rule. At least when everything is typed you know what you have to do and you keep things simple.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Tom Faust		</title>
		<link>https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-378364</link>

		<dc:creator><![CDATA[Tom Faust]]></dc:creator>
		<pubDate>Thu, 24 Oct 2019 15:56:03 +0000</pubDate>
		<guid isPermaLink="false">http://intellitect.com/?p=18631#comment-378364</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-378352&quot;&gt;Diego Pazos&lt;/a&gt;.

Indeed you are correct, thank you. I have updated the article.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-378352">Diego Pazos</a>.</p>
<p>Indeed you are correct, thank you. I have updated the article.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Diego Pazos		</title>
		<link>https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-378352</link>

		<dc:creator><![CDATA[Diego Pazos]]></dc:creator>
		<pubDate>Wed, 23 Oct 2019 15:11:14 +0000</pubDate>
		<guid isPermaLink="false">http://intellitect.com/?p=18631#comment-378352</guid>

					<description><![CDATA[When it says
&quot;You only have to change the method call, not every place it’s used.&quot;
I guess you meant
&quot;You only have to change the method declaration&quot;.]]></description>
			<content:encoded><![CDATA[<p>When it says<br />
&#8220;You only have to change the method call, not every place it’s used.&#8221;<br />
I guess you meant<br />
&#8220;You only have to change the method declaration&#8221;.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Tom Faust		</title>
		<link>https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-376196</link>

		<dc:creator><![CDATA[Tom Faust]]></dc:creator>
		<pubDate>Tue, 06 Aug 2019 16:43:56 +0000</pubDate>
		<guid isPermaLink="false">http://intellitect.com/?p=18631#comment-376196</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-376168&quot;&gt;Thomas Reasoner&lt;/a&gt;.

I appreciate your comment. To answer your question, I care because I prefer visual clarity, even if technically Visual Studio and the compiler will make sure var always works. We all have our preferences. Mine is as I describe here. But I also understand that others have different opinions, which is why I also referenced &lt;a href=&quot;http://blog.michaelbrennan.net/2010/06/why-you-should-always-use-var-keyword.html&quot; rel=&quot;nofollow&quot;&gt;Michael Brennan&#039;s article&lt;/a&gt;. I would assume you agree more with his reasons than mine and that&#039;s okay with me.]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-376168">Thomas Reasoner</a>.</p>
<p>I appreciate your comment. To answer your question, I care because I prefer visual clarity, even if technically Visual Studio and the compiler will make sure var always works. We all have our preferences. Mine is as I describe here. But I also understand that others have different opinions, which is why I also referenced <a href="http://blog.michaelbrennan.net/2010/06/why-you-should-always-use-var-keyword.html" rel="nofollow">Michael Brennan&#8217;s article</a>. I would assume you agree more with his reasons than mine and that&#8217;s okay with me.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Thomas Reasoner		</title>
		<link>https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-376168</link>

		<dc:creator><![CDATA[Thomas Reasoner]]></dc:creator>
		<pubDate>Tue, 06 Aug 2019 00:18:40 +0000</pubDate>
		<guid isPermaLink="false">http://intellitect.com/?p=18631#comment-376168</guid>

					<description><![CDATA[If you have:
var bar = foo.GetBar(); // returns an IBar
bar.DoABarThing();

Why do you care what type foo.GetBar() returns? We can see right in the code that bar can DoABarThing() without needing to explicitly state that bar is an IBar. I can count on zero fingers the number of times that an explicitly stated type was helpful for me in reading and understanding someone else&#039;s code.]]></description>
			<content:encoded><![CDATA[<p>If you have:<br />
var bar = foo.GetBar(); // returns an IBar<br />
bar.DoABarThing();</p>
<p>Why do you care what type foo.GetBar() returns? We can see right in the code that bar can DoABarThing() without needing to explicitly state that bar is an IBar. I can count on zero fingers the number of times that an explicitly stated type was helpful for me in reading and understanding someone else&#8217;s code.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Robin		</title>
		<link>https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-375658</link>

		<dc:creator><![CDATA[Robin]]></dc:creator>
		<pubDate>Fri, 12 Jul 2019 07:49:58 +0000</pubDate>
		<guid isPermaLink="false">http://intellitect.com/?p=18631#comment-375658</guid>

					<description><![CDATA[Great article, thank you very much for the explicit explanation!]]></description>
			<content:encoded><![CDATA[<p>Great article, thank you very much for the explicit explanation!</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Tom Faust		</title>
		<link>https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-375100</link>

		<dc:creator><![CDATA[Tom Faust]]></dc:creator>
		<pubDate>Thu, 09 May 2019 16:03:39 +0000</pubDate>
		<guid isPermaLink="false">http://intellitect.com/?p=18631#comment-375100</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-375097&quot;&gt;DaTurk&lt;/a&gt;.

I stand corrected. Thank you DaTurk. An anonymous object does indeed require a var. For example, the following object could not be held in a variable without using var.

&lt;code&gt;
    var anon = new
    {
        Name = &quot;Enigo Montoya&quot;,
        FavoriteNumber = 42
    };
&lt;/code&gt;]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-375097">DaTurk</a>.</p>
<p>I stand corrected. Thank you DaTurk. An anonymous object does indeed require a var. For example, the following object could not be held in a variable without using var.</p>
<p><code><br />
    var anon = new<br />
    {<br />
        Name = "Enigo Montoya",<br />
        FavoriteNumber = 42<br />
    };<br />
</code></p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: DaTurk		</title>
		<link>https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-375097</link>

		<dc:creator><![CDATA[DaTurk]]></dc:creator>
		<pubDate>Thu, 09 May 2019 15:42:57 +0000</pubDate>
		<guid isPermaLink="false">http://intellitect.com/?p=18631#comment-375097</guid>

					<description><![CDATA[In reply to &lt;a href=&quot;https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-368914&quot;&gt;Tom Faust&lt;/a&gt;.

When declaring an Anonymous Object you have to use var ...]]></description>
			<content:encoded><![CDATA[<p>In reply to <a href="https://intellitect.com/blog/when-to-use-and-not-use-var-in-c/#comment-368914">Tom Faust</a>.</p>
<p>When declaring an Anonymous Object you have to use var &#8230;</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
