SortedSet<T> クラス
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
一定の並べ替え順序で管理されたオブジェクトのコレクションを表します。
generic <typename T>
public ref class SortedSet : System::Collections::Generic::ICollection<T>, System::Collections::Generic::IEnumerable<T>, System::Collections::Generic::IReadOnlyCollection<T>, System::Collections::Generic::ISet<T>, System::Collections::ICollection
generic <typename T>
public ref class SortedSet : System::Collections::Generic::ICollection<T>, System::Collections::Generic::IEnumerable<T>, System::Collections::Generic::IReadOnlyCollection<T>, System::Collections::Generic::IReadOnlySet<T>, System::Collections::Generic::ISet<T>, System::Collections::ICollection, System::Runtime::Serialization::IDeserializationCallback, System::Runtime::Serialization::ISerializable
generic <typename T>
public ref class SortedSet : System::Collections::Generic::ICollection<T>, System::Collections::Generic::IEnumerable<T>, System::Collections::Generic::IReadOnlyCollection<T>, System::Collections::Generic::ISet<T>, System::Collections::ICollection, System::Runtime::Serialization::IDeserializationCallback, System::Runtime::Serialization::ISerializable
generic <typename T>
public ref class SortedSet : System::Collections::Generic::ICollection<T>, System::Collections::Generic::IEnumerable<T>, System::Collections::Generic::ISet<T>, System::Collections::ICollection, System::Runtime::Serialization::IDeserializationCallback, System::Runtime::Serialization::ISerializable
generic <typename T>
public ref class SortedSet : System::Collections::Generic::ICollection<T>, System::Collections::Generic::IEnumerable<T>, System::Collections::Generic::ISet<T>, System::Collections::ICollection
public class SortedSet<T> : System.Collections.Generic.ICollection<T>, System.Collections.Generic.IEnumerable<T>, System.Collections.Generic.IReadOnlyCollection<T>, System.Collections.Generic.ISet<T>, System.Collections.ICollection
public class SortedSet<T> : System.Collections.Generic.ICollection<T>, System.Collections.Generic.IEnumerable<T>, System.Collections.Generic.IReadOnlyCollection<T>, System.Collections.Generic.IReadOnlySet<T>, System.Collections.Generic.ISet<T>, System.Collections.ICollection, System.Runtime.Serialization.IDeserializationCallback, System.Runtime.Serialization.ISerializable
public class SortedSet<T> : System.Collections.Generic.ICollection<T>, System.Collections.Generic.IEnumerable<T>, System.Collections.Generic.IReadOnlyCollection<T>, System.Collections.Generic.ISet<T>, System.Collections.ICollection, System.Runtime.Serialization.IDeserializationCallback, System.Runtime.Serialization.ISerializable
[System.Serializable]
public class SortedSet<T> : System.Collections.Generic.ICollection<T>, System.Collections.Generic.IEnumerable<T>, System.Collections.Generic.ISet<T>, System.Collections.ICollection, System.Runtime.Serialization.IDeserializationCallback, System.Runtime.Serialization.ISerializable
[System.Serializable]
public class SortedSet<T> : System.Collections.Generic.ICollection<T>, System.Collections.Generic.IEnumerable<T>, System.Collections.Generic.IReadOnlyCollection<T>, System.Collections.Generic.ISet<T>, System.Collections.ICollection, System.Runtime.Serialization.IDeserializationCallback, System.Runtime.Serialization.ISerializable
public class SortedSet<T> : System.Collections.Generic.ICollection<T>, System.Collections.Generic.IEnumerable<T>, System.Collections.Generic.ISet<T>, System.Collections.ICollection
type SortedSet<'T> = class
interface ICollection<'T>
interface seq<'T>
interface IEnumerable
interface IReadOnlyCollection<'T>
interface ISet<'T>
interface ICollection
type SortedSet<'T> = class
interface ICollection<'T>
interface seq<'T>
interface IEnumerable
interface IReadOnlyCollection<'T>
interface ISet<'T>
interface IReadOnlySet<'T>
interface ICollection
interface IDeserializationCallback
interface ISerializable
type SortedSet<'T> = class
interface ICollection<'T>
interface seq<'T>
interface IEnumerable
interface IReadOnlyCollection<'T>
interface ISet<'T>
interface ICollection
interface IDeserializationCallback
interface ISerializable
[<System.Serializable>]
type SortedSet<'T> = class
interface ISet<'T>
interface ICollection<'T>
interface seq<'T>
interface ICollection
interface IEnumerable
interface ISerializable
interface IDeserializationCallback
[<System.Serializable>]
type SortedSet<'T> = class
interface ISet<'T>
interface ICollection<'T>
interface seq<'T>
interface IEnumerable
interface ICollection
interface ISerializable
interface IDeserializationCallback
interface IReadOnlyCollection<'T>
type SortedSet<'T> = class
interface ISet<'T>
interface ICollection<'T>
interface seq<'T>
interface ICollection
interface IEnumerable
Public Class SortedSet(Of T)
Implements ICollection, ICollection(Of T), IEnumerable(Of T), IReadOnlyCollection(Of T), ISet(Of T)
Public Class SortedSet(Of T)
Implements ICollection, ICollection(Of T), IDeserializationCallback, IEnumerable(Of T), IReadOnlyCollection(Of T), IReadOnlySet(Of T), ISerializable, ISet(Of T)
Public Class SortedSet(Of T)
Implements ICollection, ICollection(Of T), IDeserializationCallback, IEnumerable(Of T), IReadOnlyCollection(Of T), ISerializable, ISet(Of T)
Public Class SortedSet(Of T)
Implements ICollection, ICollection(Of T), IDeserializationCallback, IEnumerable(Of T), ISerializable, ISet(Of T)
Public Class SortedSet(Of T)
Implements ICollection, ICollection(Of T), IEnumerable(Of T), ISet(Of T)
型パラメーター
- T
セット内の要素の型。
- 継承
-
SortedSet<T>
- 属性
- 実装
例
次の例では、 を SortedSet<T> パラメーターとして受け取る IComparer<T> コンストラクターを使用して作成されるクラスを示します。 この比較子 (ByFileExtension
) は、拡張子によってファイル名の一覧を並べ替えるために使用されます。
この例では、メディア ファイル名の並べ替えられたセットを作成し、不要な要素を削除し、要素の範囲を表示し、セットを別の並べ替えられたセットと比較する方法を示します。
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
class Program
{
static void Main(string[] args)
{
try
{
// Get a list of the files to use for the sorted set.
IEnumerable<string> files1 =
Directory.EnumerateFiles(@"\\archives\2007\media",
"*", SearchOption.AllDirectories);
// Create a sorted set using the ByFileExtension comparer.
var mediaFiles1 = new SortedSet<string>(new ByFileExtension());
// Note that there is a SortedSet constructor that takes an IEnumerable,
// but to remove the path information they must be added individually.
foreach (string f in files1)
{
mediaFiles1.Add(f.Substring(f.LastIndexOf(@"\") + 1));
}
// Remove elements that have non-media extensions.
// See the 'IsDoc' method.
Console.WriteLine("Remove docs from the set...");
Console.WriteLine($"\tCount before: {mediaFiles1.Count}");
mediaFiles1.RemoveWhere(IsDoc);
Console.WriteLine($"\tCount after: {mediaFiles1.Count}");
Console.WriteLine();
// List all the avi files.
SortedSet<string> aviFiles = mediaFiles1.GetViewBetween("avi", "avj");
Console.WriteLine("AVI files:");
foreach (string avi in aviFiles)
{
Console.WriteLine($"\t{avi}");
}
Console.WriteLine();
// Create another sorted set.
IEnumerable<string> files2 =
Directory.EnumerateFiles(@"\\archives\2008\media",
"*", SearchOption.AllDirectories);
var mediaFiles2 = new SortedSet<string>(new ByFileExtension());
foreach (string f in files2)
{
mediaFiles2.Add(f.Substring(f.LastIndexOf(@"\") + 1));
}
// Remove elements in mediaFiles1 that are also in mediaFiles2.
Console.WriteLine("Remove duplicates (of mediaFiles2) from the set...");
Console.WriteLine($"\tCount before: {mediaFiles1.Count}");
mediaFiles1.ExceptWith(mediaFiles2);
Console.WriteLine($"\tCount after: {mediaFiles1.Count}");
Console.WriteLine();
Console.WriteLine("List of mediaFiles1:");
foreach (string f in mediaFiles1)
{
Console.WriteLine($"\t{f}");
}
// Create a set of the sets.
IEqualityComparer<SortedSet<string>> comparer =
SortedSet<string>.CreateSetComparer();
var allMedia = new HashSet<SortedSet<string>>(comparer);
allMedia.Add(mediaFiles1);
allMedia.Add(mediaFiles2);
}
catch(IOException ioEx)
{
Console.WriteLine(ioEx.Message);
}
catch (UnauthorizedAccessException AuthEx)
{
Console.WriteLine(AuthEx.Message);
}
}
// Defines a predicate delegate to use
// for the SortedSet.RemoveWhere method.
private static bool IsDoc(string s)
{
s = s.ToLower();
return (s.EndsWith(".txt") ||
s.EndsWith(".xls") ||
s.EndsWith(".xlsx") ||
s.EndsWith(".pdf") ||
s.EndsWith(".doc") ||
s.EndsWith(".docx"));
}
}
// Defines a comparer to create a sorted set
// that is sorted by the file extensions.
public class ByFileExtension : IComparer<string>
{
string xExt, yExt;
CaseInsensitiveComparer caseiComp = new CaseInsensitiveComparer();
public int Compare(string x, string y)
{
// Parse the extension from the file name.
xExt = x.Substring(x.LastIndexOf(".") + 1);
yExt = y.Substring(y.LastIndexOf(".") + 1);
// Compare the file extensions.
int vExt = caseiComp.Compare(xExt, yExt);
if (vExt != 0)
{
return vExt;
}
else
{
// The extension is the same,
// so compare the filenames.
return caseiComp.Compare(x, y);
}
}
}
Imports System.Collections
Imports System.Collections.Generic
Imports System.IO
Module Module1
Sub Main()
Try
' Get a list of the files to use for the sorted set.
Dim files1 As IEnumerable = _
Directory.EnumerateFiles("\\archives\2007\media", "*", _
SearchOption.AllDirectories)
' Create a sorted set using the ByFileExtension comparer.
Dim mediaFiles1 As New SortedSet(Of String)(New ByFileExtension)
' Note that there is a SortedSet constructor that takes an IEnumerable,
' but to remove the path information they must be added individually.
For Each f As String In files1
mediaFiles1.Add(f.Substring((f.LastIndexOf("\") + 1)))
Next
' Remove elements that have non-media extensions. See the 'IsDoc' method.
Console.WriteLine("Remove docs from the set...")
Console.WriteLine($"{vbTab}Count before: {mediaFiles1.Count}")
mediaFiles1.RemoveWhere(AddressOf IsDoc)
Console.WriteLine($"{vbTab}Count after: {mediaFiles1.Count}")
Console.WriteLine()
' List all the avi files.
Dim aviFiles As SortedSet(Of String) = mediaFiles1.GetViewBetween("avi", "avj")
Console.WriteLine("AVI files:")
For Each avi As String In aviFiles
Console.WriteLine($"{vbTab}{avi}")
Next
Console.WriteLine()
' Create another sorted set.
Dim files2 As IEnumerable = _
Directory.EnumerateFiles("\\archives\2008\media", "*", _
SearchOption.AllDirectories)
Dim mediaFiles2 As New SortedSet(Of String)(New ByFileExtension)
For Each f As String In files2
mediaFiles2.Add(f.Substring((f.LastIndexOf("\") + 1)))
Next
' Remove elements in mediaFiles1 that are also in mediaFiles2.
Console.WriteLine("Remove duplicates (of mediaFiles2) from the set...")
Console.WriteLine($"{vbTab}Count before: {mediaFiles1.Count}")
mediaFiles1.ExceptWith(mediaFiles2)
Console.WriteLine($"{vbTab}Count after: {mediaFiles1.Count}")
Console.WriteLine()
Console.WriteLine("List of mediaFiles1:")
For Each f As String In mediaFiles1
Console.WriteLine($"{vbTab}{f}")
Next
' Create a set of the sets.
Dim comparer As IEqualityComparer(Of SortedSet(Of String)) = _
SortedSet(Of String).CreateSetComparer()
Dim allMedia As New HashSet(Of SortedSet(Of String))(comparer)
allMedia.Add(mediaFiles1)
allMedia.Add(mediaFiles2)
Catch ioEx As IOException
Console.WriteLine(ioEx.Message)
Catch AuthEx As UnauthorizedAccessException
Console.WriteLine(AuthEx.Message)
End Try
End Sub
' Defines a predicate delegate to use
' for the SortedSet.RemoveWhere method.
Private Function IsDoc(s As String) As Boolean
s = s.ToLower()
Return s.EndsWith(".txt") OrElse
s.EndsWith(".doc") OrElse
s.EndsWith(".xls") OrElse
s.EndsWith(".xlsx") OrElse
s.EndsWith(".pdf") OrElse
s.EndsWith(".doc") OrElse
s.EndsWith(".docx")
End Function
' Defines a comparer to create a sorted set
' that is sorted by the file extensions.
Public Class ByFileExtension
Implements IComparer(Of String)
Dim xExt, yExt As String
Dim caseiComp As CaseInsensitiveComparer = _
New CaseInsensitiveComparer
Public Function Compare(x As String, y As String) _
As Integer Implements IComparer(Of String).Compare
' Parse the extension from the file name.
xExt = x.Substring(x.LastIndexOf(".") + 1)
yExt = y.Substring(y.LastIndexOf(".") + 1)
' Compare the file extensions.
Dim vExt As Integer = caseiComp.Compare(xExt, yExt)
If vExt <> 0 Then
Return vExt
Else
' The extension is the same,
' so compare the filenames.
Return caseiComp.Compare(x, y)
End If
End Function
End Class
End Module
注釈
オブジェクトは SortedSet<T> 、要素が挿入および削除されるため、パフォーマンスに影響を与えずに並べ替えられた順序を維持します。 重複する要素は使用できません。 既存の項目の並べ替え値の変更はサポートされていないため、予期しない動作が発生する可能性があります。
に代わるスレッド セーフな方法については、次を SortedSet<T>参照してください。 ImmutableSortedSet<T>
コンストラクター
SortedSet<T>() |
SortedSet<T> クラスの新しいインスタンスを初期化します。 |
SortedSet<T>(IComparer<T>) |
指定された比較子を使用する SortedSet<T> クラスの新しいインスタンスを初期化します。 |
SortedSet<T>(IEnumerable<T>) |
指定の列挙可能なコレクションからコピーされた要素を格納する、SortedSet<T> クラスの新しいインスタンスを初期化します。 |
SortedSet<T>(IEnumerable<T>, IComparer<T>) |
指定の列挙可能なコレクションからコピーされた要素を格納し、指定された比較子を使用する、SortedSet<T> クラスの新しいインスタンスを初期化します。 |
SortedSet<T>(SerializationInfo, StreamingContext) |
古い.
シリアル化したデータを格納する、SortedSet<T> クラスの新しいインスタンスを初期化します。 |
プロパティ
Comparer |
SortedSet<T> の中の値を順序付けするために使用する IComparer<T> オブジェクトを取得します。 |
Count |
SortedSet<T> にある要素の数を取得します。 |
Max |
比較子によって定義された、SortedSet<T> 内の最大値を取得します。 |
Min |
比較子によって定義された、SortedSet<T> 内の最小値を取得します。 |
メソッド
Add(T) |
要素をセットに追加し、正常に追加されたかどうかを示す値を返します。 |
Clear() |
すべての要素をセットから削除します。 |
Contains(T) |
セットに特定の要素が含まれているかどうかを判断します。 |
CopyTo(T[]) |
SortedSet<T> 全体を互換性のある 1 次元の配列にコピーします。コピー操作は、コピー先の配列の先頭から始まります。 |
CopyTo(T[], Int32) |
SortedSet<T> 全体を互換性のある 1 次元配列にコピーします。コピー操作は、配列の指定したインデックスから始まります。 |
CopyTo(T[], Int32, Int32) |
指定された数の要素を SortedSet<T> から互換性のある 1 次元配列にコピーします。コピー操作は、指定された配列インデックスから始まります。 |
CreateSetComparer() |
個々のセットを含んだコレクションを作成する際に使用できる IEqualityComparer オブジェクトを返します。 |
CreateSetComparer(IEqualityComparer<T>) |
個々のセットを含んだコレクションを作成する際に使用できる IEqualityComparer オブジェクトを、指定された比較子に従って返します。 |
Equals(Object) |
指定されたオブジェクトが現在のオブジェクトと等しいかどうかを判断します。 (継承元 Object) |
ExceptWith(IEnumerable<T>) |
現在の SortedSet<T> オブジェクトから、指定されたコレクションに含まれる要素をすべて削除します。 |
GetEnumerator() |
SortedSet<T> を反復処理する列挙子を返します。 |
GetHashCode() |
既定のハッシュ関数として機能します。 (継承元 Object) |
GetObjectData(SerializationInfo, StreamingContext) |
ISerializable インターフェイスを実装し、SortedSet<T> オブジェクトをシリアル化するために必要なデータを返します。 |
GetType() |
現在のインスタンスの Type を取得します。 (継承元 Object) |
GetViewBetween(T, T) |
SortedSet<T> 内のサブセットのビューを返します。 |
IntersectWith(IEnumerable<T>) |
指定されたコレクションに存在する要素だけが含まれるように現在の SortedSet<T> オブジェクトを変更します。 |
IsProperSubsetOf(IEnumerable<T>) |
SortedSet<T> オブジェクトが、指定されたコレクションの真のサブセット (真部分集合) であるかどうかを判断します。 |
IsProperSupersetOf(IEnumerable<T>) |
SortedSet<T> オブジェクトが、指定されたコレクションの真のスーパーセット (真上位集合) であるかどうかを判断します。 |
IsSubsetOf(IEnumerable<T>) |
SortedSet<T> オブジェクトが、指定されたコレクションのサブセットであるかどうかを判断します。 |
IsSupersetOf(IEnumerable<T>) |
SortedSet<T> オブジェクトが、指定されたコレクションのスーパーセットであるかどうかを判断します。 |
MemberwiseClone() |
現在の Object の簡易コピーを作成します。 (継承元 Object) |
OnDeserialization(Object) |
ISerializable インターフェイスを実装し、逆シリアル化が完了したときに逆シリアル化イベントを発生させます。 |
Overlaps(IEnumerable<T>) |
現在の SortedSet<T> オブジェクトと指定されたコレクションとが共通の要素を共有しているかどうかを判断します。 |
Remove(T) |
指定した項目を SortedSet<T> から削除します。 |
RemoveWhere(Predicate<T>) |
指定の述語によって定義された条件に一致するすべての要素を SortedSet<T> から削除します。 |
Reverse() |
IEnumerable<T> を逆順で反復処理する SortedSet<T> を返します。 |
SetEquals(IEnumerable<T>) |
現在の SortedSet<T> オブジェクトと指定されたコレクションに同じ要素が存在するかどうかを判断します。 |
SymmetricExceptWith(IEnumerable<T>) |
現在の SortedSet<T> オブジェクトを、そのオブジェクトと指定されたコレクションの (両方に存在するのではなく) どちらか一方に存在する要素だけが格納されるように変更します。 |
ToString() |
現在のオブジェクトを表す文字列を返します。 (継承元 Object) |
TryGetValue(T, T) |
指定された値をセットで検索し、見つかった場合は同じ値を返します。 |
UnionWith(IEnumerable<T>) |
現在の SortedSet<T> オブジェクトを、現在のオブジェクトまたは指定したコレクションのいずれかに存在するすべての要素が格納されるように変更します。 |
明示的なインターフェイスの実装
ICollection.CopyTo(Array, Int32) |
SortedSet<T> 全体を互換性のある 1 次元配列にコピーします。コピー操作は、配列の指定したインデックスから始まります。 |
ICollection.IsSynchronized |
ICollection へのアクセスが同期されるかどうか (スレッド セーフかどうか) を示す値を取得します。 |
ICollection.SyncRoot |
ICollection へのアクセスを同期するために使用できるオブジェクトを取得します。 |
ICollection<T>.Add(T) |
ICollection<T> オブジェクトに項目を追加します。 |
ICollection<T>.IsReadOnly |
ICollection が読み取り専用かどうかを示す値を取得します。 |
IDeserializationCallback.OnDeserialization(Object) |
IDeserializationCallback インターフェイスを実装し、逆シリアル化が完了したときに逆シリアル化イベントを発生させます。 |
IEnumerable.GetEnumerator() |
コレクションを反復処理する列挙子を返します。 |
IEnumerable<T>.GetEnumerator() |
コレクションを反復処理する列挙子を返します。 |
ISerializable.GetObjectData(SerializationInfo, StreamingContext) |
ISerializable インターフェイスを実装し、SortedSet<T> インスタンスをシリアル化するために必要なデータを返します。 |
拡張メソッド
適用対象
こちらもご覧ください
.NET
フィードバック
https://aka.ms/ContentUserFeedback」を参照してください。
以下は間もなく提供いたします。2024 年を通じて、コンテンツのフィードバック メカニズムとして GitHub の issue を段階的に廃止し、新しいフィードバック システムに置き換えます。 詳細については、「フィードバックの送信と表示