C#での配列の良い例は何ですか?
配列は、データのコレクションを格納するために使用されます。連続したメモリ位置で構成されています。
配列の例には、-
が含まれます。3つのソートされた配列で共通の要素を見つける
using System;
class Demo {
static void commonElements(int []one, int []two, int []three) {
int i = 0, j = 0, k = 0;
while (i < one.Length && j < two.Length && k < three.Length) {
if (one[i] == two[j] && two[j] == three[k]) {
Console.Write(one[i] + " ");
i++;j++;k++;
}
else if (one[i] < two[j])
i++;
else if (two[j] < three[k])
j++;
else
k++;
}
}
public static void Main() {
int []one = {20, 35, 57, 70};
int []two = {9, 35, 57, 70, 92};
int []three = {25, 35, 55, 57, 67, 70};
Console.Write("Common elements: ");
commonElements(one, two, three);
}
} C#で動的に配列を作成する
using System;
using System.Collections;
namespace CollectionApplication {
class Program {
static void Main(string[] args) {
ArrayList al = new ArrayList();
al.Add(99);
al.Add(47);
al.Add(64);
Console.WriteLine("Count: {0}", al.Count);
Console.Write("List: ");
foreach (int i in al) {
Console.Write(i + " ");
}
Console.WriteLine();
Console.ReadKey();
}
}
} ジャグ配列を操作してC#の要素にアクセスする
using System;
namespace ArrayApplication {
class MyArray {
static void Main(string[] args) {
int[][] points = new int[][]{new int[]{10,5},new int[]{30,40}, new int[]{70,80},new int[]{ 60, 70 }};
int i, j;
for (i = 0; i < 3; i++) {
for (j = 0; j < 2; j++) {
Console.WriteLine("a[{0}][{1}] = {2}", i, j, points[i][j]);
}
}
// access
int x = points[0][1];
Console.WriteLine(x);
Console.ReadKey();
}
}
} -
C#の名前空間とは何ですか?
名前空間は、ある名前のセットを別の名前のセットから分離する方法を提供するためのものです。名前空間の定義は、次のように、キーワードnamespaceで始まり、その後に名前空間名が続きます- namespace namespace_name { // code declarations } 名前空間を定義する- namespace namespace_name { // code declarations } 以下は、C#で名前空間を使用する方法を示す例です- 例 using System; namespace first_space {
-
C#の配列クラスのプロパティは何ですか?
Arrayクラスは、C#のすべての配列の基本クラスです。これは、システム名前空間で定義されます。配列クラスのプロパティは次のとおりです- Arrayクラスのプロパティは次のとおりです- Sr.No プロパティと説明 1 IsFixedSize 配列のサイズが固定されているかどうかを示す値を取得します。 2 IsReadOnly 配列が読み取り専用かどうかを示す値を取得します。 3 長さ 配列のすべての次元の要素の総数を表す32ビット整数を取得します。 4 LongLength 配列のすべての次元の要素の総数を