C# ソートセット
並べ替えられた順序で並べられたオブジェクトのコレクションは C# では SortedSet と呼ばれ、コレクションは名前空間 Systems.Collections.Generic 名前空間に属するジェネリック型です。また、差、交差、和集合などの数学の集合演算も SortedSet クラスによって提供され、SortedSet のサイズは集合に新しい要素が追加されると増加します。したがって、これは動的なコレクションであり、要素は表示、削除できます。または、SortedSet のコレクションに追加されます。SortedSet は、SortedSet 内の要素に重複がなく、降順で並べ替えられます。つまり、一意の要素のみが SortedSet に保存されます。
構文:
SortedSet<Type>set_name = new SortedSet<Type>();
ここで、Type はソートされたセットのタイプです。
set_name はセットの名前です。
C# の SortedSet の関数
- SortedSet は、降順に並べ替えられた個別の要素を保存、表示、削除するために使用されます。
- SortedSet に格納される要素の型は同じである必要があります。
- IReadOnlyCollection インターフェイス、IDeserializationCallBack インターフェイス、IEnumerable インターフェイス、ISet インターフェイス、ISerializable インターフェイスは SortedSet クラスによって実装されます。
- SortedSet が保持できる要素の数を SortedSet の容量といいます。
- SortedSet 内に重複する要素は存在できず、SortedSet は冗長性を回避します。
C# の SortedSet のコンストラクター
以下は C# SortedSet のコンストラクターです:
1. SortedSet(): Sorted クラスの新しいインスタンスが初期化されます。
2. SortedSet(IComparer): パラメーターとして指定された Comparer を使用する、Sorted クラスの新しいインスタンスが初期化されます。
3. SortedSet(IEnumerable): パラメーターとして指定された enumerable のコレクションから取得された要素で構成される Sorted クラスの新しいインスタンスが初期化されます。
4. SortedSet(IEnumerable, IComparer): パラメータとして指定された enumerable のコレクションから取得された要素で構成され、パラメータとして指定された比較子を使用する Sorted クラスの新しいインスタンスが初期化されます。
5. SortedSet(SerializationInfo, StreamingContext): シリアル化されたデータで構成される Sorted クラスの新しいインスタンスが初期化されます。
C# の SortedSet のメソッド
以下は C# SortedSet のメソッドです:
1. Add(T): Add(T) メソッドを使用して要素が SortedSet に追加され、SortedSet への要素の追加が成功すると、追加の成功を示す値が返されます。
2. UnionWith(IEnumerable): 現在の Sorted オブジェクトは、現在のオブジェクトに存在するか、パラメーターとして指定されたコレクションに存在するすべての要素で構成されるように変更されます。
3. Clear(): SortedSet のすべての要素が削除されます。
4. TryGetValue(T,T): パラメーターとして指定された値を SortedSet で検索し、値が見つかった場合は、等しい値を返します。
5. Contains(T): パラメータとして指定された要素がソート セット内でチェックされ、ソート セットに存在するかどうかが確認されます。
6. ToString(): 現在のオブジェクトを表す文字列が返されます。
7. CopyTo(): ソートされたセット内の一部の要素またはソートされたセット内のすべての要素が、ソートされたセットと互換性のある 1 次元の配列にコピーされ、インデックスが配列の先頭になります。コピーが開始される場所、または指定されたインデックス。
8. SymmetricExceptWith(IEnumerable): 現在の Sorted オブジェクトは、現在のオブジェクトに存在する要素、またはパラメーターとして指定されたコレクションに存在する要素のみで構成されるように変更されますが、その両方では構成されません。
9. CreateSetComparer(): IEqualityComparer オブジェクトは、CreateSetComparer() メソッドを使用して返され、これを使用して個々のセットを含むコレクションが作成されます。
10. SetEquals(IEnumerable): SetEquals(IEnumerable) メソッドは、並べ替えられたセットの現在のオブジェクトとパラメーターとして指定されたコレクションに同じ要素が存在するかどうかを確認します。
11. CreateSetComparer(IEqualityComparer): CreateSetComparer(IEqualityComparer) メソッドを使用して、パラメーターとして指定された比較子に従って IEqualityComparer オブジェクトが返されます。このメソッドを使用して、個々のセットを含むコレクションが作成されます。
12. Reverse(): IEnumerable は、ソートされたセットを逆の順序でループする Reverse() メソッドを使用して返されます。
13. Equals(Object): パラメータとして指定されたオブジェクトが現在のオブジェクトと等しいかどうかを確認します。
14. RemoveWhere(Predicate): All the elements of the sorted set matching the conditions set by the predicate specified as a parameter is removed.
15. ExceptWith(IEnumerable): The elements in the collection specified as the parameter are removed from the current sorted set object.
16. Remove(T): The item specified as the parameter will be removed from the sorted set.
17. GetEnumerator(): An Enumerator is returned using GetEnumertor() method which loops through the sorted set.
18. Overlaps(IEnumerable): The Overlaps(IEnumerable) method is used to check if the elements in the current sorted set and the elements in the collection specified as parameters are the same.
19. GetHashCode(): The GetHashCode() method is the hash function by default.
20. OnDeserilaization(Object): The event of deserialization is raised after the completion of deserialization and the ISerializable interface is implemented.
21. GetObjectData(SerilaizationInfo, StreamingContext): The data that is necessary to serialize a sorted set object is returned, and the ISerializableinterface is implemented.
22. MemberwiseClone(): The shallow copy of the current object is created.
23. GetType(): The type of the current instance is returned.
24. IsSupersetOf(IEnumerable): The IsSupersetOf(IEnumerable) method is used to determine if the object of a sorted set is a superset of the collection specified as a parameter.
25. GetViewBetween(T,T): A view of the subset in the sorted set is returned.
26. IsSubsetOf(IEnumerable): The IsSubsetOf(IEnumerable) method is used to determine if the object of a sorted set is a subset of the collection specified as a parameter.
27. IntersectWith(IEnumerable)The current Sorted object is changed in such a way that it consists only of the elements present in the collection specified as a parameter.
28. IsProperSupersetOf(IEnumerable): The IsProperSupersetOf(IEnumerable) method is used to determine if the object of the sorted set is a proper superset of the collection specified as a parameter.
29. IsProperSubsetOf(IEnumerable): The IsProperSubsetOf(IEnumerable) method is used to determine if the object of a sorted set is a proper subset of the collection specified as a parameter.
Example
Below are the examples of C# SortedSet:
C# program to create a SortedSetby using Add(T) method and then demonstrate the Remove(T) method and IsSubsetof(IEnumerable) method.
Code:
using System; using System.Collections.Generic; class program { public static void Main() { SortedSet<string>Set = new SortedSet<string>(); Set.Add("Shobha"); Set.Add("Ramya"); Set.Add("Nandan"); Set.Add("Nalina"); Set.Add("Sindhu"); Console.WriteLine("The elements of the sorted set are:"); foreach(string t in Set) { Console.WriteLine(t); } Console.WriteLine("The elements of the sorted set after using Remove method are:"); Set.Remove("Sindhu"); Set.Remove("Nalina"); foreach(string x in Set) { Console.WriteLine(x); } SortedSet<string> Set1 = new SortedSet<string>(); Set1.Add("Sahana"); Set1.Add("Suhaas"); Set1.Add("Nalina"); Console.WriteLine("Checking if the elements of the sorted set is a subset of the first set:"); Console.WriteLine(Set1.IsSubsetOf(Set)); } }
Output:
Explanation: In the above program, a class called program is called. Then the main method is called. Then a sorted set to store the strings is created. Then elements are added to the sorted set using add() method. Then the foreach loop is used to display the elements of the sorted set. Then remove() method is used to remove the elements of the sorted set. Then again the foreach loop is used to display the elements of the sorted set. Then again a new sorted set to store strings is created. Then again elements are added to the new sorted set using add() method. Then IsSubsetof() method is used to check if the newly created sorted set is a subset of the first sorted set. The output of the program is shown in the snapshot above.
以上がC# ソートセットの詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。

ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

