Trim spaces (#9777)
This commit is contained in:
Родитель
501785d899
Коммит
05abaf3118
|
@ -1,4 +1,4 @@
|
|||
### YamlMime:XRefMap
|
||||
### YamlMime:XRefMap
|
||||
hrefUpdated: true
|
||||
references:
|
||||
- uid: System.Xml.Linq.XElement.Elements*
|
||||
|
@ -300,7 +300,7 @@ references:
|
|||
name: OvalShape
|
||||
name.vb: OvalShape
|
||||
fullName: Microsoft.VisualBasic.PowerPacks.OvalShape
|
||||
fullName.vb: Microsoft.VisualBasic.PowerPacks.OvalShape
|
||||
fullName.vb: Microsoft.VisualBasic.PowerPacks.OvalShape
|
||||
- uid: Microsoft.VisualBasic.PowerPacks.Printing
|
||||
href: https://msdn.microsoft.com/library/microsoft.visualbasic.powerpacks.printing.aspx
|
||||
name: Microsoft.VisualBasic.PowerPacks.Printing
|
||||
|
@ -516,7 +516,7 @@ references:
|
|||
name: SetIsVirtualizing
|
||||
name.vb: SetIsVirtualizing
|
||||
fullName: VirtualizingStackPanel.SetIsVirtualizing
|
||||
fullName.vb: VirtualizingStackPanel.SetIsVirtualizing
|
||||
fullName.vb: VirtualizingStackPanel.SetIsVirtualizing
|
||||
- uid: System.Windows.Localization.Attributes*
|
||||
href: https://msdn.microsoft.com/library/system.windows.localization.attributes.aspx
|
||||
name: Attributes
|
||||
|
@ -546,7 +546,7 @@ references:
|
|||
name: IsVisualHostMaterial
|
||||
name.vb: IsVisualHostMaterial
|
||||
fullName: Viewport2DVisual3D.IsVisualHostMaterial
|
||||
fullName.vb: TimeViewport2DVisual3Dline.IsVisualHostMaterial
|
||||
fullName.vb: TimeViewport2DVisual3Dline.IsVisualHostMaterial
|
||||
- uid: System.Windows.Navigation.BaseUriHelper.BaseUri*
|
||||
href: https://msdn.microsoft.com/library/system.windows.navigation.baseurihelper.baseuri.aspx
|
||||
name: BaseUri
|
||||
|
@ -600,4 +600,4 @@ references:
|
|||
name: XlRangeAutoFormat
|
||||
name.vb: XlRangeAutoFormat
|
||||
fullName: Microsoft.Office.Interop.Excel.XlRangeAutoFormat
|
||||
fullName.vb: Microsoft.Office.Interop.Excel.XlRangeAutoFormat
|
||||
fullName.vb: Microsoft.Office.Interop.Excel.XlRangeAutoFormat
|
||||
|
|
|
@ -16,7 +16,7 @@ install:
|
|||
build_script:
|
||||
# dotnet info
|
||||
- ps: dotnet --info
|
||||
# Run dotnet new
|
||||
# Run dotnet new
|
||||
- ps: mkdir "test\test-dotnet-new" -Force | Push-Location
|
||||
- ps: dotnet new console -lang f#
|
||||
- ps: dotnet restore
|
||||
|
@ -25,5 +25,5 @@ build_script:
|
|||
- ps: Pop-Location
|
||||
|
||||
|
||||
test: off
|
||||
test: off
|
||||
version: 0.0.1.{build}
|
||||
|
|
|
@ -27,7 +27,7 @@ items:
|
|||
Console.WriteLine("The answer is greater than 10.");
|
||||
```
|
||||
|
||||
Modify the declaration of `b` so that the sum is less than 10:
|
||||
Modify the declaration of `b` so that the sum is less than 10:
|
||||
|
||||
```csharp
|
||||
int b = 3;
|
||||
|
@ -42,9 +42,9 @@ items:
|
|||
> find those errors and report them to you. When the output
|
||||
> contains error messages, look closely at the example code,
|
||||
> and the code in the interactive window to see what to fix.
|
||||
> That exercise will help you learn the structure of C# code.
|
||||
> That exercise will help you learn the structure of C# code.
|
||||
|
||||
This first sample shows the power of `if` and boolean types. A *boolean* is a variable that can have one of two values: `true` or `false`. C# defines a special type, `bool` for boolean variables. The `if` statement checks the value of a `bool`. When the value is `true`, the statement following the `if` executes. Otherwise, it is skipped.
|
||||
This first sample shows the power of `if` and boolean types. A *boolean* is a variable that can have one of two values: `true` or `false`. C# defines a special type, `bool` for boolean variables. The `if` statement checks the value of a `bool`. When the value is `true`, the statement following the `if` executes. Otherwise, it is skipped.
|
||||
|
||||
This process of checking conditions and executing statements based on those conditions is very powerful. Let's explore more.
|
||||
|
||||
|
@ -54,8 +54,8 @@ items:
|
|||
- title: Make if and else work together
|
||||
durationInMinutes: 10
|
||||
content: |
|
||||
|
||||
To execute different code in both the true and false branches, you
|
||||
|
||||
To execute different code in both the true and false branches, you
|
||||
create an `else` branch that executes when the condition is false. Try this:
|
||||
|
||||
```csharp
|
||||
|
@ -68,10 +68,10 @@ items:
|
|||
```
|
||||
|
||||
The statement following the `else` keyword executes only when the condition being tested is `false`. Combining `if` and `else` with boolean conditions provides all the power you need.
|
||||
|
||||
|
||||
> [!IMPORTANT]
|
||||
> The indentation under the `if` and `else` statements is for human readers.
|
||||
> The C# language doesn't treat indentation or white space as significant.
|
||||
> The C# language doesn't treat indentation or white space as significant.
|
||||
> The statement following the `if` or `else` keyword will be executed based
|
||||
> on the condition. All the samples in this tutorial follow a common
|
||||
> practice to indent lines based on the control flow of statements.
|
||||
|
@ -116,11 +116,11 @@ items:
|
|||
Console.WriteLine("Or the first number is not greater than the second");
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
The `&&` represents "and". It means both conditions must be true to execute
|
||||
the statement in the true branch. These examples also show that you can have multiple
|
||||
statements in each conditional branch, provided you enclose them in `{` and `}`.
|
||||
|
||||
|
||||
You can also use `||` to represent "or":
|
||||
|
||||
```csharp
|
||||
|
@ -174,7 +174,7 @@ items:
|
|||
> code will time out and you'll see no output from your program.
|
||||
|
||||
The `while` loop tests the condition before executing the code
|
||||
following the `while`. The `do` ... `while` loop executes the
|
||||
following the `while`. The `do` ... `while` loop executes the
|
||||
code first, and then checks the condition. It looks like this:
|
||||
|
||||
```csharp
|
||||
|
@ -185,9 +185,9 @@ items:
|
|||
counter++;
|
||||
} while (counter < 10);
|
||||
```
|
||||
|
||||
This `do` loop and the earlier `while` loop work the same.
|
||||
|
||||
|
||||
This `do` loop and the earlier `while` loop work the same.
|
||||
|
||||
Let's move on to one last loop statement.
|
||||
|
||||
> [!NOTE]
|
||||
|
@ -203,12 +203,12 @@ items:
|
|||
for(int counter = 0; counter < 10; counter++)
|
||||
{
|
||||
Console.WriteLine($"Hello World! The counter is {counter}");
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
This does the same work as the `while` loop and the `do` loop you've
|
||||
already used. The `for` statement has three parts that control
|
||||
how it works.
|
||||
how it works.
|
||||
|
||||
The first part is the **for initializer**: `int counter = 0;` declares
|
||||
that `counter` is the loop variable, and sets its initial value to `0`.
|
||||
|
@ -238,7 +238,7 @@ items:
|
|||
constructs in the C# language, see if you can write C# code to
|
||||
find the sum of all integers 1 through 20 that are divisible
|
||||
by 3. Here are a few hints:
|
||||
|
||||
|
||||
- The `%` operator gives you the remainder of a division operation.
|
||||
- The `if` statement gives you the condition to see if a number should be part of the sum.
|
||||
- The `for` loop can help you repeat a series of steps for all the numbers 1 through 20.
|
||||
|
@ -271,7 +271,7 @@ items:
|
|||
- title: Congratulations!
|
||||
content: |
|
||||
You've completed the "branches and loops" interactive tutorial. You can click the **Interpolated strings** link below to start the next interactive tutorial, or you can visit the [.NET site](https://www.microsoft.com/net/learn/dotnet/hello-world-tutorial) to download the .NET Core SDK, create a project on your machine, and keep coding. The "Keep Learning" step brings you back to these tutorials.
|
||||
|
||||
|
||||
You can learn more about these concepts in these topics:
|
||||
|
||||
- [If and else statement](../../language-reference/keywords/if-else.md)
|
||||
|
|
|
@ -26,7 +26,7 @@ items:
|
|||
|
||||
Congratulations! You've run your first C# program. It's a simple program that prints the message "Hello World!". It used the <xref:System.Console.WriteLine%2A?displayProperty=nameWithType> method to print that message. `Console` is a type that represents the console window. `WriteLine` is a method of the `Console` type that prints a line of text to that text console.
|
||||
|
||||
Let's move on and explore more. The rest of this lesson explores working with the `string` type, which represents text in C#. Like the `Console` type, the `string` type has methods. The `string` methods work with text.
|
||||
Let's move on and explore more. The rest of this lesson explores working with the `string` type, which represents text in C#. Like the `Console` type, the `string` type has methods. The `string` methods work with text.
|
||||
|
||||
> [!NOTE]
|
||||
> This online coding experience is in preview mode. If you encounter problems, please report them [on the dotnet/try repo](https://github.com/dotnet/try/issues).
|
||||
|
@ -35,15 +35,15 @@ items:
|
|||
durationInMinutes: 3
|
||||
content: |
|
||||
Your first program printed the `string` "Hello World!" on
|
||||
the screen.
|
||||
|
||||
the screen.
|
||||
|
||||
> [!TIP]
|
||||
> As you explore C# (or any programming language), you'll
|
||||
> make mistakes when you write code. The **compiler** will
|
||||
> find those errors and report them to you. When the output
|
||||
> contains error messages, look closely at the example code,
|
||||
> and the code in the interactive window to see what to fix.
|
||||
> That exercise will help you learn the structure of C# code.
|
||||
> That exercise will help you learn the structure of C# code.
|
||||
|
||||
Your first program is limited to printing one message. You can write more
|
||||
useful programs by using **variables**. A **variable** is a symbol you can
|
||||
|
@ -81,7 +81,7 @@ items:
|
|||
|
||||
You've been using `+` to build strings from **variables** and **constant** strings. There's a better way.
|
||||
You can place a variable between `{` and `}` characters to tell C# to replace that text with the value of the variable.
|
||||
|
||||
|
||||
This is called [String interpolation](../../language-reference/tokens/interpolated.md).
|
||||
|
||||
If you add a `$` before the opening quote of the string, you can then include variables, like `aFriend`, inside the string between curly braces. Give it a try:
|
||||
|
@ -129,8 +129,8 @@ items:
|
|||
- title: Do more with strings
|
||||
durationInMinutes: 5
|
||||
content: |
|
||||
You've been using a **method**, <xref:System.Console.WriteLine%2A?displayProperty=nameWithType>, to print messages. A **method** is a block of code that implements some action. It has a name, so you can access it.
|
||||
|
||||
You've been using a **method**, <xref:System.Console.WriteLine%2A?displayProperty=nameWithType>, to print messages. A **method** is a block of code that implements some action. It has a name, so you can access it.
|
||||
|
||||
Suppose your strings have leading or trailing spaces that you don't want to display. You want to **trim** the spaces from the strings.
|
||||
The <xref:System.String.Trim%2A> method and related methods <xref:System.String.TrimStart%2A> and <xref:System.String.TrimEnd%2A> do that work. You can just use those methods to remove leading and trailing spaces. Try the following code:
|
||||
|
||||
|
@ -198,7 +198,7 @@ items:
|
|||
> Watch your punctuation when you test for the text at the end of the string. If the string
|
||||
> ends with a period, you must check for a string that ends with a period.
|
||||
|
||||
You should get `true` for starting with "You" and ending with "hello" and false for starting with or ending with "goodbye".
|
||||
You should get `true` for starting with "You" and ending with "hello" and false for starting with or ending with "goodbye".
|
||||
|
||||
> [!NOTE]
|
||||
> This online coding experience is in preview mode. If you encounter problems, please report them [on the dotnet/try repo](https://github.com/dotnet/try/issues).
|
||||
|
@ -219,10 +219,10 @@ items:
|
|||
|
||||
> [!NOTE]
|
||||
> This online coding experience is in preview mode. If you encounter problems, please report them [on the dotnet/try repo](https://github.com/dotnet/try/issues).
|
||||
|
||||
|
||||
- content: |
|
||||
You've completed the "Hello C#" introduction to C# tutorial. You can click the **Numbers in C#** link below to start the next interactive tutorial, or you can visit the [.NET site](https://www.microsoft.com/net/learn/dotnet/hello-world-tutorial) to download the .NET Core SDK, create a project on your machine, and keep coding. The "Keep Learning" step brings you back to these tutorials.
|
||||
|
||||
For further reading on the `string` type:
|
||||
- [C# Programming Guide](../../programming-guide/index.md) topic on [strings](../../programming-guide/strings/index.md).
|
||||
- [C# Programming Guide](../../programming-guide/index.md) topic on [strings](../../programming-guide/strings/index.md).
|
||||
- [How to tips on working with strings](../../how-to/index.md#working-with-strings).
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
### YamlMime:Tutorial
|
||||
title: Use string interpolation to construct formatted strings
|
||||
title: Use string interpolation to construct formatted strings
|
||||
metadata:
|
||||
title: String interpolation - C# interactive tutorial
|
||||
title: String interpolation - C# interactive tutorial
|
||||
description: In this tutorial, you use your browser to explore the C# string interpolation feature interactively. You write C# code and see the results of compiling and running your code directly in the browser.
|
||||
audience: Developer
|
||||
ms.custom: mvc
|
||||
|
@ -25,33 +25,33 @@ items:
|
|||
Console.WriteLine($"Hello, {name}. It's a pleasure to meet you!");
|
||||
```
|
||||
|
||||
When you run the code, **Output** displays a string that includes your name in the greeting. The string argument of the <xref:System.Console.WriteLine%2A> method call is an *interpolated string*. It's a kind of template that lets you construct a single string (called the *result string*) from a string that includes embedded code. Interpolated strings are particularly useful for inserting values into a string or concatenating (joining together) several strings.
|
||||
|
||||
The example above contains the two elements that every interpolated string must have:
|
||||
When you run the code, **Output** displays a string that includes your name in the greeting. The string argument of the <xref:System.Console.WriteLine%2A> method call is an *interpolated string*. It's a kind of template that lets you construct a single string (called the *result string*) from a string that includes embedded code. Interpolated strings are particularly useful for inserting values into a string or concatenating (joining together) several strings.
|
||||
|
||||
- A string literal that begins with the `$` character before its opening quotation mark character. There can't be any spaces between the `$` symbol and the quotation mark character. (If you'd like to see what happens if you include one, insert a space after the `$` character in the interactive window and run the updated code. The C# compiler complains, "Unexpected character '$'".)
|
||||
The example above contains the two elements that every interpolated string must have:
|
||||
|
||||
- One or more *interpolated expressions*. An interpolated expression is indicated by an opening and closing brace (`{` and `}`). You can put any C# expression that returns a value (including `null`) inside the braces.
|
||||
- A string literal that begins with the `$` character before its opening quotation mark character. There can't be any spaces between the `$` symbol and the quotation mark character. (If you'd like to see what happens if you include one, insert a space after the `$` character in the interactive window and run the updated code. The C# compiler complains, "Unexpected character '$'".)
|
||||
|
||||
- One or more *interpolated expressions*. An interpolated expression is indicated by an opening and closing brace (`{` and `}`). You can put any C# expression that returns a value (including `null`) inside the braces.
|
||||
|
||||
Let's try a few more string interpolation examples with some other data types.
|
||||
|
||||
|
||||
> [!NOTE]
|
||||
> This online coding experience is in preview mode. If you encounter problems, please report them [on the dotnet/try repo](https://github.com/dotnet/try/issues).
|
||||
|
||||
- title: Include different data types
|
||||
durationInMinutes: 5
|
||||
content: |
|
||||
In the previous step, you used string interpolation to insert one string inside of another. The result of an interpolated expression can be of any data type, though. Let's include values of various data types in an interpolated string.
|
||||
|
||||
In the previous step, you used string interpolation to insert one string inside of another. The result of an interpolated expression can be of any data type, though. Let's include values of various data types in an interpolated string.
|
||||
|
||||
In the following example, we first define a [class](../../programming-guide/classes-and-structs/classes.md) data type `Vegetable` that has a `Name` [property](../../properties.md) and a `ToString` [method](../../methods.md), which [overrides](../../language-reference/keywords/override.md) the behavior of the <xref:System.Object.ToString?displayProperty=nameWithType> method. The [`public` access modifier](../../language-reference/keywords/public.md) makes that method available to any client code to get the string representation of a `Vegetable` instance. In the example the `Vegetable.ToString` method returns the value of the `Name` property that is initialized at the `Vegetable` [constructor](../../programming-guide/classes-and-structs/constructors.md): `Vegetable(string name) => Name = name;`. Then we create an instance of the `Vegetable` class named `item` by using the [`new` keyword](../../language-reference/keywords/new-operator.md) and providing a name for the constructor `Vegetable`. Finally, we include that instance into an interpolated string that also contains a <xref:System.DateTime> value, a <xref:System.Decimal> value, and a `Unit` [enumeration](../../programming-guide/enumeration-types.md) value. Run the following code in the interactive window:
|
||||
|
||||
```csharp
|
||||
public class Vegetable
|
||||
{
|
||||
public Vegetable(string name) => Name = name;
|
||||
|
||||
|
||||
public string Name { get; }
|
||||
|
||||
|
||||
public override string ToString() => Name;
|
||||
}
|
||||
|
||||
|
@ -63,12 +63,12 @@ items:
|
|||
var unit = Unit.item;
|
||||
Console.WriteLine($"On {date}, the price of {item} was {price} per {unit}.");
|
||||
```
|
||||
|
||||
|
||||
Note that the interpolated expression `item` in the interpolated string resolves to the text "eggplant" in the result string. That's because, when the type of the expression result is not a string, the result is resolved to a string in the following way:
|
||||
|
||||
- If the interpolated expression evaluates to `null`, an empty string ("", or <xref:System.String.Empty?displayProperty=nameWithType>) is used.
|
||||
|
||||
- If the interpolated expression doesn't evaluate to `null`, typically the `ToString` method of the result type is called. You can test this by updating the implementation of the `Vegetable.ToString` method. You might not even need to implement the `ToString` method since every type has some implementation of this method. To test this, comment out the definition of the `Vegetable.ToString` method in the example (to do that, put a comment symbol, `//`, in front of it). In the output, the string "eggplant" is replaced by the fully qualified type name (the namespace defined by the C# REPL along with the type name), which is the default behavior of the <xref:System.Object.ToString?displayProperty=nameWithType> method. The default behavior of the `ToString` method for an enumeration value is to return the string representation of the value.
|
||||
- If the interpolated expression doesn't evaluate to `null`, typically the `ToString` method of the result type is called. You can test this by updating the implementation of the `Vegetable.ToString` method. You might not even need to implement the `ToString` method since every type has some implementation of this method. To test this, comment out the definition of the `Vegetable.ToString` method in the example (to do that, put a comment symbol, `//`, in front of it). In the output, the string "eggplant" is replaced by the fully qualified type name (the namespace defined by the C# REPL along with the type name), which is the default behavior of the <xref:System.Object.ToString?displayProperty=nameWithType> method. The default behavior of the `ToString` method for an enumeration value is to return the string representation of the value.
|
||||
|
||||
In the output from this example, the date is too precise (the price of eggplant doesn't change every second), and the price value doesn't indicate a unit of currency. In the next step, you'll learn how to fix those issues by controlling the format of string representations of the expression results.
|
||||
|
||||
|
@ -83,7 +83,7 @@ items:
|
|||
```csharp
|
||||
Console.WriteLine($"On {date:d}, the price of {item} was {price:C2} per {unit}.");
|
||||
```
|
||||
|
||||
|
||||
You specify a format string by following the interpolated expression with a colon (":") and the format string. "d" is a [standard date and time format string](../../../standard/base-types/standard-date-and-time-format-strings.md#the-short-date-d-format-specifier) that represents the short date format. "C2" is a [standard numeric format string](../../../standard/base-types/standard-numeric-format-strings.md#the-currency-c-format-specifier) that represents a number as a currency value with two digits after the decimal point.
|
||||
|
||||
A number of types in the .NET libraries support a predefined set of format strings. These include all the numeric types and the date and time types. For a complete list of types that support format strings, see [Format Strings and .NET Class Library Types](../../../standard/base-types/formatting-types.md#stringRef) in the [Formatting Types in .NET](../../../standard/base-types/formatting-types.md) article.
|
||||
|
@ -99,7 +99,7 @@ items:
|
|||
durationInMinutes: 6
|
||||
content: |
|
||||
Ordinarily, when the result of an interpolated expression is formatted to string, that string is included in a result string without leading or trailing spaces. Particularly when you work with a set of data, being able to control a field width and text alignment helps to produce a more readable output. To see this, run the following code:
|
||||
|
||||
|
||||
```csharp
|
||||
var inventory = new Dictionary<string, int>()
|
||||
{
|
||||
|
@ -114,7 +114,7 @@ items:
|
|||
foreach (var item in inventory)
|
||||
Console.WriteLine($"|{item.Key,-25}|{item.Value,10}|");
|
||||
```
|
||||
|
||||
|
||||
The item names are left-aligned, and their quantities are right-aligned. You specify the alignment by adding a comma (",") after an interpolated expression and designating the *minimum* field width. If the specified value is a positive number, the field is right-aligned. If it is a negative number, the field is left-aligned.
|
||||
|
||||
Try removing the negative signs from the `{"Item",-25}` and `{item.Key,-25}` code and run the example again. This time, the item names are right-aligned.
|
||||
|
|
|
@ -32,7 +32,7 @@ items:
|
|||
The code to display names makes use of the [string interpolation](../../language-reference/tokens/interpolated.md) feature. When you precede a `string` with the `$` character, you can embed C# code in the string declaration. The actual string replaces that C# code with the value it generates. In this example, it replaces the `{name.ToUpper()}` with each name, converted to capital letters, because you called the <xref:System.String.ToUpper%2A?displayProperty=nameWithType> method.
|
||||
|
||||
Let's keep exploring.
|
||||
|
||||
|
||||
> [!NOTE]
|
||||
> This online coding experience is in preview mode. If you encounter problems, please report them [on the dotnet/try repo](https://github.com/dotnet/try/issues).
|
||||
|
||||
|
@ -40,7 +40,7 @@ items:
|
|||
durationInMinutes: 3
|
||||
content: |
|
||||
The collection you created uses the <xref:System.Collections.Generic.List%601> type. This type stores sequences of elements. You specify the type of the elements between the angle brackets.
|
||||
|
||||
|
||||
One important aspect of this <xref:System.Collections.Generic.List%601> type is that it can grow or shrink, enabling you to add or remove elements. Add the following code below the code you've already written:
|
||||
|
||||
```csharp
|
||||
|
@ -55,7 +55,7 @@ items:
|
|||
```
|
||||
|
||||
You've added two more names to the end of the list. You've also removed one as well.
|
||||
|
||||
|
||||
The <xref:System.Collections.Generic.List%601> enables you to reference individual items by **index** as well. You access items using the `[` and `]` tokens. Add the following code below what you've already written and try it:
|
||||
|
||||
```csharp
|
||||
|
@ -68,7 +68,7 @@ items:
|
|||
```csharp
|
||||
Console.WriteLine($"The list has {names.Count} people in it");
|
||||
```
|
||||
|
||||
|
||||
Click **Run** again to see the results. In C#, indices start at 0, so the largest valid index is one less than the number of items in the list.
|
||||
|
||||
> [!NOTE]
|
||||
|
@ -117,7 +117,7 @@ items:
|
|||
```csharp
|
||||
var previous = fibonacciNumbers[fibonacciNumbers.Count - 1];
|
||||
var previous2 = fibonacciNumbers[fibonacciNumbers.Count - 2];
|
||||
|
||||
|
||||
fibonacciNumbers.Add(previous + previous2);
|
||||
|
||||
foreach(var item in fibonacciNumbers)
|
||||
|
@ -149,7 +149,7 @@ items:
|
|||
{
|
||||
var previous = fibonacciNumbers[fibonacciNumbers.Count - 1];
|
||||
var previous2 = fibonacciNumbers[fibonacciNumbers.Count - 2];
|
||||
|
||||
|
||||
fibonacciNumbers.Add(previous + previous2);
|
||||
}
|
||||
foreach(var item in fibonacciNumbers)
|
||||
|
@ -160,11 +160,11 @@ items:
|
|||
|
||||
> [!NOTE]
|
||||
> This online coding experience is in preview mode. If you encounter problems, please report them [on the dotnet/try repo](https://github.com/dotnet/try/issues).
|
||||
|
||||
|
||||
- content: |
|
||||
You've completed the list interactive tutorial. That's the final introduction to C# interactive tutorial. You can visit the [.NET site](https://www.microsoft.com/net/learn/dotnet/hello-world-tutorial) to download the .NET Core SDK, create a project on your machine, and keep coding. The "Keep Learning" step brings you back to these tutorials to build projects on your machine.
|
||||
|
||||
You can learn more about [.NET collections](../../../standard/collections/index.md) in the following topics:
|
||||
- [Selecting a collection type](../../../standard/collections/selecting-a-collection-class.md)
|
||||
- [Commonly used collection types](../../../standard/collections/commonly-used-collection-types.md)
|
||||
- [When to use generic collections](../../../standard/collections/when-to-use-generic-collections.md)
|
||||
- [When to use generic collections](../../../standard/collections/when-to-use-generic-collections.md)
|
||||
|
|
|
@ -50,12 +50,12 @@ items:
|
|||
int c = a * b;
|
||||
```
|
||||
|
||||
Division:
|
||||
Division:
|
||||
|
||||
```csharp
|
||||
int c = a / b;
|
||||
```
|
||||
|
||||
|
||||
You can also experiment by performing multiple mathematics operations in the same line, if you'd like.
|
||||
|
||||
> [!TIP]
|
||||
|
@ -64,7 +64,7 @@ items:
|
|||
> find those errors and report them to you. When the output
|
||||
> contains error messages, look closely at the example code,
|
||||
> and the code in the interactive window to see what to fix.
|
||||
> That exercise will help you learn the structure of C# code.
|
||||
> That exercise will help you learn the structure of C# code.
|
||||
|
||||
> [!NOTE]
|
||||
> This online coding experience is in preview mode. If you encounter problems, please report them [on the dotnet/try repo](https://github.com/dotnet/try/issues).
|
||||
|
@ -122,7 +122,7 @@ items:
|
|||
|
||||
> [!NOTE]
|
||||
> This online coding experience is in preview mode. If you encounter problems, please report them [on the dotnet/try repo](https://github.com/dotnet/try/issues).
|
||||
|
||||
|
||||
- title: Explore integer precision and limits
|
||||
durationInMinutes: 5
|
||||
content: |
|
||||
|
@ -142,7 +142,7 @@ items:
|
|||
The C# integer type differs from mathematical integers in one other
|
||||
way: the `int` type has minimum and maximum limits. Run this code
|
||||
in the interactive window to see those limits:
|
||||
|
||||
|
||||
```csharp
|
||||
int max = int.MaxValue;
|
||||
int min = int.MinValue;
|
||||
|
@ -158,9 +158,9 @@ items:
|
|||
int what = max + 3;
|
||||
Console.WriteLine($"An example of overflow: {what}");
|
||||
```
|
||||
|
||||
|
||||
Notice that the answer is very close to the minimum (negative) integer. It's
|
||||
the same as `min + 2`.
|
||||
the same as `min + 2`.
|
||||
The addition operation **overflowed** the allowed values for integers.
|
||||
The answer is a very large negative number because an overflow "wraps around"
|
||||
from the largest possible integer value to the smallest.
|
||||
|
@ -212,7 +212,7 @@ items:
|
|||
|
||||
These values are printed out in scientific notation. The number to
|
||||
the left of the `E` is the significand. The number to the right is the exponent,
|
||||
as a power of 10.
|
||||
as a power of 10.
|
||||
|
||||
Just like decimal numbers in math, doubles in C# can have rounding errors. Try this code:
|
||||
|
||||
|
@ -220,7 +220,7 @@ items:
|
|||
double third = 1.0 / 3.0;
|
||||
Console.WriteLine(third);
|
||||
```
|
||||
|
||||
|
||||
You know that `0.3` repeating is not exactly the same as `1/3`.
|
||||
|
||||
***Challenge***
|
||||
|
@ -262,14 +262,14 @@ items:
|
|||
`decimal` type.
|
||||
|
||||
Notice that the math using the decimal type has more digits to the right
|
||||
of the decimal point.
|
||||
of the decimal point.
|
||||
|
||||
***Challenge***
|
||||
|
||||
Now that you've seen the different numeric types, write code that calculates
|
||||
the area of a circle whose radius is 2.50 centimeters. Remember that the area of a circle
|
||||
is the radius squared multiplied by PI. One hint: .NET contains a constant
|
||||
for PI, <xref:System.Math.PI?displayProperty=nameWithType> that you can use for that value.
|
||||
for PI, <xref:System.Math.PI?displayProperty=nameWithType> that you can use for that value.
|
||||
|
||||
> [!NOTE]
|
||||
> This online coding experience is in preview mode. If you encounter problems, please report them [on the dotnet/try repo](https://github.com/dotnet/try/issues).
|
||||
|
@ -294,7 +294,7 @@ items:
|
|||
|
||||
- content: |
|
||||
You've completed the "Numbers in C#" interactive tutorial. You can click the **Branches and Loops** link below to start the next interactive tutorial, or you can visit the [.NET site](https://www.microsoft.com/net/learn/dotnet/hello-world-tutorial) to download the .NET Core SDK, create a project on your machine, and keep coding. The "Keep Learning" step brings you back to these tutorials.
|
||||
|
||||
|
||||
You can learn more about numbers in C# in the following topics:
|
||||
|
||||
- [Integral Types Table](../../language-reference/keywords/integral-types-table.md)
|
||||
|
|
6
toc.yml
6
toc.yml
|
@ -5,7 +5,7 @@
|
|||
- name: .NET
|
||||
tocHref: /dotnet/
|
||||
topicHref: /dotnet/index
|
||||
items:
|
||||
items:
|
||||
- name: .NET API Browser
|
||||
tocHref: /dotnet/api/
|
||||
topicHref: /dotnet/api/index
|
||||
|
@ -27,10 +27,10 @@
|
|||
topicHref: /dotnet/standard/modernize-with-azure-and-containers/index
|
||||
- name: .NET Microservices - DevOps e-book
|
||||
tocHref: /dotnet/standard/containerized-lifecycle-architecture/
|
||||
topicHref: /dotnet/standard/containerized-lifecycle-architecture/index
|
||||
topicHref: /dotnet/standard/containerized-lifecycle-architecture/index
|
||||
- name: Serverless apps e-book
|
||||
tocHref: /dotnet/standard/serverless-architecture/
|
||||
topicHref: /dotnet/standard/serverless-architecture/index
|
||||
topicHref: /dotnet/standard/serverless-architecture/index
|
||||
- name: Asynchronous Programming Patterns
|
||||
tocHref: /dotnet/standard/asynchronous-programming-patterns/
|
||||
topicHref: /dotnet/standard/asynchronous-programming-patterns/index
|
||||
|
|
Загрузка…
Ссылка в новой задаче