1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

C# の配列いろいろ (Array, ArrayList, List<T>)

Last updated at Posted at 2025-02-26

バージョン:.NET 8

名前空間 クラス 利用場面
System Array 要素数が固定
インデックス指定で読み書きがメイン
System.Collections ArrayList 使わない(Microsoft 非推奨)
System.Collections.Generic List<T> 要素数が可変
検索や並べ替えなど柔軟な操作が必要

System.Array クラス

System.Collections 名前空間のクラスとは異なり、Array には固定容量があります。 容量を増やすには、必要な容量を持つ新しい Array オブジェクトを作成し、古い Array オブジェクトから新しいオブジェクトに要素をコピーし、古い Arrayを削除する必要があります。

System.Collections.ArrayList クラス

必要に応じてサイズが動的に拡大される配列を使用して IList インターフェイスを実装します。
新しい開発には クラスを ArrayList 使用しないことをお勧めします。 代わりに、ジェネリック List<T> クラスを使用することをお勧めします。 クラスは ArrayList 、オブジェクトの異種コレクションを保持するように設計されています。 ただし、常に最高のパフォーマンスを提供するとは限りません。

System.Collections.Generic.List<T> クラス

インデックスでアクセスできるオブジェクトの厳密に型指定されたリストを表します。 リストの検索、並べ替え、操作を行うメソッドを提供します。

ジェネリッククラスとメソッド

ジェネリックを使用すると、コードでクラスやメソッドを使用するまで 1 つ以上の型パラメーターの指定を遅延させるクラスおよびメソッドを設計することができます。 ジェネリック型パラメーター T は、コンパイル時に型引数に置き換えられます。
.NET クラス ライブラリには、複数のジェネリック コレクション クラスが System.Collections.Generic 名前空間に含まれています。 System.Collections 名前空間の ArrayList などのクラスの代わりとして、ジェネリック コレクションをできる限り使用してください。

System.Collections.Concurrent 名前空間

複数のスレッドがコレクションに同時にアクセス可能なスレッド セーフなコレクション クラスをいくつか提供します。

1
0
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?