Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f1f3b6a

Browse files
Update consolidated snippets
1 parent 9708e53 commit f1f3b6a

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

‎public/consolidated/_index.json‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
"lang": "CPP",
88
"icon": "/icons/cpp.svg"
99
},
10+
{
11+
"lang": "CSHARP",
12+
"icon": "/icons/csharp.svg"
13+
},
1014
{
1115
"lang": "CSS",
1216
"icon": "/icons/css.svg"

‎public/consolidated/csharp.json‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
[
2+
{
3+
"categoryName": "List Utilities",
4+
"snippets": [
5+
{
6+
"title": "Swap two items at determined indexes",
7+
"description": "Swaps two items at determined indexes",
8+
"author": "omegaleo",
9+
"tags": [
10+
"csharp",
11+
"c#",
12+
"list",
13+
"utility"
14+
],
15+
"contributors": [],
16+
"code": "/// <summary>\n/// Swaps the position of 2 elements inside of a List\n/// </summary>\n/// <returns>List with swapped elements</returns>\npublic static IList<T> Swap<T>(this IList<T> list, int indexA, int indexB)\n{\n (list[indexA], list[indexB]) = (list[indexB], list[indexA]);\n return list;\n}\n\nvar list = new List<string>() {\"Test\", \"Test2\"};\n\nConsole.WriteLine(list[0]); // Outputs: Test\nConsole.WriteLine(list[1]); // Outputs: Test2\n\nlist = list.Swap(0, 1).ToList();\n\nConsole.WriteLine(list[0]); // Outputs: Test2\nConsole.WriteLine(list[1]); // Outputs: Test\n"
17+
}
18+
]
19+
},
20+
{
21+
"categoryName": "String Utilities",
22+
"snippets": [
23+
{
24+
"title": "Truncate a String",
25+
"description": "Cut off a string once it reaches a determined amount of characters and add '...' to the end of the string",
26+
"author": "omegaleo",
27+
"tags": [
28+
"csharp",
29+
"c#",
30+
"list",
31+
"utility"
32+
],
33+
"contributors": [],
34+
"code": "/// <summary>\n/// Cut off a string once it reaches a <paramref name=\"maxChars\"/> amount of characters and add '...' to the end of the string\n/// </summary>\npublic static string Truncate(this string value, int maxChars)\n{\n return value.Length <= maxChars ? value : value.Substring(0, maxChars) + \"...\";\n}\n\nvar str = \"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam tristique rhoncus bibendum. Vivamus laoreet tortor vel neque lacinia, nec rhoncus ligula pellentesque. Nullam eu ornare nibh. Donec tincidunt viverra nulla.\";\n\nConsole.WriteLine(str); // Outputs the full string\nConsole.WriteLine(str.Truncate(5)); // Outputs Lorem...\n"
35+
}
36+
]
37+
}
38+
]

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /