Class IntExtensions
Int 扩展方法
Inherited Members
Namespace: Lett.Extensions
Assembly: Lett.Extensions.dll
Syntax
public static class IntExtensions
Methods
| Improve this Doc View SourceGetEnumDescription(Int32, Type)
获取对应枚举的描述
Declaration
public static string GetEnumDescription(this int this, Type enumType)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | this | |
| Type | enumType | 枚举类型 |
Returns
| Type | Description |
|---|---|
| String | 获取失败 返回null |
Examples
enum MyEnum
{
[System.ComponentModel.Description("这里是EnumValue0的说明")]
EnumValue0 = 0,
}
0.GetEnumDescription(typeof(MyEnum); // "这里是EnumValue0的说明"
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException |
|
| ArgumentException |
|
| ArgumentNullException | |
| ArgumentException | |
| NotSupportedException | |
| AmbiguousMatchException | |
| TypeLoadException |
IsEven(Int32)
是否偶数
Declaration
public static bool IsEven(this int this)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | this |
Returns
| Type | Description |
|---|---|
| Boolean |
Examples
0.IsEven(); // true
|
Improve this Doc
View Source
IsInRange(Int32, Int32, Int32)
是否在指定范围内
Declaration
public static bool IsInRange(this int this, int min, int max)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | this | |
| Int32 | min | 最小值 |
| Int32 | max | 最大值 |
Returns
| Type | Description |
|---|---|
| Boolean |
Examples
(-1).IsInRange(0, 10); // false
10.IsInRange(0, 10); // true
|
Improve this Doc
View Source
IsOdd(Int32)
是否奇数
Declaration
public static bool IsOdd(this int this)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | this |
Returns
| Type | Description |
|---|---|
| Boolean |
Examples
(-1).IsOdd(); // true
|
Improve this Doc
View Source
Times(Int32, Action)
执行次数操作,次数基于 this
Declaration
public static void Times(this int this, Action action)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | this | |
| Action | action | 执行的操作 |
Examples
var rs = 0;
10.Times(() => rs += 1); // rs == 10
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | 执行次数 |
Times(Int32, Action<Int32>)
执行次数操作,次数基于 this
Declaration
public static void Times(this int this, Action<int> action)
Parameters
| Type | Name | Description |
|---|---|---|
| Int32 | this | |
| Action<Int32> | action | 执行的操作(参数是从0开始的 index) |
Examples
var rs2 = 0;
10.Times(i => rs2 += i); // rs2 == 45
Exceptions
| Type | Condition |
|---|---|
| ArgumentOutOfRangeException | 执行次数 |