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 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
Download from the command line
curl -L -o Sample.cs https://files.samplefiles.com/code/cs/Sample.cswget https://files.samplefiles.com/code/cs/Sample.cshttps://files.samplefiles.com/code/cs/Sample.csprintf '%s %s\n' 58148e2407cb5750b099718e404b2a4190ff3eccfa5adae25c4a56536735f5fe Sample.cs | shasum -a 256 -cOr check the download in your browser with the checksum calculator.