Provides extension methods for working with System.Collections.Generic.Dictionary2`. These methods enhance dictionary functionality with efficient retrieval, addition, and updating of values.
public static class DictionaryExtensions
TValue GetOrAdd(this Dictionary<TKey, TValue> dict, TKey key, TValue value)Summary: Retrieves the value associated with the specified key or adds a new value if the key does not exist.
Parameters:
dict- The dictionary instance.
key- The key whose value to get or add.
value- The value to add if the key does not exist.Returns: The existing or newly added value.
TValue GetOrAdd(this Dictionary<TKey, TValue> dict, TKey key, Func<TKey, TValue> valueFactory)Summary: Retrieves the value associated with the specified key or adds a new value if the key does not exist.
Parameters:
dict- The dictionary instance.
key- The key whose value to get or add.
value- The value to add if the key does not exist.Returns: The existing or newly added value.
bool TryUpdate(this Dictionary<TKey, TValue> dict, TKey key, TValue value)Summary: Attempts to update the value of an existing key in the dictionary.
Parameters:
dict- The dictionary instance.
key- The key whose value should be updated.
value- The new value to assign.Returns:
trueif the key exists and the value was updated; otherwise,false.
bool TryUpdate(this Dictionary<TKey, TValue> dict, TKey key, Func<TKey, TValue, TValue> valueFactory)Summary: Attempts to update the value of an existing key in the dictionary.
Parameters:
dict- The dictionary instance.
key- The key whose value should be updated.
value- The new value to assign.Returns:
trueif the key exists and the value was updated; otherwise,false.
Provides extension methods for asynchronous enumeration of collections.
public static class EnumerableExtensions
Task<int> CountAsync(this IEnumerable<T> source, CancellationToken cancellationToken = null)Summary: Asynchronously counts the elements in a sequence.
Parameters:
source- The source sequence to count.
cancellationToken- A to observe while waiting for the asynchronous operation to complete.Returns: A task that represents the asynchronous operation. The task result contains the number of elements in the sequence.
TResult[] SelectToArray(this IEnumerable<TSource> source, Func<TSource, TResult> selector)Summary: Projects each element of a sequence into a new form and returns the results as an array.
Parameters:
source- The sequence of elements to transform.
selector- A transform function to apply to each element.Returns: An array containing the transformed elements from the source sequence.
Remarks: This is a convenience method that combines
System.Linq.Enumerable.Select``2(System.Collections.Generic.IEnumerable{``0},System.Func{``0,``1})andSystem.Linq.Enumerable.ToArray``1(System.Collections.Generic.IEnumerable{``0}).
List<TResult> SelectToList(this IEnumerable<TSource> source, Func<TSource, TResult> selector)Summary: Projects each element of a sequence into a new form and returns the results as a
System.Collections.Generic.List1`.Parameters:
source- The sequence of elements to transform.
selector- A transform function to apply to each element.Returns: A
System.Collections.Generic.List1` containing the transformed elements from the source sequence.Remarks: This is a convenience method that combines
System.Linq.Enumerable.Select``2(System.Collections.Generic.IEnumerable{``0},System.Func{``0,``1})andSystem.Linq.Enumerable.ToList``1(System.Collections.Generic.IEnumerable{``0}).
IAsyncEnumerable<T> ToAsyncEnumerable(this IEnumerable<T> source, CancellationToken cancellationToken = null)Summary: Converts an
System.Collections.Generic.IEnumerable1to anSystem.Collections.Generic.IAsyncEnumerable1.Parameters:
source- The source sequence to convert.
cancellationToken- A to observe while waiting for the asynchronous operation to complete.Returns: An
System.Collections.Generic.IAsyncEnumerable1` that contains the elements from the input sequence.
Task<List<T>> ToListAsync(this IEnumerable<T> source, CancellationToken cancellationToken = null)Summary: Asynchronously creates a
System.Collections.Generic.List1from anSystem.Collections.Generic.IEnumerable1.Parameters:
source- The source sequence to convert to a list.
cancellationToken- A to observe while waiting for the asynchronous operation to complete.Returns: A task that represents the asynchronous operation. The task result contains a list with the elements from the input sequence.
public static class ReadOnlyListExtensions
IEnumerable<IEnumerable<T>> GetPowerSet(this IReadOnlyList<T> list)
IEnumerable<IEnumerable<string>> GetUniqueCombinations(this IReadOnlyList<string> list)
IEnumerable<string> GetUniqueCombinationsAsCommaSeparated(this IReadOnlyList<string> list)