<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Coderholic &#187; C#</title>
	<atom:link href="http://www.coderholic.com/category/programming/c-2/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.coderholic.com</link>
	<description>Addicted to Development</description>
	<lastBuildDate>Tue, 31 Aug 2010 09:19:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>C# variable and namespace conflicts</title>
		<link>http://www.coderholic.com/c-variable-and-namespace-conflicts/</link>
		<comments>http://www.coderholic.com/c-variable-and-namespace-conflicts/#comments</comments>
		<pubDate>Wed, 04 Jun 2008 17:00:17 +0000</pubDate>
		<dc:creator>Ben</dc:creator>
				<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://www.dowling.me.uk/blog/c-variable-and-namespace-conflicts/</guid>
		<description><![CDATA[I recently came across a problem in some C# code: Somebody had created a variable with the same name as an existing namespace. I wanted to refer to the namespace but I couldn&#8217;t because of the variable. An example is below: class Test { public Function() { string System = "this is a string called [...]]]></description>
			<content:encoded><![CDATA[<p>I recently came across a problem in some C# code: Somebody had created a variable with the same name as an existing namespace. I wanted to refer to the namespace but I couldn&#8217;t because of the variable. An example is below:</p>
<pre name="code" class="c#">
class Test
{
    public Function()
    {
        string System = "this is a string called System";
        // the line below will cause an error, because System
        // refers to the variable above, not the "System" namespace
        System.GC.Collect();
    }
}</pre>
<p>Obviously giving a variable the same name as an existing namespace isn&#8217;t a very good idea, and should probably be avoided at all costs. However, I was intrigued to see if it was possible to get around this issue without having to rename the variable. C# does provide a solution:</p>
<pre name="code" class="c#">
using Sys = System;

class Test
{
    public Function()
    {
        string System = "this is a string called System";
        Sys.GC.Collect();
    }
}</pre>
<p>The line</p>
<pre>using Sys = System;</pre>
<p>creates an alias for the System namespace, which you can then use.</p>
<p>I&#8217;ve never run into this problem before because generally speaking people are sensible enough not to give their variables the same names as namespaces. I suspect this issue isn&#8217;t only a C# one though, and I&#8217;d be interested to see if there are any similar work arounds in other languages. If you know of any please leave a comment!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.coderholic.com/c-variable-and-namespace-conflicts/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
