Created
July 1, 2024 17:48
-
-
Save jskeet/dee7375397fad316dafeceb5a51c5c0d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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