Skip to content

Instantly share code, notes, and snippets.

@jskeet
Created July 1, 2024 17:48
Show Gist options
  • Save jskeet/dee7375397fad316dafeceb5a51c5c0d to your computer and use it in GitHub Desktop.
Save jskeet/dee7375397fad316dafeceb5a51c5c0d to your computer and use it in GitHub Desktop.
using System.Text.Json;
IUser user = new User("Jon", "Reading");
string json = JsonSerializer.Serialize(user);
Console.WriteLine(json);
public interface IUser
{
string Name { get; }
}
public class User : IUser
{
public string Name { get; }
public string Town { get; }
public User(string name, string town)
{
Name = name;
Town = town;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment