<?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 scoping in C#</title><link>http://blogs.msdn.com/b/samng/archive/2007/11/09/local-variable-scoping-in-c.aspx</link><description>In my previous post, Compiler-generated scopes for local variable declarations , I briefly touched on the issue of multiple meanings applied to the same name. In this post, I'll aim to flush out the compiler's rules with regards to binding names in their</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>Community Convergence XXXVI</title><link>http://blogs.msdn.com/b/samng/archive/2007/11/09/local-variable-scoping-in-c.aspx#6720771</link><pubDate>Mon, 10 Dec 2007 11:11:03 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6720771</guid><dc:creator>Charlie Calvert's Community Blog</dc:creator><description>&lt;p&gt;Welcome to the thirty-sixth issue of Community Convergence. This is the big day, with Visual Studio 2008&lt;/p&gt;
&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=6720771" width="1" height="1"&gt;</description></item><item><title>Community Convergence XXXVI</title><link>http://blogs.msdn.com/b/samng/archive/2007/11/09/local-variable-scoping-in-c.aspx#6720752</link><pubDate>Mon, 10 Dec 2007 11:09:07 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6720752</guid><dc:creator>Charlie Calvert's Community Blog</dc:creator><description>&lt;p&gt;Welcome to the thirty-sixth issue of Community Convergence. This is the big day, with Visual Studio 2008&lt;/p&gt;
&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=6720752" width="1" height="1"&gt;</description></item><item><title>Community Convergence XXXVI</title><link>http://blogs.msdn.com/b/samng/archive/2007/11/09/local-variable-scoping-in-c.aspx#6413162</link><pubDate>Tue, 20 Nov 2007 02:04:11 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6413162</guid><dc:creator>Charlie Calvert's Community Blog</dc:creator><description>&lt;p&gt;Welcome to the thirty-sixth issue of Community Convergence. This is the big day, with Visual Studio 2008&lt;/p&gt;
&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=6413162" width="1" height="1"&gt;</description></item><item><title>re: Local variable scoping in C#</title><link>http://blogs.msdn.com/b/samng/archive/2007/11/09/local-variable-scoping-in-c.aspx#6406672</link><pubDate>Mon, 19 Nov 2007 21:41:50 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6406672</guid><dc:creator>samng</dc:creator><description>&lt;p&gt;Hi Tanveer,&lt;/p&gt;
&lt;p&gt;You're absolutely right - a parameter can hide the name of fields, as can exception variables. Though both of these are not declared via a local variable declaration, they are both considered to be local variables.&lt;/p&gt;
&lt;p&gt;In my previous post about compiler-generated scopes for local variables, I mention the different types of local variables that the compiler allows you to create - catch variables, foreach iteration variables, anonymous method/lambda parameters, and using statements, along with the regular local variable and local method parameters.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=6406672" width="1" height="1"&gt;</description></item><item><title>re: Local variable scoping in C#</title><link>http://blogs.msdn.com/b/samng/archive/2007/11/09/local-variable-scoping-in-c.aspx#6375149</link><pubDate>Sun, 18 Nov 2007 23:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6375149</guid><dc:creator>Tanveer Badar</dc:creator><description>&lt;p&gt;There is one more case name hiding I remember, a parameter can hide the name of class scoped (instance or static, doesn't matter) variables.&lt;/p&gt;
&lt;p&gt;Additionally, an exception variable will hide a class scoped variable if that variable is not used outside catch block. This program correctly compiles with the expected meaning:&lt;/p&gt;
&lt;p&gt;public class Example&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;int ex;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;public void example( )&lt;/p&gt;
&lt;p&gt; &amp;nbsp; {&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; try&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; {&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; }&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; catch( Exception ex )&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;string message = ex.Message;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ex = null;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; };&lt;/p&gt;
&lt;p&gt; &amp;nbsp; }&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=6375149" width="1" height="1"&gt;</description></item><item><title>re: Local variable scoping in C#</title><link>http://blogs.msdn.com/b/samng/archive/2007/11/09/local-variable-scoping-in-c.aspx#6372904</link><pubDate>Sun, 18 Nov 2007 21:25:02 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6372904</guid><dc:creator>Ivan.Eryshov</dc:creator><description>&lt;p&gt;Sam, your blog is a nice addition to a great number of blogs about .NET.&lt;/p&gt;
&lt;p&gt;Go ahead!&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=6372904" width="1" height="1"&gt;</description></item><item><title>Local variable scoping in C#</title><link>http://blogs.msdn.com/b/samng/archive/2007/11/09/local-variable-scoping-in-c.aspx#6025034</link><pubDate>Fri, 09 Nov 2007 21:52:47 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6025034</guid><dc:creator>DotNetKicks.com</dc:creator><description>&lt;p&gt;You've been kicked (a good thing) - Trackback from DotNetKicks.com&lt;/p&gt;
&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=6025034" width="1" height="1"&gt;</description></item></channel></rss>