当前位置: 首页>>代码示例>>C#>>正文


C# System.GetLength方法代码示例

本文整理汇总了C#中System.GetLength方法的典型用法代码示例。如果您正苦于以下问题:C# System.GetLength方法的具体用法?C# System.GetLength怎么用?C# System.GetLength使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System的用法示例。


在下文中一共展示了System.GetLength方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestArray_Scenario_Result

 public void TestArray_Scenario_Result()
 {
     var strings = new[] { "Acme", "WB", "Universal" };
     Console.WriteLine(strings.Length);
     Console.WriteLine(strings.Rank);
     Console.WriteLine(strings.GetLength(0));
     Console.WriteLine(strings.GetUpperBound(0));
     Console.WriteLine(strings.Count());
 }
开发者ID:Foxpips,项目名称:ProgrammingCSharp,代码行数:9,代码来源:FileReaderTester.cs

示例2: Main

        static void Main(string[] args)
        {
            var grid = new[,]
                {
                    {08, 02, 22, 97, 38, 15, 00, 40, 00, 75, 04, 05, 07, 78, 52, 12, 50, 77, 91, 08},
                    {49, 49, 99, 40, 17, 81, 18, 57, 60, 87, 17, 40, 98, 43, 69, 48, 04, 56, 62, 00},
                    {81, 49, 31, 73, 55, 79, 14, 29, 93, 71, 40, 67, 53, 88, 30, 03, 49, 13, 36, 65},
                    {52, 70, 95, 23, 04, 60, 11, 42, 69, 24, 68, 56, 01, 32, 56, 71, 37, 02, 36, 91},
                    {22, 31, 16, 71, 51, 67, 63, 89, 41, 92, 36, 54, 22, 40, 40, 28, 66, 33, 13, 80},
                    {24, 47, 32, 60, 99, 03, 45, 02, 44, 75, 33, 53, 78, 36, 84, 20, 35, 17, 12, 50},
                    {32, 98, 81, 28, 64, 23, 67, 10, 26, 38, 40, 67, 59, 54, 70, 66, 18, 38, 64, 70},
                    {67, 26, 20, 68, 02, 62, 12, 20, 95, 63, 94, 39, 63, 08, 40, 91, 66, 49, 94, 21},
                    {24, 55, 58, 05, 66, 73, 99, 26, 97, 17, 78, 78, 96, 83, 14, 88, 34, 89, 63, 72},
                    {21, 36, 23, 09, 75, 00, 76, 44, 20, 45, 35, 14, 00, 61, 33, 97, 34, 31, 33, 95},
                    {78, 17, 53, 28, 22, 75, 31, 67, 15, 94, 03, 80, 04, 62, 16, 14, 09, 53, 56, 92},
                    {16, 39, 05, 42, 96, 35, 31, 47, 55, 58, 88, 24, 00, 17, 54, 24, 36, 29, 85, 57},
                    {86, 56, 00, 48, 35, 71, 89, 07, 05, 44, 44, 37, 44, 60, 21, 58, 51, 54, 17, 58},
                    {19, 80, 81, 68, 05, 94, 47, 69, 28, 73, 92, 13, 86, 52, 17, 77, 04, 89, 55, 40},
                    {04, 52, 08, 83, 97, 35, 99, 16, 07, 97, 57, 32, 16, 26, 26, 79, 33, 27, 98, 66},
                    {88, 36, 68, 87, 57, 62, 20, 72, 03, 46, 33, 67, 46, 55, 12, 32, 63, 93, 53, 69},
                    {04, 42, 16, 73, 38, 25, 39, 11, 24, 94, 72, 18, 08, 46, 29, 32, 40, 62, 76, 36},
                    {20, 69, 36, 41, 72, 30, 23, 88, 34, 62, 99, 69, 82, 67, 59, 85, 74, 04, 36, 16},
                    {20, 73, 35, 29, 78, 31, 90, 01, 74, 31, 49, 71, 48, 86, 81, 16, 23, 57, 05, 54},
                    {01, 70, 54, 71, 83, 51, 54, 69, 16, 92, 33, 48, 61, 43, 52, 01, 89, 19, 67, 48}
                };

            var width = grid.GetLength(0);
            var height = grid.GetLength(1);
            var lines = new List<List<int>>();

            for (var y = 0; y < height; y++)
            {
                var horizontal = new List<int>();

                for (var x = 0; x < width; x++)
                    horizontal.Add(grid[y, x]);

                lines.Add(horizontal);
            }

            for (var x = 0; x < width; x++)
            {
                var vertical = new List<int>();

                for (var y = 0; y < height; y++)
                    vertical.Add(grid[y, x]);

                lines.Add(vertical);
            }

            //TODO:斜めの走査
            #if DEBUG
            Console.ReadLine();
            #endif
        }
