dynamic
же есть:string json = @"[
{
'Title': 'Json.NET is awesome!',
'Author': {
'Name': 'James Newton-King',
'Twitter': '@JamesNK',
'Picture': '/jamesnk.png'
},
'Date': '2013-01-23T19:30:00',
'BodyHtml': '<h3>Title!</h3>\r\n<p>Content!</p>'
}
]";
dynamic blogPosts = JArray.Parse(json);
dynamic blogPost = blogPosts[0];
string title = blogPost.Title;
Console.WriteLine(title);
// Json.NET is awesome!
string author = blogPost.Author.Name;
Console.WriteLine(author);
// James Newton-King
DateTime postDate = blogPost.Date;
Console.WriteLine(postDate);
// 23/01/2013 7:30:00 p.m.
dynamic product = new JObject();
product.ProductName = "Elbow Grease";
product.Enabled = true;
product.Price = 4.90m;
product.StockCount = 9000;
product.StockValue = 44100;
product.Tags = new JArray("Real", "OnSale");
Console.WriteLine(product.ToString());
// {
// "ProductName": "Elbow Grease",
// "Enabled": true,
// "Price": 4.90,
// "StockCount": 9000,
// "StockValue": 44100,
// "Tags": [
// "Real",
// "OnSale"
// ]
// }
public class BarType
{ }
public class Foo
{
public static string Bar<T>() => $"Bar() is called with generic: {typeof(T).FullName}";
}
Type type = typeof(Foo);
MethodInfo mi = type.GetMethods().Single(m => m.Name == "Bar" && m.IsGenericMethodDefinition);
MethodInfo genericMi = mi.MakeGenericMethod(typeof(BarType));
object result = genericMi.Invoke(null, []);
Console.WriteLine($"Result: {result}");
>> Result: Bar() is called with generic: Example.App+BarType
public class Foo
{
public static string Bar() => "Bar() is called";
}
var type = typeof(Foo);
var mi = type.GetMethod("Bar", BindingFlags.Static | BindingFlags.Public);
var r = mi.Invoke(null, []);
Console.WriteLine($"Result: {r}");
>> Result: Bar() is called
void FormAMethod()
{
if (formB.InvokeRequired)
{
formB.Invoke( () => formB.Text = "data" );
}
else
{
formB.Text = "data";
}
}
File.ReadAllLines
...
Этот метод открывает файл, считывает каждую строку файла, а затем добавляет каждую строку в качестве элемента массива строк. Затем файл закрывается. Строка определяется как последовательность символов, за которой следует возврат каретки ('\r'), канал строки ('\n') или возврат каретки, за которым сразу же следует передача строки. Результирующая строка не содержит завершающего возврата каретки и (или) перевода строки.
public class Foo : Dictionary<string, int>
{
public new int this[string key]
{
get => this.GetValueOrDefault(key);
set => base[key] = value;
}
}
Foo f = [];
string k = "key";
Console.WriteLine($"Value not set: {f[k]}");
f[k]++;
Console.WriteLine($"Value ++: {f[k]}");
f[k]++;
Console.WriteLine($"Value ++: {f[k]}");
f[k]--;
Console.WriteLine($"Value --: {f[k]}");
Value not set: 0
Value ++: 1
Value ++: 2
Value --: 1