Ahmed El-Halwagy’s Blog

Archive for November 2009


Posted on: November 3, 2009

Hello there,
Sorry, but this blog has been moved to This Site.
This site will remain as is with no updates –only the old articles will stay here. To get the new articles that I write, please visit my other blog
So .. See you there pals! 🙂

If you dealt with COM Interop before, then you probably know what Indexed Properties mean. If you don’t, hang on with me and you will know in the coming few lines. Consuming Indexed Properties is a new feature to C# 4.0 Beta2. This is used to improve syntax like the following:

var excel = new Microsoft.Office.Interop.Excel.ApplicationClass();


This syntax can now be improved to get rid of get_Range(“A1”) and use an indexer accessor instead, here’s how C# 4.0 Beta 2 can do for you to improve this:

var range = excel.Range[“A1”];

So now, every time you use COM Interop and have to call get_x() and set_x(), you can now replace this with the new indexer syntax. I have to tell you –Well, you might have guessed it- that this is just a syntatic sugar, the compiler will do emit calls to get_x() and set_x() ultimately.

I think this little syntax improvement is pretty neat, however, people shouldn’t ask the very expected question “Well, now we can consume indexed properties in c#, why can’t we create it? we wanna create indexed properties! Indexed properties is a legal right! blah blah .. “. If C# allowed us to create indexed properties then I think, this will add an ambiguity that isn’t worth anything here. I mean take a look at the following code and tell me what would it mean to you, if C# enables you to create indexed properties?


Does it mean that SomeProperty is a type that implements an indexer, or SomeProperty is a property that requires an indexer? See the ambiguity?


What’s your thoughts on this, dear reader?


November 2009
« Aug    



Recent Twitter Updates

  • RT @MattChorley: Bring your child to work day https://t.co/QOptwEmsZ0 1 week ago
  • RT @shawky281: الواحد حاسس بفاجعة الحدث و خطورته على الجيش نفسه ككيان اكتر من موالسين الدولجية اللي صدعوا اهالينا بقالهم 6 سنين عن قدسية عم… 1 week ago
  • RT @gamaleid: ولا واحد ، ولا نص ، ولا ربع عضو من بتوع 25/30 اعلن تقديم استقالته! حار بارد ممطر جاف 1 week ago
  • RT @MalekAdly: حزب النور موافق علي إن الجزر تضيع .. طب اعتبروها كاميليا اختكم حتي #تيران_وصنافر_مصرية 1 week ago
  • RT @AmrEzzat: غلاف الأخبار اللبنانية: باع أرضه https://t.co/PfGeaLLexT 1 week ago