<?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: Extension Methods in Vb.Net and C#</title>
	<atom:link href="http://blog.gadodia.net/extension-methods-in-vbnet-and-c/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.gadodia.net/extension-methods-in-vbnet-and-c/</link>
	<description>"... tech .... fun .. bizarre ... india .... pictures ..... anything in the world ...."</description>
	<lastBuildDate>Tue, 07 Sep 2010 19:10:58 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: rj</title>
		<link>http://blog.gadodia.net/extension-methods-in-vbnet-and-c/comment-page-1/#comment-13494</link>
		<dc:creator>rj</dc:creator>
		<pubDate>Wed, 11 Nov 2009 15:30:31 +0000</pubDate>
		<guid isPermaLink="false">http://blog.gadodia.net/extension-methods-in-vbnet-and-c/#comment-13494</guid>
		<description>That would be called like

MyEnum enum1;

enum1 = enum1.FromString(thestring);

IMO that&#039;s not natural at all.</description>
		<content:encoded><![CDATA[<p>That would be called like</p>
<p>MyEnum enum1;</p>
<p>enum1 = enum1.FromString(thestring);</p>
<p>IMO that&#8217;s not natural at all.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Daniel Dority</title>
		<link>http://blog.gadodia.net/extension-methods-in-vbnet-and-c/comment-page-1/#comment-11599</link>
		<dc:creator>Daniel Dority</dc:creator>
		<pubDate>Thu, 13 Aug 2009 18:49:04 +0000</pubDate>
		<guid isPermaLink="false">http://blog.gadodia.net/extension-methods-in-vbnet-and-c/#comment-11599</guid>
		<description>Seriously, I saw this post and I cannot believe it was never resolved.

Here&#039;s your solution:

public static Enum FromString(this Enum theEnum, string fromString)
        {
            return (Enum)Enum.Parse(theEnum.GetType(), fromString);
        }</description>
		<content:encoded><![CDATA[<p>Seriously, I saw this post and I cannot believe it was never resolved.</p>
<p>Here&#8217;s your solution:</p>
<p>public static Enum FromString(this Enum theEnum, string fromString)<br />
        {<br />
            return (Enum)Enum.Parse(theEnum.GetType(), fromString);<br />
        }</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Wizdumb</title>
		<link>http://blog.gadodia.net/extension-methods-in-vbnet-and-c/comment-page-1/#comment-10789</link>
		<dc:creator>Wizdumb</dc:creator>
		<pubDate>Tue, 07 Apr 2009 16:13:19 +0000</pubDate>
		<guid isPermaLink="false">http://blog.gadodia.net/extension-methods-in-vbnet-and-c/#comment-10789</guid>
		<description>Look Cosmo and others.  You miss the point!
Please read the thread before attempting to be &quot;smart&quot;.

Do like Oboma - &quot;When I open my mouth, I like to know what I&#039;m talking about.&quot;</description>
		<content:encoded><![CDATA[<p>Look Cosmo and others.  You miss the point!<br />
Please read the thread before attempting to be &#8220;smart&#8221;.</p>
<p>Do like Oboma &#8211; &#8220;When I open my mouth, I like to know what I&#8217;m talking about.&#8221;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: cosmo</title>
		<link>http://blog.gadodia.net/extension-methods-in-vbnet-and-c/comment-page-1/#comment-10721</link>
		<dc:creator>cosmo</dc:creator>
		<pubDate>Sat, 14 Mar 2009 21:14:23 +0000</pubDate>
		<guid isPermaLink="false">http://blog.gadodia.net/extension-methods-in-vbnet-and-c/#comment-10721</guid>
		<description>I defense of the OP. I completely understand what he is trying to do.  If you had ownership of the code for System.String, you wouldn&#039;t build a method on that class to convert it to some random enum. That has nothing to do with the natural behaviour that should be encapsulated within that class. It&#039;s not the responsibility of String to know about all the enums out there. But adding an extension to the enum itself is like encapsulating that behaviour within the type (in this case an enum) itself. It&#039;s very natural. But making a string covert itself to an enum is wicked evil.</description>
		<content:encoded><![CDATA[<p>I defense of the OP. I completely understand what he is trying to do.  If you had ownership of the code for System.String, you wouldn&#8217;t build a method on that class to convert it to some random enum. That has nothing to do with the natural behaviour that should be encapsulated within that class. It&#8217;s not the responsibility of String to know about all the enums out there. But adding an extension to the enum itself is like encapsulating that behaviour within the type (in this case an enum) itself. It&#8217;s very natural. But making a string covert itself to an enum is wicked evil.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Pocketmnky</title>
		<link>http://blog.gadodia.net/extension-methods-in-vbnet-and-c/comment-page-1/#comment-10460</link>
		<dc:creator>Pocketmnky</dc:creator>
		<pubDate>Thu, 11 Dec 2008 04:51:19 +0000</pubDate>
		<guid isPermaLink="false">http://blog.gadodia.net/extension-methods-in-vbnet-and-c/#comment-10460</guid>
		<description>Well I found this site after running into the same problem.  I am using a Matrix struct that is a part of the XNA framework in c#.  I was porting over some C++ code that was using nested arrays to describe a matrix such as:

a[0][0] = Matrix.m11

Now, the Matrix struct is awesome and used in alot of places but the one thing that I can&#039;t do with it is access the rows and columns by indexer like myMatrix[0][0].  I figured I could just make an extender like Matrix.SetValueByRowAndColumn(this Matrix m, int rowindex, int colindex, float value) or something but seeing that Matrix m is passed over byVal and not byRef, you can&#039;t change any of the values!

And I NEED to write it this way, I have nested loops that run through the rows and columns of my matrix (from the ported code) that would be very sloppy if I broke them out.

So what was my simple solution?  I just changed the &quot;this&quot; into a &quot;ref&quot; and now instead of an extender, I&#039;ve got a static method that looks like:
MyNamespace.MyClass.SetValueByRowAndColumn(ref myMatrix, (int)row, (int)col, (float)val);

It&#039;s not as pretty and completely defeats the purpose, but after reading through this page and all of the comments I was ready to shove my head in the oven.  Figuring out that there was a simple fix made me ecstatic!</description>
		<content:encoded><![CDATA[<p>Well I found this site after running into the same problem.  I am using a Matrix struct that is a part of the XNA framework in c#.  I was porting over some C++ code that was using nested arrays to describe a matrix such as:</p>
<p>a[0][0] = Matrix.m11</p>
<p>Now, the Matrix struct is awesome and used in alot of places but the one thing that I can&#8217;t do with it is access the rows and columns by indexer like myMatrix[0][0].  I figured I could just make an extender like Matrix.SetValueByRowAndColumn(this Matrix m, int rowindex, int colindex, float value) or something but seeing that Matrix m is passed over byVal and not byRef, you can&#8217;t change any of the values!</p>
<p>And I NEED to write it this way, I have nested loops that run through the rows and columns of my matrix (from the ported code) that would be very sloppy if I broke them out.</p>
<p>So what was my simple solution?  I just changed the &#8220;this&#8221; into a &#8220;ref&#8221; and now instead of an extender, I&#8217;ve got a static method that looks like:<br />
MyNamespace.MyClass.SetValueByRowAndColumn(ref myMatrix, (int)row, (int)col, (float)val);</p>
<p>It&#8217;s not as pretty and completely defeats the purpose, but after reading through this page and all of the comments I was ready to shove my head in the oven.  Figuring out that there was a simple fix made me ecstatic!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vaibhav</title>
		<link>http://blog.gadodia.net/extension-methods-in-vbnet-and-c/comment-page-1/#comment-9867</link>
		<dc:creator>Vaibhav</dc:creator>
		<pubDate>Thu, 28 Aug 2008 21:13:19 +0000</pubDate>
		<guid isPermaLink="false">http://blog.gadodia.net/extension-methods-in-vbnet-and-c/#comment-9867</guid>
		<description>@Rick.. oh well, its back to the old status for me then...</description>
		<content:encoded><![CDATA[<p>@Rick.. oh well, its back to the old status for me then&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rick E</title>
		<link>http://blog.gadodia.net/extension-methods-in-vbnet-and-c/comment-page-1/#comment-9866</link>
		<dc:creator>Rick E</dc:creator>
		<pubDate>Thu, 28 Aug 2008 17:59:17 +0000</pubDate>
		<guid isPermaLink="false">http://blog.gadodia.net/extension-methods-in-vbnet-and-c/#comment-9866</guid>
		<description>This is an old article. I know this isn&#039;t true because I have a few extension methods off of system.object.</description>
		<content:encoded><![CDATA[<p>This is an old article. I know this isn&#8217;t true because I have a few extension methods off of system.object.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vaibhav</title>
		<link>http://blog.gadodia.net/extension-methods-in-vbnet-and-c/comment-page-1/#comment-9865</link>
		<dc:creator>Vaibhav</dc:creator>
		<pubDate>Thu, 28 Aug 2008 17:13:59 +0000</pubDate>
		<guid isPermaLink="false">http://blog.gadodia.net/extension-methods-in-vbnet-and-c/#comment-9865</guid>
		<description>@John, I didn&#039;t realize that... thanks for pointing that out though... of course, I was being a bit melodramatic back there, but it does make it a little better :D</description>
		<content:encoded><![CDATA[<p>@John, I didn&#8217;t realize that&#8230; thanks for pointing that out though&#8230; of course, I was being a bit melodramatic back there, but it does make it a little better <img src='http://blog.gadodia.net/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: John Moreno</title>
		<link>http://blog.gadodia.net/extension-methods-in-vbnet-and-c/comment-page-1/#comment-9864</link>
		<dc:creator>John Moreno</dc:creator>
		<pubDate>Thu, 28 Aug 2008 16:31:51 +0000</pubDate>
		<guid isPermaLink="false">http://blog.gadodia.net/extension-methods-in-vbnet-and-c/#comment-9864</guid>
		<description>If it makes you feel any better, there&#039;s something you can do in C# that you can&#039;t do in VB: create an extension method that works on System.Object.

See this blog from the VBTeam:
http://blogs.msdn.com/vbteam/archive/2007/01/24/extension-methods-and-late-binding-extension-methods-part-4.aspx</description>
		<content:encoded><![CDATA[<p>If it makes you feel any better, there&#8217;s something you can do in C# that you can&#8217;t do in VB: create an extension method that works on System.Object.</p>
<p>See this blog from the VBTeam:<br />
<a href="http://blogs.msdn.com/vbteam/archive/2007/01/24/extension-methods-and-late-binding-extension-methods-part-4.aspx" rel="nofollow">http://blogs.msdn.com/vbteam/archive/2007/01/24/extension-methods-and-late-binding-extension-methods-part-4.aspx</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vaibhav</title>
		<link>http://blog.gadodia.net/extension-methods-in-vbnet-and-c/comment-page-1/#comment-9446</link>
		<dc:creator>Vaibhav</dc:creator>
		<pubDate>Wed, 23 Jul 2008 15:30:32 +0000</pubDate>
		<guid isPermaLink="false">http://blog.gadodia.net/extension-methods-in-vbnet-and-c/#comment-9446</guid>
		<description>I am glad that you see it the same way Rick (the first part).

I always liked Maths better than literature in High School, so I guess that&#039;s why I like C# better :)

Thanks for all your comments.</description>
		<content:encoded><![CDATA[<p>I am glad that you see it the same way Rick (the first part).</p>
<p>I always liked Maths better than literature in High School, so I guess that&#8217;s why I like C# better <img src='http://blog.gadodia.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Thanks for all your comments.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rick E</title>
		<link>http://blog.gadodia.net/extension-methods-in-vbnet-and-c/comment-page-1/#comment-9445</link>
		<dc:creator>Rick E</dc:creator>
		<pubDate>Wed, 23 Jul 2008 13:48:00 +0000</pubDate>
		<guid isPermaLink="false">http://blog.gadodia.net/extension-methods-in-vbnet-and-c/#comment-9445</guid>
		<description>I agree both languages should work the same and both be capable of the same thing. However the real world just doesn&#039;t work that way. So while both languages are extremely close, there will always be some scenarios/features that will favor one over the other. This particular example is probably a bug that will be addressed in the future

For me I prefer the readability and self documenting. If you have ever had to come back to something you wrote 10+ years ago and try to figure out what you did. You will greatly appreciate those features. Granted you can do a lot of that in C# too with a little extra effort, but it&#039;s not as natural as in VB. VB reads more like English, while C# reads more like math to me. I use both, but I prefer VB for the vast majority of my projects.</description>
		<content:encoded><![CDATA[<p>I agree both languages should work the same and both be capable of the same thing. However the real world just doesn&#8217;t work that way. So while both languages are extremely close, there will always be some scenarios/features that will favor one over the other. This particular example is probably a bug that will be addressed in the future</p>
<p>For me I prefer the readability and self documenting. If you have ever had to come back to something you wrote 10+ years ago and try to figure out what you did. You will greatly appreciate those features. Granted you can do a lot of that in C# too with a little extra effort, but it&#8217;s not as natural as in VB. VB reads more like English, while C# reads more like math to me. I use both, but I prefer VB for the vast majority of my projects.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vaibhav</title>
		<link>http://blog.gadodia.net/extension-methods-in-vbnet-and-c/comment-page-1/#comment-9440</link>
		<dc:creator>Vaibhav</dc:creator>
		<pubDate>Wed, 23 Jul 2008 04:08:18 +0000</pubDate>
		<guid isPermaLink="false">http://blog.gadodia.net/extension-methods-in-vbnet-and-c/#comment-9440</guid>
		<description>@Rick.. Well, I don&#039;t want to say that I am totally a C# guy. I like it a lot better than VB. I have worked on VB at work.

Incidentally, the reason I describe it as a flaw in VB is because of what I read on the VB Team Blog (http://blogs.msdn.com/vbteam/archive/2007/01/05/extension-methods-part-2.aspx). Here they talk about making a design change while implementing extension methods in VB to bring the behavior at a parity with what it is in C#.

If there needs to be consistency in this approach, then allowing ByRef, which is something that is not possible to do in C# (even if you are using an extension method defined in a VB module), would break such a parity.

It&#039;s not just a language thing. Imagine (for argument&#039;s sake) how an API developed in VB.Net that makes use of extension methods would break if consumed from C# because it used a ByRef parameter.

There are differences in VB and C#, and most of them are style differences, but one like this doesn&#039;t make sense at all. At their core, the languages are supposed to be the same, and it shouldn&#039;t matter which one I develop in. But a difference like this can make it matter, right? (given my API example above).

Cheers.

@Chad... yes, I agree.</description>
		<content:encoded><![CDATA[<p>@Rick.. Well, I don&#8217;t want to say that I am totally a C# guy. I like it a lot better than VB. I have worked on VB at work.</p>
<p>Incidentally, the reason I describe it as a flaw in VB is because of what I read on the VB Team Blog (<a href="http://blogs.msdn.com/vbteam/archive/2007/01/05/extension-methods-part-2.aspx" rel="nofollow">http://blogs.msdn.com/vbteam/archive/2007/01/05/extension-methods-part-2.aspx</a>). Here they talk about making a design change while implementing extension methods in VB to bring the behavior at a parity with what it is in C#.</p>
<p>If there needs to be consistency in this approach, then allowing ByRef, which is something that is not possible to do in C# (even if you are using an extension method defined in a VB module), would break such a parity.</p>
<p>It&#8217;s not just a language thing. Imagine (for argument&#8217;s sake) how an API developed in VB.Net that makes use of extension methods would break if consumed from C# because it used a ByRef parameter.</p>
<p>There are differences in VB and C#, and most of them are style differences, but one like this doesn&#8217;t make sense at all. At their core, the languages are supposed to be the same, and it shouldn&#8217;t matter which one I develop in. But a difference like this can make it matter, right? (given my API example above).</p>
<p>Cheers.</p>
<p>@Chad&#8230; yes, I agree.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Chad Myers</title>
		<link>http://blog.gadodia.net/extension-methods-in-vbnet-and-c/comment-page-1/#comment-9436</link>
		<dc:creator>Chad Myers</dc:creator>
		<pubDate>Tue, 22 Jul 2008 21:04:19 +0000</pubDate>
		<guid isPermaLink="false">http://blog.gadodia.net/extension-methods-in-vbnet-and-c/#comment-9436</guid>
		<description>Principle of Least Surprise. The VB automatic ByRef semantics can be a nightmare. I pass in my value for x and suddenly x is a totally different object reference. I didn&#039;t specify &#039;ref&#039;, it just automagically happened.

Likewise with x.SomeExtMethod() causing x to be a pointer/reference to totally different object is horrible for code clarity and solubility. 

Magic pointers are bad and lead to instability and surprises in code.  I&#039;m not saying VB is bad, but I *AM* saying that magic pointers are bad. This problem existed in C/C++ and it was bad there too.

C# doesn&#039;t have this bug for precisely the reasons I mentioned above.</description>
		<content:encoded><![CDATA[<p>Principle of Least Surprise. The VB automatic ByRef semantics can be a nightmare. I pass in my value for x and suddenly x is a totally different object reference. I didn&#8217;t specify &#8216;ref&#8217;, it just automagically happened.</p>
<p>Likewise with x.SomeExtMethod() causing x to be a pointer/reference to totally different object is horrible for code clarity and solubility. </p>
<p>Magic pointers are bad and lead to instability and surprises in code.  I&#8217;m not saying VB is bad, but I *AM* saying that magic pointers are bad. This problem existed in C/C++ and it was bad there too.</p>
<p>C# doesn&#8217;t have this bug for precisely the reasons I mentioned above.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rick E</title>
		<link>http://blog.gadodia.net/extension-methods-in-vbnet-and-c/comment-page-1/#comment-9435</link>
		<dc:creator>Rick E</dc:creator>
		<pubDate>Tue, 22 Jul 2008 19:58:10 +0000</pubDate>
		<guid isPermaLink="false">http://blog.gadodia.net/extension-methods-in-vbnet-and-c/#comment-9435</guid>
		<description>&quot;I think, it’s never meant to be ByRef, and it’s a VB flaw that allows it to be ByRef&quot;

Typical of a C# guy to think it&#039;s a flaw in VB. Why can&#039;t it be a flaw in C#? Which it is! C# programmers make mistakes too, even if they don&#039;t think so.

Having learned many languages over my career, I always find the arrogance of C# guys funny.</description>
		<content:encoded><![CDATA[<p>&#8220;I think, it’s never meant to be ByRef, and it’s a VB flaw that allows it to be ByRef&#8221;</p>
<p>Typical of a C# guy to think it&#8217;s a flaw in VB. Why can&#8217;t it be a flaw in C#? Which it is! C# programmers make mistakes too, even if they don&#8217;t think so.</p>
<p>Having learned many languages over my career, I always find the arrogance of C# guys funny.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Vaibhav</title>
		<link>http://blog.gadodia.net/extension-methods-in-vbnet-and-c/comment-page-1/#comment-9434</link>
		<dc:creator>Vaibhav</dc:creator>
		<pubDate>Tue, 22 Jul 2008 18:14:06 +0000</pubDate>
		<guid isPermaLink="false">http://blog.gadodia.net/extension-methods-in-vbnet-and-c/#comment-9434</guid>
		<description>Randolpho, yes that was the problem, and I guess I was too quick to write it off (I was already frustrated at the ByRef problem).

Incidentally, here&#039;s a new thing: If I have used ByRef in the VB Extension method, I still can&#039;t use it from C#, because I get an error message saying &quot;Argument one must be passed with the &quot;ref&quot; keyword&quot;. And since I am calling this as an extension method, I can&#039;t qualify the parameter :)

I think, it&#039;s never meant to be ByRef, and it&#039;s a VB flaw that allows it to be ByRef.

Cheers.</description>
		<content:encoded><![CDATA[<p>Randolpho, yes that was the problem, and I guess I was too quick to write it off (I was already frustrated at the ByRef problem).</p>
<p>Incidentally, here&#8217;s a new thing: If I have used ByRef in the VB Extension method, I still can&#8217;t use it from C#, because I get an error message saying &#8220;Argument one must be passed with the &#8220;ref&#8221; keyword&#8221;. And since I am calling this as an extension method, I can&#8217;t qualify the parameter <img src='http://blog.gadodia.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>I think, it&#8217;s never meant to be ByRef, and it&#8217;s a VB flaw that allows it to be ByRef.</p>
<p>Cheers.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
