Ongoing C# learning

Over the last few days I been learning some interesting little .Net tip-bits.

The first is the VB.Net can do Indexer Parameters or named Indexers, where C# cannot. The indexer guideline suggests to not implement multiple indexers or some (C#) language will not be able to access them. C++ can even use them. While you can achieve the same effect via sub-classes or a generic list accessor, but they are no-where as succinct.

The primary place I have wanted to use them is my game conversion. It has data structures for the player icons that have duel data arrays for the original, and the overlaid versions. Been able to-do

icon1.data1[i] += icon2.data1[i];
icon1.data2[i] += icon2.data2[i];

without exposing the array is so much nicer. The realty is that most the functions accessing this data will become member functions once I refactor the project. So it’s not really a required feature.

The next interesting reminder was type conversion operators. This was something I have used, but re-learning is always nice. Fritz has a good post talking about using them to improve the use of constructors.

The third was found in the previous post of Fritz about the ?? Operator. This was a little gem that I plan to use in the future. MSDN URL