Posts

Showing posts from September, 2011

Some .NET Gotchas

1) For.. Each vs For... I have often wondered what is the difference between for..each and for loops in iterating over collections, because I always use the regular for loops. Today, I found out one major difference - if while iterating over the for..each, I add an item to the list being iterated, the for.. each loop will not go over this newly added item. On the other hand, if I use a regular for loop using the length of the collection, and I add an item to the list, it will also get iterated over. 2) Using LINQ and unexpected behavior... For whatever reason, I am observing that if I use LINQ to find an item from a collection, and later I check to see whether the original collection contains this item, then it always returns false. 3) Using Generic Lists I was very surprised to see that, sometimes .Contains() does not work properly, I have to use Exists() and then write a delegate to check for the existence. The same problem manifests when removing an item from the list...

ASP.NET Woes

I might have mentioned in the past a case where asp.net does not use the latest code no matter what you try, and the only way I made it work was to compile in debug mode, deploy those dlls and reload the site. Well, I found out one more case today. This can happen if you massively change web.config also. No matter what you try, if your codebase is big enough, it will not use the latest configuration. You can try iisreset, reboot or even deleting the temporary internet files from the .NET folders within the system folder. The only way to get this to work is to set debug="true" in the web.config file and even then, it takes some time for this to take effect.

Kindle 3 Review

I wanted to buy a tabler/ ereader because I read a lot of tech news both from todayamerican and from other sites. It was getting too difficult to read on the iphone and the ipad 2 was very expensive. Eye strain was a problem and so I got the very decentlly priced Kindle 3 with offers from Best Buy for a bargain price as it was the 3g version. I returned it the next day even though I liked it a lot, because after having a connected experience for so long, it has become very difficult for me to send a static PDF to an ereader and tamely read the totally disconnected PDF file. Also, the browser was very very experimental to say the least. The Kindle 3 is an excellent book replacement and nobody who still reads a lot of black and white books will regret purchasing it, but for anybody young, who already reads online blogs and news articles on the web, it will seem too tame. The best word to say is "un-exciting". I think it came too late. 10 years ago, it might have been a...

I found something surprising today..

I was seeing this code which was trying to remove an item from a list. This list object was derived from List<T> and did not override the collection based methods. I noticed that the original code did not remove the item from the list even though it tried to: listObject.Remove(listObject.Find(delegate(listItemObject p) { return p.MyProperty == x.MyProperty && p.MyProperty2 == x.MyProperty2; })); This looked fishy, so I changed this code to use LINQ to objects to get a list of items to remove and then I removed the items one by one inside a for loop just to see whether it would work or not. Surprise Surprise! - It did not work. Finally, I had to use the RemoveAll() method passing in this condition as an anonymous method to make the code remove it. I could not understand why it would not remove the item when I called remove on an object which I got from within the list itself.