This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
public class Program | |
{ | |
public static void Main() | |
{ | |
// Demonstrates common uses of List<T>. | |
// Doc: https://msdn.microsoft.com/library/6sh2ey19.aspx | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Task: Compute the sums of the values in two arrays of integers, A and B. | |
// Traditional approach: | |
for (int i = 0; i < size; i++) | |
{ | |
C[i] = A[i] + B[i]; | |
} | |
// With Vector<int> you can instead do this: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// old approach | |
let makeStrings chars lens = | |
List.zip chars lens | |
|> List.map (fun (char, len) -> new System.String(char, len)) | |
// new approach | |
let makeStrings' chars lens = | |
List.zip chars lens | |
|> List.map System.String // use ctor as function |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// old approach - need a `ref` value | |
let sumSquares n = | |
let total = ref 0 | |
{ 1 .. n } |> Seq.iter (fun i -> | |
total := !total + i*i | |
) | |
!total | |
// new approach - `mutable` just works | |
let sumSquares' n = |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type Test = | |
static member EchoExpression([<ReflectedDefinition(true)>] x : Expr<_>) = | |
let expression, value = (* decompose AST of x *) | |
printfn "%s evaluates to %O" expression value | |
let x, y, z = 42, 89.0, 92.5 | |
Test.EchoExpression(x) // "x evaluates to 42" | |
Test.EchExpression(Math.Max(y, z)) // "Math.Max(y, z) evaluates to 92.5" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public MainWindow() | |
{ | |
InitializeComponent(); | |
Loaded += async (o, e) => { | |
await Task.Delay(1000); | |
_strings = new string[] { "EnC now supports more features!", "Thanks to Roslyn!"}; | |
label.Content = (from str in _strings | |
where str.StartsWith("Enc") | |
select str).FirstOrDefault(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using static System.Console; | |
using static System.Math; | |
using static System.DayOfWeek; | |
class Program | |
{ | |
static void Main() | |
{ | |
WriteLine(Sqrt(3 * 3 + 4 * 4)); | |
WriteLine(Friday - Monday); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Imports System.Console | |
Imports System.Math | |
Imports System.DateOfWeek | |
Module Program | |
Sub Main() | |
WriteLine(Sqrt(3 * 3 + 4 * 4)) | |
WriteLine(Friday - Monday) | |
End Sub | |
End Module |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Dim s = "Write your haiku with | |
No vbCrLf | |
In VB14" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var s = @"Write your haiku with | |
No \r\n escapes | |
In C# v1"; |
OlderNewer