Project · Beginner

Contact book

Manage contacts with records and search.

All C# source files below are loaded together in the playground. Files written by a run live in its virtual directory.

Program.cs

var contacts = new List<Contact>
{
    new("Grace Hopper", "grace@example.com"),
    new("Ada Lovelace", "ada@example.com"),
    new("Alan Turing", "alan@example.com"),
    new("Linus Torvalds", "linus@example.com"),
};

var search = "a";
var matches = contacts
    .Where(c => c.Name.StartsWith(search, StringComparison.OrdinalIgnoreCase))
    .OrderBy(c => c.Name);

Console.WriteLine($"Names starting with '{search}':");
foreach (var contact in matches)
{
    Console.WriteLine($"  {contact.Name} <{contact.Email}>");
}

Models/Contact.cs

public sealed record Contact(string Name, string Email);

ContactBook.csproj

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net10.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
    <AssemblyName>ContactBook</AssemblyName>
  </PropertyGroup>
</Project>