FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Magicodes.NET/Magicodes.Utility/EnumerableUtils.cs at master · magicodes/Magicodes.NET · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
This repository was archived by the owner on Feb 21, 2022. It is now read-only.
magicodes
/
Magicodes.NET
Public archive
Notifications
You must be signed in to change notification settings
Fork
90
Star
115
Code
Issues
11
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
Magicodes.NET
/
Magicodes.Utility
/
EnumerableUtils.cs
Copy path
More file actions
More file actions
Latest commit
History
History
History
83 lines (78 loc) · 2.52 KB
Breadcrumbs
Magicodes.NET
/
Magicodes.Utility
/
EnumerableUtils.cs
Copy path
File metadata and controls
83 lines (78 loc) · 2.52 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using
System
;
using
System
.
Collections
;
using
System
.
Collections
.
Generic
;
using
System
.
Linq
;
using
System
.
Text
;
namespace
Magicodes
.
Utility
{
public
static
class
EnumerableUtils
{
/// <summary>
/// 遍历当前对象,并且调用方法进行处理
/// </summary>
/// <typeparam name="T">类型</typeparam>
/// <param name="instance">实例</param>
/// <param name="action">方法</param>
/// <returns>当前集合</returns>
public
static
IEnumerable
<
T
>
Each
<
T
>
(
this
IEnumerable
<
T
>
instance
,
Action
<
T
>
action
)
{
foreach
(
T
item
in
instance
)
{
action
(
item
)
;
}
return
instance
;
}
/// <summary>
/// 遍历N次
/// </summary>
/// <typeparam name="T"></typeparam>
/// <param name="instance"></param>
/// <param name="action"></param>
/// <returns></returns>
public
static
int
Each
<
T
>
(
this
int
instance
,
Action
<
int
>
action
)
{
for
(
int
i
=
0
;
i
<
instance
;
i
++
)
{
action
(
i
)
;
}
return
instance
;
}
/// <summary>
/// 以“,”拼接字符串
/// </summary>
/// <param name="items"></param>
/// <returns></returns>
public
static
string
Join
(
this
IEnumerable
items
)
{
return
items
.
Join
(
","
,
"{0}"
)
;
}
/// <summary>
/// 使用分隔符拼接字符串
/// </summary>
/// <param name="items"></param>
/// <param name="separator"></param>
/// <returns></returns>
public
static
string
Join
(
this
IEnumerable
items
,
string
separator
)
{
return
items
.
Join
(
separator
,
"{0}"
)
;
}
/// <summary>
/// 使用分隔符、以及模板字符串拼接字符串
/// </summary>
/// <param name="items">待拼接集合</param>
/// <param name="separator">分隔符</param>
/// <param name="template">字符串格式化模板</param>
/// <returns></returns>
public
static
string
Join
(
this
IEnumerable
items
,
string
separator
,
string
template
)
{
var
sb
=
new
StringBuilder
(
)
;
foreach
(
object
item
in
items
)
{
if
(
item
==
null
)
continue
;
sb
.
Append
(
separator
)
;
sb
.
Append
(
string
.
Format
(
template
,
item
.
ToString
(
)
)
)
;
}
return
sb
.
ToString
(
)
.
RightOf
(
separator
)
;
}
}
}
Back
|
FazBrowse Home
|
New Git URL