Class ICollectionsExtensions
ICollections 扩展方法
Inherited Members
Namespace: Lett.Extensions
Assembly: Lett.Extensions.dll
Syntax
public static class ICollectionsExtensions
Methods
| Improve this Doc View SourceAddIfNotContains<T>(ICollection<T>, T)
如果不包含,则添加
Declaration
public static void AddIfNotContains<T>(this ICollection<T> this, T item)
Parameters
Type | Name | Description |
---|---|---|
ICollection<T> | this | |
T | item | 匹配项 |
Type Parameters
Name | Description |
---|---|
T | 集合中元素的类型 |
Examples
var list = new List<string> {"aa", "bb"};
list.AddIfNotContains("cc");
list.AddIfNotContains("aa");
// {"aa", "bb", "cc"}
Exceptions
Type | Condition |
---|---|
NotSupportedException |
|
AddIfNotContains<T>(ICollection<T>, IEnumerable<T>)
如果不包含,则添加
Declaration
public static void AddIfNotContains<T>(this ICollection<T> this, IEnumerable<T> items)
Parameters
Type | Name | Description |
---|---|---|
ICollection<T> | this | |
IEnumerable<T> | items | 匹配项集合 |
Type Parameters
Name | Description |
---|---|
T | 集合中元素的类型 |
Examples
var list = new List<string> {"aa", "bb"};
var appendList = new[] {"cc", "aa"};
list.AddIfNotContains(appendList);
// {"aa", "bb", "cc"}
Exceptions
Type | Condition |
---|---|
NotSupportedException |
|
AddIfNotContainsParams<T>(ICollection<T>, T[])
如果不包含,则添加
Declaration
public static void AddIfNotContainsParams<T>(this ICollection<T> this, params T[] items)
Parameters
Type | Name | Description |
---|---|---|
ICollection<T> | this | |
T[] | items | 匹配项集合 |
Type Parameters
Name | Description |
---|---|
T | 集合中元素的类型 |
Examples
var list = new List<string> {"aa", "bb"};
list.AddIfNotContains("cc", "aa");
// {"aa", "bb", "cc"}
Exceptions
Type | Condition |
---|---|
NotSupportedException |
|
AddRange<T>(ICollection<T>, IEnumerable<T>)
批量添加
Declaration
public static void AddRange<T>(this ICollection<T> this, IEnumerable<T> items)
Parameters
Type | Name | Description |
---|---|---|
ICollection<T> | this | |
IEnumerable<T> | items |
Type Parameters
Name | Description |
---|---|
T |
Examples
var list = new List<string> {"aa", "bb"};
var appendList = new List<string> {"cc", "aa"};
list.AddRange(appendList);
// {"aa", "bb", "cc", "aa"}
Exceptions
Type | Condition |
---|---|
NotSupportedException |
|
ArgumentNullException |
|
AddRangeParams<T>(ICollection<T>, T[])
批量添加
Declaration
public static void AddRangeParams<T>(this ICollection<T> this, params T[] items)
Parameters
Type | Name | Description |
---|---|---|
ICollection<T> | this | |
T[] | items |
Type Parameters
Name | Description |
---|---|
T |
Examples
var list = new List<string> {"aa", "bb"};
list.AddRange("cc", "aa");
// {"aa", "bb", "cc", "aa"}
Exceptions
Type | Condition |
---|---|
NotSupportedException |
|