diff --git a/xml/System.Text/Encoding.xml b/xml/System.Text/Encoding.xml index 4aa04b5db22..bd5451367ee 100644 --- a/xml/System.Text/Encoding.xml +++ b/xml/System.Text/Encoding.xml @@ -259,9 +259,9 @@ > [!NOTE] > The byte[] array is the only type in this example that contains the encoded data. The .NET Char and String types are themselves Unicode, so the call decodes the data back to Unicode. - [!code-cpp[System.Text.Encoding.Convert Example#1](~/samples/snippets/cpp/VS_Snippets_CLR_System/system.Text.Encoding.Convert Example/CPP/convert.cpp#1)] - [!code-csharp[System.Text.Encoding.Convert Example#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Text.Encoding.Convert Example/CS/convert.cs#1)] - [!code-vb[System.Text.Encoding.Convert Example#1](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Text.Encoding.Convert Example/VB/convert.vb#1)] + :::code language="cpp" source="~/samples/snippets/cpp/VS_Snippets_CLR_System/system.Text.Encoding.Convert Example/CPP/convert.cpp" id="Snippet1"::: + :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Text.Encoding.Convert Example/CS/convert.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Text.Encoding.Convert Example/VB/convert.vb" id="Snippet1"::: ]]> @@ -822,9 +822,9 @@ ## Examples The following example converts a Unicode-encoded string to an ASCII-encoded string. Because the ASCII encoding object returned by the property uses replacement fallback and the Pi character is not part of the ASCII character set, the Pi character is replaced with a question mark, as the output from the example shows. - [!code-cpp[System.Text.Encoding.Convert Example#1](~/samples/snippets/cpp/VS_Snippets_CLR_System/system.Text.Encoding.Convert Example/CPP/convert.cpp#1)] - [!code-csharp[System.Text.Encoding.Convert Example#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Text.Encoding.Convert Example/CS/convert.cs#1)] - [!code-vb[System.Text.Encoding.Convert Example#1](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Text.Encoding.Convert Example/VB/convert.vb#1)] + :::code language="cpp" source="~/samples/snippets/cpp/VS_Snippets_CLR_System/system.Text.Encoding.Convert Example/CPP/convert.cpp" id="Snippet1"::: + :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Text.Encoding.Convert Example/CS/convert.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Text.Encoding.Convert Example/VB/convert.vb" id="Snippet1"::: ]]> @@ -2749,9 +2749,9 @@ On .NET Core, the property always returns ## Examples The following example converts a string from one encoding to another. - [!code-cpp[System.Text.Encoding.Convert Example#1](~/samples/snippets/cpp/VS_Snippets_CLR_System/system.Text.Encoding.Convert Example/CPP/convert.cpp#1)] - [!code-csharp[System.Text.Encoding.Convert Example#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Text.Encoding.Convert Example/CS/convert.cs#1)] - [!code-vb[System.Text.Encoding.Convert Example#1](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Text.Encoding.Convert Example/VB/convert.vb#1)] + :::code language="cpp" source="~/samples/snippets/cpp/VS_Snippets_CLR_System/system.Text.Encoding.Convert Example/CPP/convert.cpp" id="Snippet1"::: + :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Text.Encoding.Convert Example/CS/convert.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Text.Encoding.Convert Example/VB/convert.vb" id="Snippet1"::: The following example encodes a string into an array of bytes, and then decodes a range of the bytes into an array of characters. @@ -3222,9 +3222,9 @@ On .NET Core, the property always returns ## Examples The following example converts a string from one encoding to another. - [!code-cpp[System.Text.Encoding.Convert Example#1](~/samples/snippets/cpp/VS_Snippets_CLR_System/system.Text.Encoding.Convert Example/CPP/convert.cpp#1)] - [!code-csharp[System.Text.Encoding.Convert Example#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Text.Encoding.Convert Example/CS/convert.cs#1)] - [!code-vb[System.Text.Encoding.Convert Example#1](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Text.Encoding.Convert Example/VB/convert.vb#1)] + :::code language="cpp" source="~/samples/snippets/cpp/VS_Snippets_CLR_System/system.Text.Encoding.Convert Example/CPP/convert.cpp" id="Snippet1"::: + :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Text.Encoding.Convert Example/CS/convert.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Text.Encoding.Convert Example/VB/convert.vb" id="Snippet1"::: The following example encodes a string into an array of bytes, and then decodes a range of the bytes into an array of characters. diff --git a/xml/System.Text/StringBuilder.xml b/xml/System.Text/StringBuilder.xml index a0a9f80c9a6..82f9f38ff6e 100644 --- a/xml/System.Text/StringBuilder.xml +++ b/xml/System.Text/StringBuilder.xml @@ -110,8 +110,8 @@ The following example illustrates how a object allocates new memory and increases its capacity dynamically as the string assigned to the object expands. The code creates a object by calling its default (parameterless) constructor. The default capacity of this object is 16 characters, and its maximum capacity is more than 2 billion characters. Appending the string "This is a sentence." results in a new memory allocation because the string length (19 characters) exceeds the default capacity of the object. The capacity of the object doubles to 32 characters, the new string is added, and the length of the object now equals 19 characters. The code then appends the string "This is an additional sentence." to the value of the object 11 times. Whenever the append operation causes the length of the object to exceed its capacity, its existing capacity is doubled and the operation succeeds. - [!code-csharp[System.Text.StringBuilder.Class#3](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.text.stringbuilder.class/cs/default1.cs#3)] - [!code-vb[System.Text.StringBuilder.Class#3](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.text.stringbuilder.class/vb/default1.vb#3)] + :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.text.stringbuilder.class/cs/default1.cs" interactive="try-dotnet" id="Snippet3"::: + :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.text.stringbuilder.class/vb/default1.vb" id="Snippet3"::: ## Memory allocation @@ -152,8 +152,8 @@ The following example uses three of these constructor overloads to instantiate objects. - [!code-csharp[System.Text.StringBuilder.Class#6](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.text.stringbuilder.class/cs/instantiate1.cs#6)] - [!code-vb[System.Text.StringBuilder.Class#6](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.text.stringbuilder.class/vb/instantiate1.vb#6)] + :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.text.stringbuilder.class/cs/instantiate1.cs" interactive="try-dotnet" id="Snippet6"::: + :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.text.stringbuilder.class/vb/instantiate1.vb" id="Snippet6"::: ## Calling StringBuilder methods @@ -161,13 +161,13 @@ - You can make individual method calls and ignore the return value, as the following example does. - [!code-csharp[System.Text.StringBuilder.Class#4](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.text.stringbuilder.class/cs/call1.cs#4)] - [!code-vb[System.Text.StringBuilder.Class#4](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.text.stringbuilder.class/vb/call1.vb#4)] + :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.text.stringbuilder.class/cs/call1.cs" interactive="try-dotnet" id="Snippet4"::: + :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.text.stringbuilder.class/vb/call1.vb" id="Snippet4"::: - You can make a series of method calls in a single statement. This can be convenient if you want to write a single statement that chains successive operations. The following example consolidates three method calls from the previous example into a single line of code. - [!code-csharp[System.Text.StringBuilder.Class#5](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.text.stringbuilder.class/cs/call2.cs#5)] - [!code-vb[System.Text.StringBuilder.Class#5](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.text.stringbuilder.class/vb/call2.vb#5)] + :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.text.stringbuilder.class/cs/call2.cs" interactive="try-dotnet" id="Snippet5"::: + :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.text.stringbuilder.class/vb/call2.vb" id="Snippet5"::: ## Performing StringBuilder operations @@ -179,8 +179,8 @@ The following example illustrates the property. It appends ten random numbers to a object, and then iterates each character. If the character's Unicode category is , it decreases the number by 1 (or changes the number to 9 if its value is 0). The example displays the contents of the object both before and after the values of individual characters were changed. - [!code-csharp[System.Text.StringBuilder.Class#7](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.text.stringbuilder.class/cs/chars1.cs#7)] - [!code-vb[System.Text.StringBuilder.Class#7](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.text.stringbuilder.class/vb/chars1.vb#7)] + :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.text.stringbuilder.class/cs/chars1.cs" interactive="try-dotnet" id="Snippet7"::: + :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.text.stringbuilder.class/vb/chars1.vb" id="Snippet7"::: [!INCLUDE[stringbuilder-performance-note](~/includes/stringbuilder-perf-note.md)] @@ -198,8 +198,8 @@ The following example uses the , , , and methods to expand the text of a object. - [!code-csharp[System.Text.StringBuilder.Class#9](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.text.stringbuilder.class/cs/expand1.cs#9)] - [!code-vb[System.Text.StringBuilder.Class#9](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.text.stringbuilder.class/vb/expand1.vb#9)] + :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.text.stringbuilder.class/cs/expand1.cs" interactive="try-dotnet" id="Snippet9"::: + :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.text.stringbuilder.class/vb/expand1.vb" id="Snippet9"::: ### Deleting text from a StringBuilder object @@ -207,15 +207,15 @@ The following example removes some of the text from a object, displays its resulting capacity, maximum capacity, and length property values, and then calls the method to remove all the characters from the object. - [!code-csharp[System.Text.StringBuilder.Class#10](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.text.stringbuilder.class/cs/delete1.cs#10)] - [!code-vb[System.Text.StringBuilder.Class#10](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.text.stringbuilder.class/vb/delete1.vb#10)] + :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.text.stringbuilder.class/cs/delete1.cs" interactive="try-dotnet" id="Snippet10"::: + :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.text.stringbuilder.class/vb/delete1.vb" id="Snippet10"::: ### Modifying the text in a StringBuilder object The method replaces all occurrences of a character or a string in the entire object or in a particular character range. The following example uses the method to replace all exclamation points (!) with question marks (?) in the object. - [!code-csharp[System.Text.StringBuilder.Class#11](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.text.stringbuilder.class/cs/replace1.cs#11)] - [!code-vb[System.Text.StringBuilder.Class#11](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.text.stringbuilder.class/vb/replace1.vb#11)] + :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.text.stringbuilder.class/cs/replace1.cs" interactive="try-dotnet" id="Snippet11"::: + :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.text.stringbuilder.class/vb/replace1.vb" id="Snippet11"::: ## Searching the text in a StringBuilder object @@ -232,8 +232,8 @@ - If the goal of the search is to determine whether a particular substring exists (that is, if you aren't interested in the position of the substring), you can search strings before storing them in the object. The following example provides one possible implementation. It defines a `StringBuilderFinder` class whose constructor is passed a reference to a object and the substring to find in the string. In this case, the example tries to determine whether recorded temperatures are in Fahrenheit or Celsius, and adds the appropriate introductory text to the beginning of the object. A random number generator is used to select an array that contains data in either degrees Celsius or degrees Fahrenheit. - [!code-csharp[System.Text.StringBuilder.Class#12](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.text.stringbuilder.class/cs/pattern1.cs#12)] - [!code-vb[System.Text.StringBuilder.Class#12](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.text.stringbuilder.class/vb/pattern1.vb#12)] + :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.text.stringbuilder.class/cs/pattern1.cs" interactive="try-dotnet" id="Snippet12"::: + :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.text.stringbuilder.class/vb/pattern1.vb" id="Snippet12"::: - Call the method to convert the object to a object. You can search the string by using methods such as or , or you can use regular expressions and the class to search for patterns. Because both and objects use UTF-16 encoding to store characters, the index positions of characters, substrings, and regular expression matches are the same in both objects. This enables you to use methods to make changes at the same position at which that text is found in the object. @@ -242,22 +242,22 @@ The following example illustrates this approach. It stores four occurrences of each letter of the English alphabet in a object. It then converts the text to a object and uses a regular expression to identify the starting position of each four-character sequence. Finally, it adds an underscore before each four-character sequence except for the first sequence, and converts the first character of the sequence to uppercase. - [!code-csharp[System.Text.StringBuilder.Class#13](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.text.stringbuilder.class/cs/pattern2.cs#13)] - [!code-vb[System.Text.StringBuilder.Class#13](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.text.stringbuilder.class/vb/pattern2.vb#13)] + :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.text.stringbuilder.class/cs/pattern2.cs" interactive="try-dotnet" id="Snippet13"::: + :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.text.stringbuilder.class/vb/pattern2.vb" id="Snippet13"::: - Use the property to sequentially search a range of characters in a object. This approach may not be practical if the number of characters to be searched is large or the search logic is particularly complex. For the performance implications of character-by-character index-based access for very large, chunked objects, see the documentation for the property. The following example is identical in functionality to the previous example but differs in implementation. It uses the property to detect when a character value has changed, inserts an underscore at that position, and converts the first character in the new sequence to uppercase. - [!code-csharp[System.Text.StringBuilder.Class#14](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.text.stringbuilder.class/cs/pattern3.cs#14)] - [!code-vb[System.Text.StringBuilder.Class#14](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.text.stringbuilder.class/vb/pattern3.vb#14)] + :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.text.stringbuilder.class/cs/pattern3.cs" interactive="try-dotnet" id="Snippet14"::: + :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.text.stringbuilder.class/vb/pattern3.vb" id="Snippet14"::: - Store all the unmodified text in the object, call the method to convert the object to a object, and perform the modifications on the object. You can use this approach if you have only a few modifications; otherwise, the cost of working with immutable strings may negate the performance benefits of using a object. The following example is identical in functionality to the previous two examples but differs in implementation. It creates a object, converts it to a object, and then uses a regular expression to perform all remaining modifications on the string. The method uses a lambda expression to perform the replacement on each match. - [!code-csharp[System.Text.StringBuilder.Class#15](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.text.stringbuilder.class/cs/pattern4.cs#15)] - [!code-vb[System.Text.StringBuilder.Class#15](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.text.stringbuilder.class/vb/pattern4.vb#15)] + :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.text.stringbuilder.class/cs/pattern4.cs" interactive="try-dotnet" id="Snippet15"::: + :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.text.stringbuilder.class/vb/pattern4.vb" id="Snippet15"::: ## Converting the StringBuilder object to a string @@ -3659,8 +3659,8 @@ The following example instantiates a object with a string, calls the method, and then appends a new string. -[!code-csharp[System.Text.StringBuilder.Clear#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.text.stringbuilder.clear/cs/clear1.cs#1)] -[!code-vb[System.Text.StringBuilder.Clear#1](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.text.stringbuilder.clear/vb/clear1.vb#1)] +:::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.text.stringbuilder.clear/cs/clear1.cs" interactive="try-dotnet" id="Snippet1"::: +:::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.text.stringbuilder.clear/vb/clear1.vb" id="Snippet1"::: ]]> diff --git a/xml/System/DateTime.xml b/xml/System/DateTime.xml index bac6c0fa471..cb4292c0e16 100644 --- a/xml/System/DateTime.xml +++ b/xml/System/DateTime.xml @@ -159,8 +159,8 @@ You call any of the overloads of the constructor that spe You invoke the `DateTime` structure's implicit parameterless constructor when you want a `DateTime` initialized to its default value. (For details on the implicit parameterless constructor of a value type, see [Value Types](~/docs/csharp/language-reference/keywords/value-types.md).) Some compilers also support declaring a value without explicitly assigning a value to it. Creating a value without an explicit initialization also results in the default value. The following example illustrates the implicit parameterless constructor in C# and Visual Basic, as well as a declaration without assignment in Visual Basic. -[!code-vb[System.DateTime.Instantiation#5](~/samples/snippets/visualbasic/System.DateTime/Instantiation.vb#5)] -[!code-csharp-interactive[System.DateTime.Instantiation#5](~/samples/snippets/csharp/System.DateTime/Instantiation.cs#5)] +:::code language="vb" source="~/samples/snippets/visualbasic/System.DateTime/Instantiation.vb" id="Snippet5"::: +:::code language="csharp" source="~/samples/snippets/csharp/System.DateTime/Instantiation.cs" interactive="try-dotnet-method" id="Snippet5"::: #### Assigning a computed value @@ -200,8 +200,8 @@ The appearance of date and time values is dependent on culture, international st You may need to format dates in a specific culture to support web scenarios where the server may be in a different culture from the client. You specify the culture using the method to create the short date and long time representation in a specific culture. The following example uses the method to display the date and time using the short date and long time pattern for the fr-FR culture. -[!code-csharp-interactive[System.DateTime.Formatting#2](~/samples/snippets/csharp/System.DateTime/StringFormat.cs#2)] -[!code-vb[System.DateTime.Formatting#2](~/samples/snippets/visualbasic/System.DateTime/StringFormat.vb#2)] +:::code language="csharp" source="~/samples/snippets/csharp/System.DateTime/StringFormat.cs" interactive="try-dotnet-method" id="Snippet2"::: +:::code language="vb" source="~/samples/snippets/visualbasic/System.DateTime/StringFormat.vb" id="Snippet2"::: Other applications may require different string representations of a date. The method returns the string representation defined by a standard or custom format specifier using the formatting conventions of the current culture. The following example uses the method to display the full date and time pattern for the en-US culture, the current culture on the computer on which the example was run. @@ -212,14 +212,14 @@ You may need to format dates in a specific culture to support web scenarios wher Finally, you can specify both the culture and the format using the method. The following example uses the method to display the full date and time pattern for the fr-FR culture. -[!code-csharp-interactive[System.DateTime.Formatting#4](~/samples/snippets/csharp/System.DateTime/StringFormat.cs#4)] -[!code-vb[System.DateTime.Formatting#4](~/samples/snippets/visualbasic/System.DateTime/StringFormat.vb#4)] +:::code language="csharp" source="~/samples/snippets/csharp/System.DateTime/StringFormat.cs" interactive="try-dotnet-method" id="Snippet4"::: +:::code language="vb" source="~/samples/snippets/visualbasic/System.DateTime/StringFormat.vb" id="Snippet4"::: The overload can also be used with a custom format string to specify other formats. The following example shows how to format a string using the [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) standard format often used for web services. The Iso 8601 format does not have a corresponding standard format string. -[!code-csharp-interactive[System.DateTime.Formatting#5](~/samples/snippets/csharp/System.DateTime/StringFormat.cs#5)] -[!code-vb[System.DateTime.Formatting#5](~/samples/snippets/visualbasic/System.DateTime/StringFormat.vb#5)] +:::code language="csharp" source="~/samples/snippets/csharp/System.DateTime/StringFormat.cs" interactive="try-dotnet-method" id="Snippet5"::: +:::code language="vb" source="~/samples/snippets/visualbasic/System.DateTime/StringFormat.vb" id="Snippet5"::: For more information about formatting values, see [Standard Date and Time Format Strings](~/docs/standard/base-types/standard-date-and-time-format-strings.md) and [Custom Date and Time Format Strings](~/docs/standard/base-types/custom-date-and-time-format-strings.md). @@ -234,8 +234,8 @@ Parsing converts the string representation of a date and time to a or method to convert a string from one of the common date and time formats used by a culture to a value. The following example shows how you can use to convert date strings in different culture-specific formats to a value. It changes the current culture to English (Great Britain) and calls the method to generate an array of date and time strings. It then passes each element in the array to the method. The output from the example shows the parsing method was able to successfully convert each of the culture-specific date and time strings. -[!code-csharp-interactive[System.DateTime.Parsing#1](~/samples/snippets/csharp/System.DateTime/Parsing.cs#1)] -[!code-vb[System.DateTime.Parsing#1](~/samples/snippets/visualbasic/System.DateTime/Parsing.vb#1)] +:::code language="csharp" source="~/samples/snippets/csharp/System.DateTime/Parsing.cs" interactive="try-dotnet-method" id="Snippet1"::: +:::code language="vb" source="~/samples/snippets/visualbasic/System.DateTime/Parsing.vb" id="Snippet1"::: You use the and methods to convert a string that must match a particular format or formats to a value. You specify one or more date and time format strings as a parameter to the parsing method. The following example uses the method to convert strings that must be either in a "yyyyMMdd" format or a "HHmmss" format to values. @@ -246,8 +246,8 @@ You use the and is to convert a string representation from a web service, usually in [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) standard format. The following code shows the correct format string to use: -[!code-csharp-interactive[System.DateTime.Parsing#3](~/samples/snippets/csharp/System.DateTime/Parsing.cs#3)] -[!code-vb[System.DateTime.Parsing#3](~/samples/snippets/visualbasic/System.DateTime/Parsing.vb#3)] +:::code language="csharp" source="~/samples/snippets/csharp/System.DateTime/Parsing.cs" interactive="try-dotnet-method" id="Snippet3"::: +:::code language="vb" source="~/samples/snippets/visualbasic/System.DateTime/Parsing.vb" id="Snippet3"::: If a string cannot be parsed, the and methods throw an exception. The and methods return a value that indicates whether the conversion succeeded or failed. You should use the or methods in scenarios where performance is important. The parsing operation for date and time strings tends to have a high failure rate, and exception handling is expensive. Use these methods if strings are input by users or coming from an unknown source. @@ -273,8 +273,8 @@ The property expresses date and time values in u The following example illustrates the dependence of current date and time values on the resolution of the system clock. In the example, an outer loop repeats 20 times, and an inner loop serves to delay the outer loop. If the value of the outer loop counter is 10, a call to the method introduces a five-millisecond delay. The following example shows the number of milliseconds returned by the `DateTime.Now.Milliseconds` property changes only after the call to . -[!code-csharp-interactive[System.DateTime.Resolution#1](~/samples/snippets/csharp/System.DateTime/Resolution.cs#1)] -[!code-vb[System.DateTime.Resolution#1](~/samples/snippets/visualbasic/System.DateTime/Resolution.vb#1)] +:::code language="csharp" source="~/samples/snippets/csharp/System.DateTime/Resolution.cs" interactive="try-dotnet-method" id="Snippet1"::: +:::code language="vb" source="~/samples/snippets/visualbasic/System.DateTime/Resolution.vb" id="Snippet1"::: ### DateTime operations @@ -556,10 +556,10 @@ The behavior of the .NET Framework and COM means that if your application round- ## Examples The following example demonstrates one of the constructors. - - [!code-cpp[datetime.ctor_Int64#1](~/samples/snippets/cpp/VS_Snippets_CLR/datetime.ctor_Int64/CPP/ticks.cpp#1)] - [!code-csharp[datetime.ctor_Int64#1](~/samples/snippets/csharp/VS_Snippets_CLR/datetime.ctor_Int64/CS/ticks.cs#1)] - [!code-vb[datetime.ctor_Int64#1](~/samples/snippets/visualbasic/VS_Snippets_CLR/datetime.ctor_Int64/VB/ticks.vb#1)] + + :::code language="cpp" source="~/samples/snippets/cpp/VS_Snippets_CLR/datetime.ctor_Int64/CPP/ticks.cpp" id="Snippet1"::: + :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR/datetime.ctor_Int64/CS/ticks.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR/datetime.ctor_Int64/VB/ticks.vb" id="Snippet1"::: ]]> @@ -670,9 +670,9 @@ The behavior of the .NET Framework and COM means that if your application round- ## Examples The following example uses the constructor to instantiate a value. The example also illustrates that this overload creates a value whose time component equals midnight (or 0:00). - - [!code-csharp-interactive[System.DateTime.Constructor#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.datetime.constructor/cs/ctorexample1.cs#1)] - [!code-vb[System.DateTime.Constructor#1](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.constructor/vb/ctorexample1.vb#1)] + + :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.datetime.constructor/cs/ctorexample1.cs" interactive="try-dotnet-method" id="Snippet1"::: + :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.constructor/vb/ctorexample1.vb" id="Snippet1"::: ]]> @@ -823,9 +823,9 @@ The behavior of the .NET Framework and COM means that if your application round- ## Examples The following example uses the constructor to instantiate a value. - - [!code-csharp-interactive[System.DateTime.Constructor#3](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.datetime.constructor/cs/ctorexample1.cs#3)] - [!code-vb[System.DateTime.Constructor#3](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.constructor/vb/ctorexample1.vb#3)] + + :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.datetime.constructor/cs/ctorexample1.cs" interactive="try-dotnet-method" id="Snippet3"::: + :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.constructor/vb/ctorexample1.vb" id="Snippet3"::: ]]> @@ -912,9 +912,9 @@ The behavior of the .NET Framework and COM means that if your application round- ## Examples The following example uses the constructor to instantiate a value. - - [!code-csharp-interactive[System.DateTime.Constructor#7](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.datetime.constructor/cs/ctorexample1.cs#7)] - [!code-vb[System.DateTime.Constructor#7](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.constructor/vb/ctorexample1.vb#7)] + + :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.datetime.constructor/cs/ctorexample1.cs" interactive="try-dotnet-method" id="Snippet7"::: + :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.constructor/vb/ctorexample1.vb" id="Snippet7"::: ]]> @@ -1099,9 +1099,9 @@ The behavior of the .NET Framework and COM means that if your application round- ## Examples The following example uses the constructor to instantiate a value. - - [!code-csharp-interactive[System.DateTime.Constructor#5](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.datetime.constructor/cs/ctorexample1.cs#5)] - [!code-vb[System.DateTime.Constructor#5](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.constructor/vb/ctorexample1.vb#5)] + + :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.datetime.constructor/cs/ctorexample1.cs" interactive="try-dotnet-method" id="Snippet5"::: + :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.constructor/vb/ctorexample1.vb" id="Snippet5"::: ]]> @@ -1196,8 +1196,8 @@ The behavior of the .NET Framework and COM means that if your application round- ## Examples The following example uses the constructor to instantiate a value. - [!code-csharp-interactive[System.DateTime.Constructor#8](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.datetime.constructor/cs/ctorexample1.cs#8)] - [!code-vb[System.DateTime.Constructor#8](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.constructor/vb/ctorexample1.vb#8)] + :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.datetime.constructor/cs/ctorexample1.cs" interactive="try-dotnet-method" id="Snippet8"::: + :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.constructor/vb/ctorexample1.vb" id="Snippet8"::: ]]> @@ -2086,9 +2086,9 @@ The behavior of the .NET Framework and COM means that if your application round- ## Examples The following example demonstrates the method. - - [!code-csharp-interactive[System.DateTime.Compare#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.datetime.compare/cs/compare1.cs#1)] - [!code-vb[System.DateTime.Compare#1](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.compare/vb/compare1.vb#1)] + + :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.datetime.compare/cs/compare1.cs" interactive="try-dotnet-method" id="Snippet1"::: + :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.compare/vb/compare1.vb" id="Snippet1"::: ]]> @@ -2194,9 +2194,9 @@ The behavior of the .NET Framework and COM means that if your application round- ## Examples The following example instantiates three objects, one that represents today's date, another that represents the date one year previously, and a third that represents the date one year in the future. It then calls the method and displays the result of the comparison. - - [!code-csharp[DateTime.CompareTo.2#1](~/samples/snippets/csharp/VS_Snippets_CLR/DateTime.CompareTo.2/CS/CompareTo_CS1_24564.cs#1)] - [!code-vb[DateTime.CompareTo.2#1](~/samples/snippets/visualbasic/VS_Snippets_CLR/DateTime.CompareTo.2/VB/CompareTo_VB1_24564.vb#1)] + + :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR/DateTime.CompareTo.2/CS/CompareTo_CS1_24564.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR/DateTime.CompareTo.2/VB/CompareTo_VB1_24564.vb" id="Snippet1"::: ]]> @@ -2276,10 +2276,10 @@ The behavior of the .NET Framework and COM means that if your application round- ## Examples The following example demonstrates the method. - - [!code-cpp[DateTime.CompareTo#1](~/samples/snippets/cpp/VS_Snippets_CLR/DateTime.CompareTo/CPP/class1.cpp#1)] - [!code-csharp[DateTime.CompareTo#1](~/samples/snippets/csharp/VS_Snippets_CLR/DateTime.CompareTo/CS/class1.cs#1)] - [!code-vb[DateTime.CompareTo#1](~/samples/snippets/visualbasic/VS_Snippets_CLR/DateTime.CompareTo/VB/class1.vb#1)] + + :::code language="cpp" source="~/samples/snippets/cpp/VS_Snippets_CLR/DateTime.CompareTo/CPP/class1.cpp" id="Snippet1"::: + :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR/DateTime.CompareTo/CS/class1.cs" interactive="try-dotnet-method" id="Snippet1"::: + :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR/DateTime.CompareTo/VB/class1.vb" id="Snippet1"::: ]]> @@ -6935,8 +6935,8 @@ In general, the ticks represent the time according to the time zone specified by The following example uses the property to display the number of ticks that have elapsed since the beginning of the twenty-first century and to instantiate a object. The object is then used to display the elapsed time using several other time intervals. - [!code-csharp-interactive[System.DateTime.Ticks#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.Ticks/cs/Ticks.cs#1)] - [!code-vb[System.DateTime.Ticks#1](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Ticks/vb/Ticks.vb#1)] + :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.Ticks/cs/Ticks.cs" interactive="try-dotnet-method" id="Snippet1"::: + :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Ticks/vb/Ticks.vb" id="Snippet1"::: ]]> @@ -7740,8 +7740,8 @@ The value of the current object is formatted using the pa ## Examples The following example illustrates how the string representation of a value returned by the method depends on the thread current culture. It changes the current thread culture from en-US to fr-FR to ja-JP. and in each case calls the method to return the string representation of a date and time value using that culture. - [!code-csharp[System.DateTime.ToString#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.ToString/cs/ToString1.cs#1)] - [!code-vb[System.DateTime.ToString#1](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.ToString/vb/ToString1.vb#1)] + :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.ToString/cs/ToString1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.ToString/vb/ToString1.vb" id="Snippet1"::: ]]> @@ -7830,17 +7830,19 @@ The value of the current object is formatted using the pa ## Examples The following example displays the string representation of a date and time using objects that represent five different cultures. - [!code-csharp[System.DateTime.ToString#3](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.ToString/cs/ToString4.cs#3)] - [!code-vb[System.DateTime.ToString#3](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.ToString/vb/ToString4.vb#3)] + :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.ToString/cs/ToString4.cs" interactive="try-dotnet" id="Snippet3"::: + :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.ToString/vb/ToString4.vb" id="Snippet3"::: ]]> The date and time is outside the range of dates supported by the calendar used by . The method returns the string representation of the date and time in the calendar used by the culture represented by the parameter. Its calendar is defined by the property. If the value of the current instance is earlier than or later than , the method throws an . The following example provides an illustration. It attempts to format a date that is outside the range of the class. - - [!code-csharp[System.DateTime.ToString.ArgumentOutOfRangeException#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/cs/datetime.tostring.argumentoutofrangeexception1.cs#1)] - [!code-vb[System.DateTime.ToString.ArgumentOutOfRangeException#1](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/vb/datetime.tostring.argumentoutofrangeexception1.vb#1)] + + :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/cs/datetime.tostring.argumentoutofrangeexception1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/vb/datetime.tostring.argumentoutofrangeexception1.vb" id="Snippet1"::: + + @@ -7911,16 +7913,14 @@ The value of the current object is formatted using the pa The following example uses these three format strings to display a date and time value by using the conventions of the en-US and fr-FR cultures. - [!code-csharp[System.DateTime.ToString#5](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.ToString/cs/tostring5.cs#5)] - [!code-vb[System.DateTime.ToString#5](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.ToString/vb/tostring5.vb#5)] - - + :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.ToString/cs/tostring5.cs" interactive="try-dotnet" id="Snippet5"::: + :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.ToString/vb/tostring5.vb" id="Snippet5"::: ## Examples The following example uses each of the standard date and time format strings and a selection of custom date and time format strings to display the string representation of a value. The thread current culture for the example is en-US. - - [!code-csharp[System.DateTime.ToString#2](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.ToString/cs/ToString2.cs#2)] - [!code-vb[System.DateTime.ToString#2](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.ToString/vb/ToString2.vb#2)] + + :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.ToString/cs/ToString2.cs" interactive="try-dotnet" id="Snippet2"::: + :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.ToString/vb/ToString2.vb" id="Snippet2"::: ]]> @@ -7932,9 +7932,9 @@ The value of the current object is formatted using the pa The date and time is outside the range of dates supported by the calendar used by the current culture. The method returns the string representation of the date and time in the calendar used by the current culture. If the value of the current instance is earlier than or later than , the method throws an . The following example provides an illustration. It attempts to format a date that is outside the range of the class when the current culture is Hebrew (Israel). - - [!code-csharp[System.DateTime.ToString.ArgumentOutOfRangeException#3](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/cs/datetime.tostring.argumentoutofrangeexception3.cs#3)] - [!code-vb[System.DateTime.ToString.ArgumentOutOfRangeException#3](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/vb/datetime.tostring.argumentoutofrangeexception3.vb#3)] + + [!code-csharp[System.DateTime.ToString.ArgumentOutOfRangeException#3](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/cs/datetime.tostring.argumentoutofrangeexception3.cs#3)] + [!code-vb[System.DateTime.ToString.ArgumentOutOfRangeException#3](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/vb/datetime.tostring.argumentoutofrangeexception3.vb#3)] @@ -8013,15 +8013,15 @@ The value of the current object is formatted using the pa ## Examples The following example uses each of the standard date time format strings to display the string representation of a date and time for four different cultures. - - [!code-csharp[System.DateTime.ToString#4](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.ToString/cs/tostring3.cs#4)] - [!code-vb[System.DateTime.ToString#4](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.ToString/vb/tostring3.vb#4)] - + + :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.ToString/cs/tostring3.cs" interactive="try-dotnet" id="Snippet4"::: + :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.ToString/vb/tostring3.vb" id="Snippet4"::: + The following example demonstrates different ways of formatting a value using the invariant . - - [!code-cpp[Classic DateTime.ToString2 Example#1](~/samples/snippets/cpp/VS_Snippets_CLR_Classic/classic DateTime.ToString2 Example/CPP/source.cpp#1)] - [!code-csharp[Classic DateTime.ToString2 Example#1](~/samples/snippets/csharp/VS_Snippets_CLR_Classic/classic DateTime.ToString2 Example/CS/source.cs#1)] - [!code-vb[Classic DateTime.ToString2 Example#1](~/samples/snippets/visualbasic/VS_Snippets_CLR_Classic/classic DateTime.ToString2 Example/VB/source.vb#1)] + + :::code language="cpp" source="~/samples/snippets/cpp/VS_Snippets_CLR_Classic/classic DateTime.ToString2 Example/CPP/source.cpp" id="Snippet1"::: + :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_Classic/classic DateTime.ToString2 Example/CS/source.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_Classic/classic DateTime.ToString2 Example/VB/source.vb" id="Snippet1"::: ]]> @@ -8033,9 +8033,11 @@ The value of the current object is formatted using the pa The date and time is outside the range of dates supported by the calendar used by . The method returns the string representation of the date and time in the calendar used by the parameter. Its calendar is defined by the property. If the value of the current instance is earlier than or later than , the method throws an . The following example provides an illustration. It attempts to format a date that is outside the range of the class. - - [!code-csharp[System.DateTime.ToString.ArgumentOutOfRangeException#4](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/cs/datetime.tostring.argumentoutofrangeexception4.cs#4)] - [!code-vb[System.DateTime.ToString.ArgumentOutOfRangeException#4](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/vb/datetime.tostring.argumentoutofrangeexception4.vb#4)] + + :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/cs/datetime.tostring.argumentoutofrangeexception4.cs" interactive="try-dotnet" id="Snippet4"::: + :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/vb/datetime.tostring.argumentoutofrangeexception4.vb" id="Snippet4"::: + + diff --git a/xml/System/Func`2.xml b/xml/System/Func`2.xml index c38f1f63b24..e5c2f821772 100644 --- a/xml/System/Func`2.xml +++ b/xml/System/Func`2.xml @@ -74,24 +74,24 @@ > To reference a method that has one parameter and returns `void` (or in Visual Basic, that is declared as a `Sub` rather than as a `Function`), use the generic delegate instead. When you use the delegate, you do not have to explicitly define a delegate that encapsulates a method with a single parameter. For example, the following code explicitly declares a delegate named `ConvertMethod` and assigns a reference to the `UppercaseString` method to its delegate instance. - - [!code-csharp[System.Func~2#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Func~2/cs/Delegate.cs#1)] - [!code-vb[System.Func~2#1](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Func~2/vb/Delegate.vb#1)] + + :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Func~2/cs/Delegate.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Func~2/vb/Delegate.vb" id="Snippet1"::: The following example simplifies this code by instantiating the delegate instead of explicitly defining a new delegate and assigning a named method to it. - [!code-csharp-interactive[System.Func~2#2](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Func~2/cs/Func2_1.cs#2)] - [!code-vb[System.Func~2#2](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Func~2/vb/Func2_1.vb#2)] + :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Func~2/cs/Func2_1.cs" interactive="try-dotnet-method" id="Snippet2"::: + :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Func~2/vb/Func2_1.vb" id="Snippet2"::: You can also use the delegate with anonymous methods in C#, as the following example illustrates. (For an introduction to anonymous methods, see [Anonymous Methods](~/docs/csharp/programming-guide/statements-expressions-operators/anonymous-methods.md).) - - [!code-csharp-interactive[System.Func~2#3](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Func~2/cs/Anon.cs#3)] + + :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Func~2/cs/Anon.cs" interactive="try-dotnet-method" id="Snippet3"::: You can also assign a lambda expression to a delegate, as the following example illustrates. (For an introduction to lambda expressions, see [Lambda Expressions](~/docs/visual-basic/programming-guide/language-features/procedures/lambda-expressions.md) and [Lambda Expressions](~/docs/csharp/programming-guide/statements-expressions-operators/lambda-expressions.md).) - [!code-csharp-interactive[System.Func~2#4](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Func~2/cs/Lambda.cs#4)] - [!code-vb[System.Func~2#4](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Func~2/vb/Lambda.vb#4)] - + :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Func~2/cs/Lambda.cs" interactive="try-dotnet-method" id="Snippet4"::: + :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Func~2/vb/Lambda.vb" id="Snippet4"::: + The underlying type of a lambda expression is one of the generic `Func` delegates. This makes it possible to pass a lambda expression as a parameter without explicitly assigning it to a delegate. In particular, because many methods of types in the namespace have parameters, you can pass these methods a lambda expression without explicitly instantiating a delegate. @@ -99,8 +99,8 @@ ## Examples The following example demonstrates how to declare and use a delegate. This example declares a variable and assigns it a lambda expression that converts the characters in a string to uppercase. The delegate that encapsulates this method is subsequently passed to the method to change the strings in an array of strings to uppercase. - [!code-csharp-interactive[System.Func~2#5](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Func~2/cs/Example.cs#5)] - [!code-vb[System.Func~2#5](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Func~2/vb/Example.vb#5)] + :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Func~2/cs/Example.cs" interactive="try-dotnet-method" id="Snippet5"::: + :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Func~2/vb/Example.vb" id="Snippet5"::: ]]> diff --git a/xml/System/Int32.xml b/xml/System/Int32.xml index 40bdb3ef8e0..b21400059a8 100644 --- a/xml/System/Int32.xml +++ b/xml/System/Int32.xml @@ -86,14 +86,14 @@ - You can call a method of the class to convert any supported type to an value. This is possible because supports the interface. The following example illustrates the conversion of an array of values to values. - [!code-csharp[System.Convert.ToInt32#4](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.convert.toint32/cs/toint32_1.cs#4)] - [!code-vb[System.Convert.ToInt32#4](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.toint32/vb/toint32_1.vb#4)] + :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.convert.toint32/cs/toint32_1.cs" interactive="try-dotnet-method" id="Snippet4"::: + :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.toint32/vb/toint32_1.vb" id="Snippet4"::: - You can call the or method to convert the string representation of an value to an . The string can contain either decimal or hexadecimal digits. The following example illustrates the parse operation by using both a decimal and a hexadecimal string. - [!code-csharp[System.Int32.Instantiation#3](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Int32.Instantiation/cs/Instantiate1.cs#3)] - [!code-vb[System.Int32.Instantiation#3](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Int32.Instantiation/vb/Instantiate1.vb#3)] - + :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Int32.Instantiation/cs/Instantiate1.cs" interactive="try-dotnet-method" id="Snippet3"::: + :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Int32.Instantiation/vb/Instantiate1.vb" id="Snippet3"::: + ## Performing Operations on Int32 Values The type supports standard mathematical operations such as addition, subtraction, division, multiplication, negation, and unary negation. Like the other integral types, the type also supports the bitwise `AND`, `OR`, `XOR`, left shift, and right shift operators. @@ -105,14 +105,14 @@ The type provides full support for standard and custom numeric format strings. (For more information, see [Formatting Types](~/docs/standard/base-types/formatting-types.md), [Standard Numeric Format Strings](~/docs/standard/base-types/standard-numeric-format-strings.md), and [Custom Numeric Format Strings](~/docs/standard/base-types/custom-numeric-format-strings.md).) To format an value as an integral string with no leading zeros, you can call the parameterless method. By using the "D" format specifier, you can also include a specified number of leading zeros in the string representation. By using the "N" format specifier, you can include group separators and specify the number of decimal digits to appear in the string representation of the number. By using the "X" format specifier, you can represent an value as a hexadecimal string. The following example formats the elements in an array of values in these four ways. - - [!code-csharp[System.Int32.Formatting#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Int32.Formatting/cs/Formatting1.cs#1)] - [!code-vb[System.Int32.Formatting#1](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Int32.Formatting/vb/Formatting1.vb#1)] + + :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Int32.Formatting/cs/Formatting1.cs" interactive="try-dotnet-method" id="Snippet1"::: + :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Int32.Formatting/vb/Formatting1.vb" id="Snippet1"::: You can also format an value as a binary, octal, decimal, or hexadecimal string by calling the method and supplying the base as the method's second parameter. The following example calls this method to display the binary, octal, and hexadecimal representations of an array of integer values. - [!code-csharp[System.Int32.Formatting#2](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Int32.Formatting/cs/Formatting1.cs#2)] - [!code-vb[System.Int32.Formatting#2](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Int32.Formatting/vb/Formatting1.vb#2)] + :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Int32.Formatting/cs/Formatting1.cs" interactive="try-dotnet-method" id="Snippet2"::: + :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Int32.Formatting/vb/Formatting1.vb" id="Snippet2"::: ## Working with Non-Decimal 32-Bit Integer Values In addition to working with individual integers as decimal values, you may want to perform bitwise operations with integer values, or work with the binary or hexadecimal representations of integer values. values are represented in 31 bits, with the thirty-second bit used as a sign bit. Positive values are represented by using sign-and-magnitude representation. Negative values are in two's complement representation. This is important to keep in mind when you perform bitwise operations on values or when you work with individual bits. In order to perform a numeric, Boolean, or comparison operation on any two non-decimal values, both values must use the same representation. @@ -377,9 +377,11 @@ Compiler overload resolution may account for an apparent difference in the behavior of the two method overloads. If an implicit conversion between the argument and an is defined and the argument is not typed as an , compilers perform an implicit conversion and call the method. Otherwise, they call the method, which always returns if its argument is not an value. The following example illustrates the difference in behavior between the two method overloads. In the case of the , , , and values, the first comparison returns because the compiler automatically performs a widening conversion and calls the method, whereas the second comparison returns because the compiler calls the method. - - [!code-csharp[System.Int32.Equals#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.int32.equals/cs/equalsoverloads2.cs#1)] - [!code-vb[System.Int32.Equals#1](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.int32.equals/vb/equalsoverloads2.vb#1)] + + :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.int32.equals/cs/equalsoverloads2.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.int32.equals/vb/equalsoverloads2.vb" id="Snippet1"::: + + @@ -434,18 +436,20 @@ ## Examples The following example illustrates the use of `Equals` in the context of `Int32`, comparing two `int` values and returning `true` if they represent the same number, or `false` if they do not. - - [!code-cpp[Int32_Equals#1](~/samples/snippets/cpp/VS_Snippets_CLR/Int32_Equals/CPP/int32_equals.cpp#1)] - [!code-csharp[Int32_Equals#1](~/samples/snippets/csharp/VS_Snippets_CLR/Int32_Equals/CS/int32_equals.cs#1)] - [!code-vb[Int32_Equals#1](~/samples/snippets/visualbasic/VS_Snippets_CLR/Int32_Equals/VB/int32_equals.vb#1)] + + :::code language="cpp" source="~/samples/snippets/cpp/VS_Snippets_CLR/Int32_Equals/CPP/int32_equals.cpp" id="Snippet1"::: + :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR/Int32_Equals/CS/int32_equals.cs" interactive="try-dotnet-method" id="Snippet1"::: + :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR/Int32_Equals/VB/int32_equals.vb" id="Snippet1"::: ]]> Compiler overload resolution may account for an apparent difference in the behavior of the two method overloads. If an implicit conversion between the argument and an is defined and the argument is not typed as an , compilers perform an implicit conversion and call the method. Otherwise, they call the method, which always returns if its argument is not an value. The following example illustrates the difference in behavior between the two method overloads. In the case of the , , , and values, the first comparison returns because the compiler automatically performs a widening conversion and calls the method, whereas the second comparison returns because the compiler calls the method. - - [!code-csharp[System.Int32.Equals#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.int32.equals/cs/equalsoverloads2.cs#1)] - [!code-vb[System.Int32.Equals#1](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.int32.equals/vb/equalsoverloads2.vb#1)] + + :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.int32.equals/cs/equalsoverloads2.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.int32.equals/vb/equalsoverloads2.vb" id="Snippet1"::: + + @@ -2535,9 +2539,9 @@ This member is an explicit interface member implementation. It can be used only ## Examples The following example calls the method with a number of different string values. - [!code-cpp[System.Int32.TryParse#1](~/samples/snippets/cpp/VS_Snippets_CLR_System/system.Int32.TryParse/cpp/int32.tryparse1.cpp#1)] - [!code-csharp[System.Int32.TryParse#1](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Int32.TryParse/cs/TryParse1.cs#1)] - [!code-vb[System.Int32.TryParse#1](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Int32.TryParse/vb/TryParse1.vb#1)] + :::code language="cpp" source="~/samples/snippets/cpp/VS_Snippets_CLR_System/system.Int32.TryParse/cpp/int32.tryparse1.cpp" id="Snippet1"::: + :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Int32.TryParse/cs/TryParse1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Int32.TryParse/vb/TryParse1.vb" id="Snippet1"::: Some of the strings that the method is unable to convert in this example are: @@ -2708,9 +2712,9 @@ This member is an explicit interface member implementation. It can be used only ## Examples The following example calls the method with a number of different string and values. - [!code-cpp[System.Int32.TryParse#2](~/samples/snippets/cpp/VS_Snippets_CLR_System/system.Int32.TryParse/cpp/int32.tryparse2.cpp#2)] - [!code-csharp[System.Int32.TryParse#2](~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Int32.TryParse/cs/TryParse2.cs#2)] - [!code-vb[System.Int32.TryParse#2](~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Int32.TryParse/vb/TryParse2.vb#2)] + :::code language="cpp" source="~/samples/snippets/cpp/VS_Snippets_CLR_System/system.Int32.TryParse/cpp/int32.tryparse2.cpp" id="Snippet2"::: + :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.Int32.TryParse/cs/TryParse2.cs" interactive="try-dotnet" id="Snippet2"::: + :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Int32.TryParse/vb/TryParse2.vb" id="Snippet2"::: ]]>