C#
- 22 ответа
- 0 вопросов
12
Вклад в тег
private static readonly Encoding Windows1251Encoding = Encoding.GetEncoding(1251);
static string FromCyrillicStringArray(string[] values)
{
var bytes = new byte[values.Length];
for (var i = 0; i < values.Length; i++)
bytes[i] = Convert.ToByte(values[i]);
return Windows1251Encoding.GetString(bytes);
}
...
var codes = new[] { "207", "192", "207", "192" };
Console.WriteLine(FromCyrillicStringArray(codes) == "ПАПА"); // true
var classes = new[]
{
new
{
Name = "System.String",
AssemblyName = "mscorlib",
Args = new object[] { "Single argument".ToCharArray() }
},
new
{
Name = "Newtonsoft.Json.Linq.JObject",
AssemblyName = "Newtonsoft.Json",
Args = new object[] {}
},
new
{
Name = "System.IO.FileInfo",
AssemblyName = "mscorlib",
Args = new object[] { @"C:\Windows\System32\cmd.exe" }
}
};
var instances = classes
.Select(i =>
{
var assembly = Assembly.Load(i.AssemblyName);
var type = assembly.GetType(i.Name);
var instance = Activator.CreateInstance(type, i.Args);
return instance;
})
.ToArray();