Home > Backend Development > C#.Net Tutorial > How to define array in C#?

How to define array in C#?

王林
Release: 2023-09-03 16:57:02
forward
1365 people have browsed it

How to define array in C#?

Defining Array in C#-

int[] runs = new int[10];
Copy after login

Now let us initialize the array in the same line-

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

The following example shows how to declare, initialize and display array-

Example

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();
      }
   }
}
Copy after login

The above is the detailed content of How to define array in C#?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template