如何在C#中定义数组?

王林
王林 转载
2023-09-03 16:57:02 832浏览

如何在C#中定义数组?

在 C# 中定义数组 -

int[] runs = new int[10];

现在让我们在同一行中初始化数组 -

int[] runs = new int[5] {99, 92, 95};

以下示例展示了如何声明、初始化和显示数组 -

示例

using System;

namespace Program {
   class Demo {
      static void Main(string[] args) {
         int[] runs = new int[3] {149, 123, 257};
         int j;

         for (j = 0; j < 3; j++ ) {
            Console.WriteLine("Score of Cricketer[{0}] = {1}", j, runs[j]);
         }
         Console.ReadKey();
      }
   }
}

以上就是如何在C#中定义数组?的详细内容,更多请关注php中文网其它相关文章!

声明:本文转载于:tutorialspoint,如有侵犯,请联系admin@php.cn删除