Video Face Swap
完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

人気の記事

ホットツール

メモ帳++7.3.1
使いやすく無料のコードエディター

SublimeText3 中国語版
中国語版、とても使いやすい

ゼンドスタジオ 13.0.1
強力な PHP 統合開発環境

ドリームウィーバー CS6
ビジュアル Web 開発ツール

SublimeText3 Mac版
神レベルのコード編集ソフト(SublimeText3)

ホットトピック











C# を使用した Active Directory のガイド。ここでは、Active Directory の概要と、C# での動作方法について、構文と例とともに説明します。

C# データ グリッド ビューのガイド。ここでは、SQL データベースまたは Excel ファイルからデータ グリッド ビューをロードおよびエクスポートする方法の例について説明します。

マルチスレッドと非同期の違いは、マルチスレッドが複数のスレッドを同時に実行し、現在のスレッドをブロックせずに非同期に操作を実行することです。マルチスレッドは計算集約型タスクに使用されますが、非同期はユーザーインタラクションに使用されます。マルチスレッドの利点は、コンピューティングのパフォーマンスを改善することですが、非同期の利点はUIスレッドをブロックしないことです。マルチスレッドまたは非同期を選択することは、タスクの性質に依存します。計算集約型タスクマルチスレッド、外部リソースと相互作用し、UIの応答性を非同期に使用する必要があるタスクを使用します。
