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) |
사용되지 않음.
serialize된 데이터가 들어 있는 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> 개체를 serialize하는 데 필요한 데이터를 반환합니다. |
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 인터페이스를 구현하고, deserialization이 완료되면 deserialization 이벤트를 발생시킵니다. |
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 인터페이스를 구현하고, deserialization이 완료되면 deserialization 이벤트를 발생시킵니다. |
IEnumerable.GetEnumerator() |
컬렉션을 반복하는 열거자를 반환합니다. |
IEnumerable<T>.GetEnumerator() |
컬렉션을 반복하는 열거자를 반환합니다. |
ISerializable.GetObjectData(SerializationInfo, StreamingContext) |
ISerializable 인터페이스를 구현하고 SortedSet<T> 인스턴스를 serialize하는 데 필요한 데이터를 반환합니다. |
확장 메서드
적용 대상
추가 정보
.NET
피드백
https://aka.ms/ContentUserFeedback
출시 예정: 2024년 내내 콘텐츠에 대한 피드백 메커니즘으로 GitHub 문제를 단계적으로 폐지하고 이를 새로운 피드백 시스템으로 바꿀 예정입니다. 자세한 내용은 다음을 참조하세요.다음에 대한 사용자 의견 제출 및 보기