From b61a66f21092bdb6f7cd2d4f84c9204fa4d6233f Mon Sep 17 00:00:00 2001 From: Petr Kulikov Date: Tue, 11 Dec 2018 16:06:51 +0100 Subject: [PATCH 01/10] Revised the division operator article (#9486) * Revised the division operator article * Addressed feedback --- .../CSharp/division-assignment-operator_1.cs | 17 ----- .../codesnippet/CSharp/division-operator_1.cs | 34 ---------- .../operators/division-assignment-operator.md | 66 +++++++++++-------- .../operators/division-operator.md | 57 ++++++++++------ 4 files changed, 73 insertions(+), 101 deletions(-) delete mode 100644 docs/csharp/language-reference/operators/codesnippet/CSharp/division-assignment-operator_1.cs delete mode 100644 docs/csharp/language-reference/operators/codesnippet/CSharp/division-operator_1.cs diff --git a/docs/csharp/language-reference/operators/codesnippet/CSharp/division-assignment-operator_1.cs b/docs/csharp/language-reference/operators/codesnippet/CSharp/division-assignment-operator_1.cs deleted file mode 100644 index 87df4a8209610..0000000000000 --- a/docs/csharp/language-reference/operators/codesnippet/CSharp/division-assignment-operator_1.cs +++ /dev/null @@ -1,17 +0,0 @@ - class MainClass2 - { - static void Main() - { - int a = 5; - a /= 6; - Console.WriteLine(a); - double b = 5; - b /= 6; - Console.WriteLine(b); - } - } - /* - Output: - 0 - 0.833333333333333 - */ \ No newline at end of file diff --git a/docs/csharp/language-reference/operators/codesnippet/CSharp/division-operator_1.cs b/docs/csharp/language-reference/operators/codesnippet/CSharp/division-operator_1.cs deleted file mode 100644 index e0eb5388edb24..0000000000000 --- a/docs/csharp/language-reference/operators/codesnippet/CSharp/division-operator_1.cs +++ /dev/null @@ -1,34 +0,0 @@ - class Division - { - static void Main() - { - Console.WriteLine("\nDividing 7 by 3."); - // Integer quotient is 2, remainder is 1. - Console.WriteLine("Integer quotient: {0}", 7 / 3); - Console.WriteLine("Negative integer quotient: {0}", -7 / 3); - Console.WriteLine("Remainder: {0}", 7 % 3); - // Force a floating point quotient. - float dividend = 7; - Console.WriteLine("Floating point quotient: {0}", dividend / 3); - - Console.WriteLine("\nDividing 8 by 5."); - // Integer quotient is 1, remainder is 3. - Console.WriteLine("Integer quotient: {0}", 8 / 5); - Console.WriteLine("Negative integer quotient: {0}", 8 / -5); - Console.WriteLine("Remainder: {0}", 8 % 5); - // Force a floating point quotient. - Console.WriteLine("Floating point quotient: {0}", 8 / 5.0); - } - } - // Output: - //Dividing 7 by 3. - //Integer quotient: 2 - //Negative integer quotient: -2 - //Remainder: 1 - //Floating point quotient: 2.33333333333333 - - //Dividing 8 by 5. - //Integer quotient: 1 - //Negative integer quotient: -1 - //Remainder: 3 - //Floating point quotient: 1.6 \ No newline at end of file diff --git a/docs/csharp/language-reference/operators/division-assignment-operator.md b/docs/csharp/language-reference/operators/division-assignment-operator.md index 905d69a07e9c3..df95c94244ab7 100644 --- a/docs/csharp/language-reference/operators/division-assignment-operator.md +++ b/docs/csharp/language-reference/operators/division-assignment-operator.md @@ -1,8 +1,7 @@ --- title: "/= Operator - C# Reference" ms.custom: seodec18 - -ms.date: 07/20/2015 +ms.date: 12/13/2018 f1_keywords: - "/=_CSharpKeyword" helpviewer_keywords: @@ -11,30 +10,39 @@ helpviewer_keywords: ms.assetid: 50fc02b0-ee9c-4c3e-b58d-d591282caf1c --- # /= Operator (C# Reference) -The division assignment operator. - -## Remarks - An expression using the `/=` assignment operator, such as - -```csharp -x /= y -``` - - is equivalent to - -```csharp -x = x / y -``` - - except that `x` is only evaluated once. The [/ operator](../../../csharp/language-reference/operators/division-operator.md) is predefined for numeric types to perform division. - - The `/=` operator cannot be overloaded directly, but user-defined types can overload the [/ operator](../../../csharp/language-reference/operators/division-operator.md) (see [operator](../../../csharp/language-reference/keywords/operator.md)). On all compound assignment operators, overloading the binary operator implicitly overloads the equivalent compound assignment. - -## Example - [!code-csharp[csRefOperators#5](codesnippet/CSharp/division-assignment-operator_1.cs)] - -## See Also - -- [C# Reference](../../../csharp/language-reference/index.md) -- [C# Programming Guide](../../../csharp/programming-guide/index.md) -- [C# Operators](../../../csharp/language-reference/operators/index.md) + +The division assignment operator. + +An expression using the `/=` operator, such as + +```csharp +x /= y +``` + +is equivalent to + +```csharp +x = x / y +``` + +except that `x` is only evaluated once. + +The [division operator](division-operator.md) `/` divides its first operand by its second operand. It's supported by all numeric types. + +The following example demonstrates the usage of the `/=` operator: + +[!code-csharp-interactive[divide and assign](~/samples/snippets/csharp/language-reference/operators/DivisionExamples.cs#DivisionAssignment)] + +## Operator overloadability + +If a user-defined type [overloads](../keywords/operator.md) the [division operator](division-operator.md) `/`, the division assignment operator `/=` is implicitly overloaded. A user-defined type cannot explicitly overload the division assignment operator. + +## C# language specification + +For more information, see the [Compound assignment](~/_csharplang/spec/expressions.md#compound-assignment) section of the [C# language specification](../language-specification/index.md). + +## See also + +- [C# Reference](../index.md) +- [C# Programming Guide](../../programming-guide/index.md) +- [C# Operators](index.md) diff --git a/docs/csharp/language-reference/operators/division-operator.md b/docs/csharp/language-reference/operators/division-operator.md index 05861c373715a..af19a0ddda4f2 100644 --- a/docs/csharp/language-reference/operators/division-operator.md +++ b/docs/csharp/language-reference/operators/division-operator.md @@ -1,8 +1,7 @@ --- title: "/ Operator - C# Reference" ms.custom: seodec18 - -ms.date: 04/04/2018 +ms.date: 12/13/2018 f1_keywords: - "/_CSharpKeyword" helpviewer_keywords: @@ -11,22 +10,38 @@ helpviewer_keywords: ms.assetid: d155e496-678f-4efa-bebe-2bd08da2c5af --- # / Operator (C# Reference) -The division operator (`/`) divides its first operand by its second operand. All numeric types have predefined division operators. - -## Remarks - User-defined types can overload the `/` operator (see [operator](../../../csharp/language-reference/keywords/operator.md)). An overload of the `/` operator implicitly overloads the [/= operator](division-assignment-operator.md). - - When you divide two integers, the result is always an integer. For example, the result of 7 / 3 is 2. This is not to be confused with floored division, as the `/` operator rounds towards zero: -7 / 3 is -2. - - To obtain a quotient as a rational number, use the `float`, `double`, or `decimal` types. There are many ways to convert between [built in numeric types](../../../csharp/language-reference/keywords/reference-tables-for-types.md). - - To determine the remainder, use the [remainder operator](../../../csharp/language-reference/operators/remainder-operator.md) `%`. - -## Example - [!code-csharp[csRefOperators#42](../../../csharp/language-reference/operators/codesnippet/CSharp/division-operator_1.cs)] - -## See Also - -- [C# Reference](../../../csharp/language-reference/index.md) -- [C# Programming Guide](../../../csharp/programming-guide/index.md) -- [C# Operators](../../../csharp/language-reference/operators/index.md) + +The division operator `/` divides its first operand by its second operand. All numeric types support the division operator. + +## Integer division + +For the operands of integer types, the result of the `/` operator is of an integer type and equals the quotient of the two operands rounded towards zero: + +[!code-csharp-interactive[integer division](~/samples/snippets/csharp/language-reference/operators/DivisionExamples.cs#Integer)] + +To obtain the quotient of the two operands as a floating-point number, use the `float`, `double`, or `decimal` type: + +[!code-csharp-interactive[integer as floating-point division](~/samples/snippets/csharp/language-reference/operators/DivisionExamples.cs#IntegerAsFloatingPoint)] + +## Floating-point division + +For the `float`, `double`, and `decimal` types, the result of the `/` operator is the quotient of the two operands: + +[!code-csharp-interactive[floating-point division](~/samples/snippets/csharp/language-reference/operators/DivisionExamples.cs#FloatingPoint)] + +If one of the operands is `decimal`, another operand can be neither `float` nor `double`, because neither `float` nor `double` is implicitly convertible to `decimal`. You must explicitly convert the `float` or `double` operand to the `decimal` type. For more information about implicit conversions between numeric types, see [Implicit numeric conversions table](../keywords/implicit-numeric-conversions-table.md). + +## Operator overloadability + +User-defined types can [overload](../keywords/operator.md) the `/` operator. When the `/` operator is overloaded, the [division assignment operator](division-assignment-operator.md) `/=` is also implicitly overloaded. + +## C# language specification + +For more information, see the [Division operator](~/_csharplang/spec/expressions.md#division-operator) section of the [C# language specification](../language-specification/index.md). + +## See also + +- [C# Reference](../index.md) +- [C# Programming Guide](../../programming-guide/index.md) +- [C# Operators](index.md) +- [% Operator](remainder-operator.md) From 63045a3e4a2da925c99652ff1b9ad4450ff0d511 Mon Sep 17 00:00:00 2001 From: Jonathan Markman Date: Tue, 11 Dec 2018 10:26:10 -0500 Subject: [PATCH 02/10] Quick fix: add iteration example to string literal indexing docs (#9524) * quick fix: add iteration example to string literal indexing docs * fixed the output comment as per @pkulikov --- docs/csharp/language-reference/keywords/string.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/docs/csharp/language-reference/keywords/string.md b/docs/csharp/language-reference/keywords/string.md index ea6edbe19c926..a8793e30a2c75 100644 --- a/docs/csharp/language-reference/keywords/string.md +++ b/docs/csharp/language-reference/keywords/string.md @@ -52,6 +52,18 @@ string str = "test"; char x = str[2]; // x = 's'; ``` +In similar fashion, the [] operator can also be used for iterating over each character in a `string`: + +```csharp +string str = "test"; + +for (int i = 0; i < str.Length; i++) +{ + Console.Write(str[i] + " "); +} +// Output: t e s t +``` + String literals are of type `string` and can be written in two forms, quoted and @-quoted. Quoted string literals are enclosed in double quotation marks ("): ```csharp From 4161d6697643d50d4a1d62ef3d1ef25ff901b485 Mon Sep 17 00:00:00 2001 From: Martin Koudelka <42440351+v-makoud@users.noreply.github.com> Date: Tue, 11 Dec 2018 16:27:08 +0100 Subject: [PATCH 03/10] CC86610: Fixing inline field name (#9541) Hello, @mairaw, @BillWagner, @mikeblome, This proposed file change comes from https://github.com/dotnet/docs.ja-jp/pull/182 . Could you review this contribution and help to merge if agreed? Many thanks in advance. --- docs/csharp/language-reference/keywords/class.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/csharp/language-reference/keywords/class.md b/docs/csharp/language-reference/keywords/class.md index 9ac067f9e1fc3..d983625738c09 100644 --- a/docs/csharp/language-reference/keywords/class.md +++ b/docs/csharp/language-reference/keywords/class.md @@ -89,7 +89,7 @@ Accessing private members of `Child` from `Main` would only be possible if `Main Types declared inside a class without an access modifier default to `private`, so the data members in this example would still be `private` if the keyword were removed. -Finally, notice that for the object created using the default constructor (`child3`), the age field was initialized to zero by default. +Finally, notice that for the object created using the default constructor (`child3`), the `age` field was initialized to zero by default. ## C# language specification From 244bc88c82c396b94679b9ab4ab57bfa2d655c1f Mon Sep 17 00:00:00 2001 From: Jensen Date: Tue, 11 Dec 2018 16:33:26 +0100 Subject: [PATCH 04/10] Fixes #9540 (#9544) --- .../programming-guide/classes-and-structs/polymorphism.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/csharp/programming-guide/classes-and-structs/polymorphism.md b/docs/csharp/programming-guide/classes-and-structs/polymorphism.md index 0ef3a20a4aa78..2b015bf9c7358 100644 --- a/docs/csharp/programming-guide/classes-and-structs/polymorphism.md +++ b/docs/csharp/programming-guide/classes-and-structs/polymorphism.md @@ -91,8 +91,7 @@ Polymorphism is often referred to as the third pillar of object-oriented program ## See Also -- [C# Programming Guide](../../../csharp/programming-guide/index.md) -- [C# Programming Guide](../../../csharp/programming-guide/index.md) +- [C# Programming Guide](../../../csharp/programming-guide/index.md) - [Inheritance](../../../csharp/programming-guide/classes-and-structs/inheritance.md) - [Abstract and Sealed Classes and Class Members](../../../csharp/programming-guide/classes-and-structs/abstract-and-sealed-classes-and-class-members.md) - [Methods](../../../csharp/programming-guide/classes-and-structs/methods.md) From 8349ea26494ea92964250abfab061e71fb669c42 Mon Sep 17 00:00:00 2001 From: Jensen Date: Tue, 11 Dec 2018 16:34:39 +0100 Subject: [PATCH 05/10] Fixes #9513 (#9545) --- docs/csharp/language-reference/keywords/delegate.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/csharp/language-reference/keywords/delegate.md b/docs/csharp/language-reference/keywords/delegate.md index 4401016ae3cab..a40be70512218 100644 --- a/docs/csharp/language-reference/keywords/delegate.md +++ b/docs/csharp/language-reference/keywords/delegate.md @@ -47,5 +47,6 @@ The delegate must be instantiated with a method or lambda expression that has a - [Reference Types](../../../csharp/language-reference/keywords/reference-types.md) - [Delegates](../../../csharp/programming-guide/delegates/index.md) - [Events](../../../csharp/programming-guide/events/index.md) -- [Delegates with Named vs. Anonymous Methods](../../../csharp/programming-guide/delegates/delegates-with-named-vs-anonymous-methods.md) +- [Delegates with Named vs. Anonymous Methods](../../../csharp/programming-guide/delegates/delegates-with-named-vs-anonymous-methods.md) - [Anonymous Methods](../../../csharp/programming-guide/statements-expressions-operators/anonymous-methods.md) +- [Lambda Expressions](../../../csharp/programming-guide/statements-expressions-operators/lambda-expressions.md) From 9185b8cfab72cfbf6a31c07de3e277761cc12d65 Mon Sep 17 00:00:00 2001 From: "kkm (aka Kirill Katsnelson)" Date: Tue, 11 Dec 2018 07:47:58 -0800 Subject: [PATCH 06/10] Fix capitalization of MSBuild (#9537) --- docs/core/tools/csproj.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/core/tools/csproj.md b/docs/core/tools/csproj.md index dba6615d68f58..1f9eadb76aa3f 100644 --- a/docs/core/tools/csproj.md +++ b/docs/core/tools/csproj.md @@ -173,7 +173,7 @@ The following example specifies the fallbacks only for the `netcoreapp2.1` targe ``` ## NuGet metadata properties -With the move to MSbuild, we have moved the input metadata that is used when packing a NuGet package from *project.json* to *.csproj* files. The inputs are MSBuild properties so they have to go within a `` group. The following is the list of properties that are used as inputs to the packing process when using the `dotnet pack` command or the `Pack` MSBuild target that is part of the SDK. +With the move to MSBuild, we have moved the input metadata that is used when packing a NuGet package from *project.json* to *.csproj* files. The inputs are MSBuild properties so they have to go within a `` group. The following is the list of properties that are used as inputs to the packing process when using the `dotnet pack` command or the `Pack` MSBuild target that is part of the SDK. ### IsPackable A Boolean value that specifies whether the project can be packed. The default value is `true`. From 3efcddfeffea91c9a282a63949e12c0501a253ff Mon Sep 17 00:00:00 2001 From: roger-cruz <45692830+roger-cruz@users.noreply.github.com> Date: Tue, 11 Dec 2018 10:49:47 -0500 Subject: [PATCH 07/10] Update fundamental-concepts.md (#9534) --- docs/framework/wcf/fundamental-concepts.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/framework/wcf/fundamental-concepts.md b/docs/framework/wcf/fundamental-concepts.md index f7ccd91be7ea2..fa7bc2a6baf7c 100644 --- a/docs/framework/wcf/fundamental-concepts.md +++ b/docs/framework/wcf/fundamental-concepts.md @@ -49,7 +49,7 @@ This document provides a high-level view of the Windows Communication Foundation A construct that exposes one or more endpoints, with each endpoint exposing one or more service operations. endpoint - A construct at which messages are sent or received (or both). It comprises a location (an address) that defines where messages can be sent, a specification of the communication mechanism (a binding) that described how messages should be sent, and a definition for a set of messages that can be sent or received (or both) at that location (a service contract) that describes what message can be sent. + A construct at which messages are sent or received (or both). It comprises a location (an address) that defines where messages can be sent, a specification of the communication mechanism (a binding) that describes how messages should be sent, and a definition for a set of messages that can be sent or received (or both) at that location (a service contract) that describes what message can be sent. A WCF service is exposed to the world as a collection of endpoints. From 5858989ce10d9db11ff3633c1cd3a42dfad91455 Mon Sep 17 00:00:00 2001 From: Mikkel Nylander Bundgaard Date: Tue, 11 Dec 2018 17:34:42 +0100 Subject: [PATCH 08/10] Remove wrong KB link (#9516) * Update how-to-set-environment-variables-for-the-visual-studio-command-line.md * Corrections requested in review * quick word change. --- ...nt-variables-for-the-visual-studio-command-line.md | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/docs/csharp/language-reference/compiler-options/how-to-set-environment-variables-for-the-visual-studio-command-line.md b/docs/csharp/language-reference/compiler-options/how-to-set-environment-variables-for-the-visual-studio-command-line.md index 07542b8eb6ae8..9d40f6a6001cc 100644 --- a/docs/csharp/language-reference/compiler-options/how-to-set-environment-variables-for-the-visual-studio-command-line.md +++ b/docs/csharp/language-reference/compiler-options/how-to-set-environment-variables-for-the-visual-studio-command-line.md @@ -18,7 +18,7 @@ ms.assetid: 7ec09480-5612-4f6a-8d00-ad90ea9bca5d --- # How to: Set Environment Variables for the Visual Studio Command Line -The VsDevCmd.bat file sets the appropriate environment variables to enable command-line builds. For more information about VsDevCmd.bat, see [Knowledge Base article Q248802](https://support.microsoft.com/help/248802/you-receive-the-out-of-environment-space-error-message-when-you-execut). +The VsDevCmd.bat file sets the appropriate environment variables to enable command-line builds. > [!NOTE] > The VsDevCmd.bat file is a new file delivered with Visual Studio 2017. Visual Studio 2015 and earlier versions used VSVARS32.bat for the same purpose. This file was stored in \Program Files\Microsoft Visual Studio\\*Version*\Common7\Tools or Program Files (x86)\Microsoft Visual Studio\\*Version*\Common7\Tools. @@ -35,7 +35,14 @@ If the current version of Visual Studio is installed on a computer that also has > [!CAUTION] > VsDevCmd.bat can vary from computer to computer. Do not replace a missing or damaged VsDevCmd.bat file with a VsDevCmd.bat from another computer. Instead, rerun setup to replace the missing file. - + +### Available options for VsDevCmd.BAT + +To see the available options for VsDevCmd.BAT, run the command with the `-help` option: +```console +VsDevCmd.bat -help +``` + ## See Also - [Command-line Building With csc.exe](../../../csharp/language-reference/compiler-options/command-line-building-with-csc-exe.md) From 8302c5b6074bb598cdd8038cef84f866e1f13622 Mon Sep 17 00:00:00 2001 From: Ron Petrusha Date: Tue, 11 Dec 2018 08:50:00 -0800 Subject: [PATCH 09/10] Added information on next Japanese calendar era (#9529) * Added information on next Japanese calendar era * Noted testing is for Windows only --- docs/standard/datetime/working-with-calendars.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/standard/datetime/working-with-calendars.md b/docs/standard/datetime/working-with-calendars.md index b615fc08eccfe..5a0604837a89b 100644 --- a/docs/standard/datetime/working-with-calendars.md +++ b/docs/standard/datetime/working-with-calendars.md @@ -131,6 +131,9 @@ However, there is one important exception. The default (uninitialized) value of Calendars typically divide dates into eras. However, the classes in .NET do not support every era defined by a calendar, and most of the classes support only a single era. Only the and classes support multiple eras. +> [!IMPORTANT] +> A new era in the and begins on May 1, 2019. This change affects all applications that use these calendars. See [Handling a new era in the Japanese calendar in .NET](https://blogs.msdn.microsoft.com/dotnet/2018/11/14/handling-a-new-era-in-the-japanese-calendar-in-net/) for more information and to determine whether your applications are affected. See [Prepare your application for the Japanese era change](~/windows/uwp/design/globalizing/japanese-era-change) for information on testing your applications on Windows to ensure their readiness for the era change. + ### Eras and era names In .NET, integers that represent the eras supported by a particular calendar implementation are stored in reverse order in the array. The current era is at index zero, and for classes that support multiple eras, each successive index reflects the previous era. The static property defines the index of the current era in the array; it is a constant whose value is always zero. Individual classes also include static fields that return the value of the current era. They are listed in the following table. From 954fdb771c7b5a2d70d4946ce9ead37f96dc3139 Mon Sep 17 00:00:00 2001 From: Phillip Carter Date: Tue, 11 Dec 2018 12:44:17 -0800 Subject: [PATCH 10/10] Update formatting based on feedback (#9549) https://github.com/dotnet/docs/issues/5552 https://github.com/fsprojects/fantomas/issues/372 --- docs/fsharp/style-guide/formatting.md | 96 ++++++++++++++++++--------- 1 file changed, 65 insertions(+), 31 deletions(-) diff --git a/docs/fsharp/style-guide/formatting.md b/docs/fsharp/style-guide/formatting.md index f925409ee7da0..23ab9486276d3 100644 --- a/docs/fsharp/style-guide/formatting.md +++ b/docs/fsharp/style-guide/formatting.md @@ -337,16 +337,23 @@ type PostalAddress = } ``` -Placing the opening token on the same line and the closing token on a new line is also fine, but be aware that you need to use the [verbose syntax](../language-reference/verbose-syntax.md) to define members (the `with` keyword): +Placing the opening token on a new line and the closing token on a new line is preferrable if you are declaring interface implementations or members on the record: ```fsharp -// OK, but verbose syntax required -type PostalAddress = { - Address: string - City: string - Zip: string -} with +// Declaring additional members on PostalAddress +type PostalAddress = + { + Address: string + City: string + Zip: string + } with member x.ZipAndCity = sprintf "%s %s" x.Zip x.City + +type MyRecord = + { + SomeField : int + } + interface IMyInterface ``` ## Formatting records @@ -365,27 +372,51 @@ let rainbow = Lackeys = ["Zippy"; "George"; "Bungle"] } ``` -Placing the opening token on the same line and the closing token on a new line is also fine: +Placing the opening token on a new line, the contents tabbed over one scope, and the closing token on a new line is preferrable if you are: + +* Moving records around in code with different indentation scopes +* Piping them into a function ```fsharp -let rainbow = { - Boss1 = "Jeffrey" - Boss2 = "Jeffrey" - Boss3 = "Jeffrey" - Boss4 = "Jeffrey" - Boss5 = "Jeffrey" - Boss6 = "Jeffrey" - Boss7 = "Jeffrey" - Boss8 = "Jeffrey" - Lackeys = ["Zippy"; "George"; "Bungle"] -} +let rainbow = + { + Boss1 = "Jeffrey" + Boss2 = "Jeffrey" + Boss3 = "Jeffrey" + Boss4 = "Jeffrey" + Boss5 = "Jeffrey" + Boss6 = "Jeffrey" + Boss7 = "Jeffrey" + Boss8 = "Jeffrey" + Lackeys = ["Zippy"; "George"; "Bungle"] + } + +type MyRecord = + { + SomeField : int + } + interface IMyInterface + +let foo a = + a + |> Option.map (fun x -> + { + MyField = x + }) ``` The same rules apply for list and array elements. ## Formatting lists and arrays -Write `x :: l` with spaces around the `::` operator (`::` is an infix operator, hence surrounded by spaces) and `[1; 2; 3]` (`;` is a delimiter, hence followed by a space). +Write `x :: l` with spaces around the `::` operator (`::` is an infix operator, hence surrounded by spaces). + +List and arrays declared on a single line should have a space after the opening bracket and before the closing bracket: + +```fsharp +let xs = [ 1; 2; 3 ] +let ys = [| 1; 2; 3; |] +``` Always use at least one space between two distinct brace-like operators. For example, leave a space between a `[` and a `{`. @@ -408,19 +439,22 @@ Always use at least one space between two distinct brace-like operators. For exa Lists and arrays that split across multiple lines follow a similar rule as records do: ```fsharp -let pascalsTriangle = [| - [|1|] - [|1; 1|] - [|1; 2; 1|] - [|1; 3; 3; 1|] - [|1; 4; 6; 4; 1|] - [|1; 5; 10; 10; 5; 1|] - [|1; 6; 15; 20; 15; 6; 1|] - [|1; 7; 21; 35; 35; 21; 7; 1|] - [|1; 8; 28; 56; 70; 56; 28; 8; 1|] -|] +let pascalsTriangle = + [| + [|1|] + [|1; 1|] + [|1; 2; 1|] + [|1; 3; 3; 1|] + [|1; 4; 6; 4; 1|] + [|1; 5; 10; 10; 5; 1|] + [|1; 6; 15; 20; 15; 6; 1|] + [|1; 7; 21; 35; 35; 21; 7; 1|] + [|1; 8; 28; 56; 70; 56; 28; 8; 1|] + |] ``` +And as with records, declaring the opening and closing brackets on their own line will make moving code around and piping into functions easier. + ## Formatting if expressions Indentation of conditionals depends on the sizes of the expressions that make them up. If `cond`, `e1` and `e2` are short, simply write them on one line: