Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Array of indexers?
Message
From
25/07/2009 05:38:11
 
 
To
23/07/2009 16:38:39
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
C# 3.0
OS:
Windows XP SP2
Miscellaneous
Thread ID:
01414024
Message ID:
01414440
Views:
52
>>I don't know whether my head is just not working right these days (keep your comments to yourself), or if it really is has hard as I'm making it for myself, but how do you deal with an array of indexers? What is the syntax for accessing the indexer values in an array of indexers?
>>
>>Thanks
>
>'S'ok. I figured it out. I seems you declare it like any other array, but you access it like a 2 dimensional array (I think).

In fact, you're accessing them like jagged arrays ( http://msdn.microsoft.com/en-us/library/2s05feca.aspx )


The 'indexers' are evaluated left to right
	class Test
	{
		public static void Main()
		{
			// an array of lists that have dictionaries
			var q = new List<Dictionary<string, int>>[] 
			{
				// q[0]
				new List<Dictionary<string, int>> 
					{ 
						// q[0][0]
						new Dictionary<string, int>
						{
							{ "george I", 1},
							{ "alan I", 2},
							{ "don I", 3}
						},
						// q[0][1]
						new Dictionary<string, int>
						{
							{ "sam I", 1},
							{ "pat I", 2}
						}
					},
				// q[1]
				new List<Dictionary<string, int>> 
					{ 
						// q[1][0]
						new Dictionary<string, int>
						{
							{ "george II", 21},
							{ "alan II", 22},
							{ "don II", 23}
						}
					}
			};

			Console.WriteLine(" {0}", q[1][0]["alan II"]); //22 
			Console.ReadLine();
			
		}
	}
Gregory
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform