C# / .NETin-browser interpreter · runs locally
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System; class Product { public int Id; public string Name; public Product(int id, string n) { Id = id; Name = n; } } class ProductsController { static Product[] products = new Product[] { new Product(1, "Keyboard"), new Product(2, "Monitor") }; public void Index() { Console.WriteLine("GET /products -> Index"); for (int i = 0; i < products.Length; i++) { Console.WriteLine(" " + products[i].Id + ": " + products[i].Name); } } public void Details(int id) { Console.WriteLine("GET /products/" + id + " -> Details"); for (int i = 0; i < products.Length; i++) { if (products[i].Id == id) { Console.WriteLine(" " + products[i].Name); return; } } Console.WriteLine(" Not found"); } } class Program { static void Main() { ProductsController c = new ProductsController(); c.Index(); c.Details(2); c.Details(99); } }
42 lines
Output
Write some code, then press Run. Stdout and errors appear here.