Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Collections And Indexers
Message
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01403311
Message ID:
01403336
Views:
49
>Do Indexers only work with arrays? I can't seem to find an example of an indexer used with a collection.

Look at the IDictionary interface and the IDictionary[TKey, TValue] Interface
public interface IDictionary<TKey, TValue>
   : ICollection<KeyValuePair<TKey, TValue>>, IEnumerable
{
    ...
    TValue this[TKey key]  {get; set; } // Main indexer by key
    ...
}
and - the index does not have to be numeric
		public static void Main()
		{
			var xx = new Dictionary<string, int>();
			xx.Add("01", 1);
			xx.Add("02", 2);

			xx["01"] = 7;

			Console.WriteLine("xx[\"01\"] = {0}", xx["01"]); //7
			Console.ReadLine();

		}
Gregory
Previous
Reply
Map
View

Click here to load this message in the networking platform