在c#中,如何定义一个数组?怎样详细解析一个数组??

如题所述

1、第一种:string[] Array1=new string[10]。

2、第二种string[] Array2={"1","2"}。

3、第三种string[] Array3=new string[3]{"1","2","3"}。

4、第四种 string[] Array4=new string[]{"1","2","3","4"}。

注意事项:

C#是一种安全的、稳定的、简单的、优雅的,由C和C++衍生出来的面向对象的编程语言。它在继承C和C++强大功能的同时去掉了一些它们的复杂特性。

温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2018-03-20
我可是抱着100块钱的教材抄给你的
格式<basetype>[] <name>;
其中basetype可以是任何变量类型
数组必须访问之前初始化
初始化有2种
int [] a={5,9,8};
int [] a=new int[3];本回答被提问者和网友采纳
第2个回答  2011-05-30
int a[10]
定义一个为十位的数组,也可以把10变成变量
int a[i]
第3个回答  2011-05-30
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TestConsole
{
class Program
{
static void Main(string[] args)
{
int n = 5;
//一维数组
//创建
int[] a = new int[n];
//初始化
int i;
for (i = 0; i < n; i++)
a[i] = i;
Console.WriteLine("整型一维数组");
foreach (int k in a)
Console.Write("{0}\t", k);
Console.Write("\n");
//二维数组
char[,] c; //声明
c = new char[n, n]; //申请空间
//初始化
int j;
char ch = 'a';
for (i = 0; i < n; i++)
for (j = 0; j < n; j++)
c[i, j] = Convert.ToChar(Convert.ToInt32(ch)+i+j);
Console.WriteLine("字符型二维数组");
for (i = 0; i < n; i++)
{
for (j = 0; j < n; j++)
Console.Write("{0}\t", c[i, j]);
Console.WriteLine();
}
Console.WriteLine();
}
}
}
第4个回答  2011-05-30
1、string [] str=new string[数组的长度];
2、string [] str=new string{1,2,3}
数据取值
for(int i=0;i<str.lenth;i++)
{
str[i].tostring();
}