开发者ID:herara-ofnir3,项目名称:ProjectEuler,代码行数:55,代码来源:Program.cs

示例3: AccessToOutOfRangeElements

        public void AccessToOutOfRangeElements()
        {
            // Arrange
            var element = new[,] { { 0 } };

            // Act
            var matrix = new Matrix<int>(element);
            Func<int> accessToInvalidIndex = () => matrix[element.GetLength(0) + 1, element.GetLength(1) + 1];

            accessToInvalidIndex();
        }
开发者ID:ZenLulz,项目名称:Matrix.NET,代码行数:11,代码来源:ElementsTests.cs

示例4: WriteArray

        public void WriteArray(System.Array _array)
        {
            // Initialise with symbol to indicate start of array
            StringBuilder.Append('[');

            switch (_array.Rank)
            {
            case 1:
                int _1DArrayLength				= _array.Length;

                for (int _iter = 0; _iter < _1DArrayLength; _iter++)
                {
                    if (_iter != 0)
                        StringBuilder.Append(',');

                    WriteObjectValue(_array.GetValue(_iter));
                }

                break;

            case 2:
                int _outerArrayLength				= _array.GetLength(0);
                int _innerArrayLength				= _array.GetLength(1);

                for (int _outerIter = 0; _outerIter < _outerArrayLength; _outerIter++)
                {
                    if (_outerIter != 0)
                        StringBuilder.Append(',');

                    // Append symbol to indicate start of json string representation of inner array
                    StringBuilder.Append('[');

                    for (int _innerIter = 0; _innerIter < _innerArrayLength; _innerIter++)
                    {
                        if (_innerIter != 0)
                            StringBuilder.Append(',');

                        WriteObjectValue(_array.GetValue(_outerIter, _innerIter));
                    }

                    // Append symbol to indicate end of json string representation of inner array
                    StringBuilder.Append(']');
                }

                break;
            }

            // Append symbol to indicate end of json string representation of array
            StringBuilder.Append(']');
            return;
        }
开发者ID:ASchvartzman,项目名称:518Project-ASK,代码行数:51,代码来源:JSONWriter.cs

示例5: Main

        static void Main(string[] args)
        {
            int SelectItem;
            RegistryKey[] regs = new[] {
            Registry.ClassesRoot,
            Registry.CurrentUser,
            Registry.LocalMachine,
            Registry.Users,
            Registry.CurrentConfig,
            };

            do
            {
                int i = 1;
                Console.WriteLine("Choose part system registry");
                foreach(RegistryKey reg in regs)
                {
                    Console.WriteLine("{0}. {1}" ,i++,reg.Name);
                }
                Console.WriteLine("0.Exit");
                Console.Write("> ");
                SelectItem = Convert.ToInt32(Console.ReadLine()[0]) - 48;
                Console.WriteLine();
                if (SelectItem > 0 && SelectItem <= regs.GetLength(0))
                    PrintRegKeys(regs[SelectItem - 1]);
            } while (SelectItem != 0);
        }
开发者ID:RoykoSerhiy,项目名称:visualStudio_projects,代码行数:27,代码来源:Program.cs

示例6: SingleDimensionalArrayTest

 public void SingleDimensionalArrayTest()
 {
     var items = new[] {1, 2, 3};
     Assert.AreEqual(3, items.Length);
     Assert.AreEqual(1, items.Rank);
     Assert.AreEqual(3, items.GetLength(0));
 }
开发者ID:matry-ny,项目名称:brain,代码行数:7,代码来源:ArraysTest.cs

