예제 #1
0
 public static PositionTuple FirstPositionOf(this int[,] someTwoDimensionalArray, int someNumber)
 {
     return(someTwoDimensionalArray
            .AsEnumerable()
            .Select((num, index) => new { Number = num, Tuple = new PositionTuple {
                                              X = index / (someTwoDimensionalArray.GetUpperBound(1) + 1), Y = index % (someTwoDimensionalArray.GetUpperBound(1) + 1)
                                          } })
            .Where(pair => pair.Number == someNumber)
            .Select(pair => pair.Tuple)
            .First());
 }
        public void AsEnumerable()
        {
            int[,] candidate =
            {
                {  1,  2,  3, },
                {  4,  5,  6, },
                {  7,  8,  9, },
                { 10, 11, 12, },
            };

            CollectionAssert.AreEqual(Enumerable.Range(1, 12).ToArray(), candidate.AsEnumerable().ToArray());
        }