<?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/"
	xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Name it Later</title>
	<atom:link href="http://vivekr.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://vivekr.wordpress.com</link>
	<description>Programming is an ART. Code is a Poem.</description>
	<lastBuildDate>Fri, 26 Jan 2007 01:07:12 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='vivekr.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/d17e6c967e5ef89000e81fe33aefe960?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Name it Later</title>
		<link>http://vivekr.wordpress.com</link>
	</image>
			<item>
		<title>mov(wordpress, livespaces);</title>
		<link>http://vivekr.wordpress.com/2007/01/26/movwordpress-livespaces/</link>
		<comments>http://vivekr.wordpress.com/2007/01/26/movwordpress-livespaces/#comments</comments>
		<pubDate>Fri, 26 Jan 2007 01:07:12 +0000</pubDate>
		<dc:creator>Vivek Ragunathan</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://vivekr.wordpress.com/2007/01/26/movwordpress-livespaces/</guid>
		<description><![CDATA[I no longer blog here. Visit me @ http://vivekragunathan.spaces.live.com.
       <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vivekr.wordpress.com&blog=188395&post=31&subd=vivekr&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I no longer blog here. Visit me @ <a href="http://vivekragunathan.spaces.live.com/">http://vivekragunathan.spaces.live.com</a>.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/vivekr.wordpress.com/31/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/vivekr.wordpress.com/31/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/vivekr.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/vivekr.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/vivekr.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/vivekr.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/vivekr.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/vivekr.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/vivekr.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/vivekr.wordpress.com/31/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/vivekr.wordpress.com/31/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/vivekr.wordpress.com/31/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vivekr.wordpress.com&blog=188395&post=31&subd=vivekr&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://vivekr.wordpress.com/2007/01/26/movwordpress-livespaces/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c4c5284872338a4767f6ecc42bec4563?s=96&#38;d=identicon" medium="image">
			<media:title type="html">vivekr</media:title>
		</media:content>
	</item>
		<item>
		<title>out, ref and InvokeMember !!!</title>
		<link>http://vivekr.wordpress.com/2006/05/12/out-ref-and-invokemember/</link>
		<comments>http://vivekr.wordpress.com/2006/05/12/out-ref-and-invokemember/#comments</comments>
		<pubDate>Fri, 12 May 2006 19:21:49 +0000</pubDate>
		<dc:creator>Vivek Ragunathan</dc:creator>
				<category><![CDATA[CSharp]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">https://vivekr.wordpress.com/2006/05/12/out-ref-and-invokemember/</guid>
		<description><![CDATA[When I was working on the .NET reflection extravaganza thing that I explained in my previous column, i learnt one another interesting thing, that is about the Type.InvokeMember. How will pass out or ref parameters for the method invoked using Type.InvokeMember ? If you are going to invoke a method with the prototype
int DoSomething(string someString, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vivekr.wordpress.com&blog=188395&post=29&subd=vivekr&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>When I was working on the .NET reflection extravaganza thing that I explained in my previous column, i learnt one another interesting thing, that is about the Type.InvokeMember. How will pass out or ref parameters for the method invoked using Type.InvokeMember ? If you are going to invoke a method with the prototype</p>
<pre><font size="2" color="#006600" face="Courier New">int DoSomething(string someString, int someInt);</font></pre>
<p>then you would use InvokeMember like this:-</p>
<pre><font size="2" color="#006600" face="Courier New">object obj = someType.InvokeMember(&quot;DoSomething&quot;,
	BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance,
	null,
	this,
	new object[] {&quot;Largest Integer&quot;, 1});</font></pre>
<p>or use some variables in the new object[] {&#8230;}. But what do you with the args if DoSomething takes out or ref parameters ?</p>
<pre><font size="3" color="#006600" face="Courier New">int DoSomething(out string someString, ref int someInt);</font></pre>
<p>Something like this will not work</p>
<pre><font size="2" color="#006600" face="Courier New">string someText = string.Empty;
int someInt = 0;
object obj = someType.InvokeMember(&quot;DoSomething&quot;,
	BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance,
	null,
	this,
	new object[] {someText, someInt});</font></pre>
<p>It is tricky.</p>
<pre><font size="2" color="#006600" face="Courier New">object[] args = new object[] { someText, someInt };
object obj = someType.InvokeMember(&quot;DoSomething&quot;,
	BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance,
	null,
	this,
	args);</font></pre>
<p>or even suprisingly this works:-</p>
<pre><font size="2" color="#006600" face="Courier New">object[] args = new object[2];
// or object[] args = new object[] { null, null };            

object obj = someType.InvokeMember(&quot;DoSomething&quot;,
	BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance,
	null,
	this,
	args);</font></pre>
<p>Access the values by indexing args. So declaring the argument object[] as a local variable solves the problem, but I do not understand why this behaviour. May be somebody can explain !!!</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/vivekr.wordpress.com/29/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/vivekr.wordpress.com/29/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/vivekr.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/vivekr.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/vivekr.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/vivekr.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/vivekr.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/vivekr.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/vivekr.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/vivekr.wordpress.com/29/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/vivekr.wordpress.com/29/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/vivekr.wordpress.com/29/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vivekr.wordpress.com&blog=188395&post=29&subd=vivekr&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://vivekr.wordpress.com/2006/05/12/out-ref-and-invokemember/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c4c5284872338a4767f6ecc42bec4563?s=96&#38;d=identicon" medium="image">
			<media:title type="html">vivekr</media:title>
		</media:content>
	</item>
		<item>
		<title>.NET Reflection Extravanganza !!!</title>
		<link>http://vivekr.wordpress.com/2006/05/11/net-reflection-extravanganza/</link>
		<comments>http://vivekr.wordpress.com/2006/05/11/net-reflection-extravanganza/#comments</comments>
		<pubDate>Thu, 11 May 2006 03:05:27 +0000</pubDate>
		<dc:creator>Vivek Ragunathan</dc:creator>
				<category><![CDATA[CSharp]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">https://vivekr.wordpress.com/2006/05/11/net-reflection-extravanganza/</guid>
		<description><![CDATA[I was involved in this module for the past few weeks and successfully completed it in a very innovative way. Ok, this was the problem. We have a COM server, let us name it Server. I had to write an assembly in C#, let us call it Bridge, that will listen to all of the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vivekr.wordpress.com&blog=188395&post=27&subd=vivekr&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><font size="2">I was involved in this module for the past few weeks and successfully completed it in a very innovative way. Ok, this was the problem. We have a COM server, let us name it Server. I had to write an assembly in C#, let us call it Bridge, that will listen to all of the events fired by the Server and perform an action Action. To keep that Action simple, let us assume we have to log them in the database. But the Server fires hundreds of events, and it is not wise to write up static event handlers for all of them. Also if more events are added in the future, it is possible to support the Bridge.</font></p>
<p><font size="2">So I came up with a different approach with the incredible Reflection in .NET. All of the events fired by the Server, its prototype and other relevant information can be got through reflection, and for each of the event methods, an event sink [event handler] can be generated at runtime. This means I have to create a method at runtime matching the prototype of the event. The dynamic method thus generated runtime has to appended with some method body so as to do the Action, and then has to be registered as the event sink for the corresponding event. So when the event is fired by the Server, the dynamically created event handler is called without any intervention. This is the theme of my solution. This keeps the Bridge unaffected for any event related changes in the Server.</font></p>
<p><font size="2">But achieving this solution and make it work, it was a great and exciting adventure.</font></p>
<p><font size="2">1. I was able to get the event information about the events fired by Server through reflection. I used the following sort of code for generating the dynamic method or the supposedly the dynamic event handler:-</font></p>
<pre><font color="#0000ff" size="2">
using System;
using System.Threading;
using System.Reflection;
using System.Reflection.Emit;

class TaskDynamicEventHandler
{

public static void CreateDynamicEventHandler(ref TypeBuilder myTypeBld,
                         string methodName,
                         Type[] eventMethodParameters,
                         Type eventreturnType)
    {

MethodBuilder myMthdBld = myTypeBld.DefineMethod(methodName,
                          MethodAttributes.Public | MethodAttributes.Static,
                          eventreturnType,
                          eventMethodParameters);

ILGenerator ILout = myMthdBld.GetILGenerator();

int numParams = eventMethodParameters.Length;

for (byte x = 0; x &lt; numParams; x++)
        {
            // Load the parameter onto the evaulation stack
            ILout.Emit(OpCodes.Ldarg_S, x);
        }

// Use the above sort of logic to access the event parameter
        // values and then package into a hashtable, and then call
        // a static method HandleEvent in TaskDynamicEventHandler,
        // which takes the hashtable as a parameter. All the code is
        // generated in IL using ILGenerator.

ILout.Emit(OpCodes.Ret);
    }

public static void Main()
    {

AppDomain myDomain = Thread.GetDomain();
        AssemblyName asmName = new AssemblyName(&quot;DynamicAssembly1&quot;);
        AssemblyBuilder myAsmBuilder = myDomain.DefineDynamicAssembly(asmName,
                       AssemblyBuilderAccess.RunAndSave);

ModuleBuilder myModule = myAsmBuilder.DefineDynamicModule(&quot;DynamicModule1&quot;,
                                      &quot;MyDynamicAsm.dll&quot;);

TypeBuilder myTypeBld = myModule.DefineType(&quot;MyDynamicType&quot;, TypeAttributes.Public);

string dynamicMethodName = &quot;DynamicEventHandler&quot;;
        CreateDynamicEventHandler(myTypeBld,
                         dynamicMethodName,
                         eventMethodParameters,
                         eventreturnType);        

Type myType = myTypeBld.CreateType();

myAsmBuilder.Save(&quot;MyDynamicAsm.dll&quot;);

// returnType - event method&#39;s return type
        // parameterTypes - event method&#39;s parameter types list
        ArrayList parameterTypes = new ArrayList(parameterTypes);
        parameterTypes.Insert(0, this.GetType());

DynamicMethod dynamicEventHandler = new DynamicMethod(methodName,
            returnType,
            (Type[])parameterTypes.ToArray(typeof(Type)),
            typeof(TaskDynamicEventHandler));
    }
}
</font></pre>
<p><font size="2">The drawback in this approach was that a dynamic assembly+module+type was getting created for each event. This was not efficient enough, and so slightly altered the logic to create the dynamic assembly+module+type once and add the methods [dynamic event handlers] to the dynamic type.</font></p>
<p><font size="2">Though a level of efficieny may have been achieved, it was not elegant enough to be satisfied. The dynamic event handlers [DEH] are all methods of a specific type belonging to a different assembly that is generated at run-time, and these DEH do not belong to the same assembly as the TaskDynamicEventHandler class. The responsibility of the DEHs was to read its parameter name and values at runtime, package them into a hashtable and call a method HandleEvent of TaskDynamicEventHandler, and it is in HandleEvent that the actual job of logging is done. Well, the actual job is not only logging but other things that require access to the memebers of TaskDynamicEventHandler. So the non-elegance here was that HandleEvent was exposed as public static method so that the DEH in the dynamic assembly could call, which lead to the ugliness where HandleEvent was exposed to the outside world from the assembly to which TaskDynamicEventHandler belongs to. So HandleEvent cannot be non-public. But it was required for other reasons to be an instance method.</font></p>
<p><font size="2">2. Here is the most interesting part. The aim was then make the DEH call an instance method of the TaskDynamicEventHandler ie HandleEvent. How do you make a static method call an instance method ? Well, if I have an object reference of the TaskDynamicEventHandler class in the DEH execution, and IF i can load that on to the evaluation stack [using the IL code/ILGenerator], then i call an instance method. That was the pain and it was pretty tricky and interesting that everybody to whomever I explained could not correctly grasp that the &#39;this&#39; used during the compiled code will not be the same in the runtime IL code of the DEH, and neither can I load an object reference without me creating it or getting it as a parameter. That is all the .NET type security. You will not be given any chance to do reinterpret_cast kind of stuff at all. But you can pass the TaskDynamicEventHandler object reference [this] to the DEH but that beats the goal where the prototype of the DEH will not match the prototpye of its corresponding event and so cannot act as a sink.</font></p>
<p><font size="2">3. Here comes .NET 2.0 for the rescue to a certain extent, and helps us acheive the aim &#8211; Efficiency and Elegance. There is a class by name DynamicMethod to dynamically create methods. The beauty of the DynamicMethod is that it is possible to add the dynamic method as member of the current class TaskDynamicEventHandler.</font></p>
<pre><font color="#ff0000" size="2">
// returnType - event method&#39;s return type
// parameterTypes - event method&#39;s parameter types list
ArrayList parameterTypes = new ArrayList(parameterTypes);
parameterTypes.Insert(0, this.GetType());

DynamicMethod dynamicEventHandler = new DynamicMethod(methodName,
            returnType,
            (Type[])parameterTypes.ToArray(typeof(Type)),
            typeof(TaskDynamicEventHandler));
</font></pre>
<p><font size="2">Hence the DEH is now a part of the same assembly and class and it can call even non-public methods.  Efficiency was well achieved but still elegant was a few feet away. The dynamic method created and added to TaskDynamicEventHandler using DynamicMethod class is a static method and hence cannot access instance methods of TaskDynamicEventHandler, although it can access non-public methods.</font><br />
<font size="2">3. Here is the most interesting part. The aim of this iteration is to make the DEH call an instance method of the TaskDynamicEventHandler ie HandleEvent. How do you make a static method call an instance method ? Well, if I have an object reference of the TaskDynamicEventHandler class during the DEH execution, and if i can load that on to the evaluation stack [using the IL code/ILGenerator], then i call an instance method. Things are going to get interesting now. The difference between an instance and static method is that an instance method has the object reference, to which it belongs, as the first parameter while a static method does not. Though syntactically, the object reference is not added, the compiler adds it. So while creating the dynamic method [DEH] for an event, the TaskDynamicEventHandler object reference [this] is added as the first parameter to the event parameter list. This makes the DEH seem to be an instance method. So during runtime, when an event is fired, its corresponding DEH executes, the Lgarg_0 in the IL code represents the object reference it belongs to, and it is the same as that for HandleEvent.</font></p>
<p><font size="2">4. But even now the HandleEvent is public and is vulnerable for improper usage. I made it a virtual method. That is fun, and now it is entirely the user&#39;s responsibility to avoid improper usage, and it is upto the user to override HandleEvent to do whatever he wants.</font></p>
<p><font size="2">5. Few minor things- Added Trace.WriteLine in the IL code using ILGenerator for debugging; Added try-catch exception blocks for catching exceptions, but unfortunately does not seem to work.</font></p>
<p><font size="2">All of these approaches until the final efficient and elegant solution took several iterations of revisit and review. I will not able to explain about the difficulties and tough IL debugging experience that I went through trying to make the HandleEvent an instance virtual method, although I will be able to share the joy and knowledge now. It was a great experience !!!</font></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/vivekr.wordpress.com/27/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/vivekr.wordpress.com/27/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/vivekr.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/vivekr.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/vivekr.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/vivekr.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/vivekr.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/vivekr.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/vivekr.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/vivekr.wordpress.com/27/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/vivekr.wordpress.com/27/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/vivekr.wordpress.com/27/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vivekr.wordpress.com&blog=188395&post=27&subd=vivekr&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://vivekr.wordpress.com/2006/05/11/net-reflection-extravanganza/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c4c5284872338a4767f6ecc42bec4563?s=96&#38;d=identicon" medium="image">
			<media:title type="html">vivekr</media:title>
		</media:content>
	</item>
		<item>
		<title>Where is my C++ ?</title>
		<link>http://vivekr.wordpress.com/2006/05/04/where-is-my-c/</link>
		<comments>http://vivekr.wordpress.com/2006/05/04/where-is-my-c/#comments</comments>
		<pubDate>Thu, 04 May 2006 06:10:41 +0000</pubDate>
		<dc:creator>Vivek Ragunathan</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">https://vivekr.wordpress.com/2006/05/04/where-is-my-c/</guid>
		<description><![CDATA[I have been using C# for quite some time now, and that too VS 2005. I see that Programming Pain at a macro level has boiled down to thinking than coding. Though it might be an advantage on one side, I feel I have become lazy. Since I am a programmer from the C++ world, [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vivekr.wordpress.com&blog=188395&post=23&subd=vivekr&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I have been using C# for quite some time now, and that too VS 2005. I see that Programming Pain at a macro level has boiled down to thinking than coding. Though it might be an advantage on one side, I feel I have become lazy. Since I am a programmer from the C++ world, it was very easy to become lazy. The small and handy applications that I write for myself in C++, I am writing them in C#. Even now I am a great disciple of C++. And even though C++/CLI is out there, and I work a small amount of it in my project, I am getting inclined to C#.</p>
<p>I am not sure why I am writing this.<br />
Is it the fear or sorrow of getting away from C++ ?<br />
Or am I just expecting much elegant syntax and features like in C# ?</p>
<p>But I have begun to feel that the result you achieve out of the code you write is much more important than the programming language you use. Does anyone care whether Windows or Visual Studio or Yahoo Messenger or Google Talk or Internet Explorer or FireFox or any application you love, is written in C++ or C# or C++/CLI ? That is the way I consoled myself.</p>
<p>But I wish that C++ never go exile in my programming life.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/vivekr.wordpress.com/23/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/vivekr.wordpress.com/23/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/vivekr.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/vivekr.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/vivekr.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/vivekr.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/vivekr.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/vivekr.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/vivekr.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/vivekr.wordpress.com/23/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/vivekr.wordpress.com/23/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/vivekr.wordpress.com/23/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vivekr.wordpress.com&blog=188395&post=23&subd=vivekr&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://vivekr.wordpress.com/2006/05/04/where-is-my-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c4c5284872338a4767f6ecc42bec4563?s=96&#38;d=identicon" medium="image">
			<media:title type="html">vivekr</media:title>
		</media:content>
	</item>
		<item>
		<title>Infinite .NET Languages !!!</title>
		<link>http://vivekr.wordpress.com/2006/04/26/infinite-net-languages/</link>
		<comments>http://vivekr.wordpress.com/2006/04/26/infinite-net-languages/#comments</comments>
		<pubDate>Wed, 26 Apr 2006 23:15:07 +0000</pubDate>
		<dc:creator>Vivek Ragunathan</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">https://vivekr.wordpress.com/2006/04/26/infinite-net-languages/</guid>
		<description><![CDATA[Though I knew that there are quite a few languages for the .NET platform, I came to know when surfing today that there are many well beyond my knowledge, most surprisingly like the COBOL.
Check it out @ http://www.dotnetpowered.com/languages.aspx
       <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vivekr.wordpress.com&blog=188395&post=22&subd=vivekr&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Though I knew that there are quite a few languages for the .NET platform, I came to know when surfing today that there are many well beyond my knowledge, most surprisingly like the COBOL.</p>
<p>Check it out @ <a href="http://www.dotnetpowered.com/languages.aspx" title="DotNetPowered.COM" target="_blank">http://www.dotnetpowered.com/languages.aspx</a></p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/vivekr.wordpress.com/22/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/vivekr.wordpress.com/22/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/vivekr.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/vivekr.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/vivekr.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/vivekr.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/vivekr.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/vivekr.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/vivekr.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/vivekr.wordpress.com/22/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/vivekr.wordpress.com/22/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/vivekr.wordpress.com/22/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vivekr.wordpress.com&blog=188395&post=22&subd=vivekr&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://vivekr.wordpress.com/2006/04/26/infinite-net-languages/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c4c5284872338a4767f6ecc42bec4563?s=96&#38;d=identicon" medium="image">
			<media:title type="html">vivekr</media:title>
		</media:content>
	</item>
		<item>
		<title>Implementing COM OutOfProc Servers in C# .NET !!!</title>
		<link>http://vivekr.wordpress.com/2006/04/26/implementing-com-outofproc-servers-in-c-net/</link>
		<comments>http://vivekr.wordpress.com/2006/04/26/implementing-com-outofproc-servers-in-c-net/#comments</comments>
		<pubDate>Wed, 26 Apr 2006 23:01:30 +0000</pubDate>
		<dc:creator>Vivek Ragunathan</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">https://vivekr.wordpress.com/2006/04/26/implementing-com-outofproc-servers-in-c-net/</guid>
		<description><![CDATA[Step 1:
Implement IClassFactory in a class in .NET
Step 2:
[DllImport(&#34;ole32.dll&#34;)]
private static extern int CoRegisterClassObject(ref Guid rclsid,
   [MarshalAs(UnmanagedType.Interface)]IClassFactory pUnkn,
   int dwClsContext,
   int flags,
   out int lpdwRegister);

[DllImport(&#34;ole32.dll&#34;)]
private static extern int CoRevokeClassObject(int dwRegister);

Step 3:
Use these functions to register your own IClassFactory
Step 4:
IClassFactory has a CreateInstance method. Implement this method to return [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vivekr.wordpress.com&blog=188395&post=21&subd=vivekr&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Step 1:<br />
Implement IClassFactory in a class in .NET</p>
<p>Step 2:</p>
<pre><font color="#3366ff" face="Courier New" size="3">[DllImport(&quot;ole32.dll&quot;)]
private static extern int CoRegisterClassObject(ref Guid rclsid,
   [MarshalAs(UnmanagedType.Interface)]IClassFactory pUnkn,
   int dwClsContext,
   int flags,
   out int lpdwRegister);

[DllImport(&quot;ole32.dll&quot;)]
private static extern int CoRevokeClassObject(int dwRegister);
</font></pre>
<p>Step 3:<br />
Use these functions to register your own IClassFactory</p>
<p>Step 4:<br />
IClassFactory has a CreateInstance method. Implement this method to return a reference (IntPtr) to your own object. Use Marshal.GetIUnknownForObject to get IUnknown pointer to your object.</p>
<p>Step 5:<br />
The COM client receives a pointer to this object, and can use it as a regular COM object. .NET does the reference counting for you, and the GC will collect these objects when the COM-reference-count decremetns to zero.</p>
<p>Walking through and closely examining the working of ClassFactories for COM will give a clear sight of the objects that you need to implement in .NET, and a solution for COM Server in managed world.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/vivekr.wordpress.com/21/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/vivekr.wordpress.com/21/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/vivekr.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/vivekr.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/vivekr.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/vivekr.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/vivekr.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/vivekr.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/vivekr.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/vivekr.wordpress.com/21/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/vivekr.wordpress.com/21/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/vivekr.wordpress.com/21/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vivekr.wordpress.com&blog=188395&post=21&subd=vivekr&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://vivekr.wordpress.com/2006/04/26/implementing-com-outofproc-servers-in-c-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c4c5284872338a4767f6ecc42bec4563?s=96&#38;d=identicon" medium="image">
			<media:title type="html">vivekr</media:title>
		</media:content>
	</item>
		<item>
		<title>Non-conventional Window Shapes [I love C#] !!!</title>
		<link>http://vivekr.wordpress.com/2006/04/15/non-conventional-window-shapes-i-love-c/</link>
		<comments>http://vivekr.wordpress.com/2006/04/15/non-conventional-window-shapes-i-love-c/#comments</comments>
		<pubDate>Sat, 15 Apr 2006 05:44:00 +0000</pubDate>
		<dc:creator>Vivek Ragunathan</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">https://vivekr.wordpress.com/2006/04/15/non-conventional-window-shapes-i-love-c/</guid>
		<description><![CDATA[I am not a UI guy. More specifically, I love to work with UIs. I think (only) a UI can give a better picture of the system in a multitasking environment unlike Unix. I do not say I hate Unix. And I do not like to work on UIs ie program on UIs cuz I [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vivekr.wordpress.com&blog=188395&post=20&subd=vivekr&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I am not a UI guy. More specifically, I love to work with UIs. I think (only) a UI can give a better picture of the system in a multitasking environment unlike Unix. I do not say I hate Unix. And I do not like to work on UIs ie program on UIs cuz I do not know much. But have always wanted to create a non-conventional window, say an elliptical one. .NET made things like that very easy for guys like me. Look at the code below for creating a ellipitcal window.</p>
<pre><font color="#3366ff" face="Courier New" size="3">GraphicsPath windowShape = new GraphicsPath();
windowShape.AddEllipse(0, 0, 320, 200);
this.Region = new Region(windowShape);
</font></pre>
<p>The GraphicsPath has methods to create wiondows of other shapes too.</p>
<p>I am not sure but I think it was not this straight forward in the MFC/Win32 programming world. Thanks to C#.NET. I love this 3 lines of code.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/vivekr.wordpress.com/20/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/vivekr.wordpress.com/20/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/vivekr.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/vivekr.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/vivekr.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/vivekr.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/vivekr.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/vivekr.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/vivekr.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/vivekr.wordpress.com/20/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/vivekr.wordpress.com/20/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/vivekr.wordpress.com/20/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vivekr.wordpress.com&blog=188395&post=20&subd=vivekr&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://vivekr.wordpress.com/2006/04/15/non-conventional-window-shapes-i-love-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c4c5284872338a4767f6ecc42bec4563?s=96&#38;d=identicon" medium="image">
			<media:title type="html">vivekr</media:title>
		</media:content>
	</item>
		<item>
		<title>Serialization and Exceptions !!!</title>
		<link>http://vivekr.wordpress.com/2006/04/14/serialization-and-exceptions/</link>
		<comments>http://vivekr.wordpress.com/2006/04/14/serialization-and-exceptions/#comments</comments>
		<pubDate>Fri, 14 Apr 2006 17:23:00 +0000</pubDate>
		<dc:creator>Vivek Ragunathan</dc:creator>
				<category><![CDATA[CSharp]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">https://vivekr.wordpress.com/2006/04/14/serialization-and-exceptions/</guid>
		<description><![CDATA[I am just in a stage like Alice in Wonderland, and not yet got out of the wonders of the .NET framework, C# and the VS 2003(5) IDE. I thought that the serialization is all not my thing until I do something big in C#. I had written this custom exception class in my project [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vivekr.wordpress.com&blog=188395&post=19&subd=vivekr&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I am just in a stage like Alice in Wonderland, and not yet got out of the wonders of the .NET framework, C# and the VS 2003(5) IDE. I thought that the serialization is all not my thing until I do something big in C#. I had written this custom exception class in my project that has 3 processes connected by .NET Remoting Infrastructure. I throw my custom exception for a scenario but all I got was some other exception that said &quot;The constructor to deserialize an object of type MyException was not found&quot;. But I had the Serializable attribute tagged to my custom expection class.</p>
<p>Let me to get to the point. Even though you attach the Serializable attribute to your custom exception class, the base class Exception implements the ISerializable interface and the constructor required during the deserialization [Exception()] is protected. So when you throw MyException, it may get serialized and cross the remoting boundaries but on the client side, it will not able to deserialize because the required ctor is not accessible. So what we do is simple as shown in the following code:-</p>
<pre>[Serializable]
public class MyException : ApplicationException
{
    // Member Data
    // Other necessary ctors 

///
    /// Let us call this ctor as Deserializing Ctor [DSCTOR]
    /// 

public MyException(SerializationInfo info, StreamingContext context)
        : base(info, context)
    {
        // Any other custom data to be transferred
        // info.AddValue(CustomDataName, DataValue);
    }

/// If any custom information needs to be transferred
    /// with the MyException thown, it must be added to the
    /// SerializationInfo object on the call to
    /// GetObjectData() and to take them from this object in
    /// the constructor for deserialization.
    public override void GetObjectData(SerializationInfo info, StreamingContext context)
    {
        base.GetObjectData(info, context);
        // Any other custom data to be transferred
        // info.AddValue(CustomDataName, DataValue);
    }

// Other methods
}</pre>
<p>This DSCTOR is very much necessary, else the exception thrown will not be caught as the one thrown and you will get this excepetion &quot;The constructor to deserialize an object of type MyException was not found&quot;.</p>
<p>If any custom data needs to be transferred with the MyException thown, it must be added to the SerializationInfo object on the call to GetObjectData() and to take them from this object in this secondary [deserialization] constructor.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/vivekr.wordpress.com/19/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/vivekr.wordpress.com/19/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/vivekr.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/vivekr.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/vivekr.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/vivekr.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/vivekr.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/vivekr.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/vivekr.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/vivekr.wordpress.com/19/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/vivekr.wordpress.com/19/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/vivekr.wordpress.com/19/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vivekr.wordpress.com&blog=188395&post=19&subd=vivekr&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://vivekr.wordpress.com/2006/04/14/serialization-and-exceptions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c4c5284872338a4767f6ecc42bec4563?s=96&#38;d=identicon" medium="image">
			<media:title type="html">vivekr</media:title>
		</media:content>
	</item>
		<item>
		<title>Know where you initialize and Do not forget to uninitialize !!!</title>
		<link>http://vivekr.wordpress.com/2006/04/10/know-where-you-initialize-and-do-not-forget-to-uninitialize/</link>
		<comments>http://vivekr.wordpress.com/2006/04/10/know-where-you-initialize-and-do-not-forget-to-uninitialize/#comments</comments>
		<pubDate>Mon, 10 Apr 2006 21:33:00 +0000</pubDate>
		<dc:creator>Vivek Ragunathan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">https://vivekr.wordpress.com/2006/04/10/know-where-you-initialize-and-do-not-forget-to-uninitialize/</guid>
		<description><![CDATA[If you have long been programming in C++/COM and then you move to C#.NET, the first difference you can feel is that you got a ctor for the object you create unlike the CoCreateInstance. In the C++/COM world, you generally would have a Initialize method to do the constrcution sort of, paired with Terminate/Uninitialize method. [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vivekr.wordpress.com&blog=188395&post=18&subd=vivekr&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>If you have long been programming in C++/COM and then you move to C#.NET, the first difference you can feel is that you got a ctor for the object you create unlike the CoCreateInstance. In the C++/COM world, you generally would have a Initialize method to do the constrcution sort of, paired with Terminate/Uninitialize method. Similar is the case with singleton classes. For singleton classes in C++, you will have public static Instance or GetInstance method to get the only and one instance of the class and then use the initialize method to do the construction. This is certainly advantageous than the ctor facility in .NET, since you will not know when the instance will be initialized without the initialze method. Any call like SingletonClass.GetInstance().SomeMethod may initialize the singleton anywhere and you will not exactly do the initialization during the application startup, which in many cases will lead to application errors after startup.</p>
<p>I do not recommend putting the initialization logic in the ctor, particularly for singletons. The Initialize/Uninitialize method seem to be primitive and kind of from the legacy age but we want code elegance rather than fashion. The pair gives a reasonable intuition and a feel of responsibility to initialize and uninitiailze. Without this simple pair, the object [singleton or any .NET object] gets initialized without control. Also the developers as soon as they enter the .NET world, with the advice from somebody next door, instantly or deliberately forget the memory management and leave everything to GC. But GC can perform the uninitialization required by the business logic.</p>
<p>The Initialize/Uninitialize pair just silently enforces to follow the pattern to initialize at the right place, and most important uninitialize, not giving the risk of remembering about Dispose.</p>
<p>I was forced to write this comment because I was forced to write that code.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/vivekr.wordpress.com/18/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/vivekr.wordpress.com/18/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/vivekr.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/vivekr.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/vivekr.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/vivekr.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/vivekr.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/vivekr.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/vivekr.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/vivekr.wordpress.com/18/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/vivekr.wordpress.com/18/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/vivekr.wordpress.com/18/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vivekr.wordpress.com&blog=188395&post=18&subd=vivekr&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://vivekr.wordpress.com/2006/04/10/know-where-you-initialize-and-do-not-forget-to-uninitialize/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c4c5284872338a4767f6ecc42bec4563?s=96&#38;d=identicon" medium="image">
			<media:title type="html">vivekr</media:title>
		</media:content>
	</item>
		<item>
		<title>An encounter with Hashtables !!!</title>
		<link>http://vivekr.wordpress.com/2006/04/10/an-encounter-with-hashtables/</link>
		<comments>http://vivekr.wordpress.com/2006/04/10/an-encounter-with-hashtables/#comments</comments>
		<pubDate>Mon, 10 Apr 2006 21:26:00 +0000</pubDate>
		<dc:creator>Vivek Ragunathan</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">https://vivekr.wordpress.com/2006/04/10/an-encounter-with-hashtables/</guid>
		<description><![CDATA[I encountered a situation like this where I had a hashtable in which the key is a string and the value is some object, and I had to change the values of all the keys [from zero to count] to null or some other value. I used the some of the facilities &#8211; enumerator, the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vivekr.wordpress.com&blog=188395&post=17&subd=vivekr&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I encountered a situation like this where I had a hashtable in which the key is a string and the value is some object, and I had to change the values of all the keys [from zero to count] to null or some other value. I used the some of the facilities &#8211; enumerator, the Keys property etc provided by the hash table itself but it did not work out, and I spent too much time on this.</p>
<p>The interesting thing is that for the following code, the compiler spits an error saying &quot;&#39;System.Collections.IDictionaryEnumerator.Value&#39; cannot be assigned to &#8212; it is read only&quot;:-</p>
<pre><font color="#000fff" face="Courier New" size="3">IDictionaryEnumerator de = ht.GetEnumerator();
while (de.MoveNext())
{
   de.Value = null;
}</font></pre>
<p>while for this code</p>
<pre><font color="#000fff" face="Courier New" size="3">foreach (string key in ht.Keys)
{
  ht[key] = null;
}
</font></pre>
<p>it compiled successfully but threw a runtime exception [An unhandled exception of type &#39;System.InvalidOperationException&#39; occurred in mscorlib.dll Additional information: Collection was modified; enumeration operation may not execute].</p>
<p>But the solution was just bit out of sight while it was in hand. Just forget that you encountered this problem, and start again, you will have the solution simple like this:-</p>
<pre><font color="#000fff" face="Courier New" size="3">ArrayList keys = new ArrayList(ht.Keys);
foreach (string key in keys)
{
   ht[key] = null;
}
</font></pre>
<p>And another thing I came to know was that the hash table entries are not maintained in the same order as they are inserted. I came to know that it is the inherent nature of the algorithm. That is basic but it was new to me.</p>
<img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/vivekr.wordpress.com/17/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/vivekr.wordpress.com/17/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/vivekr.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/vivekr.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/vivekr.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/vivekr.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/vivekr.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/vivekr.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/vivekr.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/vivekr.wordpress.com/17/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/vivekr.wordpress.com/17/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/vivekr.wordpress.com/17/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=vivekr.wordpress.com&blog=188395&post=17&subd=vivekr&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://vivekr.wordpress.com/2006/04/10/an-encounter-with-hashtables/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/c4c5284872338a4767f6ecc42bec4563?s=96&#38;d=identicon" medium="image">
			<media:title type="html">vivekr</media:title>
		</media:content>
	</item>
	</channel>
</rss>