|
Dieser Artikel wurde maschinell übersetzt. Bewegen Sie den Mauszeiger über die Sätze im Artikel, um den Originaltext anzuzeigen. Weitere Informationen
|
Übersetzung
Original
|
ICollection<T>-Schnittstelle
Namespace: System.Collections.Generic
Assembly: mscorlib (in mscorlib.dll)
Der ICollection<T>-Typ macht die folgenden Member verfügbar.
| Name | Beschreibung | |
|---|---|---|
![]() ![]() ![]() ![]() | Count | |
![]() ![]() ![]() ![]() | IsReadOnly |
| Name | Beschreibung | |
|---|---|---|
![]() ![]() ![]() ![]() | Add | |
![]() ![]() ![]() ![]() | Clear | |
![]() ![]() ![]() ![]() | Contains | |
![]() ![]() ![]() ![]() | CopyTo | |
![]() ![]() ![]() ![]() | GetEnumerator() | |
![]() ![]() ![]() ![]() | GetEnumerator() | |
![]() ![]() ![]() ![]() | Remove |
| Name | Beschreibung | |
|---|---|---|
![]() ![]() ![]() ![]() | Aggregate<T>(Func<T, T, T>) | Überladen. |
![]() ![]() ![]() ![]() | Aggregate<T, TAccumulate>(TAccumulate, Func<TAccumulate, T, TAccumulate>) | Überladen. |
![]() ![]() ![]() ![]() | Aggregate<T, TAccumulate, TResult>(TAccumulate, Func<TAccumulate, T, TAccumulate>, Func<TAccumulate, TResult>) | Überladen. |
![]() ![]() ![]() ![]() | All<T> | |
![]() ![]() ![]() ![]() | Any<T>() | Überladen. |
![]() ![]() ![]() ![]() | Any<T>(Func<T, Boolean>) | Überladen. |
![]() ![]() ![]() ![]() | AsEnumerable<T> | |
![]() ![]() ![]() | AsParallel() | Überladen. |
![]() ![]() ![]() | AsParallel<T>() | Überladen. |
![]() ![]() ![]() | AsQueryable() | Überladen. |
![]() ![]() ![]() | AsQueryable<T>() | Überladen. |
![]() ![]() ![]() ![]() | Average<T>(Func<T, Decimal>) | Überladen. |
![]() ![]() ![]() ![]() | Average<T>(Func<T, Nullable<Decimal>>) | Überladen. |
![]() ![]() ![]() ![]() | Average<T>(Func<T, Double>) | Überladen. |
![]() ![]() ![]() ![]() | Average<T>(Func<T, Nullable<Double>>) | Überladen. |
![]() ![]() ![]() ![]() | Average<T>(Func<T, Int32>) | Überladen. |
![]() ![]() ![]() ![]() | Average<T>(Func<T, Nullable<Int32>>) | Überladen. |
![]() ![]() ![]() ![]() | Average<T>(Func<T, Int64>) | Überladen. |
![]() ![]() ![]() ![]() | Average<T>(Func<T, Nullable<Int64>>) | Überladen. |
![]() ![]() ![]() ![]() | Average<T>(Func<T, Single>) | Überladen. |
![]() ![]() ![]() ![]() | Average<T>(Func<T, Nullable<Single>>) | Überladen. |
![]() ![]() ![]() ![]() | Cast<TResult> | |
![]() ![]() ![]() ![]() | Concat<T> | |
![]() ![]() ![]() ![]() | Contains<T>(T) | Überladen. |
![]() ![]() ![]() ![]() | Contains<T>(T, IEqualityComparer<T>) | Überladen. |
![]() ![]() ![]() ![]() | Count<T>() | Überladen. |
![]() ![]() ![]() ![]() | Count<T>(Func<T, Boolean>) | Überladen. |
![]() ![]() ![]() ![]() | DefaultIfEmpty<T>() | Überladen. |
![]() ![]() ![]() ![]() | DefaultIfEmpty<T>(T) | Überladen. |
![]() ![]() ![]() ![]() | Distinct<T>() | Überladen. |
![]() ![]() ![]() ![]() | Distinct<T>(IEqualityComparer<T>) | Überladen. |
![]() ![]() ![]() ![]() | ElementAt<T> | |
![]() ![]() ![]() ![]() | ElementAtOrDefault<T> | |
![]() ![]() ![]() ![]() | Except<T>(IEnumerable<T>) | Überladen. |
![]() ![]() ![]() ![]() | Except<T>(IEnumerable<T>, IEqualityComparer<T>) | Überladen. |
![]() ![]() ![]() ![]() | First<T>() | Überladen. |
![]() ![]() ![]() ![]() | First<T>(Func<T, Boolean>) | Überladen. |
![]() ![]() ![]() ![]() | FirstOrDefault<T>() | Überladen. |
![]() ![]() ![]() ![]() | FirstOrDefault<T>(Func<T, Boolean>) | Überladen. |
![]() ![]() ![]() ![]() | GroupBy<T, TKey>(Func<T, TKey>) | Überladen. |
![]() ![]() ![]() ![]() | GroupBy<T, TKey>(Func<T, TKey>, IEqualityComparer<TKey>) | Überladen. |
![]() ![]() ![]() ![]() | GroupBy<T, TKey, TElement>(Func<T, TKey>, Func<T, TElement>) | Überladen. |
![]() ![]() ![]() ![]() | GroupBy<T, TKey, TResult>(Func<T, TKey>, Func<TKey, IEnumerable<T>, TResult>) | Überladen. |
![]() ![]() ![]() ![]() | GroupBy<T, TKey, TElement>(Func<T, TKey>, Func<T, TElement>, IEqualityComparer<TKey>) | Überladen. |
![]() ![]() ![]() ![]() | GroupBy<T, TKey, TResult>(Func<T, TKey>, Func<TKey, IEnumerable<T>, TResult>, IEqualityComparer<TKey>) | Überladen. |
![]() ![]() ![]() ![]() | GroupBy<T, TKey, TElement, TResult>(Func<T, TKey>, Func<T, TElement>, Func<TKey, IEnumerable<TElement>, TResult>) | Überladen. |
![]() ![]() ![]() ![]() | GroupBy<T, TKey, TElement, TResult>(Func<T, TKey>, Func<T, TElement>, Func<TKey, IEnumerable<TElement>, TResult>, IEqualityComparer<TKey>) | Überladen. |
![]() ![]() ![]() ![]() | GroupJoin<T, TInner, TKey, TResult>(IEnumerable<TInner>, Func<T, TKey>, Func<TInner, TKey>, Func<T, IEnumerable<TInner>, TResult>) | Überladen. |
![]() ![]() ![]() ![]() | GroupJoin<T, TInner, TKey, TResult>(IEnumerable<TInner>, Func<T, TKey>, Func<TInner, TKey>, Func<T, IEnumerable<TInner>, TResult>, IEqualityComparer<TKey>) | Überladen. |
![]() ![]() ![]() ![]() | Intersect<T>(IEnumerable<T>) | Überladen. |
![]() ![]() ![]() ![]() | Intersect<T>(IEnumerable<T>, IEqualityComparer<T>) | Überladen. |
![]() ![]() ![]() ![]() | Join<T, TInner, TKey, TResult>(IEnumerable<TInner>, Func<T, TKey>, Func<TInner, TKey>, Func<T, TInner, TResult>) | Überladen. |
![]() ![]() ![]() ![]() | Join<T, TInner, TKey, TResult>(IEnumerable<TInner>, Func<T, TKey>, Func<TInner, TKey>, Func<T, TInner, TResult>, IEqualityComparer<TKey>) | Überladen. |
![]() ![]() ![]() ![]() | Last<T>() | Überladen. |
![]() ![]() ![]() ![]() | Last<T>(Func<T, Boolean>) | Überladen. |
![]() ![]() ![]() ![]() | LastOrDefault<T>() | Überladen. |
![]() ![]() ![]() ![]() | LastOrDefault<T>(Func<T, Boolean>) | Überladen. |
![]() ![]() ![]() ![]() | LongCount<T>() | Überladen. |
![]() ![]() ![]() ![]() | LongCount<T>(Func<T, Boolean>) | Überladen. |
![]() ![]() ![]() ![]() | Max<T>() | Überladen. |
![]() ![]() ![]() ![]() | Max<T>(Func<T, Decimal>) | Überladen. |
![]() ![]() ![]() ![]() | Max<T>(Func<T, Nullable<Decimal>>) | Überladen. |
![]() ![]() ![]() ![]() | Max<T>(Func<T, Double>) | Überladen. |
![]() ![]() ![]() ![]() | Max<T>(Func<T, Nullable<Double>>) | Überladen. |
![]() ![]() ![]() ![]() | Max<T>(Func<T, Int32>) | Überladen. |
![]() ![]() ![]() ![]() | Max<T>(Func<T, Nullable<Int32>>) | Überladen. |
![]() ![]() ![]() ![]() | Max<T>(Func<T, Int64>) | Überladen. |
![]() ![]() ![]() ![]() | Max<T>(Func<T, Nullable<Int64>>) | Überladen. |
![]() ![]() ![]() ![]() | Max<T>(Func<T, Single>) | Überladen. |
![]() ![]() ![]() ![]() | Max<T>(Func<T, Nullable<Single>>) | Überladen. |
![]() ![]() ![]() ![]() | Max<T, TResult>(Func<T, TResult>) | Überladen. |
![]() ![]() ![]() ![]() | Min<T>() | Überladen. |
![]() ![]() ![]() ![]() | Min<T>(Func<T, Decimal>) | Überladen. |
![]() ![]() ![]() ![]() | Min<T>(Func<T, Nullable<Decimal>>) | Überladen. |
![]() ![]() ![]() ![]() | Min<T>(Func<T, Double>) | Überladen. |
![]() ![]() ![]() ![]() | Min<T>(Func<T, Nullable<Double>>) | Überladen. |
![]() ![]() ![]() ![]() | Min<T>(Func<T, Int32>) | Überladen. |
![]() ![]() ![]() ![]() | Min<T>(Func<T, Nullable<Int32>>) | Überladen. |
![]() ![]() ![]() ![]() | Min<T>(Func<T, Int64>) | Überladen. |
![]() ![]() ![]() ![]() | Min<T>(Func<T, Nullable<Int64>>) | Überladen. |
![]() ![]() ![]() ![]() | Min<T>(Func<T, Single>) | Überladen. |
![]() ![]() ![]() ![]() | Min<T>(Func<T, Nullable<Single>>) | Überladen. |
![]() ![]() ![]() ![]() | Min<T, TResult>(Func<T, TResult>) | Überladen. |
![]() ![]() ![]() ![]() | OfType<TResult> | |
![]() ![]() ![]() ![]() | OrderBy<T, TKey>(Func<T, TKey>) | Überladen. |
![]() ![]() ![]() ![]() | OrderBy<T, TKey>(Func<T, TKey>, IComparer<TKey>) | Überladen. |
![]() ![]() ![]() ![]() | OrderByDescending<T, TKey>(Func<T, TKey>) | Überladen. |
![]() ![]() ![]() ![]() | OrderByDescending<T, TKey>(Func<T, TKey>, IComparer<TKey>) | Überladen. |
![]() ![]() ![]() ![]() | Reverse<T> | |
![]() ![]() ![]() ![]() | Select<T, TResult>(Func<T, TResult>) | Überladen. |
![]() ![]() ![]() ![]() | Select<T, TResult>(Func<T, Int32, TResult>) | Überladen. |
![]() ![]() ![]() ![]() | SelectMany<T, TResult>(Func<T, IEnumerable<TResult>>) | Überladen. |
![]() ![]() ![]() ![]() | SelectMany<T, TResult>(Func<T, Int32, IEnumerable<TResult>>) | Überladen. |
![]() ![]() ![]() ![]() | SelectMany<T, TCollection, TResult>(Func<T, Int32, IEnumerable<TCollection>>, Func<T, TCollection, TResult>) | Überladen. |
![]() ![]() ![]() ![]() | SelectMany<T, TCollection, TResult>(Func<T, IEnumerable<TCollection>>, Func<T, TCollection, TResult>) | Überladen. |
![]() ![]() ![]() ![]() | SequenceEqual<T>(IEnumerable<T>) | Überladen. |
![]() ![]() ![]() ![]() | SequenceEqual<T>(IEnumerable<T>, IEqualityComparer<T>) | Überladen. |
![]() ![]() ![]() ![]() | Single<T>() | Überladen. |
![]() ![]() ![]() ![]() | Single<T>(Func<T, Boolean>) | Überladen. |
![]() ![]() ![]() ![]() | SingleOrDefault<T>() | Überladen. |
![]() ![]() ![]() ![]() | SingleOrDefault<T>(Func<T, Boolean>) | Überladen. |
![]() ![]() ![]() ![]() | Skip<T> | |
![]() ![]() ![]() ![]() | SkipWhile<T>(Func<T, Boolean>) | Überladen. |
![]() ![]() ![]() ![]() | SkipWhile<T>(Func<T, Int32, Boolean>) | Überladen. |
![]() ![]() ![]() ![]() | Sum<T>(Func<T, Decimal>) | Überladen. |
![]() ![]() ![]() ![]() | Sum<T>(Func<T, Nullable<Decimal>>) | Überladen. |
![]() ![]() ![]() ![]() | Sum<T>(Func<T, Double>) | Überladen. |
![]() ![]() ![]() ![]() | Sum<T>(Func<T, Nullable<Double>>) | Überladen. |
![]() ![]() ![]() ![]() | Sum<T>(Func<T, Int32>) | Überladen. |
![]() ![]() ![]() ![]() | Sum<T>(Func<T, Nullable<Int32>>) | Überladen. |
![]() ![]() ![]() ![]() | Sum<T>(Func<T, Int64>) | Überladen. |
![]() ![]() ![]() ![]() | Sum<T>(Func<T, Nullable<Int64>>) | Überladen. |
![]() ![]() ![]() ![]() | Sum<T>(Func<T, Single>) | Überladen. |
![]() ![]() ![]() ![]() | Sum<T>(Func<T, Nullable<Single>>) | Überladen. |
![]() ![]() ![]() ![]() | Take<T> | |
![]() ![]() ![]() ![]() | TakeWhile<T>(Func<T, Boolean>) | Überladen. |
![]() ![]() ![]() ![]() | TakeWhile<T>(Func<T, Int32, Boolean>) | Überladen. |
![]() ![]() ![]() ![]() | ToArray<T> | |
![]() ![]() ![]() ![]() | ToDictionary<T, TKey>(Func<T, TKey>) | Überladen. |
![]() ![]() ![]() ![]() | ToDictionary<T, TKey>(Func<T, TKey>, IEqualityComparer<TKey>) | Überladen. |
![]() ![]() ![]() ![]() | ToDictionary<T, TKey, TElement>(Func<T, TKey>, Func<T, TElement>) | Überladen. |
![]() ![]() ![]() ![]() | ToDictionary<T, TKey, TElement>(Func<T, TKey>, Func<T, TElement>, IEqualityComparer<TKey>) | Überladen. |
![]() ![]() ![]() ![]() | ToList<T> | |
![]() ![]() ![]() ![]() | ToLookup<T, TKey>(Func<T, TKey>) | Überladen. |
![]() ![]() ![]() ![]() | ToLookup<T, TKey>(Func<T, TKey>, IEqualityComparer<TKey>) | Überladen. |
![]() ![]() ![]() ![]() | ToLookup<T, TKey, TElement>(Func<T, TKey>, Func<T, TElement>) | Überladen. |
![]() ![]() ![]() ![]() | ToLookup<T, TKey, TElement>(Func<T, TKey>, Func<T, TElement>, IEqualityComparer<TKey>) | Überladen. |
![]() ![]() ![]() ![]() | Union<T>(IEnumerable<T>) | Überladen. |
![]() ![]() ![]() ![]() | Union<T>(IEnumerable<T>, IEqualityComparer<T>) | Überladen. |
![]() ![]() ![]() ![]() | Where<T>(Func<T, Boolean>) | Überladen. |
![]() ![]() ![]() ![]() | Where<T>(Func<T, Int32, Boolean>) | Überladen. |
![]() ![]() ![]() | Zip<T, TSecond, TResult> |
using System; using System.Collections; using System.Collections.Generic; class Program { static void Main(string[] args) { BoxCollection bxList = new BoxCollection(); bxList.Add(new Box(10, 4, 6)); bxList.Add(new Box(4, 6, 10)); bxList.Add(new Box(6, 10, 4)); bxList.Add(new Box(12, 8, 10)); // Same dimensions. Cannot be added: bxList.Add(new Box(10, 4, 6)); // Test the Remove method. PrintResults(bxList); Console.WriteLine("Removing 6x10x4"); bxList.Remove(new Box(6, 10, 4)); PrintResults(bxList); // Test the Contains method. Box BoxCheck = new Box(8, 12, 10); Console.WriteLine("Contains {0}x{1}x{2} by dimensions: {3}", BoxCheck.Height.ToString(), BoxCheck.Length.ToString(), BoxCheck.Width.ToString(), bxList.Contains(BoxCheck).ToString()); // Test the Contains method overload with a specified equality comparer. Console.WriteLine("Contains {0}x{1}x{2} by volume: {3}", BoxCheck.Height.ToString(), BoxCheck.Length.ToString(), BoxCheck.Width.ToString(), bxList.Contains(BoxCheck, new BoxSameVol()).ToString()); } public static void PrintResults(BoxCollection bxList) { Console.WriteLine("\nHeight\tLength\tWidth\tHash Code"); foreach (Box bx in bxList) { Console.WriteLine("{0}\t{1}\t{2}\t{3}", bx.Height.ToString(), bx.Length.ToString(), bx.Width.ToString(), bx.GetHashCode().ToString()); } // Results by manipulating the enumerator directly: //IEnumerator enumerator = bxList.GetEnumerator(); //Console.WriteLine("\nHeight\tLength\tWidth\tHash Code"); //while (enumerator.MoveNext()) //{ // Box b = (Box)enumerator.Current; // Console.WriteLine("{0}\t{1}\t{2}\t{3}", // b.Height.ToString(), b.Length.ToString(), // b.Width.ToString(), b.GetHashCode().ToString()); //} Console.WriteLine(); } } public class Box : IEquatable<Box> { public Box(int h, int l, int w) { this.Height = h; this.Length = l; this.Width = w; } public int Height { get; set; } public int Length { get; set; } public int Width { get; set; } // Defines equality using the // BoxSameDimensions equality comparer. public bool Equals(Box other) { if (new BoxSameDimensions().Equals(this, other)) { return true; } else { return false; } } public override bool Equals(object obj) { return base.Equals(obj); } public override int GetHashCode() { return base.GetHashCode(); } } public class BoxCollection : ICollection<Box> { // The generic enumerator obtained from IEnumerator<Box> // by GetEnumerator can also be used with the non-generic IEnumerator. // To avoid a naming conflict, the non-generic IEnumerable method // is explicitly implemented. public IEnumerator<Box> GetEnumerator() { return new BoxEnumerator(this); } IEnumerator IEnumerable.GetEnumerator() { return new BoxEnumerator(this); } // The inner collection to store objects. private List<Box> innerCol; // For IsReadOnly private bool isRO = false; public BoxCollection() { innerCol = new List<Box>(); } // Adds an index to the collection. public Box this[int index] { get { return (Box)innerCol[index]; } set { innerCol[index] = value; } } // Determines if an item is in the collection // by using the BoxSameDimensions equality comparer. public bool Contains(Box item) { bool found = false; foreach (Box bx in innerCol) { // Equality defined by the Box // class's implmentation of IEquitable<T>. if (bx.Equals(item)) { found = true; } } return found; } // Determines if an item is in the // collection by using a specified equality comparer. public bool Contains(Box item, EqualityComparer<Box> comp) { bool found = false; foreach (Box bx in innerCol) { if (comp.Equals(bx, item)) { found = true; } } return found; } // Adds an item if it is not already in the collection // as determined by calling the Contains method. public void Add(Box item) { if (!Contains(item)) { innerCol.Add(item); } else { Console.WriteLine("A box with {0}x{1}x{2} dimensions was already added to the collection.", item.Height.ToString(), item.Length.ToString(), item.Width.ToString()); } } public void Clear() { innerCol.Clear(); } public void CopyTo(Box[] array, int arrayIndex) { for (int i = 0; i < innerCol.Count; i++) { array[i] = (Box)innerCol[i]; } } public int Count { get { return innerCol.Count; } } public bool IsReadOnly { get { return isRO; } } public bool Remove(Box item) { bool result = false; // Iterate the inner collection to // find the box to be removed. for (int i = 0; i < innerCol.Count; i++) { Box curBox = (Box)innerCol[i]; if (new BoxSameDimensions().Equals(curBox, item)) { innerCol.RemoveAt(i); result = true; break; } } return result; } } // Defines the enumerator for the Boxes collection. // (Some prefer this class nested in the collection class.) public class BoxEnumerator : IEnumerator<Box> { private BoxCollection _collection; private int curIndex; private Box curBox; public BoxEnumerator(BoxCollection collection) { _collection = collection; curIndex = -1; curBox = default(Box); } public bool MoveNext() { //Avoids going beyond the end of the collection. if (++curIndex >= _collection.Count) { return false; } else { // Set current box to next item in collection. curBox = _collection[curIndex]; } return true; } public void Reset() { curIndex = -1; } void IDisposable.Dispose() { } public Box Current { get { return curBox; } } object IEnumerator.Current { get { return Current; } } } // Defines two boxes as equal if they have the same dimensions. public class BoxSameDimensions : EqualityComparer<Box> { public override bool Equals(Box b1, Box b2) { if (b1.Height == b2.Height && b1.Length == b2.Length && b1.Width == b2.Width) { return true; } else { return false; } } public override int GetHashCode(Box bx) { int hCode = bx.Height ^ bx.Length ^ bx.Width; return hCode.GetHashCode(); } } // Defines two boxes as equal if they have the same volume. public class BoxSameVol : EqualityComparer<Box> { public override bool Equals(Box b1, Box b2) { if ((b1.Height * b1.Length * b1.Width) == (b2.Height * b2.Length * b2.Width)) { return true; } else { return false; } } public override int GetHashCode(Box bx) { int hCode = bx.Height ^ bx.Length ^ bx.Width; Console.WriteLine("HC: {0}", hCode.GetHashCode()); return hCode.GetHashCode(); } } /* This code example displays the following output: ================================================ A box with 10x4x6 dimensions was already added to the collection. Height Length Width Hash Code 10 4 6 46104728 4 6 10 12289376 6 10 4 43495525 12 8 10 55915408 Removing 6x10x4 Height Length Width Hash Code 10 4 6 46104728 4 6 10 12289376 12 8 10 55915408 Contains 8x12x10 by dimensions: False Contains 8x12x10 by volume: True */
Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core-Rolle wird nicht unterstützt), Windows Server 2008 R2 (Server Core-Rolle wird mit SP1 oder höher unterstützt; Itanium wird nicht unterstützt)
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen für .NET Framework.


