Skip to content

Instantly share code, notes, and snippets.

@jindraivanek
Last active March 27, 2019 17:22
Show Gist options
  • Save jindraivanek/b178d3cc993bfe77e07b7d0c4a9a3593 to your computer and use it in GitHub Desktop.
Save jindraivanek/b178d3cc993bfe77e07b7d0c4a9a3593 to your computer and use it in GitHub Desktop.
Sample of cs2fs output
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication3
{
class Example
{
public string Conditionals()
{
var x = 1 > 2 ? "a" : "b";
return x;
}
public string Arrays(string[] strings)
{
if (strings == null)
{
return "null";
}
else
{
var x = "";
foreach (var s in strings)
{
x += "," + s;
}
return x;
}
}
public List<int> Linq()
{
int[] ints = {1, 2, 3, 4, 5, 6, 7, 8};
var big = ints.Where(i => i > 4).Select(i => i*2).ToList();
return big;
}
public string Delegates()
{
Action<int, string> del = (a, b) =>
{
Console.WriteLine("{0} {1}", a, b);
};
Func<int, string> del2 = a => "hello" + a;
InvokeIt(del);
return del2(1);
}
private void InvokeIt(Action<int, string> del)
{
del(1, "hello");
}
public static void Main()
{
var i = 1.ToString();
Console.WriteLine(i);
var x = new Example();
Console.WriteLine(x.Conditionals());
Console.WriteLine(x.Arrays(null));
string[] strings = {"F","O","O"};
Console.WriteLine(x.Arrays(strings));
x.Linq().ForEach(y => Console.WriteLine(y));
Console.WriteLine(x.Delegates());
}
}
}
namespace global
open System
open System.Collections.Generic
open System.Linq
open System.Text
open System.Threading.Tasks
namespace ConsoleApplication3
type Example() =
member this.Conditionals() =
let mutable x =
if 1 > 2
then "a"
else "b"
x
member this.Arrays(strings : string[]) =
if strings :> obj = Unchecked.defaultof<_>
then "null"
else
let mutable x = ""
for s in strings do
x <- x + "," + s
x
member this.Linq() =
let mutable (ints : int[]) = [|1; 2; 3; 4; 5; 6; 7; 8|]
let mutable big = ((ints.Where (fun i -> i > 4)).Select (fun i -> i * 2)).ToList ()
big
member this.Delegates() =
let mutable (del : ((int * string) -> unit)) = fun (a, b) -> Console.WriteLine ("{0} {1}", a, b)
let mutable (del2 : (int -> string)) = fun a -> "hello" + a
this.InvokeIt (del)
del2 (1)
member private this.InvokeIt(del : ((int * string) -> unit)) =
del (1, "hello")
static member Main() =
let mutable i = (1).ToString ()
Console.WriteLine (i)
let mutable x = new Example()
Console.WriteLine (x.Conditionals ())
Console.WriteLine (x.Arrays (Unchecked.defaultof<_>))
let mutable (strings : string[]) = [|"F"; "O"; "O"|]
Console.WriteLine (x.Arrays (strings))
(x.Linq ()).ForEach (fun y -> Console.WriteLine (y))
Console.WriteLine (x.Delegates ())
module Example__run =
[<EntryPoint>]
let main =
Example.Main ()
0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment