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
using System; class BankAccount { private double balance; public BankAccount(double initial) { balance = initial; } public double GetBalance() { return balance; } public void Deposit(double amount) { if (amount > 0) balance += amount; } public bool Withdraw(double amount) { if (amount > 0 && amount <= balance) { balance -= amount; return true; } return false; } } class Program { static void Main() { BankAccount acct = new BankAccount(100); acct.Deposit(500); Console.WriteLine("Balance: " + acct.GetBalance()); bool ok = acct.Withdraw(200); Console.WriteLine("Withdraw 200: " + ok); Console.WriteLine("Balance: " + acct.GetBalance()); bool over = acct.Withdraw(10000); Console.WriteLine("Overdraw: " + over); Console.WriteLine("Balance: " + acct.GetBalance()); } }
40 lines
Output
Write some code, then press Run. Stdout and errors appear here.