From Schmid.wiki
Jump to: navigation, search

C# REPL (Read-Eval-Print-Loop)

Mono

Mono comes with the 'csharp' command:

predator:~$ csharp
csharp> 2+2;
4
csharp> Math.Sin(Math.PI*.5);
1
csharp> var x = new List<int>{1,2,3};
csharp> foreach(var x in l) { print(x*2); }
2
4
6
csharp> foreach(var l in File.ReadLines("file.txt")) Console.WriteLine(l);
This is a text file
with text in it

The interactive interpreter enables using C# as a scripting language:

predator ~$ cat <<eof >test.cs
> #!/usr/bin/csharp
> print(2+2);
> eof
predator ~$ chmod u+x test.cs
predator ~$ ./test.s
4