C# Array類的基本操作
C#中Array類可以用於對陣列進行定義,與常規的定義方式不同,Array類定義的陣列可以從任意正整數開始,而不一定要從0開始。
一維陣列的例子:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ArrayDemo
{
class Program
{
static void Main(string[] args)
{
int []dim={5};
int[]lowBound={2};
Array myArray=Array.CreateInstance(typeof(int),dim, lowBound);
for(int i=1;i<=5;i++)
{
myArray.SetValue(i,1+i);
}
for(int i=2; i<=6;i++)
Console.WriteLine(myArray.GetValue(i));
Console.ReadLine();
}
}
}
二維陣列的例子:
<span style="font-family:SimHei;font-size:18px;">using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace arrayDemo
{
class Program
{
static void Main(string[] args)
{
Array intarray1=Array.CreateInstance(typeof(int), 5);
for (int i = 0; i < 5;i++)
intarray1.SetValue(20, i);
for (int i = 0; i < 5; i++)
Console.Write("{0,5}",intarray1.GetValue(i));
Console.WriteLine();
int[] lengths = { 2, 3 };
int[] lowBounds = { 1, 10 };
Array computerLanguage = Array.CreateInstance(typeof(string), lengths, lowBounds);
for (int i = lowBounds[0]; i < lowBounds[0] + lengths[0]; i++)
for (int j = lowBounds[1]; j < lowBounds[1] + lengths[1]; j++)
computerLanguage.SetValue("cLanguage", i, j);
for (int i = lowBounds[0]; i < lowBounds[0] + lengths[0]; i++)
{
for (int j = lowBounds[1]; j < lowBounds[1] + lengths[1]; j++)
Console.Write("{0,10}",computerLanguage.GetValue(i, j));
Console.WriteLine();
}
Console.ReadLine();
}
}
}</span>
相關文章
- C#中URL的操作類C#
- C#學習——基本類——Math類C#
- c# Lambda操作類封裝C#封裝
- C#中PDF文件操作類C#
- C#神器"BlockingCollection"類實現C#神仙操作C#BloCGC
- c# 操作Redis的五種基本型別總結C#Redis型別
- C# convert ImageSource to byte arrayC#
- Python3資料庫操作基本類Python資料庫
- Go 操作 Redis 的基本操作GoRedis
- 瞭解下C# 陣列(Array)C#陣列
- Docker的基本操作Docker
- MySQL的基本操作MySql
- git的基本操作Git
- [C#]C#中字串的操作C#字串
- 深度分析C#中Array的儲存結構C#
- C#程式設計學習(04):基本操作學習總結C#程式設計
- C#操作Microsoft.Office.Interop.Word類庫完整例子C#ROS
- JS — 物件的基本操作JS物件
- Spring Boot的基本操作Spring Boot
- Docker映象的基本操作Docker
- Hbase shell的基本操作
- react的基本操作(1)React
- Vim命令的基本操作
- Numpy的基本操作(五)
- 陣列的基本操作陣列
- Hive表的基本操作Hive
- JQ操作類與JS操作類的區別JS
- C#網路程式設計(基本概念和操作) - Part.1C#程式設計
- MongoDB基本操作MongoDB
- webpack 基本操作Web
- mongo基本操作Go
- SQL基本操作SQL
- ElasticSearch - 基本操作Elasticsearch
- candance 基本操作
- svn基本操作
- oracle基本操作Oracle
- Hash基本操作
- python基本操作Python
- FFMPEG基本操作