Code · 1 file

Sample C# File

C# is Microsoft’s language for .NET, Unity and Windows apps. The C# sample is a small program — a customer record, a VIP check and a formatted total — that is the same in every language we offer, so you can compare them side by side.

C# · 689 B

Sample C# file

An idiomatic C# example: a customer record type, a VIP check, a total and a formatted loop — the same program in every language we offer.

CC0 · free for any use · Verified by an independent tool · Report a problem

Sample.cs — first linesC#
// Sample C# program — samplefiles.com
using System;
using System.Collections.Generic;
using System.Linq;

record Customer(int Id, string Name, decimal Balance)
{
    public bool IsVip => Balance >= 10_000m;
}

static class Program
{
    static decimal TotalBalance(IEnumerable<Customer> customers) => customers.Sum(c => c.Balance);

    static void Main()
    {
        var customers = new List<Customer> { new(1, "Ada", 12_500m), new(2, "Grace", 830.5m), new(3, "Linus", 10_000m) };
        foreach (var c in customers)
            Console.WriteLine($"{c.Name,-6} {c.Balance,10:N2} {(c.IsVip ? "VIP" : "")}");
        Console.WriteLine($"Total: {TotalBalance(customers):N2}");
    }
}

File details

Size
689 B (689 bytes)
MIME type
text/x-csharp
SHA-256
58148e2407cb5750b099718e404b2a4190ff3eccfa5adae25c4a56536735f5fe
MD5
e0f5f5659c5ec96ba3937d45a16836f4

Download from the command line

curl -L -o Sample.cs https://files.samplefiles.com/code/cs/Sample.cs

Or check the download in your browser with the checksum calculator.