-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExtensions.cs
50 lines (42 loc) · 1.22 KB
/
Extensions.cs
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
using System;
using System.Collections.Generic;
using System.Text;
namespace ExtensionMethods
{
public static class Extensions
{
private static readonly Random rand = new Random();
public static void Shuffle<T>(this IList<T> list)
{
int n = list.Count;
while (n > 1)
{
n--;
int k = rand.Next(n + 1);
T value = list[k];
list[k] = list[n];
list[n] = value;
}
}
public static T RandomItem<T>(this IList<T> list)
{
var index = rand.Next(list.Count);
return list[index];
}
public static string ToUpperFirstLetter(this string source)
{
if (string.IsNullOrEmpty(source))
{
return string.Empty;
}
char[] letters = source.ToCharArray();
letters[0] = char.ToUpper(letters[0]);
return new string(letters);
}
public static string RemoveAccent(this string txt)
{
byte[] bytes = Encoding.GetEncoding("Cyrillic").GetBytes(txt);
return Encoding.ASCII.GetString(bytes);
}
}
}