C# Playground

A starter program to experiment with. Edit it here, press Copy, paste it into a file called Program.cs, and run it with dotnet run Program.cs — no project needed. Lesson 2 shows how to install the .NET SDK.

Try it yourself · Program.cs
Edit the code, copy it into Program.cs and run it with dotnet run Program.cs (.NET 10 or later). How to set up .NET
Output
Backpack    1 x  39.90 =   39.90
Notebook    4 x   3.50 =   14.00
Pen        10 x   1.20 =   12.00
Total: 65.90
Cheapest line: Pen

Ideas to try

  • Apply a 10% discount when the total is over 50 (lessons 12–13).
  • Ask the user for an item and quantity with Console.ReadLine and add it to the basket (lesson 11).
  • Group the items into "cheap" and "expensive" with LINQ's GroupBy (lesson 50).
  • Reject negative prices by adding validation to the record (lesson 40).
  • Save the basket to a JSON file and load it back (lesson 55).
  • Format prices as currency for another culture with CultureInfo (lesson 18).

Running C# without installing anything

Online playgrounds such as .NET Fiddle and SharpLab compile and run C# in your browser. They're fine for quick experiments, but some features — files, packages, and the newest language versions — may not be available there.