From d8db3bc7e7157dbbdf74a4d26b6e4fe8208b3d2a Mon Sep 17 00:00:00 2001 From: Petr Kulikov Date: Sat, 24 Nov 2018 19:05:18 +0100 Subject: [PATCH 1/6] Value types: explicitly mention char --- .../keywords/value-types.md | 76 ++++++++++--------- 1 file changed, 40 insertions(+), 36 deletions(-) diff --git a/docs/csharp/language-reference/keywords/value-types.md b/docs/csharp/language-reference/keywords/value-types.md index 0e975df483de7..afca51086a80e 100644 --- a/docs/csharp/language-reference/keywords/value-types.md +++ b/docs/csharp/language-reference/keywords/value-types.md @@ -1,5 +1,5 @@ --- -title: "Value Types (C# Reference)" +title: "Value types (C# Reference)" ms.date: 07/20/2015 f1_keywords: - "cs.valuetypes" @@ -9,26 +9,28 @@ helpviewer_keywords: - "C# language, value types" ms.assetid: 471eb994-2958-49d5-a6be-19b4313f80a3 --- -# Value Types (C# Reference) -The value types consist of two main categories: - -- [Structs](../../../csharp/language-reference/keywords/struct.md) - -- [Enumerations](../../../csharp/language-reference/keywords/enum.md) - - Structs fall into these categories: - -- Numeric types - - - [Integral types](../../../csharp/language-reference/keywords/integral-types-table.md) - - - [Floating-point types](../../../csharp/language-reference/keywords/floating-point-types-table.md) - -- [bool](../../../csharp/language-reference/keywords/bool.md) - -- User defined structs. +# Value types (C# Reference) + +The value types consist of two main categories: + +- [Structs](struct.md) + +- [Enumerations](enum.md) + + Structs fall into these categories: + +- Numeric types and [char](char.md) + + - [Integral types](integral-types-table.md) (including the [char](char.md) type) + + - [Floating-point types](floating-point-types-table.md) + +- [bool](bool.md) + +- User-defined structs. -## Main Features of Value Types +## Main features of value types + Variables that are based on value types directly contain values. Assigning one value type variable to another copies the contained value. This differs from the assignment of reference type variables, which copies a reference to the object but not the object itself. All value types are derived implicitly from the . @@ -37,16 +39,18 @@ The value types consist of two main categories: Unlike reference types, a value type cannot contain the `null` value. However, the [nullable types](../../../csharp/programming-guide/nullable-types/index.md) feature does allow for value types to be assigned to `null`. - Each value type has an implicit default constructor that initializes the default value of that type. For information about default values of value types, see [Default Values Table](../../../csharp/language-reference/keywords/default-values-table.md). + Each value type has an implicit default constructor that initializes the default value of that type. For information about default values of value types, see [Default values table](../../../csharp/language-reference/keywords/default-values-table.md). -## Main Features of Simple Types - All of the simple types -- those integral to the C# language -- are aliases of the .NET Framework System types. For example, [int](../../../csharp/language-reference/keywords/int.md) is an alias of . For a complete list of aliases, see [Built-In Types Table](../../../csharp/language-reference/keywords/built-in-types-table.md). +## Main features of simple types + + All of the simple types -- those integral to the C# language -- are aliases of the .NET types. For example, [int](int.md) is an alias of . For a complete list of aliases, see [Built-in types table](../../../csharp/language-reference/keywords/built-in-types-table.md). Constant expressions, whose operands are all simple type constants, are evaluated at compilation time. - Simple types can be initialized by using literals. For example, 'A' is a literal of the type `char` and 2001 is a literal of the type `int`. + Simple types can be initialized by using literals. For example, `'A'` is a literal of the type `char` and `2001` is a literal of the type `int`. -## Initializing Value Types +## Initializing value types + Local variables in C# must be initialized before they are used. For example, you might declare a local variable without initialization as in the following example: ```csharp @@ -77,9 +81,9 @@ int myInt = new int(); int myInt = 0; ``` - Using the [new](../../../csharp/language-reference/keywords/new.md) operator calls the default constructor of the specific type and assigns the default value to the variable. In the preceding example, the default constructor assigned the value `0` to `myInt`. For more information about values assigned by calling default constructors, see [Default Values Table](../../../csharp/language-reference/keywords/default-values-table.md). + Using the [new](new.md) operator calls the default constructor of the specific type and assigns the default value to the variable. In the preceding example, the default constructor assigned the value `0` to `myInt`. For more information about values assigned by calling default constructors, see [Default values table](default-values-table.md). - With user-defined types, use [new](../../../csharp/language-reference/keywords/new.md) to invoke the default constructor. For example, the following statement invokes the default constructor of the `Point` struct: + With user-defined types, use [new](new.md) to invoke the default constructor. For example, the following statement invokes the default constructor of the `Point` struct: ```csharp Point p = new Point(); // Invoke default constructor for the struct. @@ -87,16 +91,16 @@ Point p = new Point(); // Invoke default constructor for the struct. After this call, the struct is considered to be definitely assigned; that is, all its members are initialized to their default values. - For more information about the new operator, see [new](../../../csharp/language-reference/keywords/new.md). + For more information about the `new` operator, see [new](new.md). - For information about formatting the output of numeric types, see [Formatting Numeric Results Table](../../../csharp/language-reference/keywords/formatting-numeric-results-table.md). + For information about formatting the output of numeric types, see [Formatting numeric results table](formatting-numeric-results-table.md). -## See Also +## See also -- [C# Reference](../../../csharp/language-reference/index.md) -- [C# Programming Guide](../../../csharp/programming-guide/index.md) -- [C# Keywords](../../../csharp/language-reference/keywords/index.md) -- [Types](../../../csharp/language-reference/keywords/types.md) -- [Reference Tables for Types](../../../csharp/language-reference/keywords/reference-tables-for-types.md) -- [Reference Types](../../../csharp/language-reference/keywords/reference-types.md) +- [C# Reference](../index.md) +- [C# Programming Guide](../../programming-guide/index.md) +- [C# Keywords](index.md) +- [Types](types.md) +- [Reference tables for types](reference-tables-for-types.md) +- [Reference Types](reference-types.md) - [Nullable types](../../programming-guide/nullable-types/index.md) From 69195a3bd759a52df9b2c516893121a1b2006953 Mon Sep 17 00:00:00 2001 From: Petr Kulikov Date: Sat, 24 Nov 2018 19:09:28 +0100 Subject: [PATCH 2/6] More links simplified --- docs/csharp/language-reference/keywords/value-types.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/csharp/language-reference/keywords/value-types.md b/docs/csharp/language-reference/keywords/value-types.md index afca51086a80e..277fbc4bd1a7d 100644 --- a/docs/csharp/language-reference/keywords/value-types.md +++ b/docs/csharp/language-reference/keywords/value-types.md @@ -39,11 +39,11 @@ The value types consist of two main categories: Unlike reference types, a value type cannot contain the `null` value. However, the [nullable types](../../../csharp/programming-guide/nullable-types/index.md) feature does allow for value types to be assigned to `null`. - Each value type has an implicit default constructor that initializes the default value of that type. For information about default values of value types, see [Default values table](../../../csharp/language-reference/keywords/default-values-table.md). + Each value type has an implicit default constructor that initializes the default value of that type. For information about default values of value types, see [Default values table](default-values-table.md). ## Main features of simple types - All of the simple types -- those integral to the C# language -- are aliases of the .NET types. For example, [int](int.md) is an alias of . For a complete list of aliases, see [Built-in types table](../../../csharp/language-reference/keywords/built-in-types-table.md). + All of the simple types -- those integral to the C# language -- are aliases of the .NET types. For example, [int](int.md) is an alias of . For a complete list of aliases, see [Built-in types table](built-in-types-table.md). Constant expressions, whose operands are all simple type constants, are evaluated at compilation time. From 1b3449e353f6faecf3e991c3d27a284cdb62d051 Mon Sep 17 00:00:00 2001 From: Petr Kulikov Date: Sun, 25 Nov 2018 20:37:37 +0100 Subject: [PATCH 3/6] Rework struct categorization --- .../keywords/value-types.md | 37 +++++++++---------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/docs/csharp/language-reference/keywords/value-types.md b/docs/csharp/language-reference/keywords/value-types.md index 277fbc4bd1a7d..58d902df08d5c 100644 --- a/docs/csharp/language-reference/keywords/value-types.md +++ b/docs/csharp/language-reference/keywords/value-types.md @@ -1,6 +1,6 @@ --- title: "Value types (C# Reference)" -ms.date: 07/20/2015 +ms.date: 11/26/2018 f1_keywords: - "cs.valuetypes" helpviewer_keywords: @@ -16,19 +16,7 @@ The value types consist of two main categories: - [Structs](struct.md) - [Enumerations](enum.md) - - Structs fall into these categories: -- Numeric types and [char](char.md) - - - [Integral types](integral-types-table.md) (including the [char](char.md) type) - - - [Floating-point types](floating-point-types-table.md) - -- [bool](bool.md) - -- User-defined structs. - ## Main features of value types Variables that are based on value types directly contain values. Assigning one value type variable to another copies the contained value. This differs from the assignment of reference type variables, which copies a reference to the object but not the object itself. @@ -41,13 +29,24 @@ The value types consist of two main categories: Each value type has an implicit default constructor that initializes the default value of that type. For information about default values of value types, see [Default values table](default-values-table.md). -## Main features of simple types +## Simple types - All of the simple types -- those integral to the C# language -- are aliases of the .NET types. For example, [int](int.md) is an alias of . For a complete list of aliases, see [Built-in types table](built-in-types-table.md). - - Constant expressions, whose operands are all simple type constants, are evaluated at compilation time. - - Simple types can be initialized by using literals. For example, `'A'` is a literal of the type `char` and `2001` is a literal of the type `int`. +The *simple types* are a set of predefined struct types provided by C# and comprise the following types: + +- [Integral types](integral-types-table.md): integer numeric types and the [char](char.md) type +- [Floating-point types](floating-point-types-table.md) +- [bool](bool.md) + +The simple types are identified through keywords, but these keywords are simply aliases for predefined struct types in the +namespace. For example, [int](int.md) is an alias of . For a complete list of aliases, see [Built-in types table](built-in-types-table.md). + +The simple types differ from other struct types in that they permit certain additional operations: + +- Simple types can be initialized by using literals. For example, `'A'` is a literal of the type `char` and `2001` is a literal of the type `int`. + +- You can declare constants of the simple types with the [const](const.md) keyword. It's not possible to have constants of other struct types. + +- Constant expressions, whose operands are all simple type constants, are evaluated at compile time. ## Initializing value types From 2255293459de4c01daafd8cfa1f2dc344dc49656 Mon Sep 17 00:00:00 2001 From: Petr Kulikov Date: Sun, 25 Nov 2018 20:38:32 +0100 Subject: [PATCH 4/6] Remove a line break --- docs/csharp/language-reference/keywords/value-types.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/csharp/language-reference/keywords/value-types.md b/docs/csharp/language-reference/keywords/value-types.md index 58d902df08d5c..658da6d6f2cee 100644 --- a/docs/csharp/language-reference/keywords/value-types.md +++ b/docs/csharp/language-reference/keywords/value-types.md @@ -37,8 +37,7 @@ The *simple types* are a set of predefined struct types provided by C# and compr - [Floating-point types](floating-point-types-table.md) - [bool](bool.md) -The simple types are identified through keywords, but these keywords are simply aliases for predefined struct types in the -namespace. For example, [int](int.md) is an alias of . For a complete list of aliases, see [Built-in types table](built-in-types-table.md). +The simple types are identified through keywords, but these keywords are simply aliases for predefined struct types in the namespace. For example, [int](int.md) is an alias of . For a complete list of aliases, see [Built-in types table](built-in-types-table.md). The simple types differ from other struct types in that they permit certain additional operations: From c6d939304446c4e156c3570dd5f95531e97c9fbe Mon Sep 17 00:00:00 2001 From: Petr Kulikov Date: Sun, 25 Nov 2018 20:51:42 +0100 Subject: [PATCH 5/6] Added link to the C# spec --- docs/csharp/language-reference/keywords/value-types.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/csharp/language-reference/keywords/value-types.md b/docs/csharp/language-reference/keywords/value-types.md index 658da6d6f2cee..4b588b3988dc4 100644 --- a/docs/csharp/language-reference/keywords/value-types.md +++ b/docs/csharp/language-reference/keywords/value-types.md @@ -46,6 +46,8 @@ The simple types differ from other struct types in that they permit certain addi - You can declare constants of the simple types with the [const](const.md) keyword. It's not possible to have constants of other struct types. - Constant expressions, whose operands are all simple type constants, are evaluated at compile time. + +For more information, see the [Simple types](~/_csharplang/spec/types.md#simple-types) section of the [C# language specification](../language-specification/index.md). ## Initializing value types From f15fc4db3d7b05a58dbf3f03cb1f1aa6de537db4 Mon Sep 17 00:00:00 2001 From: Petr Kulikov Date: Sun, 25 Nov 2018 23:24:43 +0100 Subject: [PATCH 6/6] Addressed feedback --- .../language-reference/keywords/value-types.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/docs/csharp/language-reference/keywords/value-types.md b/docs/csharp/language-reference/keywords/value-types.md index 4b588b3988dc4..e5a2f1a3f8d16 100644 --- a/docs/csharp/language-reference/keywords/value-types.md +++ b/docs/csharp/language-reference/keywords/value-types.md @@ -11,7 +11,7 @@ ms.assetid: 471eb994-2958-49d5-a6be-19b4313f80a3 --- # Value types (C# Reference) -The value types consist of two main categories: +There are two kinds of value types: - [Structs](struct.md) @@ -19,15 +19,15 @@ The value types consist of two main categories: ## Main features of value types - Variables that are based on value types directly contain values. Assigning one value type variable to another copies the contained value. This differs from the assignment of reference type variables, which copies a reference to the object but not the object itself. - - All value types are derived implicitly from the . +A variable of a value type contains a value of the type. For example, a variable of the `int` type might contain the value `42`. This differs from a variable of a reference type, which contains a reference to an instance of the type, also known as an object. When you assign a new value to a variable of a value type, that value is copied. When you assign a new value to a variable of a reference type, the reference is copied, not the object itself. + +All value types are derived implicitly from the . - Unlike with reference types, you cannot derive a new type from a value type. However, like reference types, structs can implement interfaces. +Unlike with reference types, you cannot derive a new type from a value type. However, like reference types, structs can implement interfaces. - Unlike reference types, a value type cannot contain the `null` value. However, the [nullable types](../../../csharp/programming-guide/nullable-types/index.md) feature does allow for value types to be assigned to `null`. +Value type variables cannot be `null` by default. However, variables of the corresponding [nullable types](../../../csharp/programming-guide/nullable-types/index.md) can be `null`. - Each value type has an implicit default constructor that initializes the default value of that type. For information about default values of value types, see [Default values table](default-values-table.md). +Each value type has an implicit default constructor that initializes the default value of that type. For information about default values of value types, see [Default values table](default-values-table.md). ## Simple types