打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
c#语法之ArryList
userphoto

2010.11.24

关注
/*
*
*1,配置--修改电脑的系统环境参数
*我的电脑->內容->高级->环境参数中的系统参数中的path后面加上";"号再加上"C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727"后这时候在cmd环境下就可以直接使用csc来編译.
*
* Created by SharpDevelop.
* User: Administrator
* Date: 2008/8/26
* Time: 上午 08:48
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/

using System;
namespace Athrun
{
   
class Run
    {
       
static void Main()
        {
            Console.WriteLine(
"Hello World!");
        }
    }
}

 

 

Code
//数组的介紹
using System;
class Test
{
static void Main()
{
//数组的声明方式
//int[] arr=new int[] {1,2,3};
int[] arr=new int[3];
arr[
0]=0;
arr[
1]=1;
arr[
2]=2;
//两种不同的方式来读取数组内数组內的元素
for (int i=0;i<arr.Length;i++)
System.Console.WriteLine(arr[i]);
//foreach(int i in arr)
//System.Console.WriteLine(i);
}
}

 

 

Code
//在方法内对数组进行操作
using System;
class Test
{
//一个静态方法。根据所输入的长度来建立一个一维数组,来进行初始化以及在屏幕上打印数组元素
static void PrintArr(int ArrLength)
{
int[] arr=new int[ArrLength];
for (int i=0;i<arr.Length;i++)
arr[i]
=i;
Console.WriteLine(
"Print Array's value");
for (int i=0;i<arr.Length;i++)
Console.WriteLine(
"arr[{0}]={1}",i,arr[i]);
}
int i=1;
while (i>0)
{
Console.WriteLine(
"Please enter the array's Length:");
i
=Int32.Parse(Console.ReadLine());
PrintArr(i);
}
}

 

Code
//在另一个类中对数组进行操作
using System;
class SetArray
{
   
public void PrintArr(int ArrLength)
    {
       
int[] arr=new int[ArrLength];
       
for (int i=0;i<arr.Length;i++)
            arr[i]
=i;
        Console.WriteLine(
"Print Array's value");
       
for (int i=0;i<arr.Length;i++)
            Console.WriteLine(
"arr[{0}]={1}",i,arr[i]);
    }
}
class Test
{
   
//Main()程序的入口方法
    static void Main()
    {
       
int i=1;
        SetArray arr
=new SetArray();
       
while (i>0)
        {
            Console.WriteLine(
"Please enter the array's Length:");
            i
=Int32.Parse(Console.ReadLine());
            arr.PrintArr(i);
        }
    }
}

 

 

Code
//ArrayList动态数组
using System;
using System.Collections;
class Athrun
{
static void Main()
{
ArrayList arr
=new ArrayList();
string str1;
while(true)
{
Console.WriteLine(
"Please add a string to ArrayList:");
str1
=Console.ReadLine();
if(str1=="end")
break;
arr.Add(str1);
Console.WriteLine();
for (int i=0;i<arr.Count;i++)
Console.Write(
"{0} ",arr[i]);
Console.WriteLine(
"\n");
}
}
}

 

 

Code
//下面的例子是打印一个一维数据矩阵
using System;
using System.Collections;
class Matrix
{
static void Main()
{
int[,] arr=new int[4,6];
for(int i=0;i<4;i++)
{
for(int j=0;j<6;j++)
{
arr[i,j]
=(i+1)*10+j+1;
}
}
for (int i=0;i<4;i++)
{
for(int j=0;j<6;j++)
{
Console.Write(
"{0} ",arr[i,j]);
}
Console.WriteLine();
}
}
}
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
4.1 顺序查找算法
C# bubble sort,selection sort,insertion sort
c#学习体会:使用 ref 和 out 传递数组->>网页教学网(http://www.w...
经典算法题每日演练——第十题 树状数组
2015面试准备03
给数组扩容的几种方式
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服