博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
c# 2维数组 取一维_C#| 不同类型的一维数组声明
阅读量:2529 次
发布时间:2019-05-11

本文共 1860 字,大约阅读时间需要 6 分钟。

c# 2维数组 取一维

In the below example, we are declaring an integer array (one dimensional) with following styles:

在下面的示例中,我们声明具有以下样式的整数数组(一维)

1) One dimensional Array declaration with initialization (without array size)

1)具有初始化的一维数组声明(无数组大小)

Example:

例:

int[] arr1 = { 12, 45, 56, 78, 89 };

In this style, arr1 will automatic occupy the size of the array based on given elements.

在这种样式中, arr1将根据给定的元素自动占据数组的大小。

2) Dynamic One dimensional Array declaration with fixed size

2)具有固定大小的动态一维数组声明

Example:

例:

int[] arr2 = new int[5];

In this style, arr2 will occupy the size for 5 integers dynamically.

在这种样式中, arr2将动态占用5个整数的大小。

3) Dynamic One dimensional Array declaration with variable size

3)具有可变大小的动态一维数组声明

Example:

例:

int[] arr3 = new int[size];

In this style, we will read the size of the arr3 first and then declare the array dynamically.

在这种样式中,我们将先读取arr3的大小,然后动态声明数组。

Example: In the below given example – we are using these 3 styles to declare an array.

示例:在下面给出的示例中–我们使用这3种样式声明一个数组。

Program:

程序:

using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace Arrays{
class Program {
static void Main(string[] args) {
//Single Dimension Console.WriteLine("Type 1 : Declaration"); int[] arr1 = {
12, 45, 56, 78, 89 }; foreach(int item in arr1) {
Console.Write("{0}\t", item); } Console.WriteLine("\n\nType 2 : Declaration"); int[] arr2 = new int[5]; Console.WriteLine("Enter 5 Values:"); for(int i=0;i

Output

输出量

Type 1 : Declaration12      45      56      78      89Type 2 : DeclarationEnter 5 Values:102030405010      20      30      40      50Type 3 : DeclarationEnter Size:3Enter 3 Values:100200300100     200     300

翻译自:

c# 2维数组 取一维

转载地址:http://lwxzd.baihongyu.com/

你可能感兴趣的文章
我的第一篇CBBLOGS博客
查看>>
【MyBean调试笔记】接口的使用和清理
查看>>
07 js自定义函数
查看>>
jQueru中数据交换格式XML和JSON对比
查看>>
form表单序列化后的数据转json对象
查看>>
[PYTHON]一个简单的单元測试框架
查看>>
iOS开发网络篇—XML数据的解析
查看>>
[BZOJ4303]数列
查看>>
一般处理程序在VS2012中打开问题
查看>>
C语言中的++和--
查看>>
thinkphp3.2.3入口文件详解
查看>>
POJ 1141 Brackets Sequence
查看>>
Ubuntu 18.04 root 使用ssh密钥远程登陆
查看>>
Servlet和JSP的异同。
查看>>
虚拟机centOs Linux与Windows之间的文件传输
查看>>
ethereum(以太坊)(二)--合约中属性和行为的访问权限
查看>>
IOS内存管理
查看>>
我需要一个足够大的桌子
查看>>
middle
查看>>
[Bzoj1009][HNOI2008]GT考试(动态规划)
查看>>