示例7: Convert

        /// <summary>
        /// By default return False, i.e. the control is disabled.
        /// And, then loop through the permission matrix and enable/disable accordingly
        /// </summary>
        /// <param name="value"></param>
        /// <param name="targetType"></param>
        /// <param name="parameter"></param>
        /// <param name="culture"></param>
        /// <returns></returns>
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            const bool controlEnabledState = false;
            var thisTask = (TaskItem)value;


            /*
             * The following array represents the permission matrix for a control to be enabled.
             * <control name>,<1=enabled for assigned user>,<1=enabled for manager >
             * <control name>,<0=enabled for assigned user>,<0=enabled for manager >
             */
            var widgetPermissionMatrix= new[,] 
            {
                {"Status","1","0"},
                {"ManagementSignOff","0","1"},
                {"DueTime","0","1"},
                {"AlertTime","1","1"},//Sep 21, Alertime shoudl be controllable by manager/assignedto. Helps when manager is changing the due time.Avoids unrealistic timings
                {"EscalationTime","0","1"},
                {"LinkToProcess","0","1"},
                {"KriDefinition","0","1"},
                {"TaskDescription","0","0"},
                {"TaskName","0","0"},
                {"Manager","0","0"}

            }; 

            int  currenttaskperm=0x0;
            if (TaskItem.IsUserInAssignedTo(ViewModel.Current.WssUserId, thisTask))
            {
                currenttaskperm = currenttaskperm | 0x1;
            }

            if (TaskItem.IsUserManager (ViewModel.Current.WssUserId, thisTask))
            {
                currenttaskperm = currenttaskperm | 0x2;
            }

            int controlindex = 0;
            var controlname = (string)parameter;

            for (controlindex = 0; controlindex < widgetPermissionMatrix.GetLength(0); controlindex++)
            {
                if (!controlname.Equals(widgetPermissionMatrix[controlindex, 0])) continue;
                

                System.Diagnostics.Debug.WriteLine("{0}\r\n",widgetPermissionMatrix[controlindex,0]);
                System.Diagnostics.Debug.WriteLine ("\tA:{0},M:{1}\r\n",widgetPermissionMatrix[controlindex,1],widgetPermissionMatrix[controlindex,2] );
                int allowedroleaccess = 0;
                if (widgetPermissionMatrix[controlindex, 1].Equals("1")) allowedroleaccess = allowedroleaccess | 0x1;
                if (widgetPermissionMatrix[controlindex, 2].Equals("1")) allowedroleaccess = allowedroleaccess | 0x2;
                System.Diagnostics.Debug.WriteLine("\t\taccess:{0}", allowedroleaccess);
                return (currenttaskperm & allowedroleaccess) > 0;
            }
            

            return controlEnabledState;
        }
开发者ID:nilavghosh,项目名称:VChk,代码行数:66,代码来源:TaskEditEnableWidgetLogic.cs

示例8: ShouldWorkForEnumeration

        public void ShouldWorkForEnumeration()
        {
            var list = new []{ "a", "b", "c" };
            var blk = new ValueBlock(list);

            Assert.AreEqual("[\"a\", \"b\", \"c\"]", blk.GetMessage());

            blk.WithEnumerableCount(list.GetLength(0));
            Assert.AreEqual("[\"a\", \"b\", \"c\"] (3 items)", blk.GetMessage());
        }
开发者ID:tpierrain,项目名称:NFluent,代码行数:10,代码来源:ValueBlockTests.cs

示例9: Main

        static void Main(string[] args)
        {
            var int_array = new int[] { 1, 2, 4 };
            var str_array = new string[] { "Hello", "Array", null };
            var nullable_array = new[] { 0, (int?)1, 2};

            Console.WriteLine(int_array.GetType());
            Console.WriteLine(str_array.GetType());
            Console.WriteLine(nullable_array.GetType());
            Console.WriteLine(nullable_array.GetLength(0));
        }
开发者ID:Cheha,项目名称:Object-Oriented-Programming-Examples,代码行数:11,代码来源:Program.cs

示例10: AccessTheElements

        public void AccessTheElements()
        {
            // Arrange
            var predefinedElements = new[,]
            {
                {1, 0, 0},
                {0, 1, 0},
                {0, 0, 1}
            };

            // Act
            var matrix = new Matrix<int>(predefinedElements);

            // Assert
            for (int i = 0; i < predefinedElements.GetLength(0); i++)
            {
                for (int j = 0; j < predefinedElements.GetLength(1); j++)
                {
                    Assert.AreEqual(predefinedElements[i, j], matrix[i, j], "An element is not equal to the original value used to create the matrix.");
                }
            }
        }
开发者ID:ZenLulz,项目名称:Matrix.NET,代码行数:22,代码来源:ElementsTests.cs

示例11: JaggedArrayTest

        public void JaggedArrayTest()
        {
            var items = new []
            {
                new [] {1, 2, 3},
                new [] {5},
                new [] {3, 4}
            };

            Assert.AreEqual(3, items[0][2]);
            Assert.AreEqual(3, items.Length);
            Assert.AreEqual(1, items.Rank);
            Assert.AreEqual(3, items.GetLength(0));
        }
开发者ID:matry-ny,项目名称:brain,代码行数:14,代码来源:ArraysTest.cs

示例12: DrawPolylineFeature

 public void DrawPolylineFeature(Graphics g, System.Drawing.Point[] Points_array,
     int LinePattern, System.Drawing.Color LineColor, int LineWidth)
 {
     if (LinePattern == 2)
     {
         if (Points_array.GetLength(0) > 1)
         {
             g.DrawLines(new Pen(LineColor), Points_array);
         }
     }
     else
     {
         DrawDashedPolyline(g, Points_array, LinePattern, LineColor, LineWidth, 0);
     }
 }
开发者ID:ravcio,项目名称:MapNet,代码行数:15,代码来源:RenderGDIplus.cs

示例13: DrawPolylineFeature

        internal void DrawPolylineFeature(Graphics g, System.Drawing.Point[] Points_array,
            int LinePattern, System.Drawing.Color LineColor, int LineWidth)
        {
            IntPtr drawPen;		// gdi pen
            IntPtr drawPen_old;		// gdi pen

            if (LinePattern == 2)
            {
                drawPen = (IntPtr)Win32.GDI.CreatePen(Win32.GDI.PS_GEOMETRIC, LineWidth, LineColor.ToArgb());
                drawPen_old = (IntPtr)Win32.GDI.SelectObject(m_hdc, drawPen);

                int count = Points_array.GetLength(0);
                Win32.GDI.Polyline(m_hdc, ref Points_array[0], count);

                Win32.GDI.SelectObject(m_hdc, drawPen_old);
                Win32.GDI.DeleteObject(drawPen);
            }
        }
开发者ID:ravcio,项目名称:MapNet,代码行数:18,代码来源:RenderGDI.cs

示例14: GetRandomRace

        /// <summary>
        /// Return a random race number based on a group type.
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static int GetRandomRace( int type )
        {
            int race;
            int[] animals = new[] {
                RACE_WORM, RACE_BIRD, RACE_HERBIVORE, RACE_RAT, RACE_FISH, RACE_BAT,
                RACE_SNAKE, RACE_BOAR, RACE_BEAR, RACE_HORSE, RACE_PRIMATE, RACE_INSECT
            };

            Random rand = new Random();

            switch( type )
            {
                case RACE_RANGE_ANY:
                    race = rand.Next(0, RaceList.Length - 1);
                    break;
                case RACE_RANGE_PLAYER:
                    race = rand.Next(0, Limits.MAX_PC_RACE - 1);
                    break;
                case RACE_RANGE_HUMANOID:
                    race = rand.Next(RACE_HUMAN, RACE_HUMANOID);
                    break;
                case RACE_RANGE_ANIMAL:
                    {
                        int index = rand.Next(0, animals.GetLength(0) / sizeof(int) - 1);
                        race = animals[ index ];
                    }
                    break;
                default:
                    throw new Exception("Race.GetRandomRace: invalid type");
            }
            if (race == RACE_GOD)
            {
                race = GetRandomRace(type);
            }

            return race;
        }
开发者ID:ramseur,项目名称:ModernMUD,代码行数:42,代码来源:Race.cs

示例15: Read

        public override System.Int32 Read(System.Byte[] buffer, System.Int32 offset, System.Int32 count)
        {
            // According to MS documentation, any implementation of the IO.Stream.Read function must:
            // (a) throw an exception if offset & count reference an invalid part of the buffer,
            //     or if count < 0, or if buffer is null
            // (b) return 0 only upon EOF, or if count = 0
            // (c) if not EOF, then return at least 1 byte, up to <count> bytes

            if (_streamMode == StreamMode.Undefined)
            {
                if (!this._stream.CanRead) throw new ZlibException("The stream is not readable.");
                // for the first read, set up some controls.
                _streamMode = StreamMode.Reader;
                // (The first reference to _z goes through the private accessor which
                // may initialize it.)
                z.AvailableBytesIn = 0;
                if (_flavor == ZlibStreamFlavor.GZIP)
                {
                    _gzipHeaderByteCount = _ReadAndValidateGzipHeader();
                    // workitem 8501: handle edge case (decompress empty stream)
                    if (_gzipHeaderByteCount == 0)
                        return 0;
                }
            }

            if (_streamMode != StreamMode.Reader)
                throw new ZlibException("Cannot Read after Writing.");

            if (count == 0) return 0;
            // workitem 10562
            // this quits too early if the input buffer has been consumed but
            // there's still output which hasn't been created yet (e.g. block
            // data for tables / tree, or the trailing adler32 data). we
            // need to wait for a Z_STREAM_END from Deflate instead.
            //if (nomoreinput && _wantCompress) return 0;  // workitem 8557
            if (buffer == null) throw new ArgumentNullException("buffer");
            if (count < 0) throw new ArgumentOutOfRangeException("count");
            if (offset < buffer.GetLowerBound(0)) throw new ArgumentOutOfRangeException("offset");
            if ((offset + count) > buffer.GetLength(0)) throw new ArgumentOutOfRangeException("count");

            int rc = 0;

            // set up the output of the deflate/inflate codec:
            _z.OutputBuffer = buffer;
            _z.NextOut = offset;
            _z.AvailableBytesOut = count;

            // This is necessary in case _workingBuffer has been resized. (new byte[])
            // (The first reference to _workingBuffer goes through the private accessor which
            // may initialize it.)
            _z.InputBuffer = workingBuffer;

            do
            {
                // need data in _workingBuffer in order to deflate/inflate.  Here, we check if we have any.
                if ((_z.AvailableBytesIn == 0) && (!nomoreinput))
                {
                    // No data available, so try to Read data from the captive stream.
                    _z.NextIn = 0;
                    _z.AvailableBytesIn = _stream.Read(_workingBuffer, 0, _workingBuffer.Length);
                    if (_z.AvailableBytesIn == 0)
                        nomoreinput = true;

                }
                // workitem 10562
                // if we've consumed all the input then we need to generate any
                // remaining block data and checksums and put them in the pending array
                if (nomoreinput) _flushMode = FlushType.Finish;
                // we have data in InputBuffer; now compress or decompress as appropriate
                rc = (_wantCompress)
                    ? _z.Deflate(_flushMode)
                    : _z.Inflate(_flushMode);

                if (nomoreinput && (rc == ZlibConstants.Z_BUF_ERROR))
                    return 0;

                if (rc != ZlibConstants.Z_OK && rc != ZlibConstants.Z_STREAM_END)
                    throw new ZlibException(String.Format("{0}flating:  rc={1}  msg={2}", (_wantCompress ? "de" : "in"), rc, _z.Message));

                if ((nomoreinput || rc == ZlibConstants.Z_STREAM_END) && (_z.AvailableBytesOut == count))
                {
                    // workitem 10562
                    // we've genuinely reached the end of the output stream now,
                    // including any block data and adler32 which appears after
                    // the compressed input data. we don't have any more bytes
                    // to return so we can stop processing
                    return 0; // nothing more to read
                };
            }
            //while (_z.AvailableBytesOut == count && rc == ZlibConstants.Z_OK);
            //while (_z.AvailableBytesOut > 0 && !nomoreinput && rc == ZlibConstants.Z_OK);
            while (_z.AvailableBytesOut > 0 && rc == ZlibConstants.Z_OK);

            // workitem 10562
            // the following is no longer required as we now call _z.Deflate
            // in the main loop above instead
            //// workitem 8557
            //// is there more room in output?
            //if (_z.AvailableBytesOut > 0)
            //{
//.........这里部分代码省略.........
开发者ID:pilehave,项目名称:headweb-mp,代码行数:101,代码来源:ZlibBaseStream.cs


注:本文中的System.GetLength方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。