var obj = new {Id = 15, Name = "adam"};
var str = Newtonsoft.Json.JsonConvert.SerializeObject(obj);
Person p = Newtonsoft.Json.JsonConvert.DeserializeObject<Person>(str);
System.Console.WriteLine($"{p.Id}, {p.Name}");
class Person
{
public int Id { get; set; }
public string Name { get; set; }
}
using System;
public abstract class Country
{
public string NameOfVariable { get; set; }
protected Country(string name) {
NameOfVariable = name;
}
}
public class Russia : Country
{
public Russia(string name) : base(name) {}
}
public class Italy : Country
{
public Italy(string name) : base(name) {}
}
public class Test
{
public static void Main()
{
Info(new Russia("Hello From Russia"));
Info(new Italy("me gusta!"));
}
public static void Info(Country country)
{
string text = country.NameOfVariable;
Console.WriteLine(text);
}
}
Hello From Russia
me gusta!