Skip to main content
Version: 3.5

SynchronizedList<T>

Namespace: Wisej.Core

Assembly: Wisej.Framework (3.5.0.0)

Provides a thread-safe collection that contains objects of a type specified by the generic parameter as elements.

public class SynchronizedList<T> : IList<T>, ICollection<T>, IEnumerable<T>, IEnumerable, IList, ICollection

Parameters

NameDescription
TThe type of object contained as items in the thread-safe collection.

Constructors

Instance memberSynchronizedList(capacity, collection, syncLock)

Initializes a new instance of the SynchronizedList class that contains elements copied from the specified collection and has sufficient capacity to accommodate the number of elements copied and uses the specified syncLock object to synchronize its internal operations.

NameTypeDescription
capacityInt32The optional number of element that the list can initially store.
collectionIEnumerable<T>The optional collection whose elements are copied to the new list.
syncLockObjectThe optional lock reference.

Properties

Instance memberCount

Int32: Gets the number of elements contained in the thread-safe collection.

Instance memberItem(index)

T: Gets an element from the thread-safe collection with a specified index.

Throws:

Instance memberSyncRoot

Object: Gets the object used to synchronize access to the thread-safe collection.

Methods

Instance memberAdd(item)

Adds an item to the thread-safe collection.

ParameterTypeDescription
itemTThe element to be added to the collection.

Instance memberAddRange(collection)

Adds the elements of the specified collection to the end of the List.

ParameterTypeDescription
collectionIEnumerable<T>The collection whose elements should be added to the end of the List. The collection itself cannot be null, but it can contain elements that are null, for reference types.

Throws:

Instance memberBinarySearch(item)

Searches the entire sorted List for an element using the default comparer and returns the zero-based index of the element.

ParameterTypeDescription
itemTThe object to locate. The value can be null for reference types.

Returns: Int32. The zero-based index of item in the sorted List, if item is found; otherwise, a negative number that is the bitwise complement of the index of the next element that is larger than item or, if there is no larger element, the bitwise complement of Count.

Throws:

Instance memberBinarySearch(item, comparer)

Searches the entire sorted List for an element using the specified comparer and returns the zero-based index of the element.

ParameterTypeDescription
itemTThe object to locate. The value can be null for reference types.
comparerIComparer<T>The IComparer implementation to use when comparing elements; or null to use the default comparer Default.

Returns: Int32. The zero-based index of item in the sorted List, if item is found; otherwise, a negative number that is the bitwise complement of the index of the next element that is larger than item or, if there is no larger element, the bitwise complement of Count.

Throws:

Instance memberClear()

Removes all items from the collection.

Instance memberContains(item)

Determines whether the collection contains an element with a specific value.

ParameterTypeDescription
itemTThe object to locate in the collection.

Returns: Boolean. true if the element value is found in the collection; otherwise false.

Instance memberCopyTo(array, index)

Copies the elements of the collection to a specified array, starting at a particular index.

ParameterTypeDescription
arrayT[]The destination Array for the elements copied from the collection.
indexInt32The zero-based index in the array at which copying begins.

Instance memberFind(match)

Searches for an element that matches the conditions defined by the specified predicate, and returns the first occurrence within the entire List.

ParameterTypeDescription
matchPredicate<T>The Predicate delegate that defines the conditions of the element to search for.

Returns: T. The first element that matches the conditions defined by the specified predicate, if found; otherwise, the default value.

Throws:

Instance memberFind(startIndex, match)

Searches for an element that matches the conditions defined by the specified predicate, and returns the first occurrence within the entire List.

ParameterTypeDescription
startIndexInt32The zero-based starting index of the search.
matchPredicate<T>The Predicate delegate that defines the conditions of the element to search for.

Returns: T. The first element that matches the conditions defined by the specified predicate, if found; otherwise, the default value.

Throws:

Instance memberFindAll(match)

Retrieves all the elements that match the conditions defined by the specified predicate.

ParameterTypeDescription
matchPredicate<T>The Predicate delegate that defines the conditions of the elements to search for.

Returns: List<T>. A List containing all the elements that match the conditions defined by the specified predicate, if found; otherwise, an empty List.

Throws:

Instance memberFindIndex(match)

Searches for an element that matches the conditions defined by the specified predicate, and returns the zero-based index of the first occurrence within the entire List.

ParameterTypeDescription
matchPredicate<T>The Predicate delegate that defines the conditions of the element to search for.

Returns: Int32. The zero-based index of the first occurrence of an element that matches the conditions defined by match , if found; otherwise, –1.

Throws:

Instance memberFindIndex(startIndex, match)

Searches for an element that matches the conditions defined by the specified predicate, and returns the zero-based index of the first occurrence within the range of elements in the List that extends from the specified index to the last element.

ParameterTypeDescription
startIndexInt32The zero-based starting index of the search.
matchPredicate<T>The Predicate delegate that defines the conditions of the element to search for.

Returns: Int32. The zero-based index of the first occurrence of an element that matches the conditions defined by match , if found; otherwise, –1.

Throws:

Instance memberFindIndex(startIndex, count, match)

Searches for an element that matches the conditions defined by the specified predicate, and returns the zero-based index of the first occurrence within the range of elements in the List that starts at the specified index and contains the specified number of elements.

ParameterTypeDescription
startIndexInt32The zero-based starting index of the search.
countInt32The number of elements in the section to search.
matchPredicate<T>The Predicate delegate that defines the conditions of the element to search for.

Returns: Int32. The zero-based index of the first occurrence of an element that matches the conditions defined by match , if found; otherwise, –1.

Throws:

Instance memberFindLast(match)

Searches for an element that matches the conditions defined by the specified predicate, and returns the last occurrence within the entire List.

ParameterTypeDescription
matchPredicate<T>The Predicate delegate that defines the conditions of the element to search for.

Returns: T. The last element that matches the conditions defined by the specified predicate, if found; otherwise, the default value.

Throws:

Instance memberFindLast(startIndex, match)

Searches for an element that matches the conditions defined by the specified predicate, and returns the last occurrence within the entire List.

ParameterTypeDescription
startIndexInt32The zero-based starting index of the search.
matchPredicate<T>The Predicate delegate that defines the conditions of the element to search for.

Returns: T. The last element that matches the conditions defined by the specified predicate, if found; otherwise, the default value.

Throws:

Instance memberFindLastIndex(match)

Searches for an element that matches the conditions defined by the specified predicate, and returns the zero-based index of the last occurrence within the entire List.

ParameterTypeDescription
matchPredicate<T>The Predicate delegate that defines the conditions of the element to search for.

Returns: Int32. The zero-based index of the last occurrence of an element that matches the conditions defined by match , if found; otherwise, –1.

Throws:

Instance memberFindLastIndex(startIndex, match)

Searches for an element that matches the conditions defined by the specified predicate, and returns the zero-based index of the last occurrence within the range of elements in the List that extends from the specified index to the last element.

ParameterTypeDescription
startIndexInt32The zero-based starting index of the search.
matchPredicate<T>The Predicate delegate that defines the conditions of the element to search for.

Returns: Int32. The zero-based index of the last occurrence of an element that matches the conditions defined by match , if found; otherwise, –1.

Throws:

Instance memberForEach(action)

Performs the specified action on each element of the List.

ParameterTypeDescription
actionAction<T>The Action delegate to perform on each element of the List.

Throws:

Instance memberGetEnumerator()

Returns an enumerator that iterates through the synchronized collection.

Returns: IEnumerator<T>. An IEnumerator for objects of the type stored in the collection.

Instance memberIndexOf(item)

Returns the index of the first occurrence of a value in the collection.

ParameterTypeDescription
itemTRemoves all items from the collection.

Returns: Int32. The zero-based index of the first occurrence of the value in the collection.

Instance memberInsert(index, item)

Inserts an item into the collection at a specified index.

ParameterTypeDescription
indexInt32The zero-based index of the element to be retrieved from the collection.
itemTThe object to be inserted into the collection as an element.

Throws:

Instance memberInsertRange(index, collection)

Inserts the elements of a collection into the List at the specified index.

ParameterTypeDescription
indexInt32The zero-based index at which the new elements should be inserted.
collectionIEnumerable<T>The collection whose elements should be inserted into the List. The collection itself cannot be null, but it can contain elements that are null, for reference types.

Throws:

Instance memberRemove(item)

Removes the first occurrence of a specified item from the collection.

ParameterTypeDescription
itemTThe object to remove from the collection.

Returns: Boolean. true if item was successfully removed from the collection; otherwise, false.

Instance memberRemoveAll(match)

Removes all the elements that match the conditions defined by the specified predicate.

ParameterTypeDescription
matchPredicate<T>The Predicate delegate that defines the conditions of the elements to remove.

Returns: Int32. The number of elements removed from the List .

Throws:

Instance memberRemoveAt(index)

Removes an item at a specified index from the collection.

ParameterTypeDescription
indexInt32The zero-based index of the element to be retrieved from the collection.

Throws:

Instance memberSort()

Sorts the elements in the entire List using the default comparer.

Throws:

Instance memberSort(comparer)

Sorts the elements in the entire List using the specified comparer.

ParameterTypeDescription
comparerIComparer<T>The IComparer implementation to use when comparing elements, or null to use the default comparer Default.

Throws:

  • InvalidOperationException comparer is null, and the default comparer Default cannot find implementation of the IComparable generic interface or the IComparable interface for the type of the collection elements.
  • ArgumentException The implementation of comparer caused an error during the sort. For example, comparer might not return 0 when comparing an item with itself.

Instance memberSort(comparison)

Sorts the elements in the entire List using the specified Comparison.

ParameterTypeDescription
comparisonComparison<T>The Comparison to use when comparing elements.

Throws:

  • ArgumentNullException comparison is null.
  • ArgumentException The implementation of comparison caused an error during the sort. For example, comparison might not return 0 when comparing an item with itself.

Instance memberSort(comparer, swapCallback)

Sorts the elements in the entire List using the specified comparer and a related IList to sort in sync with this collection.

ParameterTypeDescription
comparerIComparer<T>The IComparer implementation to use when comparing elements, or null to use the default comparer Default.
swapCallback optionalFunc<Int32, Int32, Boolean>An optional callback method, invoked on every swap. If the callback returns true to indicate that it handled the swap, the default swap is not performed.

Throws:

  • InvalidOperationException comparer is null, and the default comparer Default cannot find implementation of the IComparable generic interface or the IComparable interface for the type of the collection elements.
  • ArgumentException The implementation of comparer caused an error during the sort. For example, comparer might not return 0 when comparing an item with itself.

Instance memberSum(selector)

Computes the sum of the sequence of System.Int32 values that are obtained by invoking a transform function on each element of the list.

ParameterTypeDescription
selectorFunc<T, Int32>A transform function to apply to each element.

Returns: Int32. The sum of the returned values.

Throws:

Instance memberSum(selector)

Computes the sum of the sequence of System.Int64 values that are obtained by invoking a transform function on each element of the list.

ParameterTypeDescription
selectorFunc<T, Int64>A transform function to apply to each element.

Returns: Int64. The sum of the returned values.

Throws:

Instance memberSum(selector)

Computes the sum of the sequence of System.Single values that are obtained by invoking a transform function on each element of the list.

ParameterTypeDescription
selectorFunc<T, Single>A transform function to apply to each element.

Returns: Single. The sum of the returned values.

Throws:

Instance memberSum(selector)

Computes the sum of the sequence of System.Double values that are obtained by invoking a transform function on each element of the list.

ParameterTypeDescription
selectorFunc<T, Double>A transform function to apply to each element.

Returns: Double. The sum of the returned values.

Throws:

Instance memberSum(selector)

Computes the sum of the sequence of System.Decimal values that are obtained by invoking a transform function on each element of the list.

ParameterTypeDescription
selectorFunc<T, Decimal>A transform function to apply to each element.

Returns: Decimal. The sum of the returned values.

Throws:

Instance memberToArray()

Copies the elements of the List to a new array.

Returns: T[]. An array containing copies of the elements of the List.

Instance memberTrimExcess()

Sets the capacity to the actual number of elements in the List, if that number is less than a threshold value.