using System;
namespace ConsoleApp3
{
class Program
{
static void Main(string[] args)
{
var browser = new Browser();
browser.Bruh += (s, e) =>
{
Console.WriteLine("YAY");
browser.ClearEvents();
};
browser.Go();
browser.Go();
browser.Go();
}
}
class Browser
{
public event EventHandler Bruh;
public void Go()
{
Console.WriteLine("GO");
Bruh?.Invoke(this, null);
}
public void ClearEvents()
{
Bruh = null;
}
}
}
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
namespace ConsoleApplication11
{
class Test
{
public string P1 { get; set; }
public int P2 { get; set; }
}
class Program
{
static void Main(string[] args)
{
var str = JsonConvert.SerializeObject(new List<object> {
new { s = true, P1 = "one", P2 = 12 },
new { s = false, P1 = "two", P2 = 13 },
new { s = true, P1 = "three", P2 = 14 } });
dynamic dObject = JsonConvert.DeserializeObject(str);
var list = new List<Test>();
foreach (var item in dObject)
{
if (item.s == true)
{
list.Add(item.ToObject<Test>());
}
else
{
Console.WriteLine("No way");
}
}
Console.ReadKey();
}
}
}