- C# 8 Cheat Sheet
- C# Cheatsheet 2020
- C# Syntax Cheat Sheet
- C# Programming Cheat Sheet
- C Sharp Cheat Sheet
- C Sharp Syntax Cheat Sheet
This cheatsheet glances over some of the common syntax of F# 3.0. If you have any comments, corrections, or suggested additions, please open an issue or send a pull request to https://github.com/dungpa/fsharp-cheatsheet.
Int c23; //c is an array of 2 arrays of three ints. A10 follows a02 Array variables (e.g. A,b,c above) cannot be made to point to other arrays Strings are represented as character arrays terminated by ASCII zero. Pointers are indicated by left associative asterisk (.) in the type declarations: int a.a; // a is a pointer to an integer.
C# — Style Guide Cheat Sheet. Nikita Starichenko. C♯ Minor Cheat Sheet. All Cheat Sheets. (F#, C#, G#, and D#). It is the 9th most popular key among Minor keys and the 17th most popular among all keys. Minor keys, along with major keys, are a common choice for popular music. The three most important chords, built off the 1st, 4th and 5th scale degrees are all minor chords (C♯ minor, F. The markdown file of this sheet is hosted on GitHub. Contributions, bug fixes, additions, and improvements will be much appreciated. Prepared by ConstructG.com. ConstructG is an online game development academy. C# Introduction What is C#? C# is pronounced “C-Sharp”.
Comments
Block comments are placed between (*
and *)
. Line comments start from //
and continue until the end of the line.
XML doc comments come after ///
allowing us to use XML tags to generate documentation.
Strings
F# string
type is an alias for System.String
type.
Use verbatim strings preceded by @
symbol to avoid escaping control characters (except escaping '
by '
).
We don't even have to escape '
with triple-quoted strings.
Backslash strings indent string contents by stripping leading spaces.
Basic Types and Literals
Most numeric types have associated suffixes, e.g., uy
for unsigned 8-bit integers and L
for signed 64-bit integer.
Other common examples are F
or f
for 32-bit floating-point numbers, M
or m
for decimals, and I
for big integers.
See Literals (MSDN) for complete reference.
Functions
The let
keyword also defines named functions.
Pipe and composition operators
Pipe operator |>
is used to chain functions and arguments together. Double-backtick identifiers are handy to improve readability especially in unit testing:
This operator is essential in assisting the F# type checker by providing type information before use:
Composition operator >>
is used to compose functions:
Recursive functions
The rec
keyword is used together with the let
keyword to define a recursive function:
Mutually recursive functions (those functions which call each other) are indicated by and
keyword: Active development mobile phones & portable devices driver download.
Pattern Matching
Pattern matching is often facilitated through match
keyword.
In order to match sophisticated inputs, one can use when
to create filters or guards on patterns:
Pattern matching can be done directly on arguments:
or implicitly via function
keyword:
For more complete reference visit Pattern Matching (MSDN).
Collections
Lists
A list is an immutable collection of elements of the same type.
Arrays
Arrays are fixed-size, zero-based, mutable collections of consecutive data elements.
Sequences
A sequence is a logical series of elements of the same type. Individual sequence elements are computed only as required, so a sequence can provide better performance than a list in situations in which not all the elements are used.
Higher-order functions on collections
The same list [ 1; 3; 5; 7; 9 ]
or array [| 1; 3; 5; 7; 9 |]
can be generated in various ways.
Using range operator
.
Using list or array comprehensions
Using
init
function
Lists and arrays have comprehensive sets of higher-order functions for manipulation.
fold
starts from the left of the list (or array) andfoldBack
goes in the opposite directionreduce
doesn't require an initial accumulatormap
transforms every element of the list (or array)iter
ate through a list and produce side effects
All these operations are also available for sequences. The added benefits of sequences are laziness and uniform treatment of all collections implementing IEnumerable<'T>
.
Tuples and Records
A tuple is a grouping of unnamed but ordered values, possibly of different types:
The first and second elements of a tuple can be obtained using fst
, snd
, or pattern matching:
Records represent simple aggregates of named values, optionally with members:
Records can be augmented with properties and methods:
Records are essentially sealed classes with extra topping: default immutability, structural equality, and pattern matching support.
Discriminated Unions
Discriminated unions (DU) provide support for values that can be one of a number of named cases, each possibly with different values and types.
F# Core has a few built-in discriminated unions for error handling, e.g., Option and Choice.
Single-case discriminated unions are often used to create type-safe abstractions with pattern matching support:
Exceptions
The failwith
function throws an exception of type Exception
.
Exception handling is done via try/with
expressions.
The try/finally
expression enables you to execute clean-up code even if a block of code throws an exception. Here's an example which also defines custom exceptions.
Classes and Inheritance
This example is a basic class with (1) local let bindings, (2) properties, (3) methods, and (4) static members.
Call a base class from a derived one.
Upcasting is denoted by :>
operator.
Dynamic downcasting (:?>
) might throw an InvalidCastException
if the cast doesn't succeed at runtime.
Interfaces and Object Expressions
Declare IVector
interface and implement it in Vector'
.
Another way of implementing interfaces is to use object expressions.
Active Patterns
Complete active patterns:
Parameterized active patterns:
Partial active patterns share the syntax of parameterized patterns but their active recognizers accept only one argument.
Compiler Directives
Load another F# source file into FSI.
Reference a .NET assembly (/
symbol is recommended for Mono compatibility).
Include a directory in assembly search paths.
Other important directives are conditional execution in FSI (INTERACTIVE
) and querying current directory (__SOURCE_DIRECTORY__
).
Full name: fsharpcheatsheet.result
The `let` keyword defines an (immutable) value
Full name: fsharpcheatsheet.hello
Create a string using string concatenation
Full name: fsharpcheatsheet.verbatimXml
Full name: fsharpcheatsheet.tripleXml
Full name: fsharpcheatsheet.b
Full name: fsharpcheatsheet.l
Full name: fsharpcheatsheet.f
Full name: fsharpcheatsheet.bi
Full name: fsharpcheatsheet.negate
Full name: fsharpcheatsheet.square
Full name: fsharpcheatsheet.print
Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.printfn
Full name: fsharpcheatsheet.squareNegateThenPrint
Full name: fsharpcheatsheet.( square, negate, then print )
Full name: fsharpcheatsheet.sumOfLengths
val string : value:'T -> string
Full name: Microsoft.FSharp.Core.Operators.string
--------------------
type string = System.String
Full name: Microsoft.FSharp.Core.string
Full name: Microsoft.FSharp.Collections.Array.map
Full name: Microsoft.FSharp.Collections.Array.sum
Full name: fsharpcheatsheet.squareNegateThenPrint'
Full name: fsharpcheatsheet.fact
Full name: fsharpcheatsheet.even
Full name: fsharpcheatsheet.odd
Full name: fsharpcheatsheet.fib
Full name: fsharpcheatsheet.sign
Full name: fsharpcheatsheet.fst'
Full name: fsharpcheatsheet.fib'
Similar to `fib`; using `function` for pattern matching
Full name: fsharpcheatsheet.list1
Full name: fsharpcheatsheet.list2
Full name: fsharpcheatsheet.list3
Full name: fsharpcheatsheet.sum
val list : int list
--------------------
type 'T list = List<'T>
Full name: Microsoft.FSharp.Collections.list<_>
Full name: fsharpcheatsheet.array1
Full name: fsharpcheatsheet.first
Full name: fsharpcheatsheet.seq1
val seq : sequence:seq<'T> -> seq<'T>
Full name: Microsoft.FSharp.Core.Operators.seq
--------------------
type seq<'T> = System.Collections.Generic.IEnumerable<'T>
Full name: Microsoft.FSharp.Collections.seq<_>
Full name: fsharpcheatsheet.ys
Full name: fsharpcheatsheet.zs
module List
from Microsoft.FSharp.Collections
--------------------
type List<'T> =
| ( [] )
| ( :: ) of Head: 'T * Tail: 'T list
interface IEnumerable
interface IEnumerable<'T>
member Head : 'T
member IsEmpty : bool
member Item : index:int -> 'T with get
member Length : int
member Tail : 'T list
static member Cons : head:'T * tail:'T list -> 'T list
static member Empty : 'T list
Full name: Microsoft.FSharp.Collections.List<_>
C# 8 Cheat Sheet
Full name: Microsoft.FSharp.Collections.List.init
Full name: Microsoft.FSharp.Collections.Array.fold
Full name: Microsoft.FSharp.Core.ExtraTopLevelOperators.sprintf
Full name: fsharpcheatsheet.last
Full name: Microsoft.FSharp.Collections.List.reduce
Full name: fsharpcheatsheet.ys'
Full name: Microsoft.FSharp.Collections.List.iter
Full name: fsharpcheatsheet.x
Full name: fsharpcheatsheet.y
Full name: fsharpcheatsheet.b'
Full name: Microsoft.FSharp.Core.Operators.fst
Full name: Microsoft.FSharp.Core.Operators.snd
Full name: fsharpcheatsheet.print'
{Name: string;
Age: int;}
member Info : string * int
Full name: fsharpcheatsheet.Person
val int : value:'T -> int (requires member op_Explicit)
Full name: Microsoft.FSharp.Core.Operators.int
--------------------
type int = int32
Full name: Microsoft.FSharp.Core.int
--------------------
type int<'Measure> = int
Full name: Microsoft.FSharp.Core.int<_>
Full name: fsharpcheatsheet.paulsTwin
Full name: fsharpcheatsheet.Person.Info
Full name: fsharpcheatsheet.isPaul
| Node of Tree<'T> * 'T * Tree<'T>
| Leaf
Full name: fsharpcheatsheet.Tree<_>
Full name: fsharpcheatsheet.depth
Full name: Microsoft.FSharp.Core.Operators.max
Full name: fsharpcheatsheet.optionPatternMatch
Full name: fsharpcheatsheet.OrderId
Full name: fsharpcheatsheet.orderId
Full name: fsharpcheatsheet.divideFailwith
Full name: Microsoft.FSharp.Core.Operators.failwith
Full name: fsharpcheatsheet.divide
type DivideByZeroException =
inherit ArithmeticException
new : unit -> DivideByZeroException + 2 overloads
Full name: System.DivideByZeroException
--------------------
System.DivideByZeroException() : unit
System.DivideByZeroException(message: string) : unit
System.DivideByZeroException(message: string, innerException: exn) : unit
Full name: fsharpcheatsheet.InnerError
Full name: fsharpcheatsheet.OuterError
Full name: fsharpcheatsheet.handleErrors
Full name: Microsoft.FSharp.Core.Operators.raise
type Vector =
new : x:float * y:float -> Vector
member Scale : s:float -> Vector
member Mag : float
member X : float
member Y : float
static member ( + ) : a:Vector * b:Vector -> Vector
Full name: fsharpcheatsheet.Vector
--------------------
new : x:float * y:float -> Vector
val float : value:'T -> float (requires member op_Explicit)
Full name: Microsoft.FSharp.Core.Operators.float
--------------------
type float = System.Double
Full name: Microsoft.FSharp.Core.float
--------------------
type float<'Measure> = float
Full name: Microsoft.FSharp.Core.float<_>
Full name: Microsoft.FSharp.Core.Operators.sqrt
Full name: fsharpcheatsheet.Vector.X
Full name: fsharpcheatsheet.Vector.Y
C# Cheatsheet 2020
Full name: fsharpcheatsheet.Vector.Mag
Full name: fsharpcheatsheet.Vector.Scale
type Animal =
new : unit -> Animal
member Rest : unit -> unit
Full name: fsharpcheatsheet.Animal
--------------------
new : unit -> Animal
Full name: fsharpcheatsheet.Animal.Rest
type Dog =
inherit Animal
new : unit -> Dog
member Run : unit -> unit
Full name: fsharpcheatsheet.Dog
--------------------
new : unit -> Dog
Full name: fsharpcheatsheet.Dog.Run
Full name: fsharpcheatsheet.animal
Full name: fsharpcheatsheet.shouldBeADog
interface
abstract member Scale : float -> IVector
end
Full name: fsharpcheatsheet.IVector
Full name: fsharpcheatsheet.IVector.Scale
type Vector' =
interface IVector
new : x:float * y:float -> Vector'
member X : float
member Y : float
Full name: fsharpcheatsheet.Vector'
--------------------
new : x:float * y:float -> Vector'
Full name: fsharpcheatsheet.Vector'.Scale
Full name: fsharpcheatsheet.Vector'.X
Full name: fsharpcheatsheet.Vector'.Y
interface
abstract member Age : int
abstract member Name : string
end
Full name: fsharpcheatsheet.ICustomer
Full name: fsharpcheatsheet.ICustomer.Name
Full name: fsharpcheatsheet.ICustomer.Age
Full name: fsharpcheatsheet.createCustomer
Full name: fsharpcheatsheet.testNumber
C# Syntax Cheat Sheet
Full name: fsharpcheatsheet.( |Even|Odd| )
C# Programming Cheat Sheet
Full name: fsharpcheatsheet.( |Even|Odd| )
C Sharp Cheat Sheet
Full name: fsharpcheatsheet.fizzBuzz
C Sharp Syntax Cheat Sheet
Full name: fsharpcheatsheet.( |DivisibleBy|_| )