You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"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"
0 commit comments