Prev: send basic text to webserver
Next: Where is my thread?
From: Peter Duniho on 19 May 2010 02:57 Rick wrote: > Would you be able to provide me with a sample code? thank you Here is a short program illustrating how to use a multi-dimensional array: using System; namespace TestMultiDimensionalArray { class Program { static void Main(string[] args) { object[,] siblings = { { "John", 25 }, { "Mike", 30 }, { "Tom", 40 } }; Console.WriteLine("There are {0} siblings in the array", siblings.GetLength(0)); for (int i = 0; i < siblings.GetLength(0); i++) { Console.WriteLine("Name: {0}, Age: {1}", siblings[i, 0], siblings[i, 1]); } Console.ReadLine(); } } }
From: vanderghast on 20 May 2010 11:29
with anonymous type (and LINQ) : var siblings = new[ ]{ new { name= "Mike", age= 28} , new { name= "Mary", age= 25}, new { name= "John", age= 31} }; int MikeAge = (from s in siblings where s.name == "Mike" select s.age).Max(); Note that it assumes there is one and only one Mike ! It would be safier to use var AllMike = from s in siblings where s.name=="Mike" then to test the count if( 1 != AllMike.Count( ) ) { } Or if you already know that the age must be 28: if( 1== (from s in sibligns where s.name == "Mike" && s.age==28 select s.age ).Count( ) ) { } Vanderghast, Access MVP "Rick" <Rick(a)discussions.microsoft.com> wrote in message news:E4E7F5C2-88A4-4D32-9F19-4C1DCA61B898(a)microsoft.com... > object[,] siblings = { { "John", 25 }, { "Mike", 30 }, { "Tom", 40 } }; > > Let say I have a value: > string searchString = "Mike"; > > How do I search for the [searchString] in the array siblings and get the > age > (in case of Mike, it is 30)? |