Locator – my first Windows Mobile App

A month back, I bought a new mobile phone (HTC S710) running Windows Mobile 6.0. I specifically bought it for playing around with the Windows Mobile API, and I’ve been trying out a few things with it. I’m pretty impressed by the .NET Compact Framework, it makes it ridiculously simple to do things that require huge chunks of code in C++. Anyways, one of the few things I wished I could do with my old phone was to use the location information broadcast by cellular networks. Almost all GSM providers (Airtel/BSNL/Vodafone) broadcast the current location to the cellphone – the … Continue reading Locator – my first Windows Mobile App

C# 3.0 compiler bug – Using object initializers, generics and value types

There is a description of the bug here. The following piece of code demonstrates the bug. class Program { interface I { int X { get; set; } } struct S : I { public int X { get; set; } } static void Main(string[] args) { Func<S>(); } static void Func<T>() where T : I, new() { var c = new T() { X = 1 }; Console.WriteLine(c.X); } } The code prints 0 instead of 1. The bug goes away if object initializers are not used – changing var c = new T() { X = 1 }; … Continue reading C# 3.0 compiler bug – Using object initializers, generics and value types

More greasemonkeying with IRCTC

I’m glad that a lot of people found AJAXAvailability useful. For people who haven’t heard about it, AJAXAvailability is a Greasemonkey script for IRCTC’s website that loads availability information asynchronously and shows it in the availability table, right alongside the list of trains (more information here). Mani suggested that the ability to sort the availability table based on departure time would be useful. That seemed like a nice idea, so here it is – SortItOut, a Greasemonkey script that modifies the availability table and makes the header texts clickable. Clicking on one of the headers, say “Departure time”, sorts the … Continue reading More greasemonkeying with IRCTC

Mucking around with instance field initializers – Part 2

We saw in Part 1 that C# doesn’t allow an instance field initializer to refer another field in the class. Before trying to figure out why, let’s first see if this is a restriction imposed by C#, rather than by the CLR.  Some disassembling and reassembling later, this is what the new IL code looks like. IL_0000: ldarg.0 IL_0001: ldc.i4.1 IL_0002: stfld int32 ConsoleApplication1.Program::x IL_0007: ldarg.0 IL_0008: ldarg.0 IL_000b: ldfld int32 ConsoleApplication1.Program::x IL_0009: ldc.i4.1 IL_000a: add IL_000c: stfld int32 ConsoleApplication1.Program::y IL_000d: ldarg.0 IL_000e: ldfld int32 ConsoleApplication1.Program::y IL_000f: call void [mscorlib]System.Console::WriteLine(int32)  It’s basically the same code in Part 1, except for … Continue reading Mucking around with instance field initializers – Part 2

Mucking around with instance field initializers – Part 1

What do you think of the following piece of code? class Program { int x = 1; int y = x + 1; } Looks simple, except that it doesn’t compile (error CS0236: A field initializer cannot reference the non-static field, method, or property ‘Program.x’) Try making x and y static – the code will compile fine now. I have been trying to find out why – so far, I haven’t got a clue. Just in case it’s not obvious, I do know that moving y = x + 1 into the body of Program’s constructor will get me what … Continue reading Mucking around with instance field initializers – Part 1