diff --git a/xml/Microsoft.Extensions.Compliance.Classification/DataClassificationSet.xml b/xml/Microsoft.Extensions.Compliance.Classification/DataClassificationSet.xml index 8e9643adb83..2976be0c82a 100644 --- a/xml/Microsoft.Extensions.Compliance.Classification/DataClassificationSet.xml +++ b/xml/Microsoft.Extensions.Compliance.Classification/DataClassificationSet.xml @@ -308,8 +308,8 @@ The resulting set which combines the current instance's classifications and the other ones. - This method doesn't modify the two input sets, it creates a new set. - + This method doesn't modify the two input sets, it creates a new set. + diff --git a/xml/System/Action.xml b/xml/System/Action.xml index 5120056cdb5..1acbf2399e6 100644 --- a/xml/System/Action.xml +++ b/xml/System/Action.xml @@ -63,38 +63,38 @@ Encapsulates a method that has no parameters and does not return a value. - [!NOTE] -> To reference a method that has no parameters and returns a value, use the generic delegate instead. - - When you use the delegate, you do not have to explicitly define a delegate that encapsulates a parameterless procedure. For example, the following code explicitly declares a delegate named `ShowValue` and assigns a reference to the `Name.DisplayToWindow` instance method to its delegate instance. - +> To reference a method that has no parameters and returns a value, use the generic delegate instead. + + When you use the delegate, you do not have to explicitly define a delegate that encapsulates a parameterless procedure. For example, the following code explicitly declares a delegate named `ShowValue` and assigns a reference to the `Name.DisplayToWindow` instance method to its delegate instance. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.action.delegate/cpp/delegate.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Action/Overview/delegate1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Action/fs/Delegate.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.action.delegate/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 language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.action.delegate/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 language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Action/cpp/action.cpp" id="Snippet2"::: :::code language="csharp" source="~/snippets/csharp/System/Action/Overview/Action.cs" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Action/fs/Action.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Action/vb/Action.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](/dotnet/csharp/programming-guide/statements-expressions-operators/anonymous-methods).) - - :::code language="csharp" source="~/snippets/csharp/System/Action/Overview/Anon.cs" id="Snippet3"::: - - You can also assign a lambda expression to an delegate instance, as the following example illustrates. (For an introduction to lambda expressions, see [Lambda Expressions (C#)](/dotnet/csharp/programming-guide/statements-expressions-operators/lambda-expressions) or [Lambda Expressions (F#)](/dotnet/fsharp/language-reference/functions/lambda-expressions-the-fun-keyword).) - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Action/vb/Action.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](/dotnet/csharp/programming-guide/statements-expressions-operators/anonymous-methods).) + + :::code language="csharp" source="~/snippets/csharp/System/Action/Overview/Anon.cs" id="Snippet3"::: + + You can also assign a lambda expression to an delegate instance, as the following example illustrates. (For an introduction to lambda expressions, see [Lambda Expressions (C#)](/dotnet/csharp/programming-guide/statements-expressions-operators/lambda-expressions) or [Lambda Expressions (F#)](/dotnet/fsharp/language-reference/functions/lambda-expressions-the-fun-keyword).) + :::code language="csharp" source="~/snippets/csharp/System/Action/Overview/Lambda.cs" id="Snippet4"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Action/fs/Lambda.fs" id="Snippet4"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Action/vb/lambda.vb" id="Snippet4"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Action/vb/lambda.vb" id="Snippet4"::: + ]]> diff --git a/xml/System/Action`1.xml b/xml/System/Action`1.xml index e3e3699c346..bb9e1d4969b 100644 --- a/xml/System/Action`1.xml +++ b/xml/System/Action`1.xml @@ -67,49 +67,49 @@ The parameter of the method that this delegate encapsulates. Encapsulates a method that has a single parameter and does not return a value. - delegate to pass a method as a parameter without explicitly declaring a custom delegate. The encapsulated method must correspond to the method signature that is defined by this delegate. This means that the encapsulated method must have one parameter that is passed to it by value, and it must not return a value. (In C#, the method must return `void`. In Visual Basic, it must be defined by the `Sub`…`End Sub` construct. It can also be a method that returns a value that is ignored.) Typically, such a method is used to perform an operation. - + delegate to pass a method as a parameter without explicitly declaring a custom delegate. The encapsulated method must correspond to the method signature that is defined by this delegate. This means that the encapsulated method must have one parameter that is passed to it by value, and it must not return a value. (In C#, the method must return `void`. In Visual Basic, it must be defined by the `Sub`…`End Sub` construct. It can also be a method that returns a value that is ignored.) Typically, such a method is used to perform an operation. + > [!NOTE] -> To reference a method that has one parameter and returns a value, 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 `DisplayMessage` and assigns a reference to either the method or the `ShowWindowsMessage` method to its delegate instance. - +> To reference a method that has one parameter and returns a value, 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 `DisplayMessage` and assigns a reference to either the method or the `ShowWindowsMessage` method to its delegate instance. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Action~1/cpp/delegate.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/ActionT/Overview/Delegate.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Action~1/fs/Delegate.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Action~1/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 language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Action~1/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 language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Action~1/cpp/action`1.cpp" id="Snippet2"::: :::code language="csharp" source="~/snippets/csharp/System/ActionT/Overview/Action1.cs" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Action~1/fs/Action1.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Action~1/vb/Action1.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](/dotnet/csharp/programming-guide/statements-expressions-operators/anonymous-methods).) - - :::code language="csharp" source="~/snippets/csharp/System/ActionT/Overview/Anon.cs" id="Snippet3"::: - - You can also assign a lambda expression to an delegate instance, as the following example illustrates. (For an introduction to lambda expressions, see [Lambda Expressions](/dotnet/csharp/programming-guide/statements-expressions-operators/lambda-expressions).) - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Action~1/vb/Action1.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](/dotnet/csharp/programming-guide/statements-expressions-operators/anonymous-methods).) + + :::code language="csharp" source="~/snippets/csharp/System/ActionT/Overview/Anon.cs" id="Snippet3"::: + + You can also assign a lambda expression to an delegate instance, as the following example illustrates. (For an introduction to lambda expressions, see [Lambda Expressions](/dotnet/csharp/programming-guide/statements-expressions-operators/lambda-expressions).) + :::code language="csharp" source="~/snippets/csharp/System/ActionT/Overview/Lambda.cs" id="Snippet4"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Action~1/fs/Lambda.fs" id="Snippet4"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Action~1/vb/lambda.vb" id="Snippet4"::: - - The and methods each take an delegate as a parameter. The method encapsulated by the delegate allows you to perform an action on each element in the array or list. The example uses the method to provide an illustration. - - - -## Examples - The following example demonstrates the use of the delegate to print the contents of a object. In this example, the `Print` method is used to display the contents of the list to the console. In addition, the C# example also demonstrates the use of anonymous methods to display the contents to the console. Note that the example does not explicitly declare an variable. Instead, it passes a reference to a method that takes a single parameter and that does not return a value to the method, whose single parameter is an delegate. Similarly, in the C# example, an delegate is not explicitly instantiated because the signature of the anonymous method matches the signature of the delegate that is expected by the method. + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Action~1/vb/lambda.vb" id="Snippet4"::: + + The and methods each take an delegate as a parameter. The method encapsulated by the delegate allows you to perform an action on each element in the array or list. The example uses the method to provide an illustration. + + + +## Examples + The following example demonstrates the use of the delegate to print the contents of a object. In this example, the `Print` method is used to display the contents of the list to the console. In addition, the C# example also demonstrates the use of anonymous methods to display the contents to the console. Note that the example does not explicitly declare an variable. Instead, it passes a reference to a method that takes a single parameter and that does not return a value to the method, whose single parameter is an delegate. Similarly, in the C# example, an delegate is not explicitly instantiated because the signature of the anonymous method matches the signature of the delegate that is expected by the method. :::code language="csharp" source="~/snippets/csharp/System/ActionT/Overview/action.cs" interactive="try-dotnet-method" id="Snippet01"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Action_PrintExample/fs/action.fs" id="Snippet01"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Action_PrintExample/vb/action.vb" id="Snippet01"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Action_PrintExample/vb/action.vb" id="Snippet01"::: + ]]> diff --git a/xml/System/Action`10.xml b/xml/System/Action`10.xml index f24dcbcc596..6ed66f3d11a 100644 --- a/xml/System/Action`10.xml +++ b/xml/System/Action`10.xml @@ -139,16 +139,16 @@ The tenth parameter of the method that this delegate encapsulates. Encapsulates a method that has 10 parameters and does not return a value. - delegate to pass a method as a parameter without explicitly declaring a custom delegate. The encapsulated method must correspond to the method signature that is defined by this delegate. This means that the encapsulated method must have 10 parameters that are all passed to it by value, and it must not return a value. (In C#, the method must return `void`. In Visual Basic, it must be defined by the `Sub`…`End Sub` construct. It can also be a method that returns a value that is ignored.) Typically, such a method is used to perform an operation. - + delegate to pass a method as a parameter without explicitly declaring a custom delegate. The encapsulated method must correspond to the method signature that is defined by this delegate. This means that the encapsulated method must have 10 parameters that are all passed to it by value, and it must not return a value. (In C#, the method must return `void`. In Visual Basic, it must be defined by the `Sub`…`End Sub` construct. It can also be a method that returns a value that is ignored.) Typically, such a method is used to perform an operation. + > [!NOTE] -> To reference a method that has 10 parameters and returns a value, use the generic delegate instead. - - You can also use the delegate with anonymous methods and lambda expressions. - +> To reference a method that has 10 parameters and returns a value, use the generic delegate instead. + + You can also use the delegate with anonymous methods and lambda expressions. + ]]> diff --git a/xml/System/Action`11.xml b/xml/System/Action`11.xml index c433a864114..85e79d639dd 100644 --- a/xml/System/Action`11.xml +++ b/xml/System/Action`11.xml @@ -147,16 +147,16 @@ The eleventh parameter of the method that this delegate encapsulates. Encapsulates a method that has 11 parameters and does not return a value. - delegate to pass a method as a parameter without explicitly declaring a custom delegate. The encapsulated method must correspond to the method signature that is defined by this delegate. This means that the encapsulated method must have 11 parameters that are all passed to it by value, and it must not return a value. (In C#, the method must return `void`. In Visual Basic, it must be defined by the `Sub`…`End Sub` construct. It can also be a method that returns a value that is ignored.) Typically, such a method is used to perform an operation. - + delegate to pass a method as a parameter without explicitly declaring a custom delegate. The encapsulated method must correspond to the method signature that is defined by this delegate. This means that the encapsulated method must have 11 parameters that are all passed to it by value, and it must not return a value. (In C#, the method must return `void`. In Visual Basic, it must be defined by the `Sub`…`End Sub` construct. It can also be a method that returns a value that is ignored.) Typically, such a method is used to perform an operation. + > [!NOTE] -> To reference a method that has 11 parameters and returns a value, use the generic delegate instead. - - You can also use the delegate with anonymous methods and lambda expressions. - +> To reference a method that has 11 parameters and returns a value, use the generic delegate instead. + + You can also use the delegate with anonymous methods and lambda expressions. + ]]> diff --git a/xml/System/Action`12.xml b/xml/System/Action`12.xml index 1b701ae2045..d7c2262173a 100644 --- a/xml/System/Action`12.xml +++ b/xml/System/Action`12.xml @@ -155,16 +155,16 @@ The twelfth parameter of the method that this delegate encapsulates. Encapsulates a method that has 12 parameters and does not return a value. - delegate to pass a method as a parameter without explicitly declaring a custom delegate. The encapsulated method must correspond to the method signature that is defined by this delegate. This means that the encapsulated method must have 12 parameters that are all passed to it by value, and it must not return a value. (In C#, the method must return `void`. In Visual Basic, it must be defined by the `Sub`…`End Sub` construct. It can also be a method that returns a value that is ignored.) Typically, such a method is used to perform an operation. - + delegate to pass a method as a parameter without explicitly declaring a custom delegate. The encapsulated method must correspond to the method signature that is defined by this delegate. This means that the encapsulated method must have 12 parameters that are all passed to it by value, and it must not return a value. (In C#, the method must return `void`. In Visual Basic, it must be defined by the `Sub`…`End Sub` construct. It can also be a method that returns a value that is ignored.) Typically, such a method is used to perform an operation. + > [!NOTE] -> To reference a method that has 12 parameters and returns a value, use the generic delegate instead. - - You can also use the delegate with anonymous methods and lambda expressions. - +> To reference a method that has 12 parameters and returns a value, use the generic delegate instead. + + You can also use the delegate with anonymous methods and lambda expressions. + ]]> diff --git a/xml/System/Action`13.xml b/xml/System/Action`13.xml index 19f68c00597..1e736becbeb 100644 --- a/xml/System/Action`13.xml +++ b/xml/System/Action`13.xml @@ -163,16 +163,16 @@ The thirteenth parameter of the method that this delegate encapsulates. Encapsulates a method that has 13 parameters and does not return a value. - delegate to pass a method as a parameter without explicitly declaring a custom delegate. The encapsulated method must correspond to the method signature that is defined by this delegate. This means that the encapsulated method must have 13 parameters that are all passed to it by value, and it must not return a value. (In C#, the method must return `void`. In Visual Basic, it must be defined by the `Sub`…`End Sub` construct. It can also be a method that returns a value that is ignored.) Typically, such a method is used to perform an operation. - + delegate to pass a method as a parameter without explicitly declaring a custom delegate. The encapsulated method must correspond to the method signature that is defined by this delegate. This means that the encapsulated method must have 13 parameters that are all passed to it by value, and it must not return a value. (In C#, the method must return `void`. In Visual Basic, it must be defined by the `Sub`…`End Sub` construct. It can also be a method that returns a value that is ignored.) Typically, such a method is used to perform an operation. + > [!NOTE] -> To reference a method that has 13 parameters and returns a value, use the generic delegate instead. - - You can also use the delegate with anonymous methods and lambda expressions. - +> To reference a method that has 13 parameters and returns a value, use the generic delegate instead. + + You can also use the delegate with anonymous methods and lambda expressions. + ]]> diff --git a/xml/System/Action`14.xml b/xml/System/Action`14.xml index 173d68657d1..6b9fdd73755 100644 --- a/xml/System/Action`14.xml +++ b/xml/System/Action`14.xml @@ -171,16 +171,16 @@ The fourteenth parameter of the method that this delegate encapsulates. Encapsulates a method that has 14 parameters and does not return a value. - delegate to pass a method as a parameter without explicitly declaring a custom delegate. The encapsulated method must correspond to the method signature that is defined by this delegate. This means that the encapsulated method must have 14 parameters that are all passed to it by value, and it must not return a value. (In C#, the method must return `void`. In Visual Basic, it must be defined by the `Sub`…`End Sub` construct. It can also be a method that returns a value that is ignored.) Typically, such a method is used to perform an operation. - + delegate to pass a method as a parameter without explicitly declaring a custom delegate. The encapsulated method must correspond to the method signature that is defined by this delegate. This means that the encapsulated method must have 14 parameters that are all passed to it by value, and it must not return a value. (In C#, the method must return `void`. In Visual Basic, it must be defined by the `Sub`…`End Sub` construct. It can also be a method that returns a value that is ignored.) Typically, such a method is used to perform an operation. + > [!NOTE] -> To reference a method that has 14 parameters and returns a value, use the generic delegate instead. - - You can also use the delegate with anonymous methods and lambda expressions. - +> To reference a method that has 14 parameters and returns a value, use the generic delegate instead. + + You can also use the delegate with anonymous methods and lambda expressions. + ]]> diff --git a/xml/System/Action`15.xml b/xml/System/Action`15.xml index db828e7d288..aae2793bd34 100644 --- a/xml/System/Action`15.xml +++ b/xml/System/Action`15.xml @@ -179,16 +179,16 @@ The fifteenth parameter of the method that this delegate encapsulates. Encapsulates a method that has 15 parameters and does not return a value. - delegate to pass a method as a parameter without explicitly declaring a custom delegate. The encapsulated method must correspond to the method signature that is defined by this delegate. This means that the encapsulated method must have 15 parameters that are all passed to it by value, and it must not return a value. (In C#, the method must return `void`. In Visual Basic, it must be defined by the `Sub`…`End Sub` construct. It can also be a method that returns a value that is ignored.) Typically, such a method is used to perform an operation. - + delegate to pass a method as a parameter without explicitly declaring a custom delegate. The encapsulated method must correspond to the method signature that is defined by this delegate. This means that the encapsulated method must have 15 parameters that are all passed to it by value, and it must not return a value. (In C#, the method must return `void`. In Visual Basic, it must be defined by the `Sub`…`End Sub` construct. It can also be a method that returns a value that is ignored.) Typically, such a method is used to perform an operation. + > [!NOTE] -> To reference a method that has 15 parameters and returns a value, use the generic delegate instead. - - You can also use the delegate with anonymous methods and lambda expressions. - +> To reference a method that has 15 parameters and returns a value, use the generic delegate instead. + + You can also use the delegate with anonymous methods and lambda expressions. + ]]> diff --git a/xml/System/Action`16.xml b/xml/System/Action`16.xml index f4ce1b29d61..ea9ddca5cfa 100644 --- a/xml/System/Action`16.xml +++ b/xml/System/Action`16.xml @@ -187,16 +187,16 @@ The sixteenth parameter of the method that this delegate encapsulates. Encapsulates a method that has 16 parameters and does not return a value. - delegate to pass a method as a parameter without explicitly declaring a custom delegate. The encapsulated method must correspond to the method signature that is defined by this delegate. This means that the encapsulated method must have 16 parameters that are all passed to it by value, and it must not return a value. (In C#, the method must return `void`. In Visual Basic, it must be defined by the `Sub`…`End Sub` construct. It can also be a method that returns a value that is ignored.) Typically, such a method is used to perform an operation. - + delegate to pass a method as a parameter without explicitly declaring a custom delegate. The encapsulated method must correspond to the method signature that is defined by this delegate. This means that the encapsulated method must have 16 parameters that are all passed to it by value, and it must not return a value. (In C#, the method must return `void`. In Visual Basic, it must be defined by the `Sub`…`End Sub` construct. It can also be a method that returns a value that is ignored.) Typically, such a method is used to perform an operation. + > [!NOTE] -> To reference a method that has 16 parameters and returns a value, use the generic delegate instead. - - You can also use the delegate with anonymous methods and lambda expressions. - +> To reference a method that has 16 parameters and returns a value, use the generic delegate instead. + + You can also use the delegate with anonymous methods and lambda expressions. + ]]> diff --git a/xml/System/Action`2.xml b/xml/System/Action`2.xml index fe1158419cb..5c00b72dd69 100644 --- a/xml/System/Action`2.xml +++ b/xml/System/Action`2.xml @@ -97,32 +97,32 @@ The second parameter of the method that this delegate encapsulates. Encapsulates a method that has two parameters and does not return a value. - delegate to pass a method as a parameter without explicitly declaring a custom delegate. The encapsulated method must correspond to the method signature that is defined by this delegate. This means that the encapsulated method must have two parameters that are both passed to it by value, and it must not return a value. (In C#, the method must return `void`. In F#, the method or function must return unit. In Visual Basic, it must be defined by the `Sub`…`End Sub` construct. It can also be a method that returns a value that is ignored.) Typically, such a method is used to perform an operation. - + delegate to pass a method as a parameter without explicitly declaring a custom delegate. The encapsulated method must correspond to the method signature that is defined by this delegate. This means that the encapsulated method must have two parameters that are both passed to it by value, and it must not return a value. (In C#, the method must return `void`. In F#, the method or function must return unit. In Visual Basic, it must be defined by the `Sub`…`End Sub` construct. It can also be a method that returns a value that is ignored.) Typically, such a method is used to perform an operation. + > [!NOTE] -> To reference a method that has two parameters and returns a value, use the generic delegate instead. - - When you use the delegate, you do not have to explicitly define a delegate that encapsulates a method with two parameters. For example, the following code explicitly declares a delegate named `ConcatStrings`. It then assigns a reference to either of two methods to its delegate instance. One method writes two strings to the console; the second writes two strings to a file. - +> To reference a method that has two parameters and returns a value, use the generic delegate instead. + + When you use the delegate, you do not have to explicitly define a delegate that encapsulates a method with two parameters. For example, the following code explicitly declares a delegate named `ConcatStrings`. It then assigns a reference to either of two methods to its delegate instance. One method writes two strings to the console; the second writes two strings to a file. + :::code language="csharp" source="~/snippets/csharp/System/ActionT1,T2/Overview/Delegate.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Action~2/fs/Delegate.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Action~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. - + + 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 language="csharp" source="~/snippets/csharp/System/ActionT1,T2/Overview/Action2.cs" interactive="try-dotnet" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Action~2/fs/Action2.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Action~2/vb/action2.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](/dotnet/csharp/programming-guide/statements-expressions-operators/anonymous-methods).) - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Action~2/vb/action2.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](/dotnet/csharp/programming-guide/statements-expressions-operators/anonymous-methods).) + :::code language="csharp" source="~/snippets/csharp/System/ActionT1,T2/Overview/Anon.cs" interactive="try-dotnet" id="Snippet3"::: - You can also assign a lambda expression to an delegate instance, as the following example illustrates. (For an introduction to lambda expressions, see [Lambda Expressions (C#)](/dotnet/csharp/programming-guide/statements-expressions-operators/lambda-expressions), or [Lambda Expressions (F#)](/dotnet/fsharp/language-reference/functions/lambda-expressions-the-fun-keyword).) - + You can also assign a lambda expression to an delegate instance, as the following example illustrates. (For an introduction to lambda expressions, see [Lambda Expressions (C#)](/dotnet/csharp/programming-guide/statements-expressions-operators/lambda-expressions), or [Lambda Expressions (F#)](/dotnet/fsharp/language-reference/functions/lambda-expressions-the-fun-keyword).) + :::code language="csharp" source="~/snippets/csharp/System/ActionT1,T2/Overview/Lambda.cs" interactive="try-dotnet" id="Snippet4"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Action~2/fs/Lambda.fs" id="Snippet4"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Action~2/vb/lambda.vb" id="Snippet4"::: diff --git a/xml/System/Action`3.xml b/xml/System/Action`3.xml index 06addfe38c4..b9373068baf 100644 --- a/xml/System/Action`3.xml +++ b/xml/System/Action`3.xml @@ -111,36 +111,36 @@ The third parameter of the method that this delegate encapsulates. Encapsulates a method that has three parameters and does not return a value. - delegate to pass a method as a parameter without explicitly declaring a custom delegate. The encapsulated method must correspond to the method signature that is defined by this delegate. This means that the encapsulated method must have three parameters that are all passed to it by value, and it must not return a value. (In C#, the method must return `void`. In F#, the method or function must return unit. In Visual Basic, it must be defined by the `Sub`…`End Sub` construct. It can also be a method that returns a value that is ignored.) Typically, such a method is used to perform an operation. - + delegate to pass a method as a parameter without explicitly declaring a custom delegate. The encapsulated method must correspond to the method signature that is defined by this delegate. This means that the encapsulated method must have three parameters that are all passed to it by value, and it must not return a value. (In C#, the method must return `void`. In F#, the method or function must return unit. In Visual Basic, it must be defined by the `Sub`…`End Sub` construct. It can also be a method that returns a value that is ignored.) Typically, such a method is used to perform an operation. + > [!NOTE] -> To reference a method that has three parameters and returns a value, use the generic delegate instead. - - When you use the delegate, you do not have to explicitly define a delegate that encapsulates a method with three parameters. For example, the following code explicitly declares a delegate named `StringCopy` and assigns a reference to the `CopyStrings` method to its delegate instance. - +> To reference a method that has three parameters and returns a value, use the generic delegate instead. + + When you use the delegate, you do not have to explicitly define a delegate that encapsulates a method with three parameters. For example, the following code explicitly declares a delegate named `StringCopy` and assigns a reference to the `CopyStrings` method to its delegate instance. + :::code language="csharp" source="~/snippets/csharp/System/ActionT1,T2,T3/Overview/Delegate.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Action~3/fs/Delegate.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Action~3/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 language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Action~3/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 language="csharp" source="~/snippets/csharp/System/ActionT1,T2,T3/Overview/Action3.cs" interactive="try-dotnet" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Action~3/fs/Action3.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Action~3/vb/Action3.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](/dotnet/csharp/programming-guide/statements-expressions-operators/anonymous-methods).) - - :::code language="csharp" source="~/snippets/csharp/System/ActionT1,T2,T3/Overview/Anon.cs" interactive="try-dotnet" id="Snippet3"::: - - You can also assign a lambda expression to an delegate instance, as the following example illustrates. (For an introduction to lambda expressions, see [Lambda Expressions (C#)](/dotnet/csharp/programming-guide/statements-expressions-operators/lambda-expressions) or [Lambda Expressions (F#)](/dotnet/fsharp/language-reference/functions/lambda-expressions-the-fun-keyword).) - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Action~3/vb/Action3.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](/dotnet/csharp/programming-guide/statements-expressions-operators/anonymous-methods).) + + :::code language="csharp" source="~/snippets/csharp/System/ActionT1,T2,T3/Overview/Anon.cs" interactive="try-dotnet" id="Snippet3"::: + + You can also assign a lambda expression to an delegate instance, as the following example illustrates. (For an introduction to lambda expressions, see [Lambda Expressions (C#)](/dotnet/csharp/programming-guide/statements-expressions-operators/lambda-expressions) or [Lambda Expressions (F#)](/dotnet/fsharp/language-reference/functions/lambda-expressions-the-fun-keyword).) + :::code language="csharp" source="~/snippets/csharp/System/ActionT1,T2,T3/Overview/Lambda.cs" interactive="try-dotnet" id="Snippet4"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Action~3/fs/Lambda.fs" id="Snippet4"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Action~3/vb/lambda.vb" id="Snippet4"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Action~3/vb/lambda.vb" id="Snippet4"::: + ]]> diff --git a/xml/System/Action`4.xml b/xml/System/Action`4.xml index 84643b9b9bf..b863c2e1277 100644 --- a/xml/System/Action`4.xml +++ b/xml/System/Action`4.xml @@ -109,36 +109,36 @@ The fourth parameter of the method that this delegate encapsulates. Encapsulates a method that has four parameters and does not return a value. - delegate to pass a method as a parameter without explicitly declaring a custom delegate. The encapsulated method must correspond to the method signature that is defined by this delegate. This means that the encapsulated method must have four parameters that are all passed to it by value, and it must not return a value. (In C#, the method must return `void`. In F#, the method or function must return unit. In Visual Basic, it must be defined by the `Sub`…`End Sub` construct. It can also be a method that returns a value that is ignored.) Typically, such a method is used to perform an operation. - + delegate to pass a method as a parameter without explicitly declaring a custom delegate. The encapsulated method must correspond to the method signature that is defined by this delegate. This means that the encapsulated method must have four parameters that are all passed to it by value, and it must not return a value. (In C#, the method must return `void`. In F#, the method or function must return unit. In Visual Basic, it must be defined by the `Sub`…`End Sub` construct. It can also be a method that returns a value that is ignored.) Typically, such a method is used to perform an operation. + > [!NOTE] -> To reference a method that has four parameters and returns a value, use the generic delegate instead. - - When you use the delegate, you do not have to explicitly define a delegate that encapsulates a method with four parameters. For example, the following code explicitly declares a delegate named `StringCopy` and assigns a reference to the `CopyStrings` method to its delegate instance. - +> To reference a method that has four parameters and returns a value, use the generic delegate instead. + + When you use the delegate, you do not have to explicitly define a delegate that encapsulates a method with four parameters. For example, the following code explicitly declares a delegate named `StringCopy` and assigns a reference to the `CopyStrings` method to its delegate instance. + :::code language="csharp" source="~/snippets/csharp/System/ActionT1,T2,T3,T4/Overview/Delegate.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Action~4/fs/Delegate.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Action~4/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 language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Action~4/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 language="csharp" source="~/snippets/csharp/System/ActionT1,T2,T3,T4/Overview/Action4.cs" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Action~4/fs/Action4.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Action~4/vb/Action4.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](/dotnet/csharp/programming-guide/statements-expressions-operators/anonymous-methods).) - - :::code language="csharp" source="~/snippets/csharp/System/ActionT1,T2,T3,T4/Overview/Anon.cs" id="Snippet3"::: - - You can also assign a lambda expression to an delegate instance, as the following example illustrates. (For an introduction to lambda expressions, see [Lambda Expressions (C#)](/dotnet/csharp/programming-guide/statements-expressions-operators/lambda-expressions) or [Lambda Expressions (F#)](/dotnet/fsharp/language-reference/functions/lambda-expressions-the-fun-keyword).) - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Action~4/vb/Action4.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](/dotnet/csharp/programming-guide/statements-expressions-operators/anonymous-methods).) + + :::code language="csharp" source="~/snippets/csharp/System/ActionT1,T2,T3,T4/Overview/Anon.cs" id="Snippet3"::: + + You can also assign a lambda expression to an delegate instance, as the following example illustrates. (For an introduction to lambda expressions, see [Lambda Expressions (C#)](/dotnet/csharp/programming-guide/statements-expressions-operators/lambda-expressions) or [Lambda Expressions (F#)](/dotnet/fsharp/language-reference/functions/lambda-expressions-the-fun-keyword).) + :::code language="csharp" source="~/snippets/csharp/System/ActionT1,T2,T3,T4/Overview/Lambda.cs" id="Snippet4"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Action~4/fs/Lambda.fs" id="Snippet4"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Action~4/vb/lambda.vb" id="Snippet4"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Action~4/vb/lambda.vb" id="Snippet4"::: + ]]> diff --git a/xml/System/Action`5.xml b/xml/System/Action`5.xml index 6b295ccc43b..1948b4e6e80 100644 --- a/xml/System/Action`5.xml +++ b/xml/System/Action`5.xml @@ -99,16 +99,16 @@ The fifth parameter of the method that this delegate encapsulates. Encapsulates a method that has five parameters and does not return a value. - delegate to pass a method as a parameter without explicitly declaring a custom delegate. The encapsulated method must correspond to the method signature that is defined by this delegate. This means that the encapsulated method must have five parameters that are all passed to it by value, and it must not return a value. (In C#, the method must return `void`. In Visual Basic, it must be defined by the `Sub`…`End Sub` construct. It can also be a method that returns a value that is ignored.) Typically, such a method is used to perform an operation. - + delegate to pass a method as a parameter without explicitly declaring a custom delegate. The encapsulated method must correspond to the method signature that is defined by this delegate. This means that the encapsulated method must have five parameters that are all passed to it by value, and it must not return a value. (In C#, the method must return `void`. In Visual Basic, it must be defined by the `Sub`…`End Sub` construct. It can also be a method that returns a value that is ignored.) Typically, such a method is used to perform an operation. + > [!NOTE] -> To reference a method that has five parameters and returns a value, use the generic delegate instead. - - You can also use the delegate with anonymous methods and lambda expressions. - +> To reference a method that has five parameters and returns a value, use the generic delegate instead. + + You can also use the delegate with anonymous methods and lambda expressions. + ]]> diff --git a/xml/System/Action`6.xml b/xml/System/Action`6.xml index bfca59e85b0..7f7d19e872e 100644 --- a/xml/System/Action`6.xml +++ b/xml/System/Action`6.xml @@ -107,16 +107,16 @@ The sixth parameter of the method that this delegate encapsulates. Encapsulates a method that has six parameters and does not return a value. - delegate to pass a method as a parameter without explicitly declaring a custom delegate. The encapsulated method must correspond to the method signature that is defined by this delegate. This means that the encapsulated method must have six parameters that are all passed to it by value, and it must not return a value. (In C#, the method must return `void`. In Visual Basic, it must be defined by the `Sub`…`End Sub` construct. It can also be a method that returns a value that is ignored.) Typically, such a method is used to perform an operation. - + delegate to pass a method as a parameter without explicitly declaring a custom delegate. The encapsulated method must correspond to the method signature that is defined by this delegate. This means that the encapsulated method must have six parameters that are all passed to it by value, and it must not return a value. (In C#, the method must return `void`. In Visual Basic, it must be defined by the `Sub`…`End Sub` construct. It can also be a method that returns a value that is ignored.) Typically, such a method is used to perform an operation. + > [!NOTE] -> To reference a method that has six parameters and returns a value, use the generic delegate instead. - - You can also use the delegate with anonymous methods and lambda expressions. - +> To reference a method that has six parameters and returns a value, use the generic delegate instead. + + You can also use the delegate with anonymous methods and lambda expressions. + ]]> diff --git a/xml/System/Action`7.xml b/xml/System/Action`7.xml index 77d304dfb32..5d30379ab89 100644 --- a/xml/System/Action`7.xml +++ b/xml/System/Action`7.xml @@ -115,16 +115,16 @@ The seventh parameter of the method that this delegate encapsulates. Encapsulates a method that has seven parameters and does not return a value. - delegate to pass a method as a parameter without explicitly declaring a custom delegate. The encapsulated method must correspond to the method signature that is defined by this delegate. This means that the encapsulated method must have seven parameters that are all passed to it by value, and it must not return a value. (In C#, the method must return `void`. In Visual Basic, it must be defined by the `Sub`…`End Sub` construct. It can also be a method that returns a value that is ignored.) Typically, such a method is used to perform an operation. - + delegate to pass a method as a parameter without explicitly declaring a custom delegate. The encapsulated method must correspond to the method signature that is defined by this delegate. This means that the encapsulated method must have seven parameters that are all passed to it by value, and it must not return a value. (In C#, the method must return `void`. In Visual Basic, it must be defined by the `Sub`…`End Sub` construct. It can also be a method that returns a value that is ignored.) Typically, such a method is used to perform an operation. + > [!NOTE] -> To reference a method that has seven parameters and returns a value, use the generic delegate instead. - - You can also use the delegate with anonymous methods and lambda expressions. - +> To reference a method that has seven parameters and returns a value, use the generic delegate instead. + + You can also use the delegate with anonymous methods and lambda expressions. + ]]> diff --git a/xml/System/Action`8.xml b/xml/System/Action`8.xml index 60914136093..6018c5f404d 100644 --- a/xml/System/Action`8.xml +++ b/xml/System/Action`8.xml @@ -123,16 +123,16 @@ The eighth parameter of the method that this delegate encapsulates. Encapsulates a method that has eight parameters and does not return a value. - delegate to pass a method as a parameter without explicitly declaring a custom delegate. The encapsulated method must correspond to the method signature that is defined by this delegate. This means that the encapsulated method must have eight parameters that are all passed to it by value, and it must not return a value. (In C#, the method must return `void`. In Visual Basic, it must be defined by the `Sub`…`End Sub` construct. It can also be a method that returns a value that is ignored.) Typically, such a method is used to perform an operation. - + delegate to pass a method as a parameter without explicitly declaring a custom delegate. The encapsulated method must correspond to the method signature that is defined by this delegate. This means that the encapsulated method must have eight parameters that are all passed to it by value, and it must not return a value. (In C#, the method must return `void`. In Visual Basic, it must be defined by the `Sub`…`End Sub` construct. It can also be a method that returns a value that is ignored.) Typically, such a method is used to perform an operation. + > [!NOTE] -> To reference a method that has eight parameters and returns a value, use the generic delegate instead. - - You can also use the delegate with anonymous methods and lambda expressions. - +> To reference a method that has eight parameters and returns a value, use the generic delegate instead. + + You can also use the delegate with anonymous methods and lambda expressions. + ]]> diff --git a/xml/System/Action`9.xml b/xml/System/Action`9.xml index 228816fcbb6..319f7ed9535 100644 --- a/xml/System/Action`9.xml +++ b/xml/System/Action`9.xml @@ -131,16 +131,16 @@ The ninth parameter of the method that this delegate encapsulates. Encapsulates a method that has nine parameters and does not return a value. - delegate to pass a method as a parameter without explicitly declaring a custom delegate. The encapsulated method must correspond to the method signature that is defined by this delegate. This means that the encapsulated method must have nine parameters that are all passed to it by value, and it must not return a value. (In C#, the method must return `void`. In Visual Basic, it must be defined by the `Sub`…`End Sub` construct. It can also be a method that returns a value that is ignored.) Typically, such a method is used to perform an operation. - + delegate to pass a method as a parameter without explicitly declaring a custom delegate. The encapsulated method must correspond to the method signature that is defined by this delegate. This means that the encapsulated method must have nine parameters that are all passed to it by value, and it must not return a value. (In C#, the method must return `void`. In Visual Basic, it must be defined by the `Sub`…`End Sub` construct. It can also be a method that returns a value that is ignored.) Typically, such a method is used to perform an operation. + > [!NOTE] -> To reference a method that has nine parameters and returns a value, use the generic delegate instead. - - You can also use the delegate with anonymous methods and lambda expressions. - +> To reference a method that has nine parameters and returns a value, use the generic delegate instead. + + You can also use the delegate with anonymous methods and lambda expressions. + ]]> diff --git a/xml/System/ActivationContext+ContextForm.xml b/xml/System/ActivationContext+ContextForm.xml index 3609028265f..2d7f4b14943 100644 --- a/xml/System/ActivationContext+ContextForm.xml +++ b/xml/System/ActivationContext+ContextForm.xml @@ -17,11 +17,11 @@ Indicates the context for a manifest-activated application. - Publishing ClickOnce Applications diff --git a/xml/System/ActivationContext.xml b/xml/System/ActivationContext.xml index 916b2d52168..e0f72c27578 100644 --- a/xml/System/ActivationContext.xml +++ b/xml/System/ActivationContext.xml @@ -175,18 +175,18 @@ is . - -or- +-or- - is . + is . No deployment or application identity is specified in . - -or- +-or- - does not match the identity in the manifests. + does not match the identity in the manifests. - -or- +-or- - does not have the same number of components as the manifest paths. + does not have the same number of components as the manifest paths. diff --git a/xml/System/Activator.xml b/xml/System/Activator.xml index 3a39902edc3..f075e9d70c1 100644 --- a/xml/System/Activator.xml +++ b/xml/System/Activator.xml @@ -76,35 +76,35 @@ Contains methods to create types of objects locally or remotely, or obtain references to existing remote objects. This class cannot be inherited. - method creates an instance of a type defined in an assembly by invoking the constructor that best matches the specified arguments. If no arguments are specified, the constructor that takes no parameters, that is, the parameterless constructor, is invoked. - - You must have sufficient permission to search for and call a constructor; otherwise, an exception is thrown. By default, only public constructors are considered during the search for a constructor. If no constructor or parameterless constructor can be found, an exception is thrown. - - A binder parameter specifies an object that searches an assembly for a suitable constructor. You can specify your own binder and search criteria. If no binder is specified, a default binder is used. For more information, see the and classes. - - An evidence parameter affects the security policy and permissions for the constructor. For more information, see the class. - - An instance of a type can be created at a local or remote site. If the type is created remotely, an activation attribute parameter specifies the URI of the remote site. The call to create the instance might pass through intermediary sites before it reaches the remote site. Other activation attributes can modify the environment, or context, in which the call operates at the remote and intermediary sites. - - If the instance is created locally, a reference to that object is returned. If the instance is created remotely, a reference to a proxy is returned. The remote object is manipulated through the proxy as if it were a local object. - - The method creates a proxy to a currently running remote object, server-activated well-known object, or XML Web service. You can specify the connection medium, that is, the channel. For more information, see the class. - - Assemblies contain type definitions. The method creates an instance of a type from a currently running assembly. The method creates an instance from a file that contains an assembly. The method creates an instance of a COM object from a file that contains an assembly. - - - -## Examples - The following example shows how to use the class to dynamically construct objects at run time. - + method creates an instance of a type defined in an assembly by invoking the constructor that best matches the specified arguments. If no arguments are specified, the constructor that takes no parameters, that is, the parameterless constructor, is invoked. + + You must have sufficient permission to search for and call a constructor; otherwise, an exception is thrown. By default, only public constructors are considered during the search for a constructor. If no constructor or parameterless constructor can be found, an exception is thrown. + + A binder parameter specifies an object that searches an assembly for a suitable constructor. You can specify your own binder and search criteria. If no binder is specified, a default binder is used. For more information, see the and classes. + + An evidence parameter affects the security policy and permissions for the constructor. For more information, see the class. + + An instance of a type can be created at a local or remote site. If the type is created remotely, an activation attribute parameter specifies the URI of the remote site. The call to create the instance might pass through intermediary sites before it reaches the remote site. Other activation attributes can modify the environment, or context, in which the call operates at the remote and intermediary sites. + + If the instance is created locally, a reference to that object is returned. If the instance is created remotely, a reference to a proxy is returned. The remote object is manipulated through the proxy as if it were a local object. + + The method creates a proxy to a currently running remote object, server-activated well-known object, or XML Web service. You can specify the connection medium, that is, the channel. For more information, see the class. + + Assemblies contain type definitions. The method creates an instance of a type from a currently running assembly. The method creates an instance from a file that contains an assembly. The method creates an instance of a COM object from a file that contains an assembly. + + + +## Examples + The following example shows how to use the class to dynamically construct objects at run time. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/ActivatorX/cpp/ActivatorX.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Activator/Overview/ActivatorX.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR/ActivatorX/fs/ActivatorX.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ActivatorX/VB/ActivatorX.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ActivatorX/VB/ActivatorX.vb" id="Snippet1"::: + ]]> @@ -159,35 +159,35 @@ Creates an instance of the COM object whose name is specified, using the named assembly file and the parameterless constructor. A handle that must be unwrapped to access the newly created object, or for instances. - method to unwrap the return value. - - A attribute with a value of `true` must be applied either explicitly or by default to the COM type so the method can create an instance of that type; otherwise, is thrown. - - For information about other exceptions that can be thrown by invoked methods, see the Exceptions section of the and methods. - + method to unwrap the return value. + + A attribute with a value of `true` must be applied either explicitly or by default to the COM type so the method can create an instance of that type; otherwise, is thrown. + + For information about other exceptions that can be thrown by invoked methods, see the Exceptions section of the and methods. + > [!NOTE] -> Starting with .NET Framework 2.0, this method can be used to create nonpublic types if the caller has been granted with the flag and if the grant set of the assembly that contains the nonpublic types is restricted to the caller's grant set or to a subset thereof. (See [Security Considerations for Reflection](/dotnet/framework/reflection-and-codedom/security-considerations-for-reflection).) To use this functionality, your application should target .NET Framework 3.5 or later. - +> Starting with .NET Framework 2.0, this method can be used to create nonpublic types if the caller has been granted with the flag and if the grant set of the assembly that contains the nonpublic types is restricted to the caller's grant set or to a subset thereof. (See [Security Considerations for Reflection](/dotnet/framework/reflection-and-codedom/security-considerations-for-reflection).) To use this functionality, your application should target .NET Framework 3.5 or later. + ]]> or is . - An instance cannot be created through COM. - - -or- - - was not found in . + An instance cannot be created through COM. + +-or- + + was not found in . No matching constructor was found. is not found, or the module you are trying to load does not specify a file name extension. - Cannot create an instance of an abstract class. - - -or- - - This member was invoked with a late-binding mechanism. + Cannot create an instance of an abstract class. + + -or- + + This member was invoked with a late-binding mechanism. The caller cannot provide activation attributes for an object that does not inherit from . is the empty string (""). @@ -237,18 +237,18 @@ Creates an instance of the COM object whose name is specified, using the named assembly file and the parameterless constructor. A handle that must be unwrapped to access the newly created object, or for instances. - method to unwrap the return value. - - A attribute with a value of `true` must be applied either explicitly or by default to the COM type so the method can create an instance of that type; otherwise, is thrown. - - For information about other exceptions that can be thrown by invoked methods, see the Exceptions section of the and methods. - + method to unwrap the return value. + + A attribute with a value of `true` must be applied either explicitly or by default to the COM type so the method can create an instance of that type; otherwise, is thrown. + + For information about other exceptions that can be thrown by invoked methods, see the Exceptions section of the and methods. + > [!NOTE] -> Starting with .NET Framework 2.0, this method can be used to create nonpublic types if the caller has been granted with the flag and if the grant set of the assembly that contains the nonpublic types is restricted to the caller's grant set or to a subset thereof. (See [Security Considerations for Reflection](/dotnet/framework/reflection-and-codedom/security-considerations-for-reflection).) To use this functionality, your application should target .NET Framework 3.5 or later. - +> Starting with .NET Framework 2.0, this method can be used to create nonpublic types if the caller has been granted with the flag and if the grant set of the assembly that contains the nonpublic types is restricted to the caller's grant set or to a subset thereof. (See [Security Considerations for Reflection](/dotnet/framework/reflection-and-codedom/security-considerations-for-reflection).) To use this functionality, your application should target .NET Framework 3.5 or later. + ]]> @@ -256,10 +256,10 @@ is the empty string (""). An assembly or module was loaded twice with two different evidences. - - -or- - - is longer than the system-defined maximum length. + +-or- + + is longer than the system-defined maximum length. is not found, or the module you are trying to load does not specify a file name extension. @@ -267,17 +267,17 @@ is not a valid assembly. A code base that does not start with "file://" was specified without the required . - An instance cannot be created through COM. - - -or- - - was not found in . + An instance cannot be created through COM. + +-or- + + was not found in . No matching constructor was found. - An instance of an abstract class cannot be created. - - -or- - - This member was invoked with a late-binding mechanism. + An instance of an abstract class cannot be created. + + -or- + + This member was invoked with a late-binding mechanism. The caller cannot provide activation attributes for an object that does not inherit from . @@ -328,13 +328,13 @@ Creates an instance of the type designated by the specified object. A handle that must be unwrapped to access the newly created object, or for instances. - method to unwrap the return value. - - The activation context is used during manifest-based activation to set up the domain policy and to provide an application-based security model. The class contains an object that provides access to the application manifest. For more information, see the class. - + Use the method to unwrap the return value. + + The activation context is used during manifest-based activation to set up the domain policy and to provide an application-based security model. The class contains an object that provides access to the application manifest. For more information, see the class. + ]]> @@ -401,55 +401,49 @@ Creates an instance of the specified type using that type's parameterless constructor. A reference to the newly created object, or for instances. - [!NOTE] -> Starting with .NET Framework 2.0, this method can be used to access nonpublic types if the caller has been granted with the flag and if the grant set of the assembly that contains the nonpublic types is restricted to the caller's grant set or to a subset thereof. (See [Security Considerations for Reflection](/dotnet/framework/reflection-and-codedom/security-considerations-for-reflection).) To use this functionality, your application should target .NET Framework 3.5 or later. - - - -## Examples - The following code example demonstrates how to call the method. Instances of several different types are created and their default values are displayed. - +> Starting with .NET Framework 2.0, this method can be used to access nonpublic types if the caller has been granted with the flag and if the grant set of the assembly that contains the nonpublic types is restricted to the caller's grant set or to a subset thereof. (See [Security Considerations for Reflection](/dotnet/framework/reflection-and-codedom/security-considerations-for-reflection).) To use this functionality, your application should target .NET Framework 3.5 or later. + + + +## Examples + The following code example demonstrates how to call the method. Instances of several different types are created and their default values are displayed. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/ActivatorX/cpp/source2.cpp" id="Snippet4"::: :::code language="csharp" source="~/snippets/csharp/System/Activator/Overview/source2.cs" interactive="try-dotnet" id="Snippet4"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR/ActivatorX/fs/source2.fs" id="Snippet4"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ActivatorX/VB/source2.vb" id="Snippet4"::: - + ]]> is . - is not a . - - -or- - - is an open generic type (that is, the property returns ). + is not a . + +-or- + + is an open generic type (that is, the property returns ). - cannot be a . - - -or- - - Creation of , , , and types, or arrays of those types, is not supported. - - -or- - - The assembly that contains is a dynamic assembly that was created with . - The constructor being called throws an exception. - The caller does not have permission to call this constructor. + cannot be a . + +-or- + +Creation of , , , and types, or arrays of those types, is not supported. + +-or- -Note: In .NET for Windows Store apps or the Portable Class Library, catch the base class exception, , instead. - +The assembly that contains is a dynamic assembly that was created with . + The constructor being called throws an exception. + The caller does not have permission to call this constructor. Note: In .NET for Windows Store apps or the Portable Class Library, catch the base class exception, , instead. Cannot create an instance of an abstract class, or this member was invoked with a late-binding mechanism. The COM type was not obtained through or . - No matching public constructor was found. - -Note: In .NET for Windows Store apps or the Portable Class Library, catch the base class exception, , instead. - + No matching public constructor was found. Note: In .NET for Windows Store apps or the Portable Class Library, catch the base class exception, , instead. is a COM object but the class identifier used to obtain the type is invalid, or the identified class is not registered. @@ -495,13 +489,13 @@ Note: In .NET for Win Creates an instance of the type that is designated by the specified object and activated with the specified custom activation data. A handle that must be unwrapped to access the newly created object, or for instances. - method to unwrap the return value. - - The activation context is used during manifest-based activation to set up the domain policy and to provide an application-based security model. The class contains an object that provides access to the application manifest. For more information, see the class. - + method to unwrap the return value. + + The activation context is used during manifest-based activation to set up the domain policy and to provide an application-based security model. The class contains an object that provides access to the application manifest. For more information, see the class. + ]]> @@ -560,43 +554,43 @@ Note: In .NET for Win Creates an instance of the type whose name is specified, using the named assembly and parameterless constructor. A handle that must be unwrapped to access the newly created object, or for instances. - to unwrap the return value. - - `assemblyName` can be either of the following: - -- The simple name of an assembly, without its path or file extension. For example, you would specify `TypeExtensions` for an assembly whose path and name are .\bin\TypeExtensions.dll. - -- The full name of a signed assembly, which consists of its simple name, version, culture, and public key token; for example, "TypeExtensions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=181869f2f7435b51". - - For more information on how the common language runtime identifies and loads assemblies, see [How the Runtime Locates Assemblies](/dotnet/framework/deployment/how-the-runtime-locates-assemblies). For information on using the application configuration file to define assembly locations, see [Specifying an Assembly's Location](/dotnet/framework/configure-apps/specify-assembly-location). If `assemblyName` is found, it is loaded in the default context. - + Use to unwrap the return value. + + `assemblyName` can be either of the following: + +- The simple name of an assembly, without its path or file extension. For example, you would specify `TypeExtensions` for an assembly whose path and name are .\bin\TypeExtensions.dll. + +- The full name of a signed assembly, which consists of its simple name, version, culture, and public key token; for example, "TypeExtensions, Version=1.0.0.0, Culture=neutral, PublicKeyToken=181869f2f7435b51". + + For more information on how the common language runtime identifies and loads assemblies, see [How the Runtime Locates Assemblies](/dotnet/framework/deployment/how-the-runtime-locates-assemblies). For information on using the application configuration file to define assembly locations, see [Specifying an Assembly's Location](/dotnet/framework/configure-apps/specify-assembly-location). If `assemblyName` is found, it is loaded in the default context. + > [!NOTE] -> Starting with .NET Framework 2.0, this method can be used to create nonpublic types if the caller has been granted with the flag and if the grant set of the assembly that contains the nonpublic types is restricted to the caller's grant set or to a subset thereof. (See [Security Considerations for Reflection](/dotnet/framework/reflection-and-codedom/security-considerations-for-reflection).) To use this functionality, your application should target .NET Framework 3.5 or later. - - - -## Examples - The following example defines a class named `Person` in an assembly named `PersonInfo`. Note that the `Person` class has two constructors, one of which is parameterless. - +> Starting with .NET Framework 2.0, this method can be used to create nonpublic types if the caller has been granted with the flag and if the grant set of the assembly that contains the nonpublic types is restricted to the caller's grant set or to a subset thereof. (See [Security Considerations for Reflection](/dotnet/framework/reflection-and-codedom/security-considerations-for-reflection).) To use this functionality, your application should target .NET Framework 3.5 or later. + + + +## Examples + The following example defines a class named `Person` in an assembly named `PersonInfo`. Note that the `Person` class has two constructors, one of which is parameterless. + :::code language="csharp" source="~/snippets/csharp/System/Activator/CreateInstance/personinfo.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.activator.createinstance/fs/personinfo.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.activator.createinstance/vb/personinfo.vb" id="Snippet1"::: - - The following example calls the method to instantiate the `Person` class. It requires a reference to PersonInfo.dll to be added to the project. Because the method calls the `Person` class parameterless constructor, the example assigns a value to its `Name` property. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.activator.createinstance/vb/personinfo.vb" id="Snippet1"::: + + The following example calls the method to instantiate the `Person` class. It requires a reference to PersonInfo.dll to be added to the project. Because the method calls the `Person` class parameterless constructor, the example assigns a value to its `Name` property. + :::code language="csharp" source="~/snippets/csharp/System/Activator/CreateInstance/createinstanceex1.cs" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.activator.createinstance/fs/createinstanceex1.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.activator.createinstance/vb/createinstanceex1.vb" id="Snippet2"::: - - However, is frequently called to instantiate a type that crosses machine boundaries or that is not known at design time. In this case, you cannot include a reference to the assembly in the project and cannot make early-bound calls to the type's members. To work around this limitation, the following example uses the method along with reflection to assign a value to the `Person` object's `Name` property and to display its value. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.activator.createinstance/vb/createinstanceex1.vb" id="Snippet2"::: + + However, is frequently called to instantiate a type that crosses machine boundaries or that is not known at design time. In this case, you cannot include a reference to the assembly in the project and cannot make early-bound calls to the type's members. To work around this limitation, the following example uses the method along with reflection to assign a value to the `Person` object's `Name` property and to display its value. + :::code language="csharp" source="~/snippets/csharp/System/Activator/CreateInstance/createinstanceex1a.cs" id="Snippet3"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.activator.createinstance/fs/createinstanceex1a.fs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.activator.createinstance/vb/createinstanceex1a.vb" id="Snippet3"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.activator.createinstance/vb/createinstanceex1a.vb" id="Snippet3"::: + ]]> @@ -612,16 +606,16 @@ Note: In .NET for Win The COM type was not obtained through or . Creation of , , , and types, or arrays of those types, is not supported. - is not a valid assembly. - - -or- - - The common language runtime (CLR) version 2.0 or later is currently loaded, and was compiled for a version of the CLR that is later than the currently loaded version. Note that the .NET Framework versions 2.0, 3.0, and 3.5 all use CLR version 2.0. - An assembly or module was loaded twice with two different evidences. - - -or- - - The assembly name or code base is invalid. + is not a valid assembly. + +-or- + +The common language runtime (CLR) version 2.0 or later is currently loaded, and was compiled for a version of the CLR that is later than the currently loaded version. Note that the .NET Framework versions 2.0, 3.0, and 3.5 all use CLR version 2.0. + An assembly or module was loaded twice with two different evidences. + + -or- + + The assembly name or code base is invalid. @@ -677,33 +671,33 @@ Note: In .NET for Win Creates an instance of the specified type using that type's parameterless constructor. A reference to the newly created object, or for instances. - [!NOTE] -> Starting with .NET Framework 2.0, this method can be used to access nonpublic types and members if the caller has been granted with the flag and if the grant set of the assembly that contains the nonpublic types and members is restricted to the caller's grant set or to a subset thereof. (See [Security Considerations for Reflection](/dotnet/framework/reflection-and-codedom/security-considerations-for-reflection).) To use this functionality, your application should target .NET Framework 3.5 or later. - +> Starting with .NET Framework 2.0, this method can be used to access nonpublic types and members if the caller has been granted with the flag and if the grant set of the assembly that contains the nonpublic types and members is restricted to the caller's grant set or to a subset thereof. (See [Security Considerations for Reflection](/dotnet/framework/reflection-and-codedom/security-considerations-for-reflection).) To use this functionality, your application should target .NET Framework 3.5 or later. + ]]> is . - is not a . - - -or- - - is an open generic type (that is, the property returns ). + is not a . + +-or- + + is an open generic type (that is, the property returns ). - cannot be a . - - -or- - - Creation of , , , and types, or arrays of those types, is not supported. - - -or- - - The assembly that contains is a dynamic assembly that was created with . + cannot be a . + +-or- + +Creation of , , , and types, or arrays of those types, is not supported. + +-or- + +The assembly that contains is a dynamic assembly that was created with . The constructor being called throws an exception. The caller does not have permission to call this constructor. Cannot create an instance of an abstract class, or this member was invoked with a late-binding mechanism. @@ -794,64 +788,58 @@ Note: In .NET for Win Creates an instance of the specified type using the constructor that best matches the specified parameters. A reference to the newly created object, or for instances with no value. - [!NOTE] -> Starting with .NET Framework 2.0, this method can be used to access nonpublic types if the caller has been granted with the flag and if the grant set of the assembly that contains the nonpublic types is restricted to the caller's grant set or to a subset thereof. (See [Security Considerations for Reflection](/dotnet/framework/reflection-and-codedom/security-considerations-for-reflection).) To use this functionality, your application should target .NET Framework 3.5 or later. - - - -## Examples - The following example calls the method to create a object. It calls the constructor to instantiate a string that contains ten elements from a character array starting at the fourteenth position. - +> Starting with .NET Framework 2.0, this method can be used to access nonpublic types if the caller has been granted with the flag and if the grant set of the assembly that contains the nonpublic types is restricted to the caller's grant set or to a subset thereof. (See [Security Considerations for Reflection](/dotnet/framework/reflection-and-codedom/security-considerations-for-reflection).) To use this functionality, your application should target .NET Framework 3.5 or later. + + + +## Examples + The following example calls the method to create a object. It calls the constructor to instantiate a string that contains ten elements from a character array starting at the fourteenth position. + :::code language="csharp" source="~/snippets/csharp/System/Activator/CreateInstance/CreateInstance5.cs" interactive="try-dotnet" id="Snippet5"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.activator.createinstance/fs/CreateInstance5.fs" id="Snippet5"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.activator.createinstance/vb/CreateInstance5.vb" id="Snippet5"::: - - The following example creates a jagged array whose elements are arguments to be passed to a constructor. The example then passes each array to the method to invoke the appropriate string constructor. - + + The following example creates a jagged array whose elements are arguments to be passed to a constructor. The example then passes each array to the method to invoke the appropriate string constructor. + :::code language="csharp" source="~/snippets/csharp/System/Activator/CreateInstance/createinstance2.cs" interactive="try-dotnet" id="Snippet4"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.activator.createinstance/fs/createinstance2.fs" id="Snippet4"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.activator.createinstance/vb/createinstance2.vb" id="Snippet4"::: - + ]]> is . - is not a . - - -or- - - is an open generic type (that is, the property returns ). + is not a . + +-or- + + is an open generic type (that is, the property returns ). - cannot be a . - - -or- - - Creation of , , , and types, or arrays of those types, is not supported. - - -or- - - The assembly that contains is a dynamic assembly that was created with . - - -or- - - The constructor that best matches has arguments. - The constructor being called throws an exception. - The caller does not have permission to call this constructor. + cannot be a . + +-or- -Note: In .NET for Windows Store apps or the Portable Class Library, catch the base class exception, , instead. - +Creation of , , , and types, or arrays of those types, is not supported. + +-or- + +The assembly that contains is a dynamic assembly that was created with . + +-or- + +The constructor that best matches has arguments. + The constructor being called throws an exception. + The caller does not have permission to call this constructor. Note: In .NET for Windows Store apps or the Portable Class Library, catch the base class exception, , instead. Cannot create an instance of an abstract class, or this member was invoked with a late-binding mechanism. The COM type was not obtained through or . - No matching public constructor was found. - -Note: In .NET for Windows Store apps or the Portable Class Library, catch the base class exception, , instead. - + No matching public constructor was found. Note: In .NET for Windows Store apps or the Portable Class Library, catch the base class exception, , instead. is a COM object but the class identifier used to obtain the type is invalid, or the identified class is not registered. @@ -899,13 +887,13 @@ Note: In .NET for Win Creates an instance of the type whose name is specified in the specified remote domain, using the named assembly and parameterless constructor. A handle that must be unwrapped to access the newly created object, or for instances. - when a host needs to execute code in an application domain that has restricted security permissions. - + Use when a host needs to execute code in an application domain that has restricted security permissions. + Use to unwrap the return value. - + ]]> @@ -916,25 +904,25 @@ Note: In .NET for Win was not found. The caller does not have permission to call this constructor. - Cannot create an instance of an abstract type. - - -or- - - This member was invoked with a late-binding mechanism. + Cannot create an instance of an abstract type. + + -or- + + This member was invoked with a late-binding mechanism. The constructor, which was invoked through reflection, threw an exception. The COM type was not obtained through or . Creation of , , , and types, or arrays of those types, is not supported. - is not a valid assembly. - - -or- - - The common language runtime (CLR) version 2.0 or later is currently loaded, and was compiled for a version of the CLR that is later than the currently loaded version. Note that the .NET Framework versions 2.0, 3.0, and 3.5 all use CLR version 2.0. - An assembly or module was loaded twice with two different evidences. - - -or- - - The assembly name or code base is invalid. + is not a valid assembly. + +-or- + +The common language runtime (CLR) version 2.0 or later is currently loaded, and was compiled for a version of the CLR that is later than the currently loaded version. Note that the .NET Framework versions 2.0, 3.0, and 3.5 all use CLR version 2.0. + An assembly or module was loaded twice with two different evidences. + + -or- + + The assembly name or code base is invalid. @@ -993,20 +981,18 @@ Note: In .NET for Win The name of the assembly where the type named is sought. If is , the executing assembly is searched. The fully qualified name of the type to create an instance of. - An array of one or more attributes that can participate in activation. This is typically an array that contains a single object that specifies the URL that is required to activate a remote object. - - This parameter is related to client-activated objects. Client activation is a legacy technology that is retained for backward compatibility but is not recommended for new development. Distributed applications should instead use Windows Communication Foundation. + An array of one or more attributes that can participate in activation. This is typically an array that contains a single object that specifies the URL that is required to activate a remote object. This parameter is related to client-activated objects. Client activation is a legacy technology that is retained for backward compatibility but is not recommended for new development. Distributed applications should instead use Windows Communication Foundation. Creates an instance of the type whose name is specified, using the named assembly and parameterless constructor. A handle that must be unwrapped to access the newly created object, or for instances. - to unwrap the return value. - + Use to unwrap the return value. + > [!NOTE] -> Starting with .NET Framework 2.0, this method can be used to create nonpublic types if the caller has been granted with the flag and if the grant set of the nonpublic types is restricted to the caller's grant set or to a subset thereof. (See [Security Considerations for Reflection](/dotnet/framework/reflection-and-codedom/security-considerations-for-reflection).) To use this functionality, your application should target .NET Framework 3.5 or later. - +> Starting with .NET Framework 2.0, this method can be used to create nonpublic types if the caller has been granted with the flag and if the grant set of the nonpublic types is restricted to the caller's grant set or to a subset thereof. (See [Security Considerations for Reflection](/dotnet/framework/reflection-and-codedom/security-considerations-for-reflection).) To use this functionality, your application should target .NET Framework 3.5 or later. + ]]> @@ -1019,28 +1005,26 @@ Note: In .NET for Win The caller does not have permission to call this constructor. Cannot create an instance of an abstract class, or this member was invoked with a late-binding mechanism. The COM type was not obtained through or . - Creation of , , , and types, or arrays of those types, is not supported. - - -or- - - is not an empty array, and the type being created does not derive from . - - -or- - - is not a - - array. + Creation of , , , and types, or arrays of those types, is not supported. + +-or- + + is not an empty array, and the type being created does not derive from . + +-or- + + is not a array. - is not a valid assembly. - - -or- - - The common language runtime (CLR) version 2.0 or later is currently loaded, and was compiled for a version of the CLR that is later than the currently loaded version. Note that the .NET Framework versions 2.0, 3.0, and 3.5 all use CLR version 2.0. - An assembly or module was loaded twice with two different evidences. - - -or- - - The assembly name or code base is invalid. + is not a valid assembly. + +-or- + +The common language runtime (CLR) version 2.0 or later is currently loaded, and was compiled for a version of the CLR that is later than the currently loaded version. Note that the .NET Framework versions 2.0, 3.0, and 3.5 all use CLR version 2.0. + An assembly or module was loaded twice with two different evidences. + + -or- + + The assembly name or code base is invalid. The invoked constructor throws an exception. -or- @@ -1111,48 +1095,46 @@ An error occurred when attempting remote activation in a target specified in The type of object to create. An array of arguments that match in number, order, and type the parameters of the constructor to invoke. If is an empty array or , the constructor that takes no parameters (the parameterless constructor) is invoked. - An array of one or more attributes that can participate in activation. This is typically an array that contains a single object that specifies the URL that is required to activate a remote object. - - This parameter is related to client-activated objects. Client activation is a legacy technology that is retained for backward compatibility but is not recommended for new development. Distributed applications should instead use Windows Communication Foundation. + An array of one or more attributes that can participate in activation. This is typically an array that contains a single object that specifies the URL that is required to activate a remote object. This parameter is related to client-activated objects. Client activation is a legacy technology that is retained for backward compatibility but is not recommended for new development. Distributed applications should instead use Windows Communication Foundation. Creates an instance of the specified type using the constructor that best matches the specified parameters. A reference to the newly created object, or for instances with no value. - [!NOTE] -> Starting with .NET Framework 2.0, this method can be used to access nonpublic types if the caller has been granted with the flag and if the grant set of the assembly that contains the nonpublic types is restricted to the caller's grant set or to a subset thereof. (See [Security Considerations for Reflection](/dotnet/framework/reflection-and-codedom/security-considerations-for-reflection).) To use this functionality, your application should target .NET Framework 3.5 or later. - +> Starting with .NET Framework 2.0, this method can be used to access nonpublic types if the caller has been granted with the flag and if the grant set of the assembly that contains the nonpublic types is restricted to the caller's grant set or to a subset thereof. (See [Security Considerations for Reflection](/dotnet/framework/reflection-and-codedom/security-considerations-for-reflection).) To use this functionality, your application should target .NET Framework 3.5 or later. + ]]> is . - is not a . - - -or- - - is an open generic type (that is, the property returns ). + is not a . + +-or- + + is an open generic type (that is, the property returns ). - cannot be a . - - -or- - - Creation of , , , and types, or arrays of those types, is not supported. - - -or- - - is not an empty array, and the type being created does not derive from . - - -or- - - The assembly that contains is a dynamic assembly that was created with . - - -or- - - The constructor that best matches has arguments. + cannot be a . + +-or- + +Creation of , , , and types, or arrays of those types, is not supported. + +-or- + + is not an empty array, and the type being created does not derive from . + +-or- + +The assembly that contains is a dynamic assembly that was created with . + +-or- + +The constructor that best matches has arguments. The constructor being called throws an exception. The caller does not have permission to call this constructor. Cannot create an instance of an abstract class, or this member was invoked with a late-binding mechanism. @@ -1235,38 +1217,38 @@ An error occurred when attempting remote activation in a target specified in Creates an instance of the specified type using the constructor that best matches the specified parameters. A reference to the newly created object, or for instances with no value. - [!NOTE] -> Starting with .NET Framework 2.0, this method can be used to access nonpublic types and members if the caller has been granted with the flag and if the grant set of the assembly that contains the nonpublic types and members is restricted to the caller's grant set or to a subset thereof. (See [Security Considerations for Reflection](/dotnet/framework/reflection-and-codedom/security-considerations-for-reflection).) To use this functionality, your application should target .NET Framework 3.5 or later. - +> Starting with .NET Framework 2.0, this method can be used to access nonpublic types and members if the caller has been granted with the flag and if the grant set of the assembly that contains the nonpublic types and members is restricted to the caller's grant set or to a subset thereof. (See [Security Considerations for Reflection](/dotnet/framework/reflection-and-codedom/security-considerations-for-reflection).) To use this functionality, your application should target .NET Framework 3.5 or later. + ]]> is . - is not a . - - -or- - - is an open generic type (that is, the property returns ). + is not a . + +-or- + + is an open generic type (that is, the property returns ). - cannot be a . - - -or- - - Creation of , , , and types, or arrays of those types, is not supported. - - -or- - - The assembly that contains is a dynamic assembly that was created with . - - -or- - - The constructor that best matches has arguments. + cannot be a . + +-or- + +Creation of , , , and types, or arrays of those types, is not supported. + +-or- + +The assembly that contains is a dynamic assembly that was created with . + +-or- + +The constructor that best matches has arguments. The constructor being called throws an exception. The caller does not have permission to call this constructor. Cannot create an instance of an abstract class, or this member was invoked with a late-binding mechanism. @@ -1347,48 +1329,46 @@ An error occurred when attempting remote activation in a target specified in An object that uses and to seek and identify the constructor. If is , the default binder is used. An array of arguments that match in number, order, and type the parameters of the constructor to invoke. If is an empty array or , the constructor that takes no parameters (the parameterless constructor) is invoked. Culture-specific information that governs the coercion of to the formal types declared for the constructor. If is , the for the current thread is used. - An array of one or more attributes that can participate in activation. This is typically an array that contains a single object that specifies the URL that is required to activate a remote object. - - This parameter is related to client-activated objects. Client activation is a legacy technology that is retained for backward compatibility but is not recommended for new development. Distributed applications should instead use Windows Communication Foundation. + An array of one or more attributes that can participate in activation. This is typically an array that contains a single object that specifies the URL that is required to activate a remote object. This parameter is related to client-activated objects. Client activation is a legacy technology that is retained for backward compatibility but is not recommended for new development. Distributed applications should instead use Windows Communication Foundation. Creates an instance of the specified type using the constructor that best matches the specified parameters. A reference to the newly created object, or for instances with no value. - [!NOTE] -> Starting with .NET Framework 2.0, this method can be used to access nonpublic types and members if the caller has been granted with the flag and if the grant set of the nonpublic types and members is restricted to the caller's grant set or to a subset thereof. (See [Security Considerations for Reflection](/dotnet/framework/reflection-and-codedom/security-considerations-for-reflection).) To use this functionality, your application should target .NET Framework 3.5 or later. - +> Starting with .NET Framework 2.0, this method can be used to access nonpublic types and members if the caller has been granted with the flag and if the grant set of the nonpublic types and members is restricted to the caller's grant set or to a subset thereof. (See [Security Considerations for Reflection](/dotnet/framework/reflection-and-codedom/security-considerations-for-reflection).) To use this functionality, your application should target .NET Framework 3.5 or later. + ]]> is . - is not a . - - -or- - - is an open generic type (that is, the property returns ). + is not a . + +-or- + + is an open generic type (that is, the property returns ). - cannot be a . - - -or- - - Creation of , , , and types, or arrays of those types, is not supported. - - -or- - - is not an empty array, and the type being created does not derive from . - - -or- - - The assembly that contains is a dynamic assembly that was created with . - - -or- - - The constructor that best matches has arguments. + cannot be a . + +-or- + +Creation of , , , and types, or arrays of those types, is not supported. + +-or- + + is not an empty array, and the type being created does not derive from . + +-or- + +The assembly that contains is a dynamic assembly that was created with . + +-or- + +The constructor that best matches has arguments. The constructor being called throws an exception. The caller does not have permission to call this constructor. Cannot create an instance of an abstract class, or this member was invoked with a late-binding mechanism. @@ -1476,20 +1456,18 @@ An error occurred when attempting remote activation in a target specified in An object that uses and to seek and identify the constructor. If is , the default binder is used. An array of arguments that match in number, order, and type the parameters of the constructor to invoke. If is an empty array or , the constructor that takes no parameters (the parameterless constructor) is invoked. Culture-specific information that governs the coercion of to the formal types declared for the constructor. If is , the for the current thread is used. - An array of one or more attributes that can participate in activation. This is typically an array that contains a single object that specifies the URL that is required to activate a remote object. - - This parameter is related to client-activated objects. Client activation is a legacy technology that is retained for backward compatibility but is not recommended for new development. Distributed applications should instead use Windows Communication Foundation. + An array of one or more attributes that can participate in activation. This is typically an array that contains a single object that specifies the URL that is required to activate a remote object. This parameter is related to client-activated objects. Client activation is a legacy technology that is retained for backward compatibility but is not recommended for new development. Distributed applications should instead use Windows Communication Foundation. Creates an instance of the type whose name is specified, using the named assembly and the constructor that best matches the specified parameters. A handle that must be unwrapped to access the newly created instance, or for instances with no value. - to unwrap the return value. + Use to unwrap the return value. > [!NOTE] -> Starting with .NET Framework 2.0, this method can be used to create nonpublic types and members if the caller has been granted with the flag and if the grant set of the assembly that contains the nonpublic types and members is restricted to the caller's grant set or to a subset thereof. (See [Security Considerations for Reflection](/dotnet/framework/reflection-and-codedom/security-considerations-for-reflection).) To use this functionality, your application should target .NET Framework 3.5 or later. - +> Starting with .NET Framework 2.0, this method can be used to create nonpublic types and members if the caller has been granted with the flag and if the grant set of the assembly that contains the nonpublic types and members is restricted to the caller's grant set or to a subset thereof. (See [Security Considerations for Reflection](/dotnet/framework/reflection-and-codedom/security-considerations-for-reflection).) To use this functionality, your application should target .NET Framework 3.5 or later. + ]]> @@ -1503,26 +1481,26 @@ An error occurred when attempting remote activation in a target specified in Cannot create an instance of an abstract class, or this member was invoked with a late-binding mechanism. The constructor, which was invoked through reflection, threw an exception. The COM type was not obtained through or . - Creation of , , , and types, or arrays of those types, is not supported. - - -or- - - is not an empty array, and the type being created does not derive from . - - -or- - - The constructor that best matches has arguments. + Creation of , , , and types, or arrays of those types, is not supported. + +-or- + + is not an empty array, and the type being created does not derive from . + +-or- + +The constructor that best matches has arguments. - is not a valid assembly. - - -or- - - The common language runtime (CLR) version 2.0 or later is currently loaded, and was compiled for a version of the CLR that is later than the currently loaded version. Note that the .NET Framework versions 2.0, 3.0, and 3.5 all use CLR version 2.0. - An assembly or module was loaded twice with two different evidences. - - -or- - - The assembly name or code base is invalid. + is not a valid assembly. + +-or- + +The common language runtime (CLR) version 2.0 or later is currently loaded, and was compiled for a version of the CLR that is later than the currently loaded version. Note that the .NET Framework versions 2.0, 3.0, and 3.5 all use CLR version 2.0. + An assembly or module was loaded twice with two different evidences. + + -or- + + The assembly name or code base is invalid. @@ -1574,19 +1552,17 @@ An error occurred when attempting remote activation in a target specified in An object that uses and to seek and identify the constructor. If is , the default binder is used. An array of arguments that match in number, order, and type the parameters of the constructor to invoke. If is an empty array or , the constructor that takes no parameters (the parameterless constructor) is invoked. Culture-specific information that governs the coercion of to the formal types declared for the constructor. If is , the for the current thread is used. - An array of one or more attributes that can participate in activation. This is typically an array that contains a single object that specifies the URL that is required to activate a remote object. - - This parameter is related to client-activated objects. Client activation is a legacy technology that is retained for backward compatibility but is not recommended for new development. Distributed applications should instead use Windows Communication Foundation. + An array of one or more attributes that can participate in activation. This is typically an array that contains a single object that specifies the URL that is required to activate a remote object. This parameter is related to client-activated objects. Client activation is a legacy technology that is retained for backward compatibility but is not recommended for new development. Distributed applications should instead use Windows Communication Foundation. Creates an instance of the type whose name is specified in the specified remote domain, using the named assembly and the constructor that best matches the specified parameters. A handle that must be unwrapped to access the newly created object, or for instances with no value. - when a host needs to execute code in an application domain that has restricted security permissions. - + Use when a host needs to execute code in an application domain that has restricted security permissions. + Use to unwrap the return value. - + ]]> @@ -1600,26 +1576,26 @@ An error occurred when attempting remote activation in a target specified in Cannot create an instance of an abstract class, or this member was invoked with a late-binding mechanism. The constructor, which was invoked through reflection, threw an exception. The COM type was not obtained through or . - Creation of , , , and types, or arrays of those types, is not supported. - - -or- - - is not an empty array, and the type being created does not derive from . - - -or- - - The constructor that best matches has arguments. + Creation of , , , and types, or arrays of those types, is not supported. + +-or- + + is not an empty array, and the type being created does not derive from . + +-or- + +The constructor that best matches has arguments. - is not a valid assembly. - - -or- - - The common language runtime (CLR) version 2.0 or later is currently loaded, and was compiled for a version of the CLR that is later than the currently loaded version. Note that the .NET Framework versions 2.0, 3.0, and 3.5 all use CLR version 2.0. - An assembly or module was loaded twice with two different evidences. - - -or- - - The assembly name or code base is invalid. + is not a valid assembly. + +-or- + +The common language runtime (CLR) version 2.0 or later is currently loaded, and was compiled for a version of the CLR that is later than the currently loaded version. Note that the .NET Framework versions 2.0, 3.0, and 3.5 all use CLR version 2.0. + An assembly or module was loaded twice with two different evidences. + + -or- + + The assembly name or code base is invalid. @@ -1676,21 +1652,19 @@ An error occurred when attempting remote activation in a target specified in An object that uses and to seek and identify the constructor. If is , the default binder is used. An array of arguments that match in number, order, and type the parameters of the constructor to invoke. If is an empty array or , the constructor that takes no parameters (the parameterless constructor) is invoked. Culture-specific information that governs the coercion of to the formal types declared for the constructor. If is , the for the current thread is used. - An array of one or more attributes that can participate in activation. This is typically an array that contains a single object that specifies the URL that is required to activate a remote object. - - This parameter is related to client-activated objects. Client activation is a legacy technology that is retained for backward compatibility but is not recommended for new development. Distributed applications should instead use Windows Communication Foundation. + An array of one or more attributes that can participate in activation. This is typically an array that contains a single object that specifies the URL that is required to activate a remote object. This parameter is related to client-activated objects. Client activation is a legacy technology that is retained for backward compatibility but is not recommended for new development. Distributed applications should instead use Windows Communication Foundation. Information used to make security policy decisions and grant code permissions. Creates an instance of the type whose name is specified, using the named assembly and the constructor that best matches the specified parameters. A handle that must be unwrapped to access the newly created object, or for instances with no value. - to unwrap the return value. - + Use to unwrap the return value. + > [!NOTE] -> Starting with .NET Framework 2.0, this method can be used to create nonpublic types and members if the caller has been granted with the flag and if the grant set of the assembly that contains the nonpublic types and members is restricted to the caller's grant set or to a subset thereof. (See [Security Considerations for Reflection](/dotnet/framework/reflection-and-codedom/security-considerations-for-reflection).) To use this functionality, your application should target .NET Framework 3.5 or later. - +> Starting with .NET Framework 2.0, this method can be used to create nonpublic types and members if the caller has been granted with the flag and if the grant set of the assembly that contains the nonpublic types and members is restricted to the caller's grant set or to a subset thereof. (See [Security Considerations for Reflection](/dotnet/framework/reflection-and-codedom/security-considerations-for-reflection).) To use this functionality, your application should target .NET Framework 3.5 or later. + ]]> @@ -1704,26 +1678,26 @@ An error occurred when attempting remote activation in a target specified in Cannot create an instance of an abstract class, or this member was invoked with a late-binding mechanism. The constructor, which was invoked through reflection, threw an exception. The COM type was not obtained through or . - Creation of , , , and types, or arrays of those types, is not supported. - - -or- - - is not an empty array, and the type being created does not derive from . - - -or- - - The constructor that best matches has arguments. + Creation of , , , and types, or arrays of those types, is not supported. + +-or- + + is not an empty array, and the type being created does not derive from . + +-or- + +The constructor that best matches has arguments. - is not a valid assembly. - - -or- - - The common language runtime (CLR) version 2.0 or later is currently loaded, and was compiled for a version of the CLR that is later than the currently loaded version. Note that the .NET Framework versions 2.0, 3.0, and 3.5 all use CLR version 2.0. - An assembly or module was loaded twice with two different evidences. - - -or- - - The assembly name or code base is invalid. + is not a valid assembly. + +-or- + +The common language runtime (CLR) version 2.0 or later is currently loaded, and was compiled for a version of the CLR that is later than the currently loaded version. Note that the .NET Framework versions 2.0, 3.0, and 3.5 all use CLR version 2.0. + An assembly or module was loaded twice with two different evidences. + + -or- + + The assembly name or code base is invalid. @@ -1786,13 +1760,13 @@ An error occurred when attempting remote activation in a target specified in Creates an instance of the type whose name is specified in the specified remote domain, using the named assembly and the constructor that best matches the specified parameters. A handle that must be unwrapped to access the newly created object, or for instances with no value. - when a host needs to execute code in an application domain that has restricted security permissions. - + Use when a host needs to execute code in an application domain that has restricted security permissions. + Use to unwrap the return value. - + ]]> @@ -1806,26 +1780,26 @@ An error occurred when attempting remote activation in a target specified in Cannot create an instance of an abstract class, or this member was invoked with a late-binding mechanism. The constructor, which was invoked through reflection, threw an exception. The COM type was not obtained through or . - Creation of , , , and types, or arrays of those types, is not supported. - - -or- - - is not an empty array, and the type being created does not derive from . - - -or- - - The constructor that best matches has arguments. + Creation of , , , and types, or arrays of those types, is not supported. + +-or- + + is not an empty array, and the type being created does not derive from . + +-or- + +The constructor that best matches has arguments. - is not a valid assembly. - - -or- - - The common language runtime (CLR) version 2.0 or later is currently loaded, and was compiled for a version of the CLR that is later than the currently loaded version. Note that the .NET Framework versions 2.0, 3.0, and 3.5 all use CLR version 2.0. - An assembly or module was loaded twice with two different evidences. - - -or- - - The assembly name or code base is invalid. + is not a valid assembly. + +-or- + +The common language runtime (CLR) version 2.0 or later is currently loaded, and was compiled for a version of the CLR that is later than the currently loaded version. Note that the .NET Framework versions 2.0, 3.0, and 3.5 all use CLR version 2.0. + An assembly or module was loaded twice with two different evidences. + + -or- + + The assembly name or code base is invalid. @@ -1890,26 +1864,23 @@ An error occurred when attempting remote activation in a target specified in Creates an instance of the type designated by the specified generic type parameter, using the parameterless constructor. A reference to the newly created object, or for instances. - generic method is used by compilers to implement the instantiation of types specified by type parameters. For example, in the following generic method, the implementation of `new T()` (`gcnew T()` in C++) uses the generic method. - + generic method is used by compilers to implement the instantiation of types specified by type parameters. For example, in the following generic method, the implementation of `new T()` (`gcnew T()` in C++) uses the generic method. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.activation.createinstance~~1/cpp/remarks.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Activator/CreateInstanceT/remarks.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.activation.createinstance~~1/fs/remarks.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.activation.createinstance~~1/vb/remarks.vb" id="Snippet1"::: - - In general, there is no use for the generic method in application code, because the type must be known at compile time. If the type is known at compile time, normal instantiation syntax can be used (`new` operator in C#, `New` in Visual Basic, `gcnew` in C++). If the type is not known at compile time, you can call a non-generic overload of . - - There are no overloads of the generic method that take argument lists, because the non-generic overloads of already provide late-bound constructor resolution. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.activation.createinstance~~1/vb/remarks.vb" id="Snippet1"::: + + In general, there is no use for the generic method in application code, because the type must be known at compile time. If the type is known at compile time, normal instantiation syntax can be used (`new` operator in C#, `New` in Visual Basic, `gcnew` in C++). If the type is not known at compile time, you can call a non-generic overload of . + + There are no overloads of the generic method that take argument lists, because the non-generic overloads of already provide late-bound constructor resolution. + ]]> - Cannot create an instance of an abstract class, or the type that is specified for does not have a parameterless constructor. - -Note: In .NET for Windows Store apps or the Portable Class Library, catch the base class exception, , instead. - + Cannot create an instance of an abstract class, or the type that is specified for does not have a parameterless constructor. Note: In .NET for Windows Store apps or the Portable Class Library, catch the base class exception, , instead. @@ -1973,23 +1944,23 @@ Note: In .NET for Win Creates an instance of the type whose name is specified, using the named assembly file and parameterless constructor. A handle that must be unwrapped to access the newly created object, or for instances. - method to unwrap the return value. - - For information about other exceptions that can be thrown by invoked methods, see the Exceptions section of the and methods. - - - -## Examples - The following code example demonstrates how to call the method. This code example is part of a larger example provided for the class. - + method to unwrap the return value. + + For information about other exceptions that can be thrown by invoked methods, see the Exceptions section of the and methods. + + + +## Examples + The following code example demonstrates how to call the method. This code example is part of a larger example provided for the class. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/ActivatorX/cpp/ActivatorX.cpp" id="Snippet3"::: :::code language="csharp" source="~/snippets/csharp/System/Activator/Overview/ActivatorX.cs" id="Snippet3"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR/ActivatorX/fs/ActivatorX.fs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ActivatorX/VB/ActivatorX.vb" id="Snippet3"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ActivatorX/VB/ActivatorX.vb" id="Snippet3"::: + ]]> @@ -2004,11 +1975,11 @@ Note: In .NET for Win The constructor, which was invoked through reflection, threw an exception. The caller does have the required . - is not a valid assembly. - - -or- - - The common language runtime (CLR) version 2.0 or later is currently loaded, and was compiled for a version of the CLR that is later than the currently loaded version. Note that the .NET Framework versions 2.0, 3.0, and 3.5 all use CLR version 2.0. + is not a valid assembly. + +-or- + +The common language runtime (CLR) version 2.0 or later is currently loaded, and was compiled for a version of the CLR that is later than the currently loaded version. Note that the .NET Framework versions 2.0, 3.0, and 3.5 all use CLR version 2.0. @@ -2052,15 +2023,15 @@ Note: In .NET for Win Creates an instance of the type whose name is specified in the specified remote domain, using the named assembly file and parameterless constructor. A handle that must be unwrapped to access the newly created object, or for instances. - when a host needs to execute code in an application domain that has restricted security permissions. - + when a host needs to execute code in an application domain that has restricted security permissions. + Use the method to unwrap the return value. - - For information about other exceptions that can be thrown by invoked methods, see the Exceptions section of the and methods. - + + For information about other exceptions that can be thrown by invoked methods, see the Exceptions section of the and methods. + ]]> @@ -2075,11 +2046,11 @@ Note: In .NET for Win The constructor, which was invoked through reflection, threw an exception. The caller does have the required . - is not a valid assembly. - - -or- - - The common language runtime (CLR) version 2.0 or later is currently loaded, and was compiled for a version of the CLR that is later than the currently loaded version. Note that the .NET Framework versions 2.0, 3.0, and 3.5 all use CLR version 2.0. + is not a valid assembly. + +-or- + +The common language runtime (CLR) version 2.0 or later is currently loaded, and was compiled for a version of the CLR that is later than the currently loaded version. Note that the .NET Framework versions 2.0, 3.0, and 3.5 all use CLR version 2.0. @@ -2138,19 +2109,17 @@ Note: In .NET for Win The name of a file that contains an assembly where the type named is sought. The name of the type to create an instance of. - An array of one or more attributes that can participate in activation. This is typically an array that contains a single object that specifies the URL that is required to activate a remote object. - - This parameter is related to client-activated objects. Client activation is a legacy technology that is retained for backward compatibility but is not recommended for new development. Distributed applications should instead use Windows Communication Foundation. + An array of one or more attributes that can participate in activation. This is typically an array that contains a single object that specifies the URL that is required to activate a remote object. This parameter is related to client-activated objects. Client activation is a legacy technology that is retained for backward compatibility but is not recommended for new development. Distributed applications should instead use Windows Communication Foundation. Creates an instance of the type whose name is specified, using the named assembly file and parameterless constructor. A handle that must be unwrapped to access the newly created object, or for instances. - method to unwrap the return value. - - For information about other exceptions that can be thrown by invoked methods, see the Exceptions section of the and methods. - + method to unwrap the return value. + + For information about other exceptions that can be thrown by invoked methods, see the Exceptions section of the and methods. + ]]> @@ -2167,11 +2136,11 @@ Note: In .NET for Win is not an empty array, and the type being created does not derive from . The caller does have the required . - is not a valid assembly. - - -or- - - The common language runtime (CLR) version 2.0 or later is currently loaded, and was compiled for a version of the CLR that is later than the currently loaded version. Note that the .NET Framework versions 2.0, 3.0, and 3.5 all use CLR version 2.0. + is not a valid assembly. + +-or- + +The common language runtime (CLR) version 2.0 or later is currently loaded, and was compiled for a version of the CLR that is later than the currently loaded version. Note that the .NET Framework versions 2.0, 3.0, and 3.5 all use CLR version 2.0. @@ -2246,19 +2215,17 @@ Note: In .NET for Win An object that uses and to seek and identify the constructor. If is , the default binder is used. An array of arguments that match in number, order, and type the parameters of the constructor to invoke. If is an empty array or , the constructor that takes no parameters (the parameterless constructor) is invoked. Culture-specific information that governs the coercion of to the formal types declared for the constructor. If is , the for the current thread is used. - An array of one or more attributes that can participate in activation. This is typically an array that contains a single object that specifies the URL that is required to activate a remote object. - - This parameter is related to client-activated objects. Client activation is a legacy technology that is retained for backward compatibility but is not recommended for new development. Distributed applications should instead use Windows Communication Foundation. + An array of one or more attributes that can participate in activation. This is typically an array that contains a single object that specifies the URL that is required to activate a remote object. This parameter is related to client-activated objects. Client activation is a legacy technology that is retained for backward compatibility but is not recommended for new development. Distributed applications should instead use Windows Communication Foundation. Creates an instance of the type whose name is specified, using the named assembly file and the constructor that best matches the specified parameters. A handle that must be unwrapped to access the newly created object, or for instances. - method to unwrap the return value. - - For information about other exceptions that can be thrown by invoked methods, see the Exceptions section of the and methods. - + method to unwrap the return value. + + For information about other exceptions that can be thrown by invoked methods, see the Exceptions section of the and methods. + ]]> @@ -2275,11 +2242,11 @@ Note: In .NET for Win is not an empty array, and the type being created does not derive from . - is not a valid assembly. - - -or- - - The common language runtime (CLR) version 2.0 or later is currently loaded, and was compiled for a version of the CLR that is later than the currently loaded version. Note that the .NET Framework versions 2.0, 3.0, and 3.5 all use CLR version 2.0. + is not a valid assembly. + +-or- + +The common language runtime (CLR) version 2.0 or later is currently loaded, and was compiled for a version of the CLR that is later than the currently loaded version. Note that the .NET Framework versions 2.0, 3.0, and 3.5 all use CLR version 2.0. @@ -2331,21 +2298,19 @@ Note: In .NET for Win An object that uses and to seek and identify the constructor. If is , the default binder is used. An array of arguments that match in number, order, and type the parameters of the constructor to invoke. If is an empty array or , the constructor that takes no parameters (the parameterless constructor) is invoked. Culture-specific information that governs the coercion of to the formal types declared for the constructor. If is , the for the current thread is used. - An array of one or more attributes that can participate in activation. This is typically an array that contains a single object that specifies the URL that is required to activate a remote object. - - This parameter is related to client-activated objects. Client activation is a legacy technology that is retained for backward compatibility but is not recommended for new development. Distributed applications should instead use Windows Communication Foundation. + An array of one or more attributes that can participate in activation. This is typically an array that contains a single object that specifies the URL that is required to activate a remote object. This parameter is related to client-activated objects. Client activation is a legacy technology that is retained for backward compatibility but is not recommended for new development. Distributed applications should instead use Windows Communication Foundation. Creates an instance of the type whose name is specified in the specified remote domain, using the named assembly file and the constructor that best matches the specified parameters. A handle that must be unwrapped to access the newly created object, or for instances. - when a host needs to execute code in an application domain that has restricted security permissions. - - Use the method to unwrap the return value. - - For information about other exceptions that can be thrown by invoked methods, see the Exceptions sections of the and methods. - + when a host needs to execute code in an application domain that has restricted security permissions. + + Use the method to unwrap the return value. + + For information about other exceptions that can be thrown by invoked methods, see the Exceptions sections of the and methods. + ]]> @@ -2362,11 +2327,11 @@ Note: In .NET for Win is not an empty array, and the type being created does not derive from . - is not a valid assembly. - - -or- - - was compiled for a version of the common language runtime that is later than the version that is currently loaded. + is not a valid assembly. + +-or- + + was compiled for a version of the common language runtime that is later than the version that is currently loaded. @@ -2419,20 +2384,18 @@ Note: In .NET for Win An object that uses and to seek and identify the constructor. If is , the default binder is used. An array of arguments that match in number, order, and type the parameters of the constructor to invoke. If is an empty array or , the constructor that takes no parameters (the parameterless constructor) is invoked. Culture-specific information that governs the coercion of to the formal types declared for the constructor. If is , the for the current thread is used. - An array of one or more attributes that can participate in activation. This is typically an array that contains a single object that specifies the URL that is required to activate a remote object. - - This parameter is related to client-activated objects. Client activation is a legacy technology that is retained for backward compatibility but is not recommended for new development. Distributed applications should instead use Windows Communication Foundation. + An array of one or more attributes that can participate in activation. This is typically an array that contains a single object that specifies the URL that is required to activate a remote object. This parameter is related to client-activated objects. Client activation is a legacy technology that is retained for backward compatibility but is not recommended for new development. Distributed applications should instead use Windows Communication Foundation. Information used to make security policy decisions and grant code permissions. Creates an instance of the type whose name is specified, using the named assembly file and the constructor that best matches the specified parameters. A handle that must be unwrapped to access the newly created object, or for instances. - method to unwrap the return value. - - For information about other exceptions that can be thrown by invoked methods, see the Exceptions section of the and methods. - + method to unwrap the return value. + + For information about other exceptions that can be thrown by invoked methods, see the Exceptions section of the and methods. + ]]> @@ -2449,11 +2412,11 @@ Note: In .NET for Win is not an empty array, and the type being created does not derive from . - is not a valid assembly. - - -or- - - The common language runtime (CLR) version 2.0 or later is currently loaded, and was compiled for a version of the CLR that is later than the currently loaded version. Note that the .NET Framework versions 2.0, 3.0, and 3.5 all use CLR version 2.0. + is not a valid assembly. + +-or- + +The common language runtime (CLR) version 2.0 or later is currently loaded, and was compiled for a version of the CLR that is later than the currently loaded version. Note that the .NET Framework versions 2.0, 3.0, and 3.5 all use CLR version 2.0. @@ -2511,22 +2474,20 @@ Note: In .NET for Win An object that uses and to seek and identify the constructor. If is , the default binder is used. An array of arguments that match in number, order, and type the parameters of the constructor to invoke. If is an empty array or , the constructor that takes no parameters (the parameterless constructor) is invoked. Culture-specific information that governs the coercion of to the formal types declared for the constructor. If is , the for the current thread is used. - An array of one or more attributes that can participate in activation. This is typically an array that contains a single object that specifies the URL that is required to activate a remote object. - - This parameter is related to client-activated objects. Client activation is a legacy technology that is retained for backward compatibility but is not recommended for new development. Distributed applications should instead use Windows Communication Foundation. + An array of one or more attributes that can participate in activation. This is typically an array that contains a single object that specifies the URL that is required to activate a remote object. This parameter is related to client-activated objects. Client activation is a legacy technology that is retained for backward compatibility but is not recommended for new development. Distributed applications should instead use Windows Communication Foundation. Information used to make security policy decisions and grant code permissions. Creates an instance of the type whose name is specified in the specified remote domain, using the named assembly file and the constructor that best matches the specified parameters. A handle that must be unwrapped to access the newly created object, or for instances. - when a host needs to execute code in an application domain that has restricted security permissions. - + when a host needs to execute code in an application domain that has restricted security permissions. + Use the method to unwrap the return value. - - For information about other exceptions that can be thrown by invoked methods, see the Exceptions section of the and methods. - + + For information about other exceptions that can be thrown by invoked methods, see the Exceptions section of the and methods. + ]]> @@ -2543,11 +2504,11 @@ Note: In .NET for Win is not an empty array, and the type being created does not derive from . - is not a valid assembly. - - -or- - - The common language runtime (CLR) version 2.0 or later is currently loaded, and was compiled for a version of the CLR that is later than the currently loaded version. Note that the .NET Framework versions 2.0, 3.0, and 3.5 all use CLR version 2.0. + is not a valid assembly. + +-or- + +The common language runtime (CLR) version 2.0 or later is currently loaded, and was compiled for a version of the CLR that is later than the currently loaded version. Note that the .NET Framework versions 2.0, 3.0, and 3.5 all use CLR version 2.0. @@ -2600,11 +2561,11 @@ Note: In .NET for Win Creates a proxy for the well-known object indicated by the specified type and URL. A proxy that points to an endpoint served by the requested well-known object. - @@ -2658,13 +2619,13 @@ Note: In .NET for Win Creates a proxy for the well-known object indicated by the specified type, URL, and channel data. A proxy that points to an endpoint served by the requested well-known object. - method. - + method. + ]]> @@ -2718,11 +2679,11 @@ Note: In .NET for Win The caller-allocated array that receives the IDs corresponding to the names. Maps a set of names to a corresponding set of dispatch identifiers. - Late-bound access using the COM IDispatch interface is not supported. @@ -2766,11 +2727,11 @@ Note: In .NET for Win An object that receives a pointer to the requested type information object. Retrieves the type information for an object, which can then be used to get the type information for an interface. - Late-bound access using the COM IDispatch interface is not supported. @@ -2810,11 +2771,11 @@ Note: In .NET for Win When this method returns, contains a pointer to a location that receives the number of type information interfaces provided by the object. This parameter is passed uninitialized. Retrieves the number of type information interfaces that an object provides (either 0 or 1). - Late-bound access using the COM IDispatch interface is not supported. @@ -2868,11 +2829,11 @@ Note: In .NET for Win The index of the first argument that has an error. Provides access to properties and methods exposed by an object. - Late-bound access using the COM IDispatch interface is not supported. diff --git a/xml/System/AggregateException.xml b/xml/System/AggregateException.xml index e6ea5a837ad..a71d29c4a75 100644 --- a/xml/System/AggregateException.xml +++ b/xml/System/AggregateException.xml @@ -74,20 +74,20 @@ Represents one or more errors that occur during application execution. - is used to consolidate multiple failures into a single, throwable exception object. It is used extensively in the [Task Parallel Library (TPL)](/dotnet/standard/parallel-programming/task-parallel-library-tpl) and [Parallel LINQ (PLINQ)](/dotnet/standard/parallel-programming/parallel-linq-plinq). For more information, see [Exception Handling](/dotnet/standard/parallel-programming/exception-handling-task-parallel-library) and [How to: Handle Exceptions in a PLINQ Query](/dotnet/standard/parallel-programming/how-to-handle-exceptions-in-a-plinq-query). For additional information, see the [Aggregating Exceptions](https://docs.microsoft.com/archive/msdn-magazine/2009/brownfield/aggregating-exceptions) entry in the .NET Matters blog. - - - -## Examples - The following example catches the exception and calls the method to handle each exception it contains. Compiling and running the example with the first `task1` variable should result in an object that contains an exception. Commenting out that line, uncommenting the second `task1` variable, and compiling and running the example produces an object that contains an exception. - + is used to consolidate multiple failures into a single, throwable exception object. It is used extensively in the [Task Parallel Library (TPL)](/dotnet/standard/parallel-programming/task-parallel-library-tpl) and [Parallel LINQ (PLINQ)](/dotnet/standard/parallel-programming/parallel-linq-plinq). For more information, see [Exception Handling](/dotnet/standard/parallel-programming/exception-handling-task-parallel-library) and [How to: Handle Exceptions in a PLINQ Query](/dotnet/standard/parallel-programming/how-to-handle-exceptions-in-a-plinq-query). For additional information, see the [Aggregating Exceptions](https://docs.microsoft.com/archive/msdn-magazine/2009/brownfield/aggregating-exceptions) entry in the .NET Matters blog. + + + +## Examples + The following example catches the exception and calls the method to handle each exception it contains. Compiling and running the example with the first `task1` variable should result in an object that contains an exception. Commenting out that line, uncommenting the second `task1` variable, and compiling and running the example produces an object that contains an exception. + :::code language="csharp" source="~/snippets/csharp/System/AggregateException/Overview/exception1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.aggregateexception.class/fs/exception1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.aggregateexception.class/vb/exception1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.aggregateexception.class/vb/exception1.vb" id="Snippet1"::: + ]]> All public and protected members of are thread-safe and may be used concurrently from multiple threads. @@ -139,18 +139,18 @@ Initializes a new instance of the class with a system-supplied message that describes the error. - property of the new instance to a system-supplied message that describes the error, such as "System.AggregateException: One or more errors occurred." This message takes into account the current system culture. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||`null`.| -||The localized error message string.| - + property of the new instance to a system-supplied message that describes the error, such as "System.AggregateException: One or more errors occurred." This message takes into account the current system culture. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||`null`.| +||The localized error message string.| + ]]> Handling and Throwing Exceptions @@ -298,16 +298,16 @@ The message that describes the exception. The caller of this constructor is required to ensure that this string has been localized for the current system culture. Initializes a new instance of the class with a specified message that describes the error. - . - -|Property|Value| -|--------------|-----------| -||`null`.| -||The error message string specified in `message`.| - + . + +|Property|Value| +|--------------|-----------| +||`null`.| +||The error message string specified in `message`.| + ]]> Handling and Throwing Exceptions @@ -367,11 +367,11 @@ The contextual information about the source or destination. Initializes a new instance of the class with serialized data. - The argument is null. @@ -483,18 +483,18 @@ The exception that is the cause of the current exception. If the parameter is not , the current exception is raised in a block that handles the inner exception. Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception. - property. The property returns the same value that is passed into the constructor, or `null` if the property does not supply the inner exception value to the constructor. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||`null`.| -||The error message string specified in `message`.| - + property. The property returns the same value that is passed into the constructor, or `null` if the property does not supply the inner exception value to the constructor. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||`null`.| +||The error message string specified in `message`.| + ]]> The argument is null. @@ -603,28 +603,28 @@ Flattens an instances into a single, new instance. A new, flattened . - exception before it is propagated to the parent task, which wraps that exception in its own exception before it propagates it back to the calling thread. In such cases, the property of the exception that is caught by the , , or method contains one or more instances, not the original exceptions that caused the fault. To avoid having to iterate over nested exceptions, you can use the method to remove all the nested exceptions, so that the property of the returned object contains the original exceptions. - - This method recursively flattens all instances of exceptions that are inner exceptions of the current instance. The inner exceptions returned in the new are the union of all the inner exceptions from exception tree rooted at the current instance. - - - -## Examples - In the following example, nested instances are flattened and handled in just one loop. - + exception before it is propagated to the parent task, which wraps that exception in its own exception before it propagates it back to the calling thread. In such cases, the property of the exception that is caught by the , , or method contains one or more instances, not the original exceptions that caused the fault. To avoid having to iterate over nested exceptions, you can use the method to remove all the nested exceptions, so that the property of the returned object contains the original exceptions. + + This method recursively flattens all instances of exceptions that are inner exceptions of the current instance. The inner exceptions returned in the new are the union of all the inner exceptions from exception tree rooted at the current instance. + + + +## Examples + In the following example, nested instances are flattened and handled in just one loop. + :::code language="csharp" source="~/snippets/csharp/System/AggregateException/Flatten/flatten2.cs" id="Snippet22"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_Misc/tpl_exceptions/fs/flatten2.fs" id="Snippet22"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_Misc/tpl_exceptions/vb/flatten2.vb" id="Snippet22"::: - - You can also use the method to rethrow the inner exceptions from multiple instances thrown by multiple tasks in a single instance, as the following example shows. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_Misc/tpl_exceptions/vb/flatten2.vb" id="Snippet22"::: + + You can also use the method to rethrow the inner exceptions from multiple instances thrown by multiple tasks in a single instance, as the following example shows. + :::code language="csharp" source="~/snippets/csharp/System/AggregateException/Flatten/taskexceptions2.cs" id="Snippet13"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_Misc/tpl_exceptions/fs/taskexceptions2.fs" id="Snippet13"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_Misc/tpl_exceptions/vb/taskexceptions2.vb" id="Snippet13"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_Misc/tpl_exceptions/vb/taskexceptions2.vb" id="Snippet13"::: + ]]> Exception Handling (Task Parallel Library) @@ -731,11 +731,11 @@ The contextual information about the source or destination. Initializes a new instance of the class with serialized data. - The argument is null. @@ -785,24 +785,24 @@ The predicate to execute for each exception. The predicate accepts as an argument the to be processed and returns a Boolean to indicate whether the exception was handled. Invokes a handler on each contained by this . - was handled. After all invocations, if any exceptions went unhandled, all unhandled exceptions will be put into a new which will be thrown. Otherwise, the method simply returns. If any invocations of the `predicate` throws an exception, it will halt the processing of any more exceptions and immediately propagate the thrown exception as-is. - -## Examples - Ordinarily, an exception handler that catches an exception uses a `foreach` loop (in C#) or `For Each` loop (in Visual Basic) to handle each exception in its collection. Instead, the following example uses the method to handle each exception, and only rethrows exceptions that are not `CustomException` instances. - + +## Examples + Ordinarily, an exception handler that catches an exception uses a `foreach` loop (in C#) or `For Each` loop (in Visual Basic) to handle each exception in its collection. Instead, the following example uses the method to handle each exception, and only rethrows exceptions that are not `CustomException` instances. + :::code language="csharp" source="~/snippets/csharp/System/AggregateException/Handle/handlemethod2.cs" id="Snippet16"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_Misc/tpl_exceptions/fs/handlemethod2.fs" id="Snippet16"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_Misc/tpl_exceptions/vb/handlemethod2.vb" id="Snippet16"::: - - The following is a more complete example that uses the method to provide special handling for an when enumerating files. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_Misc/tpl_exceptions/vb/handlemethod2.vb" id="Snippet16"::: + + The following is a more complete example that uses the method to provide special handling for an when enumerating files. + :::code language="csharp" source="~/snippets/csharp/System/AggregateException/Handle/taskexceptions.cs" id="Snippet12"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_Misc/tpl_exceptions/fs/taskexceptions.fs" id="Snippet12"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_Misc/tpl_exceptions/vb/taskexceptions.vb" id="Snippet12"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_Misc/tpl_exceptions/vb/taskexceptions.vb" id="Snippet12"::: + ]]> The argument is null. diff --git a/xml/System/AppDomain.xml b/xml/System/AppDomain.xml index 2feadd467c7..39fcc80adf5 100644 --- a/xml/System/AppDomain.xml +++ b/xml/System/AppDomain.xml @@ -913,9 +913,9 @@ Application domains, which are represented by objects, h is an abstract class. - -or- +-or- - This member was invoked with a late-binding mechanism. +This member was invoked with a late-binding mechanism. The caller cannot provide activation attributes for an object that does not inherit from . is an empty string (""). @@ -993,9 +993,9 @@ Application domains, which are represented by objects, h is an abstract class. - -or- +-or- - This member was invoked with a late-binding mechanism. +This member was invoked with a late-binding mechanism. The caller cannot provide activation attributes for an object that does not inherit from . is the empty string (""). @@ -1304,9 +1304,9 @@ This method overload uses the information from the is . The application domain is . - -or- +-or- - The property is not set on the object that is supplied for . +The property is not set on the object that is supplied for . @@ -1542,9 +1542,9 @@ This method overload uses the information from the is not a valid assembly. - -or- +-or- - Version 2.0 or later of the common language runtime is currently loaded and was compiled with a later version. +Version 2.0 or later of the common language runtime is currently loaded and was compiled with a later version. An assembly or module was loaded twice with two different evidences. was not found. @@ -1621,9 +1621,7 @@ This method overload uses the information from the The display name of the assembly. See . The fully qualified name of the requested type, including the namespace but not the assembly, as returned by the property. - An array of one or more attributes that can participate in activation. Typically, an array that contains a single object that specifies the URL that is required to activate a remote object. - - This parameter is related to client-activated objects.Client activation is a legacy technology that is retained for backward compatibility but is not recommended for new development. Distributed applications should instead use Windows Communication Foundation. + An array of one or more attributes that can participate in activation. Typically, an array that contains a single object that specifies the URL that is required to activate a remote object. This parameter is related to client-activated objects.Client activation is a legacy technology that is retained for backward compatibility but is not recommended for new development. Distributed applications should instead use Windows Communication Foundation. Creates a new instance of the specified type defined in the specified assembly. A parameter specifies an array of activation attributes. An object that is a wrapper for the new instance specified by . The return value needs to be unwrapped to access the real object. @@ -1644,9 +1642,9 @@ This method overload uses the information from the is not a valid assembly. - -or- +-or- - Version 2.0 or later of the common language runtime is currently loaded and was compiled with a later version. +Version 2.0 or later of the common language runtime is currently loaded and was compiled with a later version. An assembly or module was loaded twice with two different evidences. was not found. @@ -1737,9 +1735,7 @@ This method overload uses the information from the An object that enables the binding, coercion of argument types, invocation of members, and retrieval of objects using reflection. If is null, the default binder is used. The arguments to pass to the constructor. This array of arguments must match in number, order, and type the parameters of the constructor to invoke. If the parameterless constructor is preferred, must be an empty array or null. Culture-specific information that governs the coercion of to the formal types declared for the constructor. If is , the for the current thread is used. - An array of one or more attributes that can participate in activation. Typically, an array that contains a single object that specifies the URL that is required to activate a remote object. - - This parameter is related to client-activated objects. Client activation is a legacy technology that is retained for backward compatibility but is not recommended for new development. Distributed applications should instead use Windows Communication Foundation. + An array of one or more attributes that can participate in activation. Typically, an array that contains a single object that specifies the URL that is required to activate a remote object. This parameter is related to client-activated objects. Client activation is a legacy technology that is retained for backward compatibility but is not recommended for new development. Distributed applications should instead use Windows Communication Foundation. Creates a new instance of the specified type defined in the specified assembly. Parameters specify a binder, binding flags, constructor arguments, culture-specific information used to interpret arguments, and optional activation attributes. An object that is a wrapper for the new instance specified by . The return value needs to be unwrapped to access the real object. @@ -1758,9 +1754,9 @@ This method overload uses the information from the is not a valid assembly. - -or- +-or- - was compiled with a later version of the common language runtime than the version that is currently loaded. + was compiled with a later version of the common language runtime than the version that is currently loaded. An assembly or module was loaded twice with two different evidences. was not found. @@ -1839,9 +1835,7 @@ This method overload uses the information from the An object that enables the binding, coercion of argument types, invocation of members, and retrieval of objects using reflection. If is null, the default binder is used. The arguments to pass to the constructor. This array of arguments must match in number, order, and type the parameters of the constructor to invoke. If the parameterless constructor is preferred, must be an empty array or null. Culture-specific information that governs the coercion of to the formal types declared for the constructor. If is , the for the current thread is used. - An array of one or more attributes that can participate in activation. Typically, an array that contains a single object that specifies the URL that is required to activate a remote object. - - This parameter is related to client-activated objects.Client activation is a legacy technology that is retained for backward compatibility but is not recommended for new development. Distributed applications should instead use Windows Communication Foundation. + An array of one or more attributes that can participate in activation. Typically, an array that contains a single object that specifies the URL that is required to activate a remote object. This parameter is related to client-activated objects.Client activation is a legacy technology that is retained for backward compatibility but is not recommended for new development. Distributed applications should instead use Windows Communication Foundation. Information used to authorize creation of . Creates a new instance of the specified type defined in the specified assembly. Parameters specify a binder, binding flags, constructor arguments, culture-specific information used to interpret arguments, activation attributes, and authorization to create the type. An object that is a wrapper for the new instance specified by . The return value needs to be unwrapped to access the real object. @@ -1861,9 +1855,9 @@ This method overload uses the information from the is not a valid assembly. - -or- +-or- - Version 2.0 or later of the common language runtime is currently loaded and was compiled with a later version. +Version 2.0 or later of the common language runtime is currently loaded and was compiled with a later version. An assembly or module was loaded twice with two different evidences. was not found. @@ -1871,9 +1865,9 @@ This method overload uses the information from the No matching constructor was found. The caller cannot provide activation attributes for an object that does not inherit from . - -or- +-or- - is not . When legacy CAS policy is not enabled, should be + is not . When legacy CAS policy is not enabled, should be was not found in . This instance is . @@ -1981,9 +1975,9 @@ This method overload uses the information from the is not a valid assembly. - -or- +-or- - Version 2.0 or later of the common language runtime is currently loaded and was compiled with a later version. +Version 2.0 or later of the common language runtime is currently loaded and was compiled with a later version. An assembly or module was loaded twice with two different evidences. @@ -2047,9 +2041,7 @@ This method overload uses the information from the The display name of the assembly. See . The fully qualified name of the requested type, including the namespace but not the assembly, as returned by the property. - An array of one or more attributes that can participate in activation. Typically, an array that contains a single object that specifies the URL that is required to activate a remote object. - - This parameter is related to client-activated objects.Client activation is a legacy technology that is retained for backward compatibility but is not recommended for new development. Distributed applications should instead use Windows Communication Foundation. + An array of one or more attributes that can participate in activation. Typically, an array that contains a single object that specifies the URL that is required to activate a remote object. This parameter is related to client-activated objects.Client activation is a legacy technology that is retained for backward compatibility but is not recommended for new development. Distributed applications should instead use Windows Communication Foundation. Creates a new instance of the specified type. Parameters specify the assembly where the type is defined, the name of the type, and an array of activation attributes. An instance of the object specified by . @@ -2086,9 +2078,9 @@ This method overload uses the information from the is not a valid assembly. - -or- +-or- - Version 2.0 or later of the common language runtime is currently loaded and was compiled with a later version. +Version 2.0 or later of the common language runtime is currently loaded and was compiled with a later version. An assembly or module was loaded twice with two different evidences. @@ -2171,9 +2163,7 @@ This method overload uses the information from the An object that enables the binding, coercion of argument types, invocation of members, and retrieval of objects using reflection. If is null, the default binder is used. The arguments to pass to the constructor. This array of arguments must match in number, order, and type the parameters of the constructor to invoke. If the parameterless constructor is preferred, must be an empty array or null. A culture-specific object used to govern the coercion of types. If is , the for the current thread is used. - An array of one or more attributes that can participate in activation. Typically, an array that contains a single object. that specifies the URL that is required to activate a remote object. - - This parameter is related to client-activated objects. Client activation is a legacy technology that is retained for backward compatibility but is not recommended for new development. Distributed applications should instead use Windows Communication Foundation. + An array of one or more attributes that can participate in activation. Typically, an array that contains a single object. that specifies the URL that is required to activate a remote object. This parameter is related to client-activated objects. Client activation is a legacy technology that is retained for backward compatibility but is not recommended for new development. Distributed applications should instead use Windows Communication Foundation. Creates a new instance of the specified type defined in the specified assembly, specifying whether the case of the type name is ignored; the binding attributes and the binder that are used to select the type to be created; the arguments of the constructor; the culture; and the activation attributes. An instance of the object specified by . @@ -2212,9 +2202,9 @@ This method overload uses the information from the is not a valid assembly. - -or- +-or- - was compiled with a later version of the common language runtime than the version that is currently loaded. + was compiled with a later version of the common language runtime than the version that is currently loaded. An assembly or module was loaded twice with two different evidences. @@ -2279,9 +2269,7 @@ This method overload uses the information from the An object that enables the binding, coercion of argument types, invocation of members, and retrieval of objects using reflection. If is null, the default binder is used. The arguments to pass to the constructor. This array of arguments must match in number, order, and type the parameters of the constructor to invoke. If the parameterless constructor is preferred, must be an empty array or null. A culture-specific object used to govern the coercion of types. If is , the for the current thread is used. - An array of one or more attributes that can participate in activation. Typically, an array that contains a single object that specifies the URL that is required to activate a remote object. - - This parameter is related to client-activated objects. Client activation is a legacy technology that is retained for backward compatibility but is not recommended for new development. Distributed applications should instead use Windows Communication Foundation. + An array of one or more attributes that can participate in activation. Typically, an array that contains a single object that specifies the URL that is required to activate a remote object. This parameter is related to client-activated objects. Client activation is a legacy technology that is retained for backward compatibility but is not recommended for new development. Distributed applications should instead use Windows Communication Foundation. Information used to authorize creation of . Creates a new instance of the specified type. Parameters specify the name of the type, and how it is found and created. An instance of the object specified by . @@ -2321,9 +2309,9 @@ This method overload uses the information from the is not a valid assembly. - -or- +-or- - Version 2.0 or later of the common language runtime is currently loaded and was compiled with a later version. +Version 2.0 or later of the common language runtime is currently loaded and was compiled with a later version. An assembly or module was loaded twice with two different evidences. @@ -2441,9 +2429,9 @@ This method overload uses the information from the is . - -or- +-or- - is . + is . was not found. @@ -2454,9 +2442,9 @@ This method overload uses the information from the is not a valid assembly. - -or- +-or- - Version 2.0 or later of the common language runtime is currently loaded and was compiled with a later version. +Version 2.0 or later of the common language runtime is currently loaded and was compiled with a later version. An assembly or module was loaded twice with two different evidences. This instance is . @@ -2527,9 +2515,7 @@ This method overload uses the information from the The name, including the path, of a file that contains an assembly that defines the requested type. The assembly is loaded using the method. The fully qualified name of the requested type, including the namespace but not the assembly, as returned by the property. - An array of one or more attributes that can participate in activation. Typically, an array that contains a single object that specifies the URL that is required to activate a remote object. - - This parameter is related to client-activated objects.Client activation is a legacy technology that is retained for backward compatibility but is not recommended for new development. Distributed applications should instead use Windows Communication Foundation. + An array of one or more attributes that can participate in activation. Typically, an array that contains a single object that specifies the URL that is required to activate a remote object. This parameter is related to client-activated objects.Client activation is a legacy technology that is retained for backward compatibility but is not recommended for new development. Distributed applications should instead use Windows Communication Foundation. Creates a new instance of the specified type defined in the specified assembly file. An object that is a wrapper for the new instance, or if is not found. The return value needs to be unwrapped to access the real object. @@ -2561,9 +2547,9 @@ This method overload uses the information from the is not a valid assembly. - -or- +-or- - Version 2.0 or later of the common language runtime is currently loaded and was compiled with a later version. +Version 2.0 or later of the common language runtime is currently loaded and was compiled with a later version. An assembly or module was loaded twice with two different evidences. This instance is . @@ -2647,9 +2633,7 @@ This method overload uses the information from the An object that enables the binding, coercion of argument types, invocation of members, and retrieval of objects through reflection. If is null, the default binder is used. The arguments to pass to the constructor. This array of arguments must match in number, order, and type the parameters of the constructor to invoke. If the parameterless constructor is preferred, must be an empty array or null. Culture-specific information that governs the coercion of to the formal types declared for the constructor. If is , the for the current thread is used. - An array of one or more attributes that can participate in activation. Typically, an array that contains a single object that specifies the URL that is required to activate a remote object. - - This parameter is related to client-activated objects. Client activation is a legacy technology that is retained for backward compatibility but is not recommended for new development. Distributed applications should instead use Windows Communication Foundation. + An array of one or more attributes that can participate in activation. Typically, an array that contains a single object that specifies the URL that is required to activate a remote object. This parameter is related to client-activated objects. Client activation is a legacy technology that is retained for backward compatibility but is not recommended for new development. Distributed applications should instead use Windows Communication Foundation. Creates a new instance of the specified type defined in the specified assembly file. An object that is a wrapper for the new instance, or if is not found. The return value needs to be unwrapped to access the real object. @@ -2669,9 +2653,9 @@ This method overload uses the information from the is . - -or- +-or- - is . + is . The caller cannot provide activation attributes for an object that does not inherit from . The operation is attempted on an unloaded application domain. @@ -2683,9 +2667,9 @@ This method overload uses the information from the is not a valid assembly. - -or- +-or- - was compiled with a later version of the common language runtime than the version that is currently loaded. + was compiled with a later version of the common language runtime than the version that is currently loaded. An assembly or module was loaded twice with two different evidences. This instance is . @@ -2757,9 +2741,7 @@ This method overload uses the information from the An object that enables the binding, coercion of argument types, invocation of members, and retrieval of objects through reflection. If is null, the default binder is used. The arguments to pass to the constructor. This array of arguments must match in number, order, and type the parameters of the constructor to invoke. If the parameterless constructor is preferred, must be an empty array or null. Culture-specific information that governs the coercion of to the formal types declared for the constructor. If is , the for the current thread is used. - An array of one or more attributes that can participate in activation. Typically, an array that contains a single object that specifies the URL that is required to activate a remote object. - - This parameter is related to client-activated objects. Client activation is a legacy technology that is retained for backward compatibility but is not recommended for new development. Distributed applications should instead use Windows Communication Foundation. + An array of one or more attributes that can participate in activation. Typically, an array that contains a single object that specifies the URL that is required to activate a remote object. This parameter is related to client-activated objects. Client activation is a legacy technology that is retained for backward compatibility but is not recommended for new development. Distributed applications should instead use Windows Communication Foundation. Information used to authorize creation of . Creates a new instance of the specified type defined in the specified assembly file. An object that is a wrapper for the new instance, or if is not found. The return value needs to be unwrapped to access the real object. @@ -2780,14 +2762,14 @@ This method overload uses the information from the is . - -or- +-or- - is . + is . The caller cannot provide activation attributes for an object that does not inherit from . - -or- +-or- - is not . When legacy CAS policy is not enabled, should be . + is not . When legacy CAS policy is not enabled, should be . The operation is attempted on an unloaded application domain. was not found. @@ -2798,9 +2780,9 @@ This method overload uses the information from the is not a valid assembly. - -or- +-or- - Version 2.0 or later of the common language runtime is currently loaded and was compiled with a later version. +Version 2.0 or later of the common language runtime is currently loaded and was compiled with a later version. An assembly or module was loaded twice with two different evidences. This instance is . @@ -2888,9 +2870,9 @@ This method overload uses the information from the is . - -or- +-or- - is . + is . The operation is attempted on an unloaded application domain. was not found. @@ -2901,9 +2883,9 @@ This method overload uses the information from the is not a valid assembly. - -or- +-or- - Version 2.0 or later of the common language runtime is currently loaded and was compiled with a later version. +Version 2.0 or later of the common language runtime is currently loaded and was compiled with a later version. An assembly or module was loaded twice with two different evidences. @@ -2973,9 +2955,7 @@ This method overload uses the information from the To be added. The file name and path of the assembly that defines the requested type. The fully qualified name of the requested type, including the namespace but not the assembly (see the property). - An array of one or more attributes that can participate in activation. Typically, an array that contains a single object that specifies the URL that is required to activate a remote object. - - This parameter is related to client-activated objects.Client activation is a legacy technology that is retained for backward compatibility but is not recommended for new development. Distributed applications should instead use Windows Communication Foundation. + An array of one or more attributes that can participate in activation. Typically, an array that contains a single object that specifies the URL that is required to activate a remote object. This parameter is related to client-activated objects.Client activation is a legacy technology that is retained for backward compatibility but is not recommended for new development. Distributed applications should instead use Windows Communication Foundation. Creates a new instance of the specified type defined in the specified assembly file. The requested object, or if is not found. @@ -2991,9 +2971,9 @@ This method overload uses the information from the is . - -or- +-or- - is . + is . The caller cannot provide activation attributes for an object that does not inherit from . The operation is attempted on an unloaded application domain. @@ -3005,9 +2985,9 @@ This method overload uses the information from the is not a valid assembly. - -or- +-or- - Version 2.0 or later of the common language runtime is currently loaded and was compiled with a later version. +Version 2.0 or later of the common language runtime is currently loaded and was compiled with a later version. An assembly or module was loaded twice with two different evidences. @@ -3090,9 +3070,7 @@ This method overload uses the information from the An object that enables the binding, coercion of argument types, invocation of members, and retrieval of objects through reflection. If is null, the default binder is used. The arguments to pass to the constructor. This array of arguments must match in number, order, and type the parameters of the constructor to invoke. If the parameterless constructor is preferred, must be an empty array or null. Culture-specific information that governs the coercion of to the formal types declared for the constructor. If is , the for the current thread is used. - An array of one or more attributes that can participate in activation. Typically, an array that contains a single object that specifies the URL that is required to activate a remote object. - - This parameter is related to client-activated objects. Client activation is a legacy technology that is retained for backward compatibility but is not recommended for new development. Distributed applications should instead use Windows Communication Foundation. + An array of one or more attributes that can participate in activation. Typically, an array that contains a single object that specifies the URL that is required to activate a remote object. This parameter is related to client-activated objects. Client activation is a legacy technology that is retained for backward compatibility but is not recommended for new development. Distributed applications should instead use Windows Communication Foundation. Creates a new instance of the specified type defined in the specified assembly file, specifying whether the case of the type name is ignored; the binding attributes and the binder that are used to select the type to be created; the arguments of the constructor; the culture; and the activation attributes. The requested object, or if is not found. @@ -3108,9 +3086,9 @@ This method overload uses the information from the is . - -or- +-or- - is . + is . The caller cannot provide activation attributes for an object that does not inherit from . The operation is attempted on an unloaded application domain. @@ -3122,9 +3100,9 @@ This method overload uses the information from the is not a valid assembly. - -or- +-or- - was compiled with a later version of the common language runtime that the version that is currently loaded. + was compiled with a later version of the common language runtime that the version that is currently loaded. An assembly or module was loaded twice with two different evidences. @@ -3189,9 +3167,7 @@ This method overload uses the information from the An object that enables the binding, coercion of argument types, invocation of members, and retrieval of objects through reflection. If is null, the default binder is used. The arguments to pass to the constructor. This array of arguments must match in number, order, and type the parameters of the constructor to invoke. If the parameterless constructor is preferred, must be an empty array or null. Culture-specific information that governs the coercion of to the formal types declared for the constructor. If is , the for the current thread is used. - An array of one or more attributes that can participate in activation. Typically, an array that contains a single object that specifies the URL that is required to activate a remote object. - - This parameter is related to client-activated objects. Client activation is a legacy technology that is retained for backward compatibility but is not recommended for new development. Distributed applications should instead use Windows Communication Foundation. + An array of one or more attributes that can participate in activation. Typically, an array that contains a single object that specifies the URL that is required to activate a remote object. This parameter is related to client-activated objects. Client activation is a legacy technology that is retained for backward compatibility but is not recommended for new development. Distributed applications should instead use Windows Communication Foundation. Information used to authorize creation of . Creates a new instance of the specified type defined in the specified assembly file. The requested object, or if is not found. @@ -3208,9 +3184,9 @@ This method overload uses the information from the is . - -or- +-or- - is . + is . The caller cannot provide activation attributes for an object that does not inherit from . The operation is attempted on an unloaded application domain. @@ -3222,9 +3198,9 @@ This method overload uses the information from the is not a valid assembly. - -or- +-or- - Version 2.0 or later of the common language runtime is currently loaded and was compiled with a later version. +Version 2.0 or later of the common language runtime is currently loaded and was compiled with a later version. An assembly or module was loaded twice with two different evidences. @@ -3368,9 +3344,9 @@ This method overload uses the information from the is . The property of is . - -or- +-or- - The property of begins with white space, or contains a forward or backward slash. +The property of begins with white space, or contains a forward or backward slash. The operation is attempted on an unloaded application domain. @@ -3449,9 +3425,9 @@ This method overload uses the information from the is . The property of is . - -or- +-or- - The property of starts with white space, or contains a forward or backward slash. +The property of starts with white space, or contains a forward or backward slash. The operation is attempted on an unloaded application domain. @@ -3488,8 +3464,8 @@ This method overload uses the information from the - [System.Obsolete("Assembly level declarative security is obsolete and is no longer enforced by the CLR by default. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")] - [<System.Obsolete("Assembly level declarative security is obsolete and is no longer enforced by the CLR by default. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")>] + [System.Obsolete("Assembly level declarative security is obsolete and is no longer enforced by the CLR by default. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")] + [<System.Obsolete("Assembly level declarative security is obsolete and is no longer enforced by the CLR by default. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")>] [System.Security.SecuritySafeCritical] @@ -3547,9 +3523,9 @@ This method overload uses the information from the is . The property of is . - -or- +-or- - The property of begins with white space, or contains a forward or backward slash. +The property of begins with white space, or contains a forward or backward slash. The operation is attempted on an unloaded application domain. @@ -3630,9 +3606,9 @@ This method overload uses the information from the is . The property of is . - -or- +-or- - The property of begins with white space, or contains a forward or backward slash. +The property of begins with white space, or contains a forward or backward slash. The operation is attempted on an unloaded application domain. @@ -3694,9 +3670,9 @@ This method overload uses the information from the is . The property of is . - -or- +-or- - The property of starts with white space, or contains a forward or backward slash. +The property of starts with white space, or contains a forward or backward slash. The operation is attempted on an unloaded application domain. The value of was not one of the enumeration values. @@ -3792,9 +3768,9 @@ This method overload uses the information from the is . The property of is . - -or- +-or- - The property of begins with white space, or contains a forward or backward slash. +The property of begins with white space, or contains a forward or backward slash. The operation is attempted on an unloaded application domain. @@ -3830,8 +3806,8 @@ This method overload uses the information from the - [System.Obsolete("Assembly level declarative security is obsolete and is no longer enforced by the CLR by default. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")] - [<System.Obsolete("Assembly level declarative security is obsolete and is no longer enforced by the CLR by default. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")>] + [System.Obsolete("Assembly level declarative security is obsolete and is no longer enforced by the CLR by default. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")] + [<System.Obsolete("Assembly level declarative security is obsolete and is no longer enforced by the CLR by default. See http://go.microsoft.com/fwlink/?LinkID=155570 for more information.")>] [System.Security.SecuritySafeCritical] @@ -3889,9 +3865,9 @@ This method overload uses the information from the is . The property of is . - -or- +-or- - The property of begins with white space, or contains a forward or backward slash. +The property of begins with white space, or contains a forward or backward slash. The operation is attempted on an unloaded application domain. @@ -3956,9 +3932,9 @@ This method overload uses the information from the is . The property of is . - -or- +-or- - The property of starts with white space, or contains a forward or backward slash. +The property of starts with white space, or contains a forward or backward slash. The operation is attempted on an unloaded application domain. @@ -4060,9 +4036,9 @@ This method overload uses the information from the is . The property of is . - -or- +-or- - The property of begins with white space, or contains a forward or backward slash. +The property of begins with white space, or contains a forward or backward slash. The operation is attempted on an unloaded application domain. @@ -4159,9 +4135,9 @@ This method overload uses the information from the is . The property of is . - -or- +-or- - The property of begins with white space, or contains a forward or backward slash. +The property of begins with white space, or contains a forward or backward slash. The operation is attempted on an unloaded application domain. @@ -4197,8 +4173,8 @@ This method overload uses the information from the - [System.Obsolete("Assembly level declarative security is obsolete and is no longer enforced by the CLR by default. Please see http://go.microsoft.com/fwlink/?LinkId=155570 for more information.")] - [<System.Obsolete("Assembly level declarative security is obsolete and is no longer enforced by the CLR by default. Please see http://go.microsoft.com/fwlink/?LinkId=155570 for more information.")>] + [System.Obsolete("Assembly level declarative security is obsolete and is no longer enforced by the CLR by default. Please see http://go.microsoft.com/fwlink/?LinkId=155570 for more information.")] + [<System.Obsolete("Assembly level declarative security is obsolete and is no longer enforced by the CLR by default. Please see http://go.microsoft.com/fwlink/?LinkId=155570 for more information.")>] [System.Security.SecuritySafeCritical] @@ -4264,9 +4240,9 @@ This method overload uses the information from the is . The property of is . - -or- +-or- - The property of begins with white space, or contains a forward or backward slash. +The property of begins with white space, or contains a forward or backward slash. The operation is attempted on an unloaded application domain. @@ -4372,9 +4348,9 @@ This method overload uses the information from the is . The property of is . - -or- +-or- - The property of begins with white space, or contains a forward or backward slash. +The property of begins with white space, or contains a forward or backward slash. The operation is attempted on an unloaded application domain. @@ -4467,9 +4443,9 @@ This method overload uses the information from the is . The property of is . - -or- +-or- - The property of starts with white space, or contains a forward or backward slash. +The property of starts with white space, or contains a forward or backward slash. The operation is attempted on an unloaded application domain. @@ -4913,9 +4889,9 @@ This method overload uses the information from the is not a valid assembly. - -or- +-or- - Version 2.0 or later of the common language runtime is currently loaded and was compiled with a later version. +Version 2.0 or later of the common language runtime is currently loaded and was compiled with a later version. The operation is attempted on an unloaded application domain. An assembly or module was loaded twice with two different evidences. The specified assembly has no entry point. @@ -5006,9 +4982,9 @@ This method overload uses the information from the is not a valid assembly. - -or- +-or- - Version 2.0 or later of the common language runtime is currently loaded and was compiled with a later version. +Version 2.0 or later of the common language runtime is currently loaded and was compiled with a later version. The operation is attempted on an unloaded application domain. An assembly or module was loaded twice with two different evidences. The specified assembly has no entry point. @@ -5104,9 +5080,9 @@ This method overload uses the information from the is not a valid assembly. - -or- +-or- - was compiled with a later version of the common language runtime than the version that is currently loaded. + was compiled with a later version of the common language runtime than the version that is currently loaded. The operation is attempted on an unloaded application domain. An assembly or module was loaded twice with two different evidences. The specified assembly has no entry point. @@ -5199,9 +5175,9 @@ This method overload uses the information from the is not a valid assembly. - -or- +-or- - Version 2.0 or later of the common language runtime is currently loaded and was compiled with a later version. +Version 2.0 or later of the common language runtime is currently loaded and was compiled with a later version. The operation is attempted on an unloaded application domain. An assembly or module was loaded twice with two different evidences. @@ -5314,9 +5290,9 @@ This method overload uses the information from the is not a valid assembly. - -or- +-or- - was compiled with a later version of the common language runtime than the version that is currently loaded. + was compiled with a later version of the common language runtime than the version that is currently loaded. The operation is attempted on an unloaded application domain. An assembly or module was loaded twice with two different evidences. The specified assembly has no entry point. @@ -5407,9 +5383,9 @@ This method overload uses the information from the is not a valid assembly. - -or- +-or- - Version 2.0 or later of the common language runtime is currently loaded and was compiled with a later version. +Version 2.0 or later of the common language runtime is currently loaded and was compiled with a later version. The operation is attempted on an unloaded application domain. An assembly or module was loaded twice with two different evidences. @@ -5494,9 +5470,9 @@ This method overload uses the information from the The assembly specified by is not found. The assembly specified by is not a valid assembly. - -or- +-or- - Version 2.0 or later of the common language runtime is currently loaded and was compiled with a later version. +Version 2.0 or later of the common language runtime is currently loaded and was compiled with a later version. The operation is attempted on an unloaded application domain. The assembly specified by was found, but could not be loaded. The specified assembly has no entry point. @@ -5581,9 +5557,9 @@ This method overload uses the information from the The assembly specified by was found, but could not be loaded. The assembly specified by is not a valid assembly. - -or- +-or- - was compiled with a later version of the common language runtime than the version that is currently loaded. + was compiled with a later version of the common language runtime than the version that is currently loaded. The operation is attempted on an unloaded application domain. The specified assembly has no entry point. @@ -5658,9 +5634,9 @@ This method overload uses the information from the The assembly specified by was found, but could not be loaded. The assembly specified by is not a valid assembly. - -or- +-or- - Version 2.0 or later of the common language runtime is currently loaded and was compiled with a later version. +Version 2.0 or later of the common language runtime is currently loaded and was compiled with a later version. The operation is attempted on an unloaded application domain. The specified assembly has no entry point. @@ -5745,9 +5721,9 @@ This method overload uses the information from the The assembly specified by was found, but could not be loaded. The assembly specified by is not a valid assembly. - -or- +-or- - was compiled with a later version of the common language runtime than the version that is currently loaded. + was compiled with a later version of the common language runtime than the version that is currently loaded. The operation is attempted on an unloaded application domain. The specified assembly has no entry point. @@ -5829,9 +5805,9 @@ This method overload uses the information from the The assembly specified by was found, but could not be loaded. The assembly specified by is not a valid assembly. - -or- +-or- - Version 2.0 or later of the common language runtime is currently loaded and was compiled with a later version. +Version 2.0 or later of the common language runtime is currently loaded and was compiled with a later version. The operation is attempted on an unloaded application domain. is not . When legacy CAS policy is not enabled, should be . @@ -5918,9 +5894,9 @@ This method overload uses the information from the The assembly specified by was found, but could not be loaded. The assembly specified by is not a valid assembly. - -or- +-or- - Version 2.0 or later of the common language runtime is currently loaded and was compiled with a later version. +Version 2.0 or later of the common language runtime is currently loaded and was compiled with a later version. The operation is attempted on an unloaded application domain. is not . When legacy CAS policy is not enabled, should be . @@ -6190,8 +6166,8 @@ This method overload uses the information from the - [System.Obsolete("AppDomain.GetCurrentThreadId has been deprecated because it does not provide a stable Id when managed threads are running on fibers (aka lightweight threads). To get a stable identifier for a managed thread, use the ManagedThreadId property on Thread. https://go.microsoft.com/fwlink/?linkid=14202", false)] - [<System.Obsolete("AppDomain.GetCurrentThreadId has been deprecated because it does not provide a stable Id when managed threads are running on fibers (aka lightweight threads). To get a stable identifier for a managed thread, use the ManagedThreadId property on Thread. https://go.microsoft.com/fwlink/?linkid=14202", false)>] + [System.Obsolete("AppDomain.GetCurrentThreadId has been deprecated because it does not provide a stable Id when managed threads are running on fibers (aka lightweight threads). To get a stable identifier for a managed thread, use the ManagedThreadId property on Thread. https://go.microsoft.com/fwlink/?linkid=14202", false)] + [<System.Obsolete("AppDomain.GetCurrentThreadId has been deprecated because it does not provide a stable Id when managed threads are running on fibers (aka lightweight threads). To get a stable identifier for a managed thread, use the ManagedThreadId property on Thread. https://go.microsoft.com/fwlink/?linkid=14202", false)>] [System.Obsolete("AppDomain.GetCurrentThreadId has been deprecated because it does not provide a stable Id when managed threads are running on fibers (aka lightweight threads). To get a stable identifier for a managed thread, use the ManagedThreadId property on Thread.")] @@ -6202,8 +6178,8 @@ This method overload uses the information from the [<System.Obsolete("AppDomain.GetCurrentThreadId has been deprecated because it does not provide a stable Id when managed threads are running on fibers (aka lightweight threads). To get a stable identifier for a managed thread, use the ManagedThreadId property on Thread instead.")>] - [System.Obsolete("AppDomain.GetCurrentThreadId has been deprecated because it does not provide a stable Id when managed threads are running on fibers (aka lightweight threads). To get a stable identifier for a managed thread, use the ManagedThreadId property on Thread. http://go.microsoft.com/fwlink/?linkid=14202", false)] - [<System.Obsolete("AppDomain.GetCurrentThreadId has been deprecated because it does not provide a stable Id when managed threads are running on fibers (aka lightweight threads). To get a stable identifier for a managed thread, use the ManagedThreadId property on Thread. http://go.microsoft.com/fwlink/?linkid=14202", false)>] + [System.Obsolete("AppDomain.GetCurrentThreadId has been deprecated because it does not provide a stable Id when managed threads are running on fibers (aka lightweight threads). To get a stable identifier for a managed thread, use the ManagedThreadId property on Thread. http://go.microsoft.com/fwlink/?linkid=14202", false)] + [<System.Obsolete("AppDomain.GetCurrentThreadId has been deprecated because it does not provide a stable Id when managed threads are running on fibers (aka lightweight threads). To get a stable identifier for a managed thread, use the ManagedThreadId property on Thread. http://go.microsoft.com/fwlink/?linkid=14202", false)>] [System.Obsolete("AppDomain.GetCurrentThreadId has been deprecated because it does not provide a stable Id when managed threads are running on fibers (aka lightweight threads). To get a stable identifier for a managed thread, use the ManagedThreadId property on Thread.'")] @@ -6895,9 +6871,9 @@ This method overload uses the information from the is not a valid assembly. - -or- +-or- - Version 2.0 or later of the common language runtime is currently loaded and was compiled with a later version. +Version 2.0 or later of the common language runtime is currently loaded and was compiled with a later version. The operation is attempted on an unloaded application domain. An assembly or module was loaded twice with two different evidences. @@ -6988,9 +6964,9 @@ This method overload uses the information from the is not a valid assembly. - -or- +-or- - Version 2.0 or later of the common language runtime is currently loaded and was compiled with a later version. +Version 2.0 or later of the common language runtime is currently loaded and was compiled with a later version. The operation is attempted on an unloaded application domain. An assembly or module was loaded twice with two different evidences. @@ -7067,9 +7043,9 @@ This method overload uses the information from the is not a valid assembly. - -or- +-or- - Version 2.0 or later of the common language runtime is currently loaded and was compiled with a later version. +Version 2.0 or later of the common language runtime is currently loaded and was compiled with a later version. The operation is attempted on an unloaded application domain. An assembly or module was loaded twice with two different evidences. @@ -7172,9 +7148,9 @@ This method overload uses the information from the is not a valid assembly. - -or- +-or- - Version 2.0 or later of the common language runtime is currently loaded and was compiled with a later version. +Version 2.0 or later of the common language runtime is currently loaded and was compiled with a later version. The operation is attempted on an unloaded application domain. An assembly or module was loaded twice with two different evidences. @@ -7252,9 +7228,9 @@ This method overload uses the information from the is not a valid assembly. - -or- +-or- - Version 2.0 or later of the common language runtime is currently loaded and was compiled with a later version. +Version 2.0 or later of the common language runtime is currently loaded and was compiled with a later version. The operation is attempted on an unloaded application domain. An assembly or module was loaded twice with two different evidences. @@ -7332,9 +7308,9 @@ This method overload uses the information from the is not a valid assembly. - -or- +-or- - Version 2.0 or later of the common language runtime is currently loaded and was compiled with a later version. +Version 2.0 or later of the common language runtime is currently loaded and was compiled with a later version. The operation is attempted on an unloaded application domain. An assembly or module was loaded twice with two different evidences. @@ -7426,9 +7402,9 @@ This method overload uses the information from the is not a valid assembly. - -or- +-or- - Version 2.0 or later of the common language runtime is currently loaded and was compiled with a later version. +Version 2.0 or later of the common language runtime is currently loaded and was compiled with a later version. The operation is attempted on an unloaded application domain. An assembly or module was loaded twice with two different evidences. @@ -9581,8 +9557,7 @@ In .NET Framework version 1.0 and 1.1, if the thread that calls is . - -.NET Core and .NET 5+ only: In all cases. + .NET Core and .NET 5+ only: In all cases. -or- diff --git a/xml/System/AppDomainInitializer.xml b/xml/System/AppDomainInitializer.xml index 6a95cf02500..2a380e48328 100644 --- a/xml/System/AppDomainInitializer.xml +++ b/xml/System/AppDomainInitializer.xml @@ -34,11 +34,11 @@ An array of strings to pass as arguments to the callback method. Represents the callback method to invoke when the application domain is initialized. - delegate to specify the callback method to invoke when an instance of the class is initialized. - + delegate to specify the callback method to invoke when an instance of the class is initialized. + ]]> diff --git a/xml/System/AppDomainManager.xml b/xml/System/AppDomainManager.xml index 0a9bec79a11..ecc311a9803 100644 --- a/xml/System/AppDomainManager.xml +++ b/xml/System/AppDomainManager.xml @@ -28,38 +28,38 @@ Provides a managed equivalent of an unmanaged host. - [!IMPORTANT] -> Do not use to configure an application domain in ASP.NET. In ASP.NET, configuration must be handled by the host. - - Implementing the class enables a hosting application to participate in the creation of new application domains. To replace the default , identify the assembly and type of the replacement in the APPDOMAIN_MANAGER_ASM and APPDOMAIN_MANAGER_TYPE environment variables, or use the [\](/dotnet/framework/configure-apps/file-schema/runtime/appdomainmanagerassembly-element) and [\](/dotnet/framework/configure-apps/file-schema/runtime/appdomainmanagertype-element) elements in your configuration file. The assembly must be fully trusted and be contained in the global assembly cache or the directory of the starting application. The type and assembly names must be fully qualified in the environment variables. For example: - - `set APPDOMAIN_MANAGER_TYPE=MyNamespace.TestAppDomainManager` - - `set APPDOMAIN_MANAGER_ASM=customappDomainmanager, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f1368f7b12a08d72` - +> Do not use to configure an application domain in ASP.NET. In ASP.NET, configuration must be handled by the host. + + Implementing the class enables a hosting application to participate in the creation of new application domains. To replace the default , identify the assembly and type of the replacement in the APPDOMAIN_MANAGER_ASM and APPDOMAIN_MANAGER_TYPE environment variables, or use the [\](/dotnet/framework/configure-apps/file-schema/runtime/appdomainmanagerassembly-element) and [\](/dotnet/framework/configure-apps/file-schema/runtime/appdomainmanagertype-element) elements in your configuration file. The assembly must be fully trusted and be contained in the global assembly cache or the directory of the starting application. The type and assembly names must be fully qualified in the environment variables. For example: + + `set APPDOMAIN_MANAGER_TYPE=MyNamespace.TestAppDomainManager` + + `set APPDOMAIN_MANAGER_ASM=customappDomainmanager, Version=1.0.0.0, Culture=neutral, PublicKeyToken=f1368f7b12a08d72` + > [!IMPORTANT] -> If the assembly that contains your subclass of depends on assemblies that are marked with the conditional (APTCA) attribute, you must include those assemblies in the list that you pass to the property of the you use to create application domains. Otherwise, the assemblies that are marked with the conditional APTCA attribute will be disabled. - - The is the managed equivalent of the unmanaged host. An object participates in the creation of new application domains in a process and can customize the new before other managed code runs. The can also supply host managers that participate in other aspects of common language runtime execution. For example, an can identify a object that participates in the security decisions of the application domain. - +> If the assembly that contains your subclass of depends on assemblies that are marked with the conditional (APTCA) attribute, you must include those assemblies in the list that you pass to the property of the you use to create application domains. Otherwise, the assemblies that are marked with the conditional APTCA attribute will be disabled. + + The is the managed equivalent of the unmanaged host. An object participates in the creation of new application domains in a process and can customize the new before other managed code runs. The can also supply host managers that participate in other aspects of common language runtime execution. For example, an can identify a object that participates in the security decisions of the application domain. + > [!NOTE] -> Only assemblies granted `FullTrust`, such as assemblies in the global assembly cache or identified as `fullTrustAssemblies` in the method can be loaded in the constructor and the method. - +> Only assemblies granted `FullTrust`, such as assemblies in the global assembly cache or identified as `fullTrustAssemblies` in the method can be loaded in the constructor and the method. + > [!NOTE] -> This class contains a link demand and an inheritance demand at the class level. A is thrown when either the immediate caller or the derived class does not have infrastructure permission. For details about security demands, see [Link Demands](/dotnet/framework/misc/link-demands) and [Inheritance Demands](https://docs.microsoft.com/previous-versions/dotnet/netframework-4.0/x4yx82e6(v=vs.100)). - - - -## Examples - The following example shows a very simple implementation of . - +> This class contains a link demand and an inheritance demand at the class level. A is thrown when either the immediate caller or the derived class does not have infrastructure permission. For details about security demands, see [Link Demands](/dotnet/framework/misc/link-demands) and [Inheritance Demands](https://docs.microsoft.com/previous-versions/dotnet/netframework-4.0/x4yx82e6(v=vs.100)). + + + +## Examples + The following example shows a very simple implementation of . + :::code language="csharp" source="~/snippets/csharp/System/AppDomainManager/Overview/customAppDomainManager.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.AppDomainManager/VB/customAppDomainManager.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.AppDomainManager/VB/customAppDomainManager.vb" id="Snippet1"::: + ]]> The caller does not have the correct permissions. See the Requirements section. @@ -82,13 +82,13 @@ Initializes a new instance of the class. - [!NOTE] -> Only assemblies granted `FullTrust`, such as assemblies in the global assembly cache or identified as `fullTrustAssemblies` in the method can be loaded in the constructor and the method. - +> Only assemblies granted `FullTrust`, such as assemblies in the global assembly cache or identified as `fullTrustAssemblies` in the method can be loaded in the constructor and the method. + ]]> @@ -114,11 +114,11 @@ Gets the application activator that handles the activation of add-ins and manifest-based applications for the domain. The application activator. - class in each to which all add-in and manifest-based application activation calls are routed. The for the current can provide its own custom , or an instance of the default is created. - + class in each to which all add-in and manifest-based application activation calls are routed. The for the current can provide its own custom , or an instance of the default is created. + ]]> @@ -149,13 +149,13 @@ if the host allows the operation specified by to be performed in the application domain; otherwise, . - method has been called to increase the isolated storage quota. An application that hosts the common language runtime (CLR) can override the method to perform policy decisions based on an object (which inherits ), and can then allow or prevent the increase. For example, a host could prompt the end user to approve or deny the request to increase the quota. The host's implementation of should take into account the possibility of denial-of-service attacks. For example, it should prompt the user only if the method is called from a user-initiated event such as a button click. - + method has been called to increase the isolated storage quota. An application that hosts the common language runtime (CLR) can override the method to perform policy decisions based on an object (which inherits ), and can then allow or prevent the increase. For example, a host could prompt the end user to approve or deny the request to increase the quota. The host's implementation of should take into account the possibility of denial-of-service attacks. For example, it should prompt the user only if the method is called from a user-initiated event such as a button click. + ]]> @@ -195,17 +195,17 @@ Returns a new or existing application domain. A new or existing application domain. - property. - - The default method calls the protected method to create the . Overrides of this method do not need to call the method but can return an existing domain. - + property. + + The default method calls the protected method to create the . Overrides of this method do not need to call the method but can return an existing domain. + ]]> - When you inherit from the class and override the method, you can perform custom application domain initialization activities before calling the method, or not call the helper method at all. For example, you could modify the evidence passed in as , update the fields of the associated , or reuse an exiting domain. + When you inherit from the class and override the method, you can perform custom application domain initialization activities before calling the method, or not call the helper method at all. For example, you could modify the evidence passed in as , update the fields of the associated , or reuse an exiting domain. @@ -244,13 +244,13 @@ Provides a helper method to create an application domain. A newly created application domain. - property. - + property. + ]]> @@ -284,11 +284,11 @@ Gets the entry assembly for an application. The entry assembly for the application. - method. - + method. + ]]> @@ -314,11 +314,11 @@ Gets the host execution context manager that manages the flow of the execution context. The host execution context manager. - that can participate in the flow of the execution context across asynchronous calls. - + that can participate in the flow of the execution context across asynchronous calls. + ]]> @@ -344,19 +344,19 @@ Gets the host security manager that participates in security decisions for the application domain. The host security manager. - to participate in the security decisions for the application domain. - - - -## Examples - The following example shows an override of the property for a custom application domain manager. This code example is part of a larger example provided for the class. - + to participate in the security decisions for the application domain. + + + +## Examples + The following example shows an override of the property for a custom application domain manager. This code example is part of a larger example provided for the class. + :::code language="csharp" source="~/snippets/csharp/System/AppDomainManager/Overview/customAppDomainManager.cs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.AppDomainManager/VB/customAppDomainManager.vb" id="Snippet3"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.AppDomainManager/VB/customAppDomainManager.vb" id="Snippet3"::: + ]]> @@ -414,30 +414,30 @@ An object that contains application domain initialization information. Initializes the new application domain. - [!IMPORTANT] -> Do not use this method to initialize an application domain in ASP.NET. In ASP.NET, configuration must be handled by the host. If you use this method to initialize the application domain, the host throws when it attempts to initialize the application domain. The exception message indicates that initialization has already occurred. - - This method is called immediately after the constructor. The default implementation does nothing. A custom implementation can set up internal classes and delegates, set up an interface with the unmanaged host interface, or set up event handlers for the new . - - Also, for add-in activations, a custom implementation could identify the current as the target application domain. - - Beginning with the .NET Framework 4, you can use this method to sandbox the default application domain at application startup, or to modify the sandbox of a new application domain. To do this, adjust the and properties on the object that is assigned to the property of `appDomainInfo`, before you initialize the application domain. - +> Do not use this method to initialize an application domain in ASP.NET. In ASP.NET, configuration must be handled by the host. If you use this method to initialize the application domain, the host throws when it attempts to initialize the application domain. The exception message indicates that initialization has already occurred. + + This method is called immediately after the constructor. The default implementation does nothing. A custom implementation can set up internal classes and delegates, set up an interface with the unmanaged host interface, or set up event handlers for the new . + + Also, for add-in activations, a custom implementation could identify the current as the target application domain. + + Beginning with the .NET Framework 4, you can use this method to sandbox the default application domain at application startup, or to modify the sandbox of a new application domain. To do this, adjust the and properties on the object that is assigned to the property of `appDomainInfo`, before you initialize the application domain. + > [!NOTE] -> Only assemblies granted `FullTrust`, such as assemblies in the global assembly cache or identified as `fullTrustAssemblies` in the method can be loaded in the constructor and the method. - - - -## Examples - The following example shows an override of the method for a custom application domain manager. This code example is part of a larger example provided for the class. - +> Only assemblies granted `FullTrust`, such as assemblies in the global assembly cache or identified as `fullTrustAssemblies` in the method can be loaded in the constructor and the method. + + + +## Examples + The following example shows an override of the method for a custom application domain manager. This code example is part of a larger example provided for the class. + :::code language="csharp" source="~/snippets/csharp/System/AppDomainManager/Overview/customAppDomainManager.cs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.AppDomainManager/VB/customAppDomainManager.vb" id="Snippet2"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.AppDomainManager/VB/customAppDomainManager.vb" id="Snippet2"::: + ]]> diff --git a/xml/System/AppDomainManagerInitializationOptions.xml b/xml/System/AppDomainManagerInitializationOptions.xml index 8fadbebe961..ccc105aa60d 100644 --- a/xml/System/AppDomainManagerInitializationOptions.xml +++ b/xml/System/AppDomainManagerInitializationOptions.xml @@ -27,11 +27,11 @@ Specifies the action that a custom application domain manager takes when initializing a new domain. - class. The flags apply only to custom application domain managers; they do not apply to the default manager. The method in the default application domain manager does nothing. The default enumeration value is None. - + class. The flags apply only to custom application domain managers; they do not apply to the default manager. The method in the default application domain manager does nothing. The default enumeration value is None. + ]]> diff --git a/xml/System/AppDomainSetup.xml b/xml/System/AppDomainSetup.xml index 077a6380ce2..bb0c8d65d20 100644 --- a/xml/System/AppDomainSetup.xml +++ b/xml/System/AppDomainSetup.xml @@ -70,16 +70,16 @@ Represents assembly binding information that can be added to an instance of . - instance does not affect any existing . It can affect only the creation of a new , when the method is called with the instance as a parameter. - - This class implements the interface. - + instance does not affect any existing . It can affect only the creation of a new , when the method is called with the instance as a parameter. + + This class implements the interface. + > [!CAUTION] -> The default value for the property is false. This setting is unsafe for services. To help prevent services from downloading partially trusted code, set this property to true - +> The default value for the property is false. This setting is unsafe for services. To help prevent services from downloading partially trusted code, set this property to true + ]]> How To: Configure an Application Domain @@ -154,11 +154,11 @@ The activation context to be used for an application domain. Initializes a new instance of the class with the specified activation context to use for manifest-based activation of an application domain. - object specified for `activationContext` is used to generate an object containing information required to activate a new application domain. This object can be accessed by using the property. - + object specified for `activationContext` is used to generate an object containing information required to activate a new application domain. This object can be accessed by using the property. + ]]> @@ -201,11 +201,11 @@ An object that specifies information required for the manifest-based activation of a new application domain. Initializes a new instance of the class with the specified activation arguments required for manifest-based activation of an application domain. - property. - + property. + ]]> @@ -245,13 +245,13 @@ Gets or sets data about the activation of an application domain. An object that contains data about the activation of an application domain. - object supports manifest-based activation. - + object supports manifest-based activation. + ]]> The property is set to an object whose application identity does not match the application identity of the object returned by the property. No exception is thrown if the property is . @@ -284,23 +284,23 @@ Gets or sets the delegate, which represents a callback method that is invoked when the application domain is initialized. A delegate that represents a callback method that is invoked when the application domain is initialized. - property. The array is passed to the callback method each time an is initialized. - - The callback method is executed in the context of the newly created application domain. - - - -## Examples - The following example creates a child application domain named `ChildDomain`, using an object and evidence from the default application domain. The property is set to the callback method `AppDomainInit`, which is invoked when the child domain is initialized. The arguments for the callback method are placed in an array of strings, which is assigned to the property. When the child domain is created, the callback method simply prints the strings. - + property. The array is passed to the callback method each time an is initialized. + + The callback method is executed in the context of the newly created application domain. + + + +## Examples + The following example creates a child application domain named `ChildDomain`, using an object and evidence from the default application domain. The property is set to the callback method `AppDomainInit`, which is invoked when the child domain is initialized. The arguments for the callback method are placed in an array of strings, which is assigned to the property. When the child domain is created, the callback method simply prints the strings. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/AppDomainInitializer/cpp/source.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/AppDomainSetup/AppDomainInitializer/source.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/AppDomainSetup/AppDomainInitializer/source.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AppDomainInitializer/VB/source.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AppDomainInitializer/VB/source.vb" id="Snippet1"::: + ]]> @@ -334,23 +334,23 @@ Gets or sets the arguments passed to the callback method represented by the delegate. The callback method is invoked when the application domain is initialized. An array of strings that is passed to the callback method represented by the delegate, when the callback method is invoked during initialization. - property to specify a callback method that is invoked during initialization. If the property is not set, the array assigned to this property is not used. - - The callback method is executed in the context of the newly created application domain. - - - -## Examples - The following code example creates a child application domain named `ChildDomain`, using an object and evidence from the default application domain. The property is set to the callback method `AppDomainInit`, which is invoked when the child domain is initialized. The arguments for the callback method are placed in an array of strings, which is assigned to the property. When the child domain is created, the callback method simply prints the strings. - + property to specify a callback method that is invoked during initialization. If the property is not set, the array assigned to this property is not used. + + The callback method is executed in the context of the newly created application domain. + + + +## Examples + The following code example creates a child application domain named `ChildDomain`, using an object and evidence from the default application domain. The property is set to the callback method `AppDomainInit`, which is invoked when the child domain is initialized. The arguments for the callback method are placed in an array of strings, which is assigned to the property. When the child domain is created, the callback method simply prints the strings. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/AppDomainInitializer/cpp/source.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/AppDomainSetup/AppDomainInitializer/source.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/AppDomainSetup/AppDomainInitializer/source.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AppDomainInitializer/VB/source.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AppDomainInitializer/VB/source.vb" id="Snippet1"::: + ]]> @@ -382,21 +382,21 @@ Gets or sets the display name of the assembly that provides the type of the application domain manager for application domains created using this object. The display name of the assembly that provides the of the application domain manager. - property. If either of these properties is not set, the other is ignored. - - If no type is provided, the application domain manager is created from the same type as the parent application domain (that is, the application domain from which the method is called). - - When the application domain is loaded, is thrown if the assembly does not exist, or if the assembly does not contain the type specified by the property. is thrown if the assembly is found but the version information does not match. - - To set the application domain manager for the default application domain, use the [\](/dotnet/framework/configure-apps/file-schema/runtime/appdomainmanagerassembly-element) and [\](/dotnet/framework/configure-apps/file-schema/runtime/appdomainmanagertype-element) elements in the [\](/dotnet/framework/configure-apps/file-schema/runtime/runtime-element) section of the application configuration file, or use the environment variables described in . - - This feature requires the application to have full trust. (For example, an application running on the desktop has full trust.) If the application does not have full trust, a is thrown. - - The format of the assembly display name is given by the property. - + property. If either of these properties is not set, the other is ignored. + + If no type is provided, the application domain manager is created from the same type as the parent application domain (that is, the application domain from which the method is called). + + When the application domain is loaded, is thrown if the assembly does not exist, or if the assembly does not contain the type specified by the property. is thrown if the assembly is found but the version information does not match. + + To set the application domain manager for the default application domain, use the [\](/dotnet/framework/configure-apps/file-schema/runtime/appdomainmanagerassembly-element) and [\](/dotnet/framework/configure-apps/file-schema/runtime/appdomainmanagertype-element) elements in the [\](/dotnet/framework/configure-apps/file-schema/runtime/runtime-element) section of the application configuration file, or use the environment variables described in . + + This feature requires the application to have full trust. (For example, an application running on the desktop has full trust.) If the application does not have full trust, a is thrown. + + The format of the assembly display name is given by the property. + ]]> @@ -426,21 +426,21 @@ Gets or sets the full name of the type that provides the application domain manager for application domains created using this object. The full name of the type, including the namespace. - property. If either of these properties is not set, the other is ignored. - - If no type is provided, the application domain manager is created from the same type as the parent application domain (that is, the application domain from which the method is called). - - When the application domain is loaded, is thrown if the assembly specified by the property does not contain the type specified by this property. - - To set the application domain manager for the default application domain, use the [\](/dotnet/framework/configure-apps/file-schema/runtime/appdomainmanagerassembly-element) and [\](/dotnet/framework/configure-apps/file-schema/runtime/appdomainmanagertype-element) elements in the [\](/dotnet/framework/configure-apps/file-schema/runtime/runtime-element) section of the application configuration file, or use the environment variables described in . - - This feature requires the application to have full trust. (For example, an application running on the desktop has full trust.) If the application does not have full trust, a is thrown. - - The format of the full name of a type is given by the property. - + property. If either of these properties is not set, the other is ignored. + + If no type is provided, the application domain manager is created from the same type as the parent application domain (that is, the application domain from which the method is called). + + When the application domain is loaded, is thrown if the assembly specified by the property does not contain the type specified by this property. + + To set the application domain manager for the default application domain, use the [\](/dotnet/framework/configure-apps/file-schema/runtime/appdomainmanagerassembly-element) and [\](/dotnet/framework/configure-apps/file-schema/runtime/appdomainmanagertype-element) elements in the [\](/dotnet/framework/configure-apps/file-schema/runtime/runtime-element) section of the application configuration file, or use the environment variables described in . + + This feature requires the application to have full trust. (For example, an application running on the desktop has full trust.) If the application does not have full trust, a is thrown. + + The format of the full name of a type is given by the property. + ]]> @@ -492,26 +492,26 @@ Gets the name of the directory containing the application. The name of the application base directory. - property can influence which permissions are granted to an application domain. For example, an application domain originating from the local computer normally receives full trust based on its location of origin. However, if the property of that is set to the full name of an intranet directory, the setting restricts the permissions granted to the application domain to a LocalIntranet grant even though the application domain actually originates from the local computer. - - - -## Examples - The following example demonstrates how to use the property to set the location where the assembly loader begins probing for assemblies to load into a new application domain. - + property can influence which permissions are granted to an application domain. For example, an application domain originating from the local computer normally receives full trust based on its location of origin. However, if the property of that is set to the full name of an intranet directory, the setting restricts the permissions granted to the application domain to a LocalIntranet grant even though the application domain actually originates from the local computer. + + + +## Examples + The following example demonstrates how to use the property to set the location where the assembly loader begins probing for assemblies to load into a new application domain. + > [!NOTE] -> You must ensure that the folder you specify exists. - +> You must ensure that the folder you specify exists. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/ADApplicationBase/CPP/adapplicationbase.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/AppDomain/CurrentDomain/adapplicationbase.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/CurrentDomain/adapplicationbase.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ADApplicationBase/VB/adapplicationbase.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ADApplicationBase/VB/adapplicationbase.vb" id="Snippet1"::: + ]]> @@ -547,22 +547,22 @@ Gets or sets the name of the application. The name of the application. - property when you create a new application domain. - - The example creates a new application domain, and then calls the method to load the example assembly into the new application domain and create an instance of the `Worker` class. The `Worker` class inherits , so the example can use the proxy returned by to call the `TestLoad` method. - - The `TestLoad` method loads an assembly that you specify. You must either specify a valid, fully qualified assembly name, or comment out the method. The `TestLoad` method lists the assemblies that are loaded into the new application domain, showing that your specified assembly and the example assembly are loaded. - - The example uses the attribute to tell the assembly loader how the application will share code across application domains. - + property when you create a new application domain. + + The example creates a new application domain, and then calls the method to load the example assembly into the new application domain and create an instance of the `Worker` class. The `Worker` class inherits , so the example can use the proxy returned by to call the `TestLoad` method. + + The `TestLoad` method loads an assembly that you specify. You must either specify a valid, fully qualified assembly name, or comment out the method. The `TestLoad` method lists the assemblies that are loaded into the new application domain, showing that your specified assembly and the example assembly are loaded. + + The example uses the attribute to tell the assembly loader how the application will share code across application domains. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/ADMultiDomain/CPP/admultidomain.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/AppDomainSetup/ApplicationName/admultidomain.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/AppDomainSetup/ApplicationName/admultidomain.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ADMultiDomain/VB/admultidomain.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ADMultiDomain/VB/admultidomain.vb" id="Snippet1"::: + ]]> @@ -604,11 +604,11 @@ Gets or sets an object containing security and trust information. An object that contains security and trust information. - is created. Once changed, it cannot be reset to a null reference. - + is created. Once changed, it cannot be reset to a null reference. + ]]> The property is set to an object whose application identity does not match the application identity of the object returned by the property. No exception is thrown if the property is . @@ -652,13 +652,13 @@ Gets or sets the name of an area specific to the application where files are shadow copied. The fully qualified name of the directory path and file name where files are shadow copied. - property must also be set. If the property is not set, the property is ignored and the shadow copy cache location defaults to the download cache. - - For more information on shadow copying, see [Shadow Copying Assemblies](/dotnet/framework/app-domains/shadow-copy-assemblies). - + property must also be set. If the property is not set, the property is ignored and the shadow copy cache location defaults to the download cache. + + For more information on shadow copying, see [Shadow Copying Assemblies](/dotnet/framework/app-domains/shadow-copy-assemblies). + ]]> @@ -703,13 +703,13 @@ Gets or sets the name of the configuration file for an application domain. The name of the configuration file. - Runtime Settings Schema @@ -743,13 +743,13 @@ if probing is not allowed; otherwise, . The default is . - property is `true`, the value of the property is ignored. That is, no assemblies are probed for in the directories specified by the property. In addition, the values of the property and the property are ignored. No assemblies are probed for in the directories specified by the property. - - The property provides an additional layer of control over the loading process. In the normal assembly loading sequence, the application base is probed before the event is raised. However, some applications might need to load assemblies from an OLE compound file within a document, or from a unique known location that is neither in the global assembly cache nor in the directories specified by the and properties. Such applications can use the property to avoid the delay caused by normal probing, and to avoid loading copies of the necessary assembly that might be located in the normal probing paths. - + property is `true`, the value of the property is ignored. That is, no assemblies are probed for in the directories specified by the property. In addition, the values of the property and the property are ignored. No assemblies are probed for in the directories specified by the property. + + The property provides an additional layer of control over the loading process. In the normal assembly loading sequence, the application base is probed before the event is raised. However, some applications might need to load assemblies from an OLE compound file within a document, or from a unique known location that is neither in the global assembly cache nor in the directories specified by the and properties. Such applications can use the property to avoid the delay caused by normal probing, and to avoid loading copies of the necessary assembly that might be located in the normal probing paths. + ]]> @@ -783,13 +783,13 @@ if redirection of assemblies is not allowed; if it is allowed. - property is designed to be used by services and server applications where assembly binding redirection is not part of the application scenario. - + property is designed to be used by services and server applications where assembly binding redirection is not part of the application scenario. + The value of this property is only considered when loading strong-named assemblies. Assemblies that do not have a strong-name will always have binding redirects applied. - + ]]> @@ -823,14 +823,14 @@ if HTTP download of assemblies is not allowed; if it is allowed. - property is designed to be used by services and server applications where downloading code from an intranet or the Internet is not part of the application scenario. - + property is designed to be used by services and server applications where downloading code from an intranet or the Internet is not part of the application scenario. + > [!CAUTION] -> The default value for the property is `false`. This setting is unsafe for services. To help prevent services from downloading partially trusted code, set this property to `true`. - +> The default value for the property is `false`. This setting is unsafe for services. To help prevent services from downloading partially trusted code, set this property to `true`. + ]]> @@ -864,13 +864,13 @@ if the section of the configuration file for an application domain is ignored; if the declared publisher policy is honored. - property specifically applies to a Web application that is loaded locally. Use this property to help prevent a malicious attempt to execute an unsafe Web application in safe mode. - - For more information about bypassing publisher policy, see the [Redirecting Assembly Versions](/dotnet/framework/configure-apps/redirect-assembly-versions) topic. For more information about safe mode, see the "Examining the Configuration Files" section of the [How the Runtime Locates Assemblies](/dotnet/framework/deployment/how-the-runtime-locates-assemblies) topic. - + property specifically applies to a Web application that is loaded locally. Use this property to help prevent a malicious attempt to execute an unsafe Web application in safe mode. + + For more information about bypassing publisher policy, see the [Redirecting Assembly Versions](/dotnet/framework/configure-apps/redirect-assembly-versions) topic. For more information about safe mode, see the "Examining the Configuration Files" section of the [How the Runtime Locates Assemblies](/dotnet/framework/deployment/how-the-runtime-locates-assemblies) topic. + ]]> @@ -916,39 +916,39 @@ Gets or sets the base directory where the directory for dynamically generated files is located. The directory where the is located. Note: The return value of this property is different from the value assigned. - property. Dynamic assemblies that will be loaded and executed by the new application domain can be placed there. + + When you assign a path to the property, an additional subdirectory is added; the name of this subdirectory is the hash code of the value assigned to the property. Thus, the base directory subsequently returned by this property is always different from the value assigned. -## Remarks - Use this property to set the base directory where the dynamic directory for the new application domain will be located. When code in the new application domain loads an assembly, assembly resolution looks first in the normal probing paths. If it does not find the assembly, it looks in the dynamic directory, which is returned by the property. Dynamic assemblies that will be loaded and executed by the new application domain can be placed there. - - When you assign a path to the property, an additional subdirectory is added; the name of this subdirectory is the hash code of the value assigned to the property. Thus, the base directory subsequently returned by this property is always different from the value assigned. - > [!IMPORTANT] -> Assigning a value to this property does not create any directories. The directories must be created or verified by the code that uses them. - +> Assigning a value to this property does not create any directories. The directories must be created or verified by the code that uses them. + The dynamic directory is a subdirectory of . Its simple name is the value returned by the property, so its format is *original path*\\*hash code*\\*application name*. - -## Examples - The following example demonstrates how to use the property to set the path an application domain probes when loading dynamic assemblies. - - The example creates an object and sets its property to "Example" and its property to "C:\DynamicAssemblyDir". The example then displays the property, to show that the hash code of the application name has been appended as a subdirectory of the path that was originally assigned. - + +## Examples + The following example demonstrates how to use the property to set the path an application domain probes when loading dynamic assemblies. + + The example creates an object and sets its property to "Example" and its property to "C:\DynamicAssemblyDir". The example then displays the property, to show that the hash code of the application name has been appended as a subdirectory of the path that was originally assigned. + > [!NOTE] -> The base directory in this example is intended to be outside the probing path for the example application. Be sure to compile the example in a different location. Delete the base directory and all its subdirectories each time you run the example. - - The example creates a new application domain using the object. The example then creates the dynamic directory if it does not already exist. Although the example uses the application domain's property to get the name of the dynamic directory, it could just as easily create the directory beforehand by concatenating the original path, the hash code of the application name, and the application name. - - The example has a `GenerateDynamicAssembly` method that emits an assembly named `DynamicHelloWorld.dll` and stores it in the new application domain's dynamic directory. The dynamic assembly contains one type, `HelloWorld`, that has a static method (`Shared` method in Visual Basic) named `HelloFromAD`. Calling this method displays the name of the application domain. - - The `Example` class derives from , so the example can create an instance of the class in the new application domain and call its `Test` method. The `Test` method loads the dynamic assembly by its display name and calls the static `HelloFromAD` method. - - You can show that the dynamic directory is searched after the normal probing paths by writing code for an assembly named `DynamicHelloWorld.dll` and compiling it in the same directory as this example. The assembly must have a class named `HelloWorld` with a static method named `HelloFromAD`. This method does not have to have the same functionality as the one in the example; it can simply display a string to the console. The assembly must also have an attribute that sets its version to 1.0.0.0. When you run the example, the assembly you compiled in the current directory is found before the dynamic directory is searched. - +> The base directory in this example is intended to be outside the probing path for the example application. Be sure to compile the example in a different location. Delete the base directory and all its subdirectories each time you run the example. + + The example creates a new application domain using the object. The example then creates the dynamic directory if it does not already exist. Although the example uses the application domain's property to get the name of the dynamic directory, it could just as easily create the directory beforehand by concatenating the original path, the hash code of the application name, and the application name. + + The example has a `GenerateDynamicAssembly` method that emits an assembly named `DynamicHelloWorld.dll` and stores it in the new application domain's dynamic directory. The dynamic assembly contains one type, `HelloWorld`, that has a static method (`Shared` method in Visual Basic) named `HelloFromAD`. Calling this method displays the name of the application domain. + + The `Example` class derives from , so the example can create an instance of the class in the new application domain and call its `Test` method. The `Test` method loads the dynamic assembly by its display name and calls the static `HelloFromAD` method. + + You can show that the dynamic directory is searched after the normal probing paths by writing code for an assembly named `DynamicHelloWorld.dll` and compiling it in the same directory as this example. The assembly must have a class named `HelloWorld` with a static method named `HelloFromAD`. This method does not have to have the same functionality as the one in the example; it can simply display a string to the console. The assembly must also have an attribute that sets its version to 1.0.0.0. When you run the example, the assembly you compiled in the current directory is found before the dynamic directory is searched. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/ADDynamicBase/CPP/addynamicbase.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/AppDomain/DynamicDirectory/addynamicbase.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/DynamicDirectory/addynamicbase.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ADDynamicBase/VB/addynamicbase.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ADDynamicBase/VB/addynamicbase.vb" id="Snippet1"::: + ]]> This property cannot be set because the application name on the application domain is . @@ -982,18 +982,18 @@ Returns the XML configuration information set by the method, which overrides the application's XML configuration information. An array that contains the XML configuration information that was set by the method, or if the method has not been called. - method provides a way to override the configuration information of an application that creates a new application domain. The configuration file information in `value` overrides the configuration file information for the application. For example, when the Example.exe application creates a new application domain, it can override the configuration information originally obtained from Example.exe.config file. - + method provides a way to override the configuration information of an application that creates a new application domain. The configuration file information in `value` overrides the configuration file information for the application. For example, when the Example.exe application creates a new application domain, it can override the configuration information originally obtained from Example.exe.config file. + > [!IMPORTANT] -> Some consumers of configuration file information do not use the information stored by the method. The runtime does not enforce this. To ensure that all configuration file information is overridden in a new application domain, use the property to specify a configuration file. The method does affect assembly binding. - - The XML in `value` is the same as the XML in a normal configuration file, except that it is stored as a array. - - To access the configuration bytes for an application domain, use the property to get the object for the application domain, then use the method. - +> Some consumers of configuration file information do not use the information stored by the method. The runtime does not enforce this. To ensure that all configuration file information is overridden in a new application domain, use the property to specify a configuration file. The method does affect assembly binding. + + The XML in `value` is the same as the XML in a normal configuration file, except that it is stored as a array. + + To access the configuration bytes for an application domain, use the property to get the object for the application domain, then use the method. + ]]> @@ -1065,16 +1065,16 @@ Specifies the optimization policy used to load an executable. An enumerated constant that is used with the . - property to set the optimization policy used to load the assembly into an application domain. - + property to set the optimization policy used to load the assembly into an application domain. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/ADDyno/CPP/addyno.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/AppDomain/CreateInstanceAndUnwrap/addyno.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/CreateInstanceAndUnwrap/addyno.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ADDyno/VB/addyno.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ADDyno/VB/addyno.vb" id="Snippet1"::: + ]]> @@ -1104,19 +1104,19 @@ Gets or sets a list of assemblies marked with the flag that are made visible to partial-trust code running in a sandboxed application domain. An array of partial assembly names, where each partial name consists of the simple assembly name and the public key. - (APTCA) attribute can be made conditional by setting its property to . An APTCA assembly that is marked with cannot be used by partially trusted code unless the host application allows it. - - The host of a sandboxed application domain allows code in the application domain to use assemblies with conditional APTCA attributes by creating an array that contains the simple name and public key of each assembly, and assigning the array to this property. For example, an element of the array might look like the following: "MyAssembly, PublicKey=0024000004800000940000000602000000240000525341310004000001000100db2ad5e5fedc67ea526ff72ad426ef68e08e241d296c499eedfec6648dcc62b1a12f72be5833a45bbec481b68415b08a5fbc9f9ef247b523dd72bbea65bb532784ddc5c704544bd2f1c2d46fdbe41e4f949e76f9947357b2d5cf8ca9f970701bbd6e8ab64ad31b20ad0be9b56dae4f6b83332b92a2a3b8ea2804c40efbc0b6b9". - + (APTCA) attribute can be made conditional by setting its property to . An APTCA assembly that is marked with cannot be used by partially trusted code unless the host application allows it. + + The host of a sandboxed application domain allows code in the application domain to use assemblies with conditional APTCA attributes by creating an array that contains the simple name and public key of each assembly, and assigning the array to this property. For example, an element of the array might look like the following: "MyAssembly, PublicKey=0024000004800000940000000602000000240000525341310004000001000100db2ad5e5fedc67ea526ff72ad426ef68e08e241d296c499eedfec6648dcc62b1a12f72be5833a45bbec481b68415b08a5fbc9f9ef247b523dd72bbea65bb532784ddc5c704544bd2f1c2d46fdbe41e4f949e76f9947357b2d5cf8ca9f970701bbd6e8ab64ad31b20ad0be9b56dae4f6b83332b92a2a3b8ea2804c40efbc0b6b9". + > [!IMPORTANT] -> If you are using a subclass of , and the assembly that defines it depends on assemblies that are marked with the conditional APTCA attribute, you must include those assemblies in the list that you pass to the property of the you use to create application domains. Otherwise the assemblies that are marked with the conditional APTCA attribute will be disabled. - +> If you are using a subclass of , and the assembly that defines it depends on assemblies that are marked with the conditional APTCA attribute, you must include those assemblies in the list that you pass to the property of the you use to create application domains. Otherwise the assemblies that are marked with the conditional APTCA attribute will be disabled. + > [!NOTE] -> When you are debugging an application that is running in a sandboxed application domain, some messages can be misleading. For example, a message might state that one of your fully trusted assemblies has only limited permissions, when the real cause of the problem is that a security demand that exceeds the grant set of the sandboxed application domain has propagated to the boundary of the sandboxed application domain and failed. - +> When you are debugging an application that is running in a sandboxed application domain, some messages can be misleading. For example, a message might state that one of your fully trusted assemblies has only limited permissions, when the real cause of the problem is that a security demand that exceeds the grant set of the sandboxed application domain has propagated to the boundary of the sandboxed application domain and failed. + ]]> @@ -1161,11 +1161,11 @@ Gets or sets the list of directories under the application base directory that are probed for private assemblies. A list of directory names separated by semicolons. - are not under , they are ignored. - + are not under , they are ignored. + ]]> @@ -1201,11 +1201,11 @@ Gets or sets a string value that includes or excludes from the search path for the application, and searches only . A null reference ( in Visual Basic) to include the application base path when searching for assemblies; any non-null string value to exclude the path. The default value is . - (""), to exclude the application directory path - that is, - from the search path for the application, and to search for assemblies only in . - + (""), to exclude the application directory path - that is, - from the search path for the application, and to search for assemblies only in . + ]]> @@ -1237,13 +1237,13 @@ if interface caching is disabled for interop calls in application domains created with the current object; otherwise, . - @@ -1277,25 +1277,25 @@ An enumerable set of string values that specify compatibility switches, or to erase the existing compatibility switches. Sets the specified switches, making the application domain compatible with previous versions of the .NET Framework for the specified issues. - method to specify that one or more of these breaking changes should be rolled back for the application domain, to make the behavior compatible with the previous version of the .NET Framework. - - Each time you call this method, it replaces the existing switch settings. To erase the settings, specify `null` for the `switches` parameter. - - The set of string values you provide for `switches` can be a simple string array, because arrays implement the interface. - - The following table provides examples of compatibility switches that can be set to restore the behavior of earlier versions of the .NET Framework. - -|Switch|Meaning| -|------------|-------------| -|"NetFx40_LegacySecurityPolicy"|Code access security (CAS) for the .NET Framework 3.5 is enabled in this application domain. See [<NetFx40_LegacySecurityPolicy> Element](/dotnet/framework/configure-apps/file-schema/runtime/netfx40-legacysecuritypolicy-element).| -|"NetFx40_Legacy20SortingBehavior"|String sorting defaults for the .NET Framework 3.5 are enabled in this application domain. Successfully restoring legacy sorting behavior also requires the sort00001000.dll dynamic link library to be available on the local system. See [<CompatSortNLSVersion> Element](/dotnet/framework/configure-apps/file-schema/runtime/compatsortnlsversion-element).| -|"NetFx40_Legacy40SortingBehavior"|String sorting defaults for the .NET Framework 4 and Unicode 5.0 are enabled in this application domain. Successfully restoring legacy sorting behavior also requires the sort00060101.dll dynamic link library to be available on the local system.| -|"NetFx40_TimeSpanLegacyFormatMode"| formatting behavior for the .NET Framework 3.5 is enabled in this application domain. See [<TimeSpan_LegacyFormatMode> Element](/dotnet/framework/configure-apps/file-schema/runtime/timespan-legacyformatmode-element) and the "Restoring Legacy TimeSpan Formatting" section of the topic.| -|"UseRandomizedStringHashAlgorithm"|The runtime calculates hash codes for strings on a per application domain basis instead of using a single hashing algorithm that produces a consistent hash code across application domains. See [<UseRandomizedStringHashAlgorithm> Element](/dotnet/framework/configure-apps/file-schema/runtime/userandomizedstringhashalgorithm-element).| - + method to specify that one or more of these breaking changes should be rolled back for the application domain, to make the behavior compatible with the previous version of the .NET Framework. + + Each time you call this method, it replaces the existing switch settings. To erase the settings, specify `null` for the `switches` parameter. + + The set of string values you provide for `switches` can be a simple string array, because arrays implement the interface. + + The following table provides examples of compatibility switches that can be set to restore the behavior of earlier versions of the .NET Framework. + +|Switch|Meaning| +|------------|-------------| +|"NetFx40_LegacySecurityPolicy"|Code access security (CAS) for the .NET Framework 3.5 is enabled in this application domain. See [<NetFx40_LegacySecurityPolicy> Element](/dotnet/framework/configure-apps/file-schema/runtime/netfx40-legacysecuritypolicy-element).| +|"NetFx40_Legacy20SortingBehavior"|String sorting defaults for the .NET Framework 3.5 are enabled in this application domain. Successfully restoring legacy sorting behavior also requires the sort00001000.dll dynamic link library to be available on the local system. See [<CompatSortNLSVersion> Element](/dotnet/framework/configure-apps/file-schema/runtime/compatsortnlsversion-element).| +|"NetFx40_Legacy40SortingBehavior"|String sorting defaults for the .NET Framework 4 and Unicode 5.0 are enabled in this application domain. Successfully restoring legacy sorting behavior also requires the sort00060101.dll dynamic link library to be available on the local system.| +|"NetFx40_TimeSpanLegacyFormatMode"| formatting behavior for the .NET Framework 3.5 is enabled in this application domain. See [<TimeSpan_LegacyFormatMode> Element](/dotnet/framework/configure-apps/file-schema/runtime/timespan-legacyformatmode-element) and the "Restoring Legacy TimeSpan Formatting" section of the topic.| +|"UseRandomizedStringHashAlgorithm"|The runtime calculates hash codes for strings on a per application domain basis instead of using a single hashing algorithm that produces a consistent hash code across application domains. See [<UseRandomizedStringHashAlgorithm> Element](/dotnet/framework/configure-apps/file-schema/runtime/userandomizedstringhashalgorithm-element).| + ]]> @@ -1335,16 +1335,16 @@ An array that contains the XML configuration information to be used for the application domain. Provides XML configuration information for the application domain, replacing the application's XML configuration information. - method provides a way to replace the configuration information of an application that creates a new application domain. The configuration file information in `value` replaces the configuration file information for the application. For example, when the Example.exe application creates a new application domain, it can replace the configuration information originally obtained from the Example.exe.config file. - + method provides a way to replace the configuration information of an application that creates a new application domain. The configuration file information in `value` replaces the configuration file information for the application. For example, when the Example.exe application creates a new application domain, it can replace the configuration information originally obtained from the Example.exe.config file. + > [!IMPORTANT] -> Some consumers of configuration file information do not use the information stored by the method. The runtime does not enforce this. To ensure that all configuration file information is replaced in a new application domain, use the property to specify a configuration file. The method does affect assembly binding. - - The XML in `value` is the same as the XML in a normal configuration file, except that it is stored as a array. - +> Some consumers of configuration file information do not use the information stored by the method. The runtime does not enforce this. To ensure that all configuration file information is replaced in a new application domain, use the property to specify a configuration file. The method does affect assembly binding. + + The XML in `value` is the same as the XML in a normal configuration file, except that it is stored as a array. + ]]> Runtime Settings Schema @@ -1388,35 +1388,35 @@ A pointer to the function that overrides . Provides the common language runtime with an alternate implementation of a string comparison function. - method: - -- `IsNLSDefinedString` - -- `CompareStringEx` - -- `LCMapStringEx` - -- `FindNLSStringEx` - -- `CompareStringOrdinal` - -- `GetNLSVersion` - - For information about these functions, see [National Language Support Functions](https://go.microsoft.com/fwlink/?LinkId=228134). - + method: + +- `IsNLSDefinedString` + +- `CompareStringEx` + +- `LCMapStringEx` + +- `FindNLSStringEx` + +- `CompareStringOrdinal` + +- `GetNLSVersion` + + For information about these functions, see [National Language Support Functions](https://go.microsoft.com/fwlink/?LinkId=228134). + ]]> is . - is not 1 or greater. - - -or- - - is . + is not 1 or greater. + +-or- + + is . @@ -1456,18 +1456,18 @@ Gets or sets the names of the directories containing assemblies to be shadow copied. A list of directory names separated by semicolons. - and properties. The property restricts the shadow copy to the assemblies in the directories specified by . - - If you don't assign a string to the property, or if you set this property to `null`, all assemblies in the directories specified by the and properties are shadow copied. - + and properties. The property restricts the shadow copy to the assemblies in the directories specified by . + + If you don't assign a string to the property, or if you set this property to `null`, all assemblies in the directories specified by the and properties are shadow copied. + > [!IMPORTANT] -> Directory paths must not contain semicolons, because the semicolon is the delimiter character. There is no escape character for semicolons. - - When shadow copying is in effect, assembly files are copied to another location before the assemblies are loaded. The original assembly file is not locked, so it can be updated. For more information on shadow copying, see [Shadow Copying Assemblies](/dotnet/framework/app-domains/shadow-copy-assemblies). - +> Directory paths must not contain semicolons, because the semicolon is the delimiter character. There is no escape character for semicolons. + + When shadow copying is in effect, assembly files are copied to another location before the assemblies are loaded. The original assembly file is not locked, so it can be updated. For more information on shadow copying, see [Shadow Copying Assemblies](/dotnet/framework/app-domains/shadow-copy-assemblies). + ]]> @@ -1506,11 +1506,11 @@ Gets or sets a string that indicates whether shadow copying is turned on or off. The string value "true" to indicate that shadow copying is turned on; or "false" to indicate that shadow copying is turned off. - @@ -1554,13 +1554,13 @@ Gets (or, in .NET Framework, sets) a string that specifies the target framework in a format that can be parsed by the constructor. The target framework of the executable that started the process. - property is inferred from the attribute. In Visual Studio 2010 and later, this attribute is added to the assembly automatically based on the setting of the project's **Target Framework** property. - + property is inferred from the attribute. In Visual Studio 2010 and later, this attribute is added to the assembly automatically based on the setting of the project's **Target Framework** property. + ]]> diff --git a/xml/System/AppDomainUnloadedException.xml b/xml/System/AppDomainUnloadedException.xml index dacb8c49e5c..91b5e9a7ef9 100644 --- a/xml/System/AppDomainUnloadedException.xml +++ b/xml/System/AppDomainUnloadedException.xml @@ -66,45 +66,45 @@ The exception that is thrown when an attempt is made to access an unloaded application domain. - that is not handled in user code has the following effect: - -- If a thread was started in managed code, it is terminated. The unhandled exception is not allowed to terminate the application. - -- If a task is executing on a thread, it is terminated and the thread is returned to the thread pool. The unhandled exception is not allowed to terminate the application. - -- If a thread started in unmanaged code, such as the main application thread, it is terminated. The unhandled exception is allowed to proceed, and the operating system terminates the application. - - uses the HRESULT COR_E_APPDOMAINUNLOADED, which has the value 0x80131014. - - For a list of initial property values for an instance of , see the constructors. - - - -## Examples - This section contains two code examples. The first example demonstrates the effects of an on various threads, and the second shows elementary application domain unloading. - - Example 1 - - The following code example defines a `TestClass` class that can be marshaled across application domain boundaries and an `Example` class containing a `static` (`Shared` in Visual Basic) `ThreadProc` method. The `ThreadProc` method creates an application domain, creates a `TestClass` object in the domain, and calls a method of `TestClass` that unloads the executing domain, causing an . - - The `TestClass` method is executed without exception handling from a thread and from an ordinary thread, demonstrating that the unhandled exception terminates the task or thread but not the application. It is then executed with and without exception handling from the main application thread, demonstrating that it terminates the application if not handled. - + that is not handled in user code has the following effect: + +- If a thread was started in managed code, it is terminated. The unhandled exception is not allowed to terminate the application. + +- If a task is executing on a thread, it is terminated and the thread is returned to the thread pool. The unhandled exception is not allowed to terminate the application. + +- If a thread started in unmanaged code, such as the main application thread, it is terminated. The unhandled exception is allowed to proceed, and the operating system terminates the application. + + uses the HRESULT COR_E_APPDOMAINUNLOADED, which has the value 0x80131014. + + For a list of initial property values for an instance of , see the constructors. + + + +## Examples + This section contains two code examples. The first example demonstrates the effects of an on various threads, and the second shows elementary application domain unloading. + + Example 1 + + The following code example defines a `TestClass` class that can be marshaled across application domain boundaries and an `Example` class containing a `static` (`Shared` in Visual Basic) `ThreadProc` method. The `ThreadProc` method creates an application domain, creates a `TestClass` object in the domain, and calls a method of `TestClass` that unloads the executing domain, causing an . + + The `TestClass` method is executed without exception handling from a thread and from an ordinary thread, demonstrating that the unhandled exception terminates the task or thread but not the application. It is then executed with and without exception handling from the main application thread, demonstrating that it terminates the application if not handled. + :::code language="csharp" source="~/snippets/csharp/System/AppDomainUnloadedException/Overview/Sample.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/AppDomainUnloadedException/Overview/Sample.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AppDomainUnloadedException/vb/Sample.vb" id="Snippet1"::: - - Example 2 - - The following code example creates and unloads an application domain, and demonstrates that an is thrown on a subsequent attempt to access the unloaded domain. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AppDomainUnloadedException/vb/Sample.vb" id="Snippet1"::: + + Example 2 + + The following code example creates and unloads an application domain, and demonstrates that an is thrown on a subsequent attempt to access the unloaded domain. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/ADUnload/CPP/adunload.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/AppDomain/Unload/adunload.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/Unload/adunload.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ADUnload/VB/adunload.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ADUnload/VB/adunload.vb" id="Snippet1"::: + ]]> @@ -158,18 +158,18 @@ Initializes a new instance of the class. - property of the new instance to a system-supplied message that describes the error, such as "The target application domain has been unloaded." This message takes into account the current system culture. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The localized error message string.| - + property of the new instance to a system-supplied message that describes the error, such as "The target application domain has been unloaded." This message takes into account the current system culture. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The localized error message string.| + ]]> @@ -215,18 +215,18 @@ The message that describes the error. Initializes a new instance of the class with a specified error message. - . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The error message string.| - + . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The error message string.| + ]]> @@ -291,11 +291,11 @@ The contextual information about the source or destination. Initializes a new instance of the class with serialized data. - XML and SOAP Serialization @@ -344,20 +344,20 @@ The exception that is the cause of the current exception. If the parameter is not a null reference, the current exception is raised in a block that handles the inner exception. Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception. - property. The property returns the same value that is passed into the constructor, or a null reference if the property does not supply the inner exception value to the constructor. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||The inner exception reference.| -||The error message string.| - + property. The property returns the same value that is passed into the constructor, or a null reference if the property does not supply the inner exception value to the constructor. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||The inner exception reference.| +||The error message string.| + ]]> diff --git a/xml/System/ApplicationException.xml b/xml/System/ApplicationException.xml index 3252f04a800..d51a0b3fd00 100644 --- a/xml/System/ApplicationException.xml +++ b/xml/System/ApplicationException.xml @@ -59,13 +59,13 @@ Serves as the base class for application-defined exceptions. - [!IMPORTANT] -> You should derive custom exceptions from the class rather than the class. You should not throw an exception in your code, and you should not catch an exception unless you intend to re-throw the original exception. - +> You should derive custom exceptions from the class rather than the class. You should not throw an exception in your code, and you should not catch an exception unless you intend to re-throw the original exception. + ]]> @@ -116,18 +116,18 @@ Initializes a new instance of the class. - property of the new instance to a system-supplied message that describes the error, such as "An application error has occurred." This message takes into account the current system culture. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The localized error message string.| - + property of the new instance to a system-supplied message that describes the error, such as "An application error has occurred." This message takes into account the current system culture. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The localized error message string.| + ]]> @@ -170,20 +170,20 @@ A message that describes the error. Initializes a new instance of the class with a specified error message. - . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -|`Message`|The error message string.| - + . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +|`Message`|The error message string.| + ]]> @@ -245,11 +245,11 @@ The contextual information about the source or destination. Initializes a new instance of the class with serialized data. - XML and Soap Serialization @@ -295,20 +295,20 @@ The exception that is the cause of the current exception. If the parameter is not a null reference, the current exception is raised in a block that handles the inner exception. Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception. - property. The property returns the same value that is passed into the constructor, or a null reference if the property does not supply the inner exception value to the constructor. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||The inner exception reference.| -||The error message string.| - + property. The property returns the same value that is passed into the constructor, or a null reference if the property does not supply the inner exception value to the constructor. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||The inner exception reference.| +||The error message string.| + ]]> diff --git a/xml/System/ApplicationId.xml b/xml/System/ApplicationId.xml index bdf3f2707a0..355368ba27c 100644 --- a/xml/System/ApplicationId.xml +++ b/xml/System/ApplicationId.xml @@ -157,13 +157,13 @@ is . - -or- +-or- - is . + is . - -or- +-or- - is . + is . is an empty string. diff --git a/xml/System/ApplicationIdentity.xml b/xml/System/ApplicationIdentity.xml index 26a386ce2ce..61a0f06fa58 100644 --- a/xml/System/ApplicationIdentity.xml +++ b/xml/System/ApplicationIdentity.xml @@ -43,19 +43,19 @@ Provides the ability to uniquely identify a manifest-activated application. This class cannot be inherited. - class is used in the activation of manifest-based applications. - - - -## Examples - The following code example demonstrates the use of an object to obtain the for a manifest-based application. This code example is part of a larger example provided for the class. - + class is used in the activation of manifest-based applications. + + + +## Examples + The following code example demonstrates the use of an object to obtain the for a manifest-based application. This code example is part of a larger example provided for the class. + :::code language="csharp" source="~/snippets/csharp/System/ActivationContext/Overview/program.cs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.ActivationContext/vb/program.vb" id="Snippet2"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.ActivationContext/vb/program.vb" id="Snippet2"::: + ]]> @@ -97,65 +97,65 @@ The full name of the application. Initializes a new instance of the class. - @@ -199,23 +199,23 @@ http://testserver/ActivationContext/ActivationContext.application Gets the location of the deployment manifest as a URL. The URL of the deployment manifest. - property values for an application named ActivationContext: - -- `http://testserver/ActivationContext/ActivationContext.application` - -- `file://C:/UserFiles/UserName/SolutionName/ActivationContext/publish/ActivationContext.application`. - - - -## Examples - The following code example demonstrates the use of an object to obtain the value of the property for a manifest-based application. This code example is part of a larger example provided for the class. - + property values for an application named ActivationContext: + +- `http://testserver/ActivationContext/ActivationContext.application` + +- `file://C:/UserFiles/UserName/SolutionName/ActivationContext/publish/ActivationContext.application`. + + + +## Examples + The following code example demonstrates the use of an object to obtain the value of the property for a manifest-based application. This code example is part of a larger example provided for the class. + :::code language="csharp" source="~/snippets/csharp/System/ActivationContext/Overview/program.cs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.ActivationContext/vb/program.vb" id="Snippet3"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.ActivationContext/vb/program.vb" id="Snippet3"::: + ]]> @@ -257,19 +257,19 @@ http://testserver/ActivationContext/ActivationContext.application Gets the full name of the application. The full name of the application, also known as the display name. - property, see the constructor. - - - -## Examples - The following code example demonstrates the use of an object to obtain the value of the property for a manifest-based application. This code example is part of a larger example provided for the class. - + property, see the constructor. + + + +## Examples + The following code example demonstrates the use of an object to obtain the value of the property for a manifest-based application. This code example is part of a larger example provided for the class. + :::code language="csharp" source="~/snippets/csharp/System/ActivationContext/Overview/program.cs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.ActivationContext/vb/program.vb" id="Snippet3"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.ActivationContext/vb/program.vb" id="Snippet3"::: + ]]> @@ -353,11 +353,11 @@ http://testserver/ActivationContext/ActivationContext.application Returns the full name of the manifest-activated application. The full name of the manifest-activated application. - constructor. - + constructor. + ]]> diff --git a/xml/System/ArgIterator.xml b/xml/System/ArgIterator.xml index 0d27381d62b..26e2ac56552 100644 --- a/xml/System/ArgIterator.xml +++ b/xml/System/ArgIterator.xml @@ -40,13 +40,13 @@ Represents a variable-length argument list; that is, the parameters of a function that takes a variable number of arguments. - structure to enumerate the mandatory and optional arguments in an argument list. The structure is not generally useful for applications other than compilers. - - The functionality in the structure is typically hidden in the syntax of a specific programming language. For example, in the C++ programming language you declare a variable-length argument list by specifying an ellipsis ("...") at the end of the argument list. The structure is useful primarily when a development language does not provide direct support for accessing variable-length parameters. - + structure to enumerate the mandatory and optional arguments in an argument list. The structure is not generally useful for applications other than compilers. + + The functionality in the structure is typically hidden in the syntax of a specific programming language. For example, in the C++ programming language you declare a variable-length argument list by specifying an ellipsis ("...") at the end of the argument list. The structure is useful primarily when a development language does not provide direct support for accessing variable-length parameters. + ]]> @@ -102,11 +102,11 @@ An argument list consisting of mandatory and optional arguments. Initializes a new instance of the structure using the specified argument list. - object enumerates the argument list starting from the first optional argument. - + object enumerates the argument list starting from the first optional argument. + ]]> @@ -157,11 +157,11 @@ A pointer to the argument in to access first, or the first mandatory argument in if is . Initializes a new instance of the structure using the specified argument list and a pointer to an item in the list. - object enumerates the argument list starting from the argument specified by `ptr`, or the first mandatory argument if `ptr` is `null`. - + object enumerates the argument list starting from the argument specified by `ptr`, or the first mandatory argument if `ptr` is `null`. + ]]> @@ -201,13 +201,13 @@ Concludes processing of the variable-length argument list represented by this instance. - concludes the processing of a variable-length argument list. However, this method has no actual implementation; the method body is empty. You can use this method in your code as a marker to indicate where variable-length argument list processing logically ends. - - The method corresponds to the `va_end` method in the C standard library. - + concludes the processing of a variable-length argument list. However, this method has no actual implementation; the method body is empty. You can use this method in your code as a marker to indicate where variable-length argument list processing logically ends. + + The method corresponds to the `va_end` method in the C standard library. + ]]> @@ -355,11 +355,11 @@ Returns the next argument in a variable-length argument list. The next argument as a object. - An attempt was made to read beyond the end of the list. @@ -414,11 +414,11 @@ Returns the next argument in a variable-length argument list that has a specified type. The next argument as a object. - An attempt was made to read beyond the end of the list. @@ -467,13 +467,13 @@ Returns the type of the next argument. The type of the next argument. - returns the type of the argument as specified in the calling function. For example, if an argument is type , but the calling function specifies the argument as type , reports the argument as type . - + returns the type of the argument as specified in the calling function. For example, if an argument is type , but the calling function specifies the argument as type , reports the argument as type . + ]]> diff --git a/xml/System/ArgumentException.xml b/xml/System/ArgumentException.xml index c64c7f49dba..a5e14e6f186 100644 --- a/xml/System/ArgumentException.xml +++ b/xml/System/ArgumentException.xml @@ -76,36 +76,36 @@ The exception that is thrown when one of the arguments provided to a method is not valid. - is thrown when a method is invoked and at least one of the passed arguments does not meet the parameter specification of the called method. The property identifies the invalid argument. - - Most commonly, an is thrown by the common language runtime or another class library and indicates developer error. If you throw an from your code, you should ensure that the exception's property includes a meaningful error message that describes the invalid argument and the expected range of values for the argument. - - The primary derived classes of are and . These derived classes should be used instead of , except in situations where neither of the derived classes is acceptable. For example, exceptions should be thrown by: - -- whenever `null` is passed to a method that does not accept it as a valid argument. - -- when the value of an argument is outside the range of acceptable values; for example, when the value "46" is passed as the month argument during the creation of a . - -If the method call does not have any argument or if the failure does not involve the arguments themselves, then should be used. - - uses the HRESULT COR_E_ARGUMENT, which has the value 0x80070057. - -For a list of initial property values for an instance of , see the constructors. - + is thrown when a method is invoked and at least one of the passed arguments does not meet the parameter specification of the called method. The property identifies the invalid argument. + + Most commonly, an is thrown by the common language runtime or another class library and indicates developer error. If you throw an from your code, you should ensure that the exception's property includes a meaningful error message that describes the invalid argument and the expected range of values for the argument. + + The primary derived classes of are and . These derived classes should be used instead of , except in situations where neither of the derived classes is acceptable. For example, exceptions should be thrown by: + +- whenever `null` is passed to a method that does not accept it as a valid argument. + +- when the value of an argument is outside the range of acceptable values; for example, when the value "46" is passed as the month argument during the creation of a . + +If the method call does not have any argument or if the failure does not involve the arguments themselves, then should be used. + + uses the HRESULT COR_E_ARGUMENT, which has the value 0x80070057. + +For a list of initial property values for an instance of , see the constructors. + In F#, you can use the [invalidArg](/dotnet/fsharp/language-reference/exception-handling/the-invalidarg-function) function to generate and raise an ArgumentException. - + ## Examples -The following example demonstrates how to throw and catch an . It uses the [ArgumentException.GetType().Name](xref:System.Type.Name%2A) property to display the name of the exception object, and also uses the property to display the text of the exception message. - +The following example demonstrates how to throw and catch an . It uses the [ArgumentException.GetType().Name](xref:System.Type.Name%2A) property to display the name of the exception object, and also uses the property to display the text of the exception message. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/ArgumentException/cpp/argumentexception2.cpp" id="Snippet3"::: :::code language="csharp" source="~/snippets/csharp/System/ArgumentException/Overview/argumentexception2.cs" interactive="try-dotnet" id="Snippet3"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR/ArgumentException/FS/argumentexception2.fs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ArgumentException/vb/program2.vb" id="Snippet3"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ArgumentException/vb/program2.vb" id="Snippet3"::: + ]]> @@ -162,18 +162,18 @@ The following example demonstrates how to throw and catch an Initializes a new instance of the class. - property of the new instance to a system-supplied message that describes the error, such as "An invalid argument was specified." This message takes into account the current system culture. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The localized error message string.| - + property of the new instance to a system-supplied message that describes the error, such as "An invalid argument was specified." This message takes into account the current system culture. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The localized error message string.| + ]]> @@ -220,18 +220,18 @@ The following example demonstrates how to throw and catch an The error message that explains the reason for the exception. Initializes a new instance of the class with a specified error message. - property of the new instance to a system-supplied message that describes the error, such as "An invalid argument was specified." This message takes into account the current system culture. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The error message string.| - + property of the new instance to a system-supplied message that describes the error, such as "An invalid argument was specified." This message takes into account the current system culture. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The error message string.| + ]]> @@ -293,11 +293,11 @@ The following example demonstrates how to throw and catch an The contextual information about the source or destination. Initializes a new instance of the class with serialized data. - XML and SOAP Serialization @@ -347,20 +347,20 @@ The following example demonstrates how to throw and catch an The exception that is the cause of the current exception. If the parameter is not a null reference, the current exception is raised in a block that handles the inner exception. Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception. - property of the new instance using the value of the `message` parameter. The content of the `message` parameter is intended to be understood by humans. The caller of this constructor is required to ensure that this string has been localized for the current system culture. - - An exception that is thrown as a direct result of a previous exception should include a reference to the previous exception in the property. The property returns the same value that is passed into the constructor, or `null` if the property does not supply the inner exception value to the constructor. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||The inner exception reference.| -||The localized error message string.| - + property of the new instance using the value of the `message` parameter. The content of the `message` parameter is intended to be understood by humans. The caller of this constructor is required to ensure that this string has been localized for the current system culture. + + An exception that is thrown as a direct result of a previous exception should include a reference to the previous exception in the property. The property returns the same value that is passed into the constructor, or `null` if the property does not supply the inner exception value to the constructor. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||The inner exception reference.| +||The localized error message string.| + ]]> @@ -411,28 +411,28 @@ The following example demonstrates how to throw and catch an The name of the parameter that caused the current exception. Initializes a new instance of the class with a specified error message and the name of the parameter that causes this exception. - property of the new instance using the value of the `message` parameter. The content of the `message` parameter is intended to be understood by humans. The caller of this constructor is required to ensure that this string has been localized for the current system culture. - - This constructor initializes the property of the new instance using `paramName`. The content of `paramName` is intended to be understood by humans. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||The error message string.| -||The parameter name string.| - - - -## Examples - The following code example demonstrates how to call the constructor. This code example is part of a larger example provided for the class. - + property of the new instance using the value of the `message` parameter. The content of the `message` parameter is intended to be understood by humans. The caller of this constructor is required to ensure that this string has been localized for the current system culture. + + This constructor initializes the property of the new instance using `paramName`. The content of `paramName` is intended to be understood by humans. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||The error message string.| +||The parameter name string.| + + + +## Examples + The following code example demonstrates how to call the constructor. This code example is part of a larger example provided for the class. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/ArgumentException/cpp/ArgumentException.cpp" id="Snippet2"::: :::code language="csharp" source="~/snippets/csharp/System/ArgumentException/Overview/argumentexception.cs" id="Snippet2"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR/ArgumentException/FS/argumentexception.fs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR/ArgumentException/FS/argumentexception.fs" id="Snippet2"::: ]]> @@ -484,23 +484,23 @@ The following example demonstrates how to throw and catch an The exception that is the cause of the current exception. If the parameter is not a null reference, the current exception is raised in a block that handles the inner exception. Initializes a new instance of the class with a specified error message, the parameter name, and a reference to the inner exception that is the cause of this exception. - property of the new instance using the value of the `message` parameter. The content of the `message` parameter is intended to be understood by humans. The caller of this constructor is required to ensure that this string has been localized for the current system culture. - - This constructor initializes the property of the new instance using `paramName`. The content of `paramName` is intended to be understood by humans. - - An exception that is thrown as a direct result of a previous exception should include a reference to the previous exception in the property. The property returns the same value that is passed into the constructor, or `null` if the property does not supply the inner exception value to the constructor. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||The inner exception reference.| -||The localized error message string.| -||The parameter name string.| - + property of the new instance using the value of the `message` parameter. The content of the `message` parameter is intended to be understood by humans. The caller of this constructor is required to ensure that this string has been localized for the current system culture. + + This constructor initializes the property of the new instance using `paramName`. The content of `paramName` is intended to be understood by humans. + + An exception that is thrown as a direct result of a previous exception should include a reference to the previous exception in the property. The property returns the same value that is passed into the constructor, or `null` if the property does not supply the inner exception value to the constructor. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||The inner exception reference.| +||The localized error message string.| +||The parameter name string.| + ]]> @@ -570,13 +570,13 @@ The following example demonstrates how to throw and catch an The contextual information about the source or destination. Sets the object with the parameter name and additional exception information. - sets a with all the exception object data targeted for serialization. During deserialization, the exception object is reconstituted from the transmitted over the stream. - - For more information, see . - + sets a with all the exception object data targeted for serialization. During deserialization, the exception object is reconstituted from the transmitted over the stream. + + For more information, see . + ]]> The object is a null reference ( in Visual Basic). @@ -633,27 +633,30 @@ The following example demonstrates how to throw and catch an Gets the error message and the parameter name, or only the error message if no parameter name is set. - A text string describing the details of the exception. The value of this property takes one of two forms: - - Condition - - Value - - The is a null reference ( in Visual Basic) or of zero length. - - The string passed to the constructor. - - The is not null reference ( in Visual Basic) and it has a length greater than zero. - - The string appended with the name of the invalid parameter. - - + A text string describing the details of the exception. The value of this property takes one of two forms: + + Condition + + + Value + + + + + The is a null reference ( in Visual Basic) or of zero length. + The string passed to the constructor. + + + The is not null reference ( in Visual Basic) and it has a length greater than zero. + The string appended with the name of the invalid parameter. + + - . The error message should be localized. - + . The error message should be localized. + ]]> @@ -700,15 +703,15 @@ The following example demonstrates how to throw and catch an Gets the name of the parameter that causes this exception. The parameter name. - should carry the name of the parameter that causes this exception. - - This property is read-only, and returns the same value as was passed into the constructor. Overriding methods should be used solely to customize the format of the parameter name. - - The parameter name should not be translated for localization purposes. - + should carry the name of the parameter that causes this exception. + + This property is read-only, and returns the same value as was passed into the constructor. Overriding methods should be used solely to customize the format of the parameter name. + + The parameter name should not be translated for localization purposes. + ]]> diff --git a/xml/System/ArgumentNullException.xml b/xml/System/ArgumentNullException.xml index 138ac620bd3..5b0813ed4bd 100644 --- a/xml/System/ArgumentNullException.xml +++ b/xml/System/ArgumentNullException.xml @@ -64,23 +64,23 @@ The exception that is thrown when a null reference ( in Visual Basic) is passed to a method that does not accept it as a valid argument. - exception is thrown when a method is invoked and at least one of the passed arguments is `null` but should never be `null`. - - An exception is thrown at run time in the following two major circumstances, both of which reflect developer error: - -- An uninstantiated object is passed to a method. To prevent the error, instantiate the object. - -- An object returned from a method call is then passed as an argument to a second method, but the value of the original returned object is `null`. To prevent the error, check for a return value that is `null` and call the second method only if the return value is not `null`. - - behaves identically to . It is provided so that application code can differentiate between exceptions caused by `null` arguments and exceptions caused by arguments that are not null. For errors caused by arguments that are not null, see . - - uses the HRESULT E_POINTER, which has the value 0x80004003. - - For a list of initial property values for an instance of , see the constructors. - + exception is thrown when a method is invoked and at least one of the passed arguments is `null` but should never be `null`. + + An exception is thrown at run time in the following two major circumstances, both of which reflect developer error: + +- An uninstantiated object is passed to a method. To prevent the error, instantiate the object. + +- An object returned from a method call is then passed as an argument to a second method, but the value of the original returned object is `null`. To prevent the error, check for a return value that is `null` and call the second method only if the return value is not `null`. + + behaves identically to . It is provided so that application code can differentiate between exceptions caused by `null` arguments and exceptions caused by arguments that are not null. For errors caused by arguments that are not null, see . + + uses the HRESULT E_POINTER, which has the value 0x80004003. + + For a list of initial property values for an instance of , see the constructors. + ]]> @@ -137,18 +137,18 @@ Initializes a new instance of the class. - property of the new instance to a system-supplied message that describes the error, such as "Value cannot be null." This message takes into account the current system culture. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||A localized error message string, such as "Value cannot be null." for the English language.| - + property of the new instance to a system-supplied message that describes the error, such as "Value cannot be null." This message takes into account the current system culture. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||A localized error message string, such as "Value cannot be null." for the English language.| + ]]> @@ -195,21 +195,21 @@ The name of the parameter that caused the exception. Initializes a new instance of the class with the name of the parameter that causes this exception. - property of the new instance to a system-supplied message that describes the error and includes the parameter name. This message takes into account the current system culture. - - This constructor initializes the property of the new instance using the `paramName` parameter. The content of `paramName` is intended to be understood by humans. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||A localized error message string that identifies the null argument. For example, if the `paramName` argument is "arg1", the English language message string is:

On .NET 5+ and .NET Core: `Value cannot be null. (Parameter name: 'arg1')`

On .NET Framework: `Value cannot be null.\r\nParameter name: arg1`| -||The parameter name string.| - + property of the new instance to a system-supplied message that describes the error and includes the parameter name. This message takes into account the current system culture. + + This constructor initializes the property of the new instance using the `paramName` parameter. The content of `paramName` is intended to be understood by humans. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||A localized error message string that identifies the null argument. For example, if the `paramName` argument is "arg1", the English language message string is:

On .NET 5+ and .NET Core: `Value cannot be null. (Parameter name: 'arg1')`

On .NET Framework: `Value cannot be null.\r\nParameter name: arg1`| +||The parameter name string.| + ]]>
@@ -271,11 +271,11 @@ An object that describes the source or destination of the serialized data. Initializes a new instance of the class with serialized data. - XML and SOAP Serialization @@ -370,21 +370,21 @@ A message that describes the error. Initializes an instance of the class with a specified error message and the name of the parameter that causes this exception. - property of the new instance using the value of the `message` parameter. The content of the `message` parameter is intended to be understood by humans. The caller of this constructor is required to ensure that this string has been localized for the current system culture. - - This constructor initializes the property of the new instance using the `paramName` parameter. The content of `paramName` is intended to be understood by humans. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The error message string.| -||The parameter name string.| - + property of the new instance using the value of the `message` parameter. The content of the `message` parameter is intended to be understood by humans. The caller of this constructor is required to ensure that this string has been localized for the current system culture. + + This constructor initializes the property of the new instance using the `paramName` parameter. The content of `paramName` is intended to be understood by humans. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The error message string.| +||The parameter name string.| + ]]> diff --git a/xml/System/ArgumentOutOfRangeException.xml b/xml/System/ArgumentOutOfRangeException.xml index 225c394cca6..706ad245e0f 100644 --- a/xml/System/ArgumentOutOfRangeException.xml +++ b/xml/System/ArgumentOutOfRangeException.xml @@ -830,21 +830,24 @@ The following example defines a class to contain information about an invited gu Gets the error message and the string representation of the invalid argument value, or only the error message if the argument value is null. - The text message for this exception. The value of this property takes one of two forms, as follows. - - Condition - - Value - - The is . - - The string passed to the constructor. - - The is not . - - The string appended with the string representation of the invalid argument value. - - + The text message for this exception. The value of this property takes one of two forms, as follows. + + Condition + + + Value + + + + + The is . + The string passed to the constructor. + + + The is not . + The string appended with the string representation of the invalid argument value. + + The exception that is thrown for errors in an arithmetic, casting, or conversion operation. - is the base class for the following exceptions: - -- , which is thrown in integer division when the divisor is 0. For example, attempting to divide 10 by 0 throws a exception. - -- , which is thrown when an operation is performed on or returns , , , , , , and the programming language used does not support those values. - -- , which is thrown when the result of an operation is outside the bounds of the target data type. That is, it is less than a number's `MinValue` property or greater than its `MaxValue` property. For example, attempting to assign 200 + 200 to a value throws an exception, since 400 greater than 256, the upper bound of the data type. - - Your code should not handle or throw this exception. Instead, you should either handle or throw one of its derived classes, since it more precisely indicates the exact nature of the error. - - For a list of initial property values for an instance of , see the constructors. - - uses the HRESULT COR_E_ARITHMETIC, which has the value 0x80070216. - + is the base class for the following exceptions: + +- , which is thrown in integer division when the divisor is 0. For example, attempting to divide 10 by 0 throws a exception. + +- , which is thrown when an operation is performed on or returns , , , , , , and the programming language used does not support those values. + +- , which is thrown when the result of an operation is outside the bounds of the target data type. That is, it is less than a number's `MinValue` property or greater than its `MaxValue` property. For example, attempting to assign 200 + 200 to a value throws an exception, since 400 greater than 256, the upper bound of the data type. + + Your code should not handle or throw this exception. Instead, you should either handle or throw one of its derived classes, since it more precisely indicates the exact nature of the error. + + For a list of initial property values for an instance of , see the constructors. + + uses the HRESULT COR_E_ARITHMETIC, which has the value 0x80070216. + ]]> @@ -143,18 +143,18 @@ Initializes a new instance of the class. - property of the new instance to a system-supplied message that describes the error, such as "The arithmetic operation is not allowed." This message takes into account the current system culture. - - The following table shows initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||`null`.| -||The localized error message string.| - + property of the new instance to a system-supplied message that describes the error, such as "The arithmetic operation is not allowed." This message takes into account the current system culture. + + The following table shows initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||`null`.| +||The localized error message string.| + ]]> @@ -201,18 +201,18 @@ A that describes the error. Initializes a new instance of the class with a specified error message. - . - -|Property|Value| -|--------------|-----------| -||The null reference (`Nothing` in Visual Basic).| -||The error message string.| - + . + +|Property|Value| +|--------------|-----------| +||The null reference (`Nothing` in Visual Basic).| +||The error message string.| + ]]> @@ -274,11 +274,11 @@ The contextual information about the source or destination. Initializes a new instance of the class with serialized data. - XML and SOAP Serialization @@ -328,18 +328,18 @@ The exception that is the cause of the current exception. If the parameter is not a null reference, the current exception is raised in a block that handles the inner exception. Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception. - property. The property returns the same value that is passed into the constructor, or a null reference (`Nothing` in Visual Basic) if the property does not supply the inner exception value to the constructor. - - The following table shows initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||The inner exception reference.| -||The error message string.| - + property. The property returns the same value that is passed into the constructor, or a null reference (`Nothing` in Visual Basic) if the property does not supply the inner exception value to the constructor. + + The following table shows initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||The inner exception reference.| +||The error message string.| + ]]> diff --git a/xml/System/Array.xml b/xml/System/Array.xml index e45a647cae0..691567b0aeb 100644 --- a/xml/System/Array.xml +++ b/xml/System/Array.xml @@ -143,11 +143,7 @@ ]]> - Public static ( in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe. - - This implementation does not provide a synchronized (thread safe) wrapper for an ; however, .NET classes based on provide their own synchronized version of the collection using the property. - - Enumerating through a collection is intrinsically not a thread-safe procedure. Even when a collection is synchronized, other threads can still modify the collection, which causes the enumerator to throw an exception. To guarantee thread safety during enumeration, you can either lock the collection during the entire enumeration or catch the exceptions resulting from changes made by other threads. + Public static ( in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe. This implementation does not provide a synchronized (thread safe) wrapper for an ; however, .NET classes based on provide their own synchronized version of the collection using the property. Enumerating through a collection is intrinsically not a thread-safe procedure. Even when a collection is synchronized, other threads can still modify the collection, which causes the enumerator to throw an exception. To guarantee thread safety during enumeration, you can either lock the collection during the entire enumeration or catch the exceptions resulting from changes made by other threads. Performing Culture-Insensitive String Operations in Arrays @@ -420,9 +416,9 @@ The object to search for. The implementation to use when comparing elements. - -or- +-or- - to use the implementation of each element. + to use the implementation of each element. Searches an entire one-dimensional sorted array for a value using the specified interface. The index of the specified in the specified , if is found; otherwise, a negative number. If is not found and is less than one or more elements in , the negative number returned is the bitwise complement of the index of the first element that is larger than . If is not found and is greater than all elements in , the negative number returned is the bitwise complement of (the index of the last element plus 1). If this method is called with a non-sorted , the return value can be incorrect and a negative number could be returned, even if is present in . @@ -562,15 +558,15 @@ is less than the lower bound of . - -or- +-or- - is less than zero. + is less than zero.
and do not specify a valid range in . - -or- +-or- - is of a type that is not compatible with the elements of . + is of a type that is not compatible with the elements of .
does not implement the interface, and the search encounters an element that does not implement the interface. @@ -651,9 +647,9 @@ The object to search for. The implementation to use when comparing elements. - -or- +-or- - to use the implementation of each element. + to use the implementation of each element. Searches a range of elements in a one-dimensional sorted array for a value, using the specified interface. The index of the specified in the specified , if is found; otherwise, a negative number. If is not found and is less than one or more elements in , the negative number returned is the bitwise complement of the index of the first element that is larger than . If is not found and is greater than all elements in , the negative number returned is the bitwise complement of (the index of the last element plus 1). If this method is called with a non-sorted , the return value can be incorrect and a negative number could be returned, even if is present in . @@ -691,15 +687,15 @@ is less than the lower bound of . - -or- +-or- - is less than zero. + is less than zero.
and do not specify a valid range in . - -or- +-or- - is , and is of a type that is not compatible with the elements of . + is , and is of a type that is not compatible with the elements of . is , does not implement the interface, and the search encounters an element that does not implement the interface. @@ -888,9 +884,9 @@ The object to search for. The implementation to use when comparing elements. - -or- +-or- - to use the implementation of each element. + to use the implementation of each element. Searches an entire one-dimensional sorted array for a value using the specified generic interface. The index of the specified in the specified , if is found; otherwise, a negative number. If is not found and is less than one or more elements in , the negative number returned is the bitwise complement of the index of the first element that is larger than . If is not found and is greater than all elements in , the negative number returned is the bitwise complement of (the index of the last element plus 1). If this method is called with a non-sorted , the return value can be incorrect and a negative number could be returned, even if is present in . @@ -1044,15 +1040,15 @@ is less than the lower bound of . - -or- +-or- - is less than zero. + is less than zero. and do not specify a valid range in . - -or- +-or- - is of a type that is not compatible with the elements of . + is of a type that is not compatible with the elements of . does not implement the generic interface. @@ -1139,9 +1135,9 @@ The object to search for. The implementation to use when comparing elements. - -or- +-or- - to use the implementation of each element. + to use the implementation of each element. Searches a range of elements in a one-dimensional sorted array for a value, using the specified generic interface. The index of the specified in the specified , if is found; otherwise, a negative number. If is not found and is less than one or more elements in , the negative number returned is the bitwise complement of the index of the first element that is larger than . If is not found and is greater than all elements in , the negative number returned is the bitwise complement of (the index of the last element plus 1). If this method is called with a non-sorted , the return value can be incorrect and a negative number could be returned, even if is present in . @@ -1174,15 +1170,15 @@ is less than the lower bound of . - -or- +-or- - is less than zero. + is less than zero. and do not specify a valid range in . - -or- +-or- - is , and is of a type that is not compatible with the elements of . + is , and is of a type that is not compatible with the elements of . is , and does not implement the generic interface. @@ -1323,13 +1319,13 @@ is less than the lower bound of . - -or- +-or- - is less than zero. + is less than zero. - -or- +-or- - The sum of and is greater than the size of . +The sum of and is greater than the size of . @@ -1474,7 +1470,7 @@ The that receives the data. A 32-bit integer that represents the index in the at which storing begins. A 32-bit integer that represents the number of elements to copy. - Copies a range of elements from an starting at the specified source index and pastes them to another starting at the specified destination index. Guarantees that all changes are undone if the copy does not succeed completely. + Copies a range of elements from an starting at the specified source index and pastes them to another starting at the specified destination index. Guarantees that all changes are undone if the copy does not succeed completely. is . - -or- +-or- - is . + is . and have different ranks. The type is neither the same as nor derived from the type. @@ -1510,19 +1506,19 @@ is less than the lower bound of the first dimension of . - -or- +-or- - is less than the lower bound of the first dimension of . + is less than the lower bound of the first dimension of . - -or- +-or- - is less than zero. + is less than zero. is greater than the number of elements from to the end of . - -or- +-or- - is greater than the number of elements from to the end of . + is greater than the number of elements from to the end of . @@ -1616,9 +1612,9 @@ is . - -or- +-or- - is . + is . @@ -1750,9 +1746,9 @@ is . - -or- +-or- - is . + is . and have different ranks. @@ -1763,9 +1759,9 @@ is greater than the number of elements in . - -or- +-or- - is greater than the number of elements in . + is greater than the number of elements in . @@ -1864,9 +1860,9 @@ is . - -or- +-or- - is . + is . and have different ranks. @@ -1877,9 +1873,9 @@ is greater than the number of elements in . - -or- +-or- - is greater than the number of elements in . + is greater than the number of elements in . @@ -1990,9 +1986,9 @@ is . - -or- +-or- - is . + is . and have different ranks. @@ -2001,19 +1997,19 @@ is less than the lower bound of the first dimension of . - -or- +-or- - is less than the lower bound of the first dimension of . + is less than the lower bound of the first dimension of . - -or- +-or- - is less than zero. + is less than zero. is greater than the number of elements from to the end of . - -or- +-or- - is greater than the number of elements from to the end of . + is greater than the number of elements from to the end of . @@ -2116,9 +2112,9 @@ is . - -or- +-or- - is . + is . and have different ranks. @@ -2127,19 +2123,19 @@ is outside the range of valid indexes for the . - -or- +-or- - is outside the range of valid indexes for the . + is outside the range of valid indexes for the . - -or- +-or- - is less than 0 or greater than Int32.MaxValue. + is less than 0 or greater than Int32.MaxValue. is greater than the number of elements from to the end of . - -or- +-or- - is greater than the number of elements from to the end of . + is greater than the number of elements from to the end of . @@ -2248,9 +2244,9 @@ is multidimensional. - -or- +-or- - The number of elements in the source array is greater than the available number of elements from to the end of the destination . +The number of elements in the source array is greater than the available number of elements from to the end of the destination . The type of the source cannot be cast automatically to the type of the destination . The source array is multidimensional. At least one element in the source cannot be cast to the type of destination . @@ -2331,9 +2327,9 @@ is multidimensional. - -or- +-or- - The number of elements in the source array is greater than the available number of elements from to the end of the destination . +The number of elements in the source array is greater than the available number of elements from to the end of the destination . The type of the source cannot be cast automatically to the type of the destination . The source is multidimensional. At least one element in the source cannot be cast to the type of destination . @@ -2435,9 +2431,9 @@ is not supported. For example, is not supported. - -or- +-or- - is an open generic type. + is an open generic type. is less than zero. @@ -2532,21 +2528,21 @@ is . - -or- +-or- - is . + is . is not a valid . - -or- +-or- - The array contains less than one element. +The array contains less than one element. is not supported. For example, is not supported. - -or- +-or- - is an open generic type. + is an open generic type. Any value in is less than zero. @@ -2632,21 +2628,21 @@ is . - -or- +-or- - is . + is . is not a valid . - -or- +-or- - The array contains less than one element. +The array contains less than one element. is not supported. For example, is not supported. - -or- +-or- - is an open generic type. + is an open generic type. Any value in is less than zero or greater than Int32.MaxValue. @@ -2729,15 +2725,15 @@ is not supported. For example, is not supported. - -or- +-or- - is an open generic type. + is an open generic type. is less than zero. - -or- +-or- - is less than zero. + is less than zero. @@ -2830,34 +2826,34 @@ is . - -or- +-or- - is . + is . - -or- +-or- - is . + is . is not a valid . - -or- +-or- - The array contains less than one element. +The array contains less than one element. - -or- +-or- - The and arrays do not contain the same number of elements. +The and arrays do not contain the same number of elements. is not supported. For example, is not supported. - -or- +-or- - is an open generic type. + is an open generic type. Any value in is less than zero. - -or- +-or- - Any value in is very large, such that the sum of a dimension's lower bound and length is greater than Int32.MaxValue. +Any value in is very large, such that the sum of a dimension's lower bound and length is greater than Int32.MaxValue. @@ -2941,19 +2937,19 @@ is not supported. For example, is not supported. - -or- +-or- - is an open generic type. + is an open generic type. is less than zero. - -or- +-or- - is less than zero. + is less than zero. - -or- +-or- - is less than zero. + is less than zero. @@ -3107,9 +3103,9 @@ is . - -or- +-or- - is . + is . @@ -3222,8 +3218,7 @@ The new value for the elements in the specified range. A 32-bit integer that represents the index in the at which filling begins. The number of elements to copy. - Assigns the given of type to the elements of the specified which are - within the range of (inclusive) and the next number of indices. + Assigns the given of type to the elements of the specified which are within the range of (inclusive) and the next number of indices. To be added. @@ -3315,9 +3310,9 @@ is . - -or- +-or- - is . + is . @@ -3423,9 +3418,9 @@ is . - -or- +-or- - is . + is . @@ -3539,9 +3534,9 @@ is . - -or- +-or- - is . + is . @@ -3625,9 +3620,9 @@ is . - -or- +-or- - is . + is . is outside the range of valid indexes for . @@ -3715,19 +3710,19 @@ is . - -or- +-or- - is . + is . is outside the range of valid indexes for . - -or- +-or- - is less than zero. + is less than zero. - -or- +-or- - and do not specify a valid section in . + and do not specify a valid section in . @@ -3827,9 +3822,9 @@ is . - -or- +-or- - is . + is . @@ -3943,9 +3938,9 @@ is . - -or- +-or- - is . + is . @@ -4029,9 +4024,9 @@ is . - -or- +-or- - is . + is . is outside the range of valid indexes for . @@ -4119,19 +4114,19 @@ is . - -or- +-or- - is . + is . is outside the range of valid indexes for . - -or- +-or- - is less than zero. + is less than zero. - -or- +-or- - and do not specify a valid section in . + and do not specify a valid section in . @@ -4209,16 +4204,16 @@ :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.array.foreach/cpp/source.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Array/ForEachT/source.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.array.foreach/fs/source.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.array.foreach/vb/source.vb" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.array.foreach/vb/source.vb" id="Snippet1"::: ]]> is . - -or- +-or- - is . + is . @@ -4376,9 +4371,9 @@ is less than zero. - -or- +-or- - is equal to or greater than . + is equal to or greater than . @@ -4444,9 +4439,9 @@ is less than zero. - -or- +-or- - is equal to or greater than . + is equal to or greater than . @@ -4532,9 +4527,9 @@ is less than zero. - -or- +-or- - is equal to or greater than . + is equal to or greater than . @@ -4616,9 +4611,9 @@ is less than zero. - -or- +-or- - is equal to or greater than . + is equal to or greater than . @@ -5541,13 +5536,13 @@ is outside the range of valid indexes for . - -or- +-or- - is less than zero. + is less than zero. - -or- +-or- - and do not specify a valid section in . + and do not specify a valid section in . is multidimensional. @@ -5811,13 +5806,13 @@ is outside the range of valid indexes for . - -or- +-or- - is less than zero. + is less than zero. - -or- +-or- - and do not specify a valid section in . + and do not specify a valid section in . Performing Culture-Insensitive String Operations in Arrays @@ -6376,13 +6371,13 @@ is outside the range of valid indexes for . - -or- +-or- - is less than zero. + is less than zero. - -or- +-or- - and do not specify a valid section in . + and do not specify a valid section in . is multidimensional. @@ -6648,13 +6643,13 @@ is outside the range of valid indexes for . - -or- +-or- - is less than zero. + is less than zero. - -or- +-or- - and do not specify a valid section in . + and do not specify a valid section in . Performing Culture-Insensitive String Operations in Arrays @@ -7214,9 +7209,9 @@ int[,,] TDArray = new int[1,1,1]; is less than the lower bound of . - -or- +-or- - is less than zero. + is less than zero. and do not specify a valid range in . @@ -7330,9 +7325,9 @@ int[,,] TDArray = new int[1,1,1]; is less than the lower bound of . - -or- +-or- - is less than zero. + is less than zero. and do not specify a valid range in . @@ -8194,9 +8189,9 @@ int[,,] TDArray = new int[1,1,1]; The one-dimensional that contains the keys to sort. The one-dimensional that contains the items that correspond to each of the keys in the . - -or- +-or- - to sort only the . + to sort only the . Sorts a pair of one-dimensional objects (one contains the keys and the other contains the corresponding items) based on the keys in the first using the implementation of each key. is . The is multidimensional. - -or- +-or- - The is multidimensional. +The is multidimensional. is not , and the length of is greater than the length of . One or more elements in the do not implement the interface. @@ -8309,9 +8304,9 @@ int[,,] TDArray = new int[1,1,1]; The one-dimensional array to sort. The implementation to use when comparing elements. - -or- +-or- - to use the implementation of each element. + to use the implementation of each element. Sorts the elements in a one-dimensional using the specified . The one-dimensional that contains the keys to sort. The one-dimensional that contains the items that correspond to each of the keys in the . - -or- +-or- - to sort only the . + to sort only the . The implementation to use when comparing elements. - -or- +-or- - to use the implementation of each element. + to use the implementation of each element. Sorts a pair of one-dimensional objects (one contains the keys and the other contains the corresponding items) based on the keys in the first using the specified . is . The is multidimensional. - -or- +-or- - The is multidimensional. +The is multidimensional. is not , and the length of is greater than the length of . - -or- +-or- - The implementation of caused an error during the sort. For example, might not return 0 when comparing an item with itself. +The implementation of caused an error during the sort. For example, might not return 0 when comparing an item with itself. is , and one or more elements in the do not implement the interface. @@ -8606,9 +8601,9 @@ This method is an O(`n` log `n`) operation, where `n` is the is less than the lower bound of . - -or- +-or- - is less than zero. + is less than zero. and do not specify a valid range in . One or more elements in do not implement the interface. @@ -8676,9 +8671,9 @@ This method is an O(`n` log `n`) operation, where `n` is the The one-dimensional that contains the keys to sort. The one-dimensional that contains the items that correspond to each of the keys in the . - -or- +-or- - to sort only the . + to sort only the . The starting index of the range to sort. The number of elements in the range to sort. Sorts a range of elements in a pair of one-dimensional objects (one contains the keys and the other contains the corresponding items) based on the keys in the first using the implementation of each key. @@ -8722,25 +8717,25 @@ This method is an O(`n` log `n`) operation, where `n` is the is . The is multidimensional. - -or- +-or- - The is multidimensional. +The is multidimensional. is less than the lower bound of . - -or- +-or- - is less than zero. + is less than zero. is not , and the length of is greater than the length of . - -or- +-or- - and do not specify a valid range in the . + and do not specify a valid range in the . - -or- +-or- - is not , and and do not specify a valid range in the . + is not , and and do not specify a valid range in the . One or more elements in the do not implement the interface. @@ -8810,9 +8805,9 @@ This method is an O(`n` log `n`) operation, where `n` is the The number of elements in the range to sort. The implementation to use when comparing elements. - -or- +-or- - to use the implementation of each element. + to use the implementation of each element. Sorts the elements in a range of elements in a one-dimensional using the specified . is less than the lower bound of . - -or- +-or- - is less than zero. + is less than zero. and do not specify a valid range in . - -or- +-or- - The implementation of caused an error during the sort. For example, might not return 0 when comparing an item with itself. +The implementation of caused an error during the sort. For example, might not return 0 when comparing an item with itself. is , and one or more elements in do not implement the interface. @@ -8952,16 +8947,16 @@ This method is an O(`n` log `n`) operation, where `n` is the The one-dimensional that contains the keys to sort. The one-dimensional that contains the items that correspond to each of the keys in the . - -or- +-or- - to sort only the . + to sort only the . The starting index of the range to sort. The number of elements in the range to sort. The implementation to use when comparing elements. - -or- +-or- - to use the implementation of each element. + to use the implementation of each element. Sorts a range of elements in a pair of one-dimensional objects (one contains the keys and the other contains the corresponding items) based on the keys in the first using the specified . is . The is multidimensional. - -or- +-or- - The is multidimensional. +The is multidimensional. is less than the lower bound of . - -or- +-or- - is less than zero. + is less than zero. is not , and the lower bound of does not match the lower bound of . - -or- +-or- - is not , and the length of is greater than the length of . + is not , and the length of is greater than the length of . - -or- +-or- - and do not specify a valid range in the . + and do not specify a valid range in the . - -or- +-or- - is not , and and do not specify a valid range in the . + is not , and and do not specify a valid range in the . - -or- +-or- - The implementation of caused an error during the sort. For example, might not return 0 when comparing an item with itself. +The implementation of caused an error during the sort. For example, might not return 0 when comparing an item with itself. is , and one or more elements in the do not implement the interface. @@ -9374,9 +9369,9 @@ This method is an O(`n` log `n`) operation, where `n` is the is . - -or- +-or- - is . + is . The implementation of caused an error during the sort. For example, might not return 0 when comparing an item with itself. .NET Framework 4 and earlier versions used only the Quicksort algorithm. Quicksort identifies invalid comparers in some situations in which the sorting operation throws an exception, and throws an exception to the caller. Starting with .NET Framework 4.5, it is possible that sorting operations that previously threw will not throw an exception, because the insertion sort and heapsort algorithms do not detect an invalid comparer. For the most part, this applies to arrays with less than or equal to 6 elements. @@ -9493,9 +9488,9 @@ This method is an O(`n` log `n`) operation, where `n` is the is less than the lower bound of . - -or- +-or- - is less than zero. + is less than zero. and do not specify a valid range in . One or more elements in do not implement the generic interface. @@ -9625,15 +9620,15 @@ This method is an O(`n` log `n`) operation, where `n` is the is less than the lower bound of . - -or- +-or- - is less than zero. + is less than zero. and do not specify a valid range in . - -or- +-or- - The implementation of caused an error during the sort. For example, might not return 0 when comparing an item with itself. +The implementation of caused an error during the sort. For example, might not return 0 when comparing an item with itself. is , and one or more elements in do not implement the generic interface. @@ -9774,9 +9769,9 @@ This method is an O(`n` log `n`) operation, where `n` is the is not , and the lower bound of does not match the lower bound of . - -or- +-or- - is not , and the length of is greater than the length of . + is not , and the length of is greater than the length of . One or more elements in the do not implement the generic interface. @@ -9920,13 +9915,13 @@ This method is an O(`n` log `n`) operation, where `n` is the is not , and the lower bound of does not match the lower bound of . - -or- +-or- - is not , and the length of is greater than the length of . + is not , and the length of is greater than the length of . - -or- +-or- - The implementation of caused an error during the sort. For example, might not return 0 when comparing an item with itself. +The implementation of caused an error during the sort. For example, might not return 0 when comparing an item with itself. is , and one or more elements in the do not implement the generic interface. @@ -10069,23 +10064,23 @@ This method is an O(`n` log `n`) operation, where `n` is the is less than the lower bound of . - -or- +-or- - is less than zero. + is less than zero. is not , and the lower bound of does not match the lower bound of . - -or- +-or- - is not , and the length of is greater than the length of . + is not , and the length of is greater than the length of . - -or- +-or- - and do not specify a valid range in the . + and do not specify a valid range in the . - -or- +-or- - is not , and and do not specify a valid range in the . + is not , and and do not specify a valid range in the . One or more elements in the do not implement the generic interface. @@ -10236,27 +10231,27 @@ This method is an O(`n` log `n`) operation, where `n` is the is less than the lower bound of . - -or- +-or- - is less than zero. + is less than zero. is not , and the lower bound of does not match the lower bound of . - -or- +-or- - is not , and the length of is greater than the length of . + is not , and the length of is greater than the length of . - -or- +-or- - and do not specify a valid range in the . + and do not specify a valid range in the . - -or- +-or- - is not , and and do not specify a valid range in the . + is not , and and do not specify a valid range in the . - -or- +-or- - The implementation of caused an error during the sort. For example, might not return 0 when comparing an item with itself. +The implementation of caused an error during the sort. For example, might not return 0 when comparing an item with itself. is , and one or more elements in the do not implement the generic interface. @@ -10770,9 +10765,9 @@ This member is an explicit interface member implementation. It can be used only is not a valid index in the . The is read-only. - -or- +-or- - The has a fixed size. +The has a fixed size. is null reference in the . @@ -10924,9 +10919,9 @@ This member is an explicit interface member implementation. It can be used only is less than zero. - -or- +-or- - is equal to or greater than . + is equal to or greater than . The current does not have exactly one dimension. @@ -10986,9 +10981,9 @@ This member is an explicit interface member implementation. It can be used only The is read-only. - -or- +-or- - The has a fixed size. +The has a fixed size. @@ -11048,9 +11043,9 @@ This member is an explicit interface member implementation. It can be used only index is not a valid index in the . The is read-only. - -or- +-or- - The has a fixed size. +The has a fixed size. @@ -11099,25 +11094,34 @@ This member is an explicit interface member implementation. It can be used only The object to compare with the current instance. An object that compares the current object and . Determines whether the current collection object precedes, occurs in the same position as, or follows another object in the sort order. - An integer that indicates the relationship of the current collection object to other, as shown in the following table. - - Return value - - Description - - -1 - - The current instance precedes . - - 0 - - The current instance and are equal. - - 1 - - The current instance follows . - - + An integer that indicates the relationship of the current collection object to other, as shown in the following table. + + Return value + + + Description + + + + + -1 + + + The current instance precedes . + + + 0 + + + The current instance and are equal. + + + 1 + + + The current instance follows . + + is . - -or- +-or- - is . + is . diff --git a/xml/System/ArraySegment`1+Enumerator.xml b/xml/System/ArraySegment`1+Enumerator.xml index 4bf07ec0da6..f033baa9b3a 100644 --- a/xml/System/ArraySegment`1+Enumerator.xml +++ b/xml/System/ArraySegment`1+Enumerator.xml @@ -58,18 +58,18 @@ Provides an enumerator for the elements of an . - . At this position, is undefined. You must call to advance the enumerator to the first item in the before reading the value of . returns the same value until is called. sets to the next item in the . -If passes the end of the , returns `false`. When the enumerator is at this state, subsequent calls to also return `false` and is undefined. You cannot set to the first item in the again; you must create a new enumerator instance instead. - +If passes the end of the , returns `false`. When the enumerator is at this state, subsequent calls to also return `false` and is undefined. You cannot set to the first item in the again; you must create a new enumerator instance instead. + ]]> @@ -116,17 +116,17 @@ If passes the end of the < Gets a reference to the item at the current position of the enumerator. The element of the at the current position of the enumerator. - must be called to advance the enumerator to the first element of the array segment before reading the value of `Current`. -- The last call to returned `false`, which indicates the end of the array segment. +- The last call to returned `false`, which indicates the end of the array segment. -`Current` returns the same value until is called. sets `Current` to the next item in the array segment. +`Current` returns the same value until is called. sets `Current` to the next item in the array segment. ]]> @@ -200,11 +200,11 @@ If passes the end of the < if the enumerator was successfully advanced to the next element; if the enumerator has passed the end of the array segment. - The type of the elements in the array segment. Delimits a section of a one-dimensional array. - is a wrapper around an array that delimits a range of elements in that array. Multiple instances can refer to the same original array and can overlap. The original array must be one-dimensional and must have zero-based indexing. - + is a wrapper around an array that delimits a range of elements in that array. Multiple instances can refer to the same original array and can overlap. The original array must be one-dimensional and must have zero-based indexing. + > [!NOTE] -> implements the interface starting with the .NET Framework 4.6; in previous versions of the .NET Framework, the structure did not implement this interface. - - The structure is useful whenever the elements of an array will be manipulated in distinct segments. For example: - -- You can pass an object that represents only a portion of an array as an argument to a method, rather than call a relatively expensive method like to pass a copy of a portion of an array. - -- In a multithreaded app, you can use the structure to have each thread operate on only a portion of the array. - -- For task-based asynchronous operations, you can use an object to ensure that each task operates on a distinct segment of the array. The following example divides an array into individual segments with up to ten elements. Each element in the segment is multiplied by its segment number. The result shows that using the class to manipulate elements in this way changes the values of its underlying array. - +> implements the interface starting with the .NET Framework 4.6; in previous versions of the .NET Framework, the structure did not implement this interface. + + The structure is useful whenever the elements of an array will be manipulated in distinct segments. For example: + +- You can pass an object that represents only a portion of an array as an argument to a method, rather than call a relatively expensive method like to pass a copy of a portion of an array. + +- In a multithreaded app, you can use the structure to have each thread operate on only a portion of the array. + +- For task-based asynchronous operations, you can use an object to ensure that each task operates on a distinct segment of the array. The following example divides an array into individual segments with up to ten elements. Each element in the segment is multiplied by its segment number. The result shows that using the class to manipulate elements in this way changes the values of its underlying array. + :::code language="csharp" source="~/snippets/csharp/System/ArraySegmentT/Overview/segmentexample.cs" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.ArraySegment/FS/segmentexample.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.ArraySegment/VB/segmentexample.vb" id="Snippet2"::: - - Note, however, that although the structure can be used to divide an array into distinct segments, the segments are not completely independent of one another. The property returns the entire original array, not a copy of the array; therefore, changes made to the array returned by the property are made to the original array. If this is undesirable, you should perform operations on a copy of the array, rather than an object that represents a portion of the array. - - The method and the equality and inequality operators test for reference equality when they compare two objects. For two objects to be considered equal, they must meet all of the following conditions: - -- Reference the same array. - -- Begin at the same index in the array. - -- Have the same number of elements. - - If you want to retrieve an element by its index in the object, you must cast it to an object and retrieve it or modify it by using the property. Note that this is not necessary in F#. The following example retrieves the element in an object that delimits a section of a string array. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.ArraySegment/VB/segmentexample.vb" id="Snippet2"::: + + Note, however, that although the structure can be used to divide an array into distinct segments, the segments are not completely independent of one another. The property returns the entire original array, not a copy of the array; therefore, changes made to the array returned by the property are made to the original array. If this is undesirable, you should perform operations on a copy of the array, rather than an object that represents a portion of the array. + + The method and the equality and inequality operators test for reference equality when they compare two objects. For two objects to be considered equal, they must meet all of the following conditions: + +- Reference the same array. + +- Begin at the same index in the array. + +- Have the same number of elements. + + If you want to retrieve an element by its index in the object, you must cast it to an object and retrieve it or modify it by using the property. Note that this is not necessary in F#. The following example retrieves the element in an object that delimits a section of a string array. + :::code language="csharp" source="~/snippets/csharp/System/ArraySegmentT/Overview/example1.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.arraysegment.class/fs/example1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.arraysegment.class/vb/example1.vb" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.arraysegment.class/vb/example1.vb" id="Snippet1"::: + + + +## Examples + The following code example passes an structure to a method. - - -## Examples - The following code example passes an structure to a method. - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.ArraySegment/CPP/arraysegment.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/ArraySegmentT/Overview/arraysegment.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.ArraySegment/FS/arraysegment.fs" id="Snippet1"::: @@ -165,16 +165,16 @@ Initializes a new instance of the structure. - structure to a method. - + structure to a method. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.ArraySegment/CPP/arraysegment.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/ArraySegmentT/Overview/arraysegment.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.ArraySegment/FS/arraysegment.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.ArraySegment/VB/arraysegment.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.ArraySegment/VB/arraysegment.vb" id="Snippet1"::: + ]]> @@ -219,15 +219,15 @@ The array to wrap. Initializes a new instance of the structure that delimits all the elements in the specified array. - that delimits all the elements of `array`. That is, the property of the is 0 and its property is the length of `array`. To create an that delimits only part of an array, use the constructor. - - The original array must be one-dimensional and must have zero-based indexing. - - Multiple instances can refer to the same original array and can overlap. - + that delimits all the elements of `array`. That is, the property of the is 0 and its property is the length of `array`. To create an that delimits only part of an array, use the constructor. + + The original array must be one-dimensional and must have zero-based indexing. + + Multiple instances can refer to the same original array and can overlap. + ]]> @@ -279,12 +279,12 @@ The number of elements in the range. Initializes a new instance of the structure that delimits the specified range of the elements in the specified array. - instances can refer to the same original array and can overlap. + instances can refer to the same original array and can overlap. ]]> @@ -344,21 +344,21 @@ Gets the original array containing the range of elements that the array segment delimits. The original array that was passed to the constructor, and that contains the range delimited by the . - property returns the original array, not a copy of the array; therefore, changes made through the property are made directly to the original array. - - - -## Examples - The following code example passes an to a method. - + property returns the original array, not a copy of the array; therefore, changes made through the property are made directly to the original array. + + + +## Examples + The following code example passes an to a method. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.ArraySegment/CPP/arraysegment.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/ArraySegmentT/Overview/arraysegment.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.ArraySegment/FS/arraysegment.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.ArraySegment/VB/arraysegment.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.ArraySegment/VB/arraysegment.vb" id="Snippet1"::: + ]]> @@ -408,10 +408,9 @@ To be added. The underlying array of this instance is . - -or- +-or- -The underlying array of is . - +The underlying array of is . The length of the underlying array of this instance is larger than the length of the underlying array of . @@ -543,16 +542,16 @@ The underlying array of is Gets the number of elements in the range delimited by the array segment. The number of elements in the range delimited by the . - structure to a method. - + structure to a method. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.ArraySegment/CPP/arraysegment.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/ArraySegmentT/Overview/arraysegment.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.ArraySegment/FS/arraysegment.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.ArraySegment/VB/arraysegment.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.ArraySegment/VB/arraysegment.vb" id="Snippet1"::: + ]]> @@ -664,17 +663,17 @@ The underlying array of is if the specified structure is equal to the current instance; otherwise, . - objects are considered to be equal if all the following conditions are met: - -- They reference the same array. - -- They begin at the same index in the array. - -- They have the same number of elements. - + objects are considered to be equal if all the following conditions are met: + +- They reference the same array. + +- They begin at the same index in the array. + +- They have the same number of elements. + ]]> @@ -738,17 +737,17 @@ The underlying array of is if the specified object is a structure and is equal to the current instance; otherwise, . - objects are considered to be equal if all the following conditions are met: - -- They reference the same array. - -- They begin at the same index in the array. - -- They have the same number of elements. - + objects are considered to be equal if all the following conditions are met: + +- They reference the same array. + +- They begin at the same index in the array. + +- They have the same number of elements. + ]]> @@ -915,16 +914,16 @@ The underlying array of is Gets the position of the first element in the range delimited by the array segment, relative to the start of the original array. The position of the first element in the range delimited by the , relative to the start of the original array. - structure to a method. - + structure to a method. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.ArraySegment/CPP/arraysegment.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/ArraySegmentT/Overview/arraysegment.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.ArraySegment/FS/arraysegment.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.ArraySegment/VB/arraysegment.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.ArraySegment/VB/arraysegment.vb" id="Snippet1"::: + ]]> @@ -992,17 +991,17 @@ The underlying array of is if is equal to ; otherwise, . - objects are considered to be equal if all the following conditions are met: - -- They reference the same array. - -- They begin at the same index. - -- They have the same number of elements. - + objects are considered to be equal if all the following conditions are met: + +- They reference the same array. + +- They begin at the same index. + +- They have the same number of elements. + The equivalent method for this operator is ]]> @@ -1106,17 +1105,17 @@ The underlying array of is if is not equal to ; otherwise, . - objects are considered to be unequal if they are of the same closed generic type but any of the following conditions is true: - -- They do not reference the same array. - -- They have different starting indexes. - -- They have a different number of elements. - + objects are considered to be unequal if they are of the same closed generic type but any of the following conditions is true: + +- They do not reference the same array. + +- They have different starting indexes. + +- They have a different number of elements. + The equivalent method for this operator is ]]> @@ -1204,7 +1203,7 @@ The underlying array of is is greater than the length of the underlying array of this instance. - -or- +-or- is greater than the length of the underlying array of this instance - . @@ -1349,11 +1348,11 @@ The underlying array of is if is found in the array segment; otherwise, . - instance is cast to an interface. - + instance is cast to an interface. + ]]> The underlying array is . @@ -1399,11 +1398,11 @@ The underlying array of is The zero-based index in at which copying begins. Copies the elements of the array segment to an array, starting at the specified array index. - instance is cast to an interface. - + instance is cast to an interface. + ]]> @@ -1411,15 +1410,15 @@ The underlying array of is is less than 0. - is multidimensional. - - -or- - - The number of elements in the source array segment is greater than the available space from to the end of the destination . - - -or- - - Type cannot be cast automatically to the type of the destination . + is multidimensional. + +-or- + +The number of elements in the source array segment is greater than the available space from to the end of the destination . + +-or- + +Type cannot be cast automatically to the type of the destination . The underlying array for this instance is . @@ -1462,15 +1461,15 @@ The underlying array of is System.Boolean - Gets a value that indicates whether the array segment is read-only. + Gets a value that indicates whether the array segment is read-only. if the array segment is read-only; otherwise, . - instance is cast to an interface. - + instance is cast to an interface. + ]]> @@ -1567,11 +1566,11 @@ The underlying array of is Returns an enumerator that iterates through the array segment. An enumerator that can be used to iterate through the array segment. - instance is cast to an interface. - + instance is cast to an interface. + ]]> The underlying array is . @@ -1623,11 +1622,11 @@ The underlying array of is Determines the index of a specific item in the array segment. The index of if found in the list; otherwise, -1. - instance is cast to an interface. - + instance is cast to an interface. + ]]> The underlying array is . @@ -1729,15 +1728,15 @@ The underlying array of is Gets or sets the element at the specified index. The element at the specified index. - instance is cast to an interface, as the following example shows. - + instance is cast to an interface, as the following example shows. + :::code language="csharp" source="~/snippets/csharp/System/ArraySegmentT/Overview/example1.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.arraysegment.class/fs/example1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.arraysegment.class/vb/example1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.arraysegment.class/vb/example1.vb" id="Snippet1"::: + ]]> @@ -1839,11 +1838,11 @@ The underlying array of is Gets the element at the specified index of the array segment. The element at the specified index. - instance is cast to an interface. - + instance is cast to an interface. + ]]> @@ -1895,11 +1894,11 @@ The underlying array of is Returns an enumerator that iterates through an array segment. An enumerator that can be used to iterate through the array segment. - instance is cast to an interface. - + instance is cast to an interface. + ]]> The underlying array is . diff --git a/xml/System/ArrayTypeMismatchException.xml b/xml/System/ArrayTypeMismatchException.xml index f7f7fd44124..322b4dc295c 100644 --- a/xml/System/ArrayTypeMismatchException.xml +++ b/xml/System/ArrayTypeMismatchException.xml @@ -70,33 +70,33 @@ The exception that is thrown when an attempt is made to store an element of the wrong type within an array. - is thrown when the system cannot convert the element to the type declared for the array. For example, an element of type cannot be stored in an array because conversion between these types is not supported. It is generally unnecessary for applications to throw this exception. - - The following Microsoft intermediate language (MSIL) instructions throw : - -- `ldelem.` - -- `ldelema` - -- `stelem.` - - uses the HRESULT COR_E_ARRAYTYPEMISMATCH, which has the value 0x80131503. - - For a list of initial property values for an instance of , see the constructors. - - - -## Examples - The following code example demonstrates scenarios where is thrown. - + is thrown when the system cannot convert the element to the type declared for the array. For example, an element of type cannot be stored in an array because conversion between these types is not supported. It is generally unnecessary for applications to throw this exception. + + The following Microsoft intermediate language (MSIL) instructions throw : + +- `ldelem.` + +- `ldelema` + +- `stelem.` + + uses the HRESULT COR_E_ARRAYTYPEMISMATCH, which has the value 0x80131503. + + For a list of initial property values for an instance of , see the constructors. + + + +## Examples + The following code example demonstrates scenarios where is thrown. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.ArrayTypeMismatch/CPP/class1.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/ArrayTypeMismatchException/Overview/class1.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.ArrayTypeMismatch/FS/class1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.ArrayTypeMismatch/VB/class1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.ArrayTypeMismatch/VB/class1.vb" id="Snippet1"::: + ]]> @@ -153,28 +153,28 @@ Initializes a new instance of the class. - property of the new instance to a system-supplied message that describes the error, such as "Source array type cannot be assigned to destination array type." This message takes into account the current system culture. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The localized error message string.| - - - -## Examples - The following example demonstrates the ArrayTypeMismatchException() constructor of the class. It contains a function which takes two arrays as arguments and checks whether the two arrays are of the same type. If the arrays are of different types, a new is thrown and then caught in the calling method. - + property of the new instance to a system-supplied message that describes the error, such as "Source array type cannot be assigned to destination array type." This message takes into account the current system culture. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The localized error message string.| + + + +## Examples + The following example demonstrates the ArrayTypeMismatchException() constructor of the class. It contains a function which takes two arrays as arguments and checks whether the two arrays are of the same type. If the arrays are of different types, a new is thrown and then caught in the calling method. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/ArrayTypeMisMatch_Constructor1/CPP/arraytypemismatch_constructor1.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/ArrayTypeMismatchException/.ctor/arraytypemismatch_constructor1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR/ArrayTypeMisMatch_Constructor1/FS/arraytypemismatch_constructor1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ArrayTypeMisMatch_Constructor1/VB/arraytypemismatch_constructor1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ArrayTypeMisMatch_Constructor1/VB/arraytypemismatch_constructor1.vb" id="Snippet1"::: + ]]> @@ -221,28 +221,28 @@ A that describes the error. Initializes a new instance of the class with a specified error message. - . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The error message string.| - - - -## Examples - The following example demonstrates the ArrayTypeMismatchException(String) constructor of the class. It contains a function which takes two arrays as arguments and checks whether the two arrays are of the same type. If the arrays are of different types, a new is thrown and then caught in the calling method. - + . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The error message string.| + + + +## Examples + The following example demonstrates the ArrayTypeMismatchException(String) constructor of the class. It contains a function which takes two arrays as arguments and checks whether the two arrays are of the same type. If the arrays are of different types, a new is thrown and then caught in the calling method. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/ArrayTypeMisMatch_Constructor2/CPP/arraytypemismatch_constructor2.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/ArrayTypeMismatchException/.ctor/arraytypemismatch_constructor2.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR/ArrayTypeMisMatch_Constructor2/FS/arraytypemismatch_constructor2.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ArrayTypeMisMatch_Constructor2/VB/arraytypemismatch_constructor2.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ArrayTypeMisMatch_Constructor2/VB/arraytypemismatch_constructor2.vb" id="Snippet1"::: + ]]> @@ -304,11 +304,11 @@ The contextual information about the source or destination. Initializes a new instance of the class with serialized data. - XML and SOAP Serialization @@ -358,28 +358,28 @@ The exception that is the cause of the current exception. If the parameter is not a null reference, the current exception is raised in a block that handles the inner exception. Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception. - property. The property returns the same value that is passed into the constructor, or a null reference (`Nothing` in Visual Basic) if the property does not supply the inner exception value to the constructor. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||The inner exception reference.| -||The error message string.| - - - -## Examples - The following code example demonstrates the constructor of the class. It contains a function that takes two arrays as arguments and checks whether the two arrays are of the same type. If the arrays are of different types, a new is thrown and then caught in the calling method. - + property. The property returns the same value that is passed into the constructor, or a null reference (`Nothing` in Visual Basic) if the property does not supply the inner exception value to the constructor. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||The inner exception reference.| +||The error message string.| + + + +## Examples + The following code example demonstrates the constructor of the class. It contains a function that takes two arrays as arguments and checks whether the two arrays are of the same type. If the arrays are of different types, a new is thrown and then caught in the calling method. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/ArrayTypeMisMatch_Constructor3/CPP/arraytypemismatch_constructor3.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/ArrayTypeMismatchException/.ctor/arraytypemismatch_constructor3.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR/ArrayTypeMisMatch_Constructor3/FS/arraytypemismatch_constructor3.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ArrayTypeMisMatch_Constructor3/VB/arraytypemismatch_constructor3.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ArrayTypeMisMatch_Constructor3/VB/arraytypemismatch_constructor3.vb" id="Snippet1"::: + ]]> diff --git a/xml/System/AssemblyLoadEventArgs.xml b/xml/System/AssemblyLoadEventArgs.xml index d74d08c5d07..bfecabd1bf8 100644 --- a/xml/System/AssemblyLoadEventArgs.xml +++ b/xml/System/AssemblyLoadEventArgs.xml @@ -145,11 +145,11 @@ Gets an that represents the currently loaded assembly. An instance of that represents the currently loaded assembly. - event occurs. - + event occurs. + ]]> diff --git a/xml/System/AssemblyLoadEventHandler.xml b/xml/System/AssemblyLoadEventHandler.xml index 1b6ec0d6f64..f13f5e53d0e 100644 --- a/xml/System/AssemblyLoadEventHandler.xml +++ b/xml/System/AssemblyLoadEventHandler.xml @@ -74,11 +74,11 @@ An that contains the event data. Represents the method that handles the event of an . - is used to specify the methods that are invoked in response to an event. To associate an instance of with an event, add the instance to the event. The methods referenced by the are invoked whenever an assembly is loaded, until the is removed from the event. - + is used to specify the methods that are invoked in response to an event. To associate an instance of with an event, add the instance to the event. The methods referenced by the are invoked whenever an assembly is loaded, until the is removed from the event. + ]]> diff --git a/xml/System/AsyncCallback.xml b/xml/System/AsyncCallback.xml index 585bebba634..f278c9787a5 100644 --- a/xml/System/AsyncCallback.xml +++ b/xml/System/AsyncCallback.xml @@ -62,22 +62,22 @@ The result of the asynchronous operation. References a method to be called when a corresponding asynchronous operation completes. - delegate to process the results of an asynchronous operation in a separate thread. The delegate represents a callback method that is called when the asynchronous operation completes. The callback method takes an parameter, which is subsequently used to obtain the results of the asynchronous operation. - - For more information about asynchronous programming, see [Using an AsyncCallback Delegate to End an Asynchronous Operation](/dotnet/standard/asynchronous-programming-patterns/using-an-asynccallback-delegate-to-end-an-asynchronous-operation) and [Using an AsyncCallback Delegate and State Object](/dotnet/standard/asynchronous-programming-patterns/using-an-asynccallback-delegate-and-state-object) in [Event-based Asynchronous Pattern (EAP)](/dotnet/standard/asynchronous-programming-patterns/event-based-asynchronous-pattern-eap). - - - -## Examples - The following code example demonstrates using asynchronous methods in the class to retrieve Domain Name System (DNS) information for user-specified computers. This example creates an delegate that references the `ProcessDnsInformation` method. This method is called once for each asynchronous request for DNS information. - + delegate to process the results of an asynchronous operation in a separate thread. The delegate represents a callback method that is called when the asynchronous operation completes. The callback method takes an parameter, which is subsequently used to obtain the results of the asynchronous operation. + + For more information about asynchronous programming, see [Using an AsyncCallback Delegate to End an Asynchronous Operation](/dotnet/standard/asynchronous-programming-patterns/using-an-asynccallback-delegate-to-end-an-asynchronous-operation) and [Using an AsyncCallback Delegate and State Object](/dotnet/standard/asynchronous-programming-patterns/using-an-asynccallback-delegate-and-state-object) in [Event-based Asynchronous Pattern (EAP)](/dotnet/standard/asynchronous-programming-patterns/event-based-asynchronous-pattern-eap). + + + +## Examples + The following code example demonstrates using asynchronous methods in the class to retrieve Domain Name System (DNS) information for user-specified computers. This example creates an delegate that references the `ProcessDnsInformation` method. This method is called once for each asynchronous request for DNS information. + :::code language="csharp" source="~/snippets/csharp/System/AsyncCallback/Overview/AsyncDelegateNoStateObject.cs" id="Snippet4"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR/AsyncDesignPattern/FS/AsyncDelegateNoStateObject.fs" id="Snippet4"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AsyncDesignPattern/VB/AsyncDelegateNoState.vb" id="Snippet4"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AsyncDesignPattern/VB/AsyncDelegateNoState.vb" id="Snippet4"::: + ]]> diff --git a/xml/System/AttributeTargets.xml b/xml/System/AttributeTargets.xml index 7ff96078791..e19c9cf21b7 100644 --- a/xml/System/AttributeTargets.xml +++ b/xml/System/AttributeTargets.xml @@ -59,26 +59,26 @@ Specifies the application elements on which it is valid to apply an attribute. - class uses this enumeration to specify the kind of element on which it is valid to apply an attribute. - - enumeration values can be combined with a bitwise OR operation to get the preferred combination. - - - -## Examples - The following example illustrates the application of attributes to various targets. - + class uses this enumeration to specify the kind of element on which it is valid to apply an attribute. + + enumeration values can be combined with a bitwise OR operation to get the preferred combination. + + + +## Examples + The following example illustrates the application of attributes to various targets. + > [!NOTE] -> Visual Basic and Visual C++ syntax currently do not support the application of attributes to type parameters. - +> Visual Basic and Visual C++ syntax currently do not support the application of attributes to type parameters. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/AttrTargs/CPP/attrtargs.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/AttributeTargets/Overview/attrtargs.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR/AttrTargs/FS/attrtargs.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AttrTargs/VB/AttrTargs.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AttrTargs/VB/AttrTargs.vb" id="Snippet1"::: + ]]> diff --git a/xml/System/AttributeUsageAttribute.xml b/xml/System/AttributeUsageAttribute.xml index be5e32457d9..d46f4524cba 100644 --- a/xml/System/AttributeUsageAttribute.xml +++ b/xml/System/AttributeUsageAttribute.xml @@ -60,29 +60,29 @@ Specifies the usage of another attribute class. This class cannot be inherited. - on your attribute class. The indicated attribute class must derive from , either directly or indirectly. - - Attribute classes have positional and named parameters. Each public constructor for an attribute class defines a valid sequence of positional parameters for that class. Named parameters are defined by the non-static, public, and read-write fields or properties of the attribute class. - - The three properties of are set by defining the following parameters: - -- - - This positional parameter specifies the program elements that the indicated attribute can be placed on. The set of all possible elements that you can place an attribute on is listed in the enumeration. You can combine several values using a bitwise OR operation to get the desired combination of valid program elements. - -- - - This named parameter specifies whether the indicated attribute can be specified more than once for a given program element. - -- - - This named parameter specifies whether the indicated attribute can be inherited by derived classes and overriding members. - - For more information about using attributes, see and [Attributes](/dotnet/standard/attributes/). - + on your attribute class. The indicated attribute class must derive from , either directly or indirectly. + + Attribute classes have positional and named parameters. Each public constructor for an attribute class defines a valid sequence of positional parameters for that class. Named parameters are defined by the non-static, public, and read-write fields or properties of the attribute class. + + The three properties of are set by defining the following parameters: + +- + + This positional parameter specifies the program elements that the indicated attribute can be placed on. The set of all possible elements that you can place an attribute on is listed in the enumeration. You can combine several values using a bitwise OR operation to get the desired combination of valid program elements. + +- + + This named parameter specifies whether the indicated attribute can be specified more than once for a given program element. + +- + + This named parameter specifies whether the indicated attribute can be inherited by derived classes and overriding members. + + For more information about using attributes, see and [Attributes](/dotnet/standard/attributes/). + ]]> @@ -131,23 +131,23 @@ The set of values combined using a bitwise OR operation to indicate which program elements are valid. Initializes a new instance of the class with the specified list of , the value, and the value. - values using a bitwise OR operation to get the desired combination of valid program elements. - - For default property values, see the , , and properties. - - - -## Examples - The definition of the DispId attribute illustrates the use of a bitwise OR operation to combine several values. - + values using a bitwise OR operation to get the desired combination of valid program elements. + + For default property values, see the , , and properties. + + + +## Examples + The definition of the DispId attribute illustrates the use of a bitwise OR operation to combine several values. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_Classic/classic AttributeUsageAttribute.AttributeUsageAttribute Example/CPP/source.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/AttributeUsageAttribute/.ctor/source.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_Classic/classic AttributeUsageAttribute.AttributeUsageAttribute Example/FS/source.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_Classic/classic AttributeUsageAttribute.AttributeUsageAttribute Example/VB/source.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_Classic/classic AttributeUsageAttribute.AttributeUsageAttribute Example/VB/source.vb" id="Snippet1"::: + ]]> @@ -195,11 +195,11 @@ if more than one instance is allowed to be specified; otherwise, . The default is . - @@ -247,32 +247,32 @@ if the attribute can be inherited by derived classes and overriding members; otherwise, . The default is . - property determines: - -- Whether classes derived from a base class tagged with the attribute to which the attribute is applied inherit that attribute. - -- Whether methods of derived classes that override a base class method tagged with the attribute to which the attribute is applied inherit that attribute. (If a class inherits a base class member, it also inherits any attributes applied to that member.) - - - -## Examples - The following example illustrates the difference between an attribute to which an attribute with an property value of `true` is applied and one to which attribute with an property value of `false` is applied. The example defines two attributes, `InheritedAttribute` and `NotInheritedAttribute`. Both attributes can apply to classes and methods. Because the property of the attribute applied to `InheritedAttribute` is `true`, it is inherited by derived classes and the members of derived classes that override the base class method. On the other hand, because the property of the attribute applied to `NotInheritedAttribute` is `false`, it is not inherited by derived classes and the members of derived classes that override the base class method. - + property determines: + +- Whether classes derived from a base class tagged with the attribute to which the attribute is applied inherit that attribute. + +- Whether methods of derived classes that override a base class method tagged with the attribute to which the attribute is applied inherit that attribute. (If a class inherits a base class member, it also inherits any attributes applied to that member.) + + + +## Examples + The following example illustrates the difference between an attribute to which an attribute with an property value of `true` is applied and one to which attribute with an property value of `false` is applied. The example defines two attributes, `InheritedAttribute` and `NotInheritedAttribute`. Both attributes can apply to classes and methods. Because the property of the attribute applied to `InheritedAttribute` is `true`, it is inherited by derived classes and the members of derived classes that override the base class method. On the other hand, because the property of the attribute applied to `NotInheritedAttribute` is `false`, it is not inherited by derived classes and the members of derived classes that override the base class method. + :::code language="csharp" source="~/snippets/csharp/System/AttributeUsageAttribute/Inherited/Inherited1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/System.AttributeUsageAttribute.Inherited/fs/Inherited1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.AttributeUsageAttribute.Inherited/vb/Inherited1.vb" id="Snippet1"::: - - The example then defines two base classes. The first, `BaseA`, has a single method, `MethodA`. The second, `BaseB`, has a single method, `MethodB`. `BaseA` and `MethodA` are tagged with the `InheritedAttribute` attribute, and `BaseB` and `MethodB` are tagged with the `NotInheritedAttribute` attribute. `DerivedA` inherits from `BaseA` and overrides its `MethodA` method. `DerivedB` inherits from `BaseB` and overrides its `MethodB` method. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.AttributeUsageAttribute.Inherited/vb/Inherited1.vb" id="Snippet1"::: + + The example then defines two base classes. The first, `BaseA`, has a single method, `MethodA`. The second, `BaseB`, has a single method, `MethodB`. `BaseA` and `MethodA` are tagged with the `InheritedAttribute` attribute, and `BaseB` and `MethodB` are tagged with the `NotInheritedAttribute` attribute. `DerivedA` inherits from `BaseA` and overrides its `MethodA` method. `DerivedB` inherits from `BaseB` and overrides its `MethodB` method. + :::code language="csharp" source="~/snippets/csharp/System/AttributeUsageAttribute/Inherited/Inherited1.cs" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/System.AttributeUsageAttribute.Inherited/fs/Inherited1.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.AttributeUsageAttribute.Inherited/vb/Inherited1.vb" id="Snippet2"::: - - As the output from the example shows, `DerivedA` and `DerivedA.MethodA` inherit the `InheritedAttribute` attribute, but `DerivedB` and `DerivedB.MethodB` do not inherit the `NotInheritedAttribute` attribute. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.AttributeUsageAttribute.Inherited/vb/Inherited1.vb" id="Snippet2"::: + + As the output from the example shows, `DerivedA` and `DerivedA.MethodA` inherit the `InheritedAttribute` attribute, but `DerivedB` and `DerivedB.MethodB` do not inherit the `NotInheritedAttribute` attribute. + ]]> diff --git a/xml/System/Base64FormattingOptions.xml b/xml/System/Base64FormattingOptions.xml index 8ded655fe6f..119410866b4 100644 --- a/xml/System/Base64FormattingOptions.xml +++ b/xml/System/Base64FormattingOptions.xml @@ -51,24 +51,24 @@ Specifies whether relevant and methods insert line breaks in their output. - and methods convert the value of an array of 8-bit unsigned integers to an equivalent string representation that consists of base 64 digits. The string representation can contain one or more line breaks, where a line break is defined as a carriage return character (U+000D) followed by a line feed character (U+000A). Because line breaks are considered white-space characters in a base-64 encoding, they are ignored when converting a base-64 encoded string back to a byte array. The line breaks are simply convenient when displaying the encoded string to a control or a device such as a console window. - - The `None` and `InsertLineBreaks` values are mutually exclusive. Therefore, although the `Base64FormattingOptions` enumeration is marked with the attribute, it makes no sense to perform a bitwise combination of these two values. - - - -## Examples - The following example calls the method with a `InsertLineBreaks` argument to insert line breaks in the string that is produced by encoding a 100-element byte array: - + and methods convert the value of an array of 8-bit unsigned integers to an equivalent string representation that consists of base 64 digits. The string representation can contain one or more line breaks, where a line break is defined as a carriage return character (U+000D) followed by a line feed character (U+000A). Because line breaks are considered white-space characters in a base-64 encoding, they are ignored when converting a base-64 encoded string back to a byte array. The line breaks are simply convenient when displaying the encoded string to a control or a device such as a console window. + + The `None` and `InsertLineBreaks` values are mutually exclusive. Therefore, although the `Base64FormattingOptions` enumeration is marked with the attribute, it makes no sense to perform a bitwise combination of these two values. + + + +## Examples + The following example calls the method with a `InsertLineBreaks` argument to insert line breaks in the string that is produced by encoding a 100-element byte array: + :::code language="csharp" source="~/snippets/csharp/System/Base64FormattingOptions/Overview/ToBase64String3.cs" interactive="try-dotnet" id="Snippet3"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/System.Convert.ToBase64String/fs/ToBase64String3.fs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.Convert.ToBase64String/vb/ToBase64String3.vb" id="Snippet3"::: - - As the output from the example shows, the succeeds in restoring the original byte array; the line break characters are ignored during the conversion. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.Convert.ToBase64String/vb/ToBase64String3.vb" id="Snippet3"::: + + As the output from the example shows, the succeeds in restoring the original byte array; the line break characters are ignored during the conversion. + ]]> diff --git a/xml/System/BinaryData.xml b/xml/System/BinaryData.xml index 53240f33dd0..0ff9fb24c64 100644 --- a/xml/System/BinaryData.xml +++ b/xml/System/BinaryData.xml @@ -1170,15 +1170,15 @@ Converts the value of this instance to a string using UTF-8. A string representation of the value of this instance. - diff --git a/xml/System/BitConverter.xml b/xml/System/BitConverter.xml index 39b77afb496..c7e01314def 100644 --- a/xml/System/BitConverter.xml +++ b/xml/System/BitConverter.xml @@ -65,57 +65,57 @@ Converts base data types to an array of bytes, and an array of bytes to base data types. - class helps manipulate value types in their fundamental form, as a series of bytes. A byte is defined as an 8-bit unsigned integer. The class includes static methods to convert each of the primitive types to and from an array of bytes, as the following table illustrates. - -|Type|To byte conversion|From byte conversion| -|----------|------------------------|--------------------------| -|||| -|||| -||

-or-

|

-or-

| -|||| -|||| -|||| -|||| -|||| -|||| -|||| - + class helps manipulate value types in their fundamental form, as a series of bytes. A byte is defined as an 8-bit unsigned integer. The class includes static methods to convert each of the primitive types to and from an array of bytes, as the following table illustrates. + +|Type|To byte conversion|From byte conversion| +|----------|------------------------|--------------------------| +|||| +|||| +||

-or-

|

-or-

| +|||| +|||| +|||| +|||| +|||| +|||| +|||| + If you use methods to round-trip data, make sure that the overload and the `To`*Type* method specify the same type. As the following example illustrates, restoring an array that represents a signed integer by calling the method can result in a value that is different from the original. For more information, see [Working with Signed Non-Decimal and Bitwise Values](/archive/blogs/bclteam/working-with-signed-non-decimal-and-bitwise-values-ron-petrusha). - + :::code language="csharp" source="~/snippets/csharp/System/BitConverter/Overview/example1.cs" interactive="try-dotnet" id="Snippet3"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.BitConverter.Class/FS/example1.fs" id="Snippet3"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.BitConverter.Class/VB/example1.vb" id="Snippet3"::: - - The order of bytes in the array returned by the method overloads (as well as the order of bits in the integer returned by the method) depends on whether the computer architecture is little-endian or big-endian. Similarly, the order of bytes in the array and returned by the `To`*IntegerValue* methods and the method depends on whether the computer architecture is little-endian or big-endian. The endianness of an architecture is indicated by the property, which returns `true` on little-endian systems and `false` on big-endian systems. On little-endian systems, lower-order bytes precede higher-order bytes. On big-endian system, higher-order bytes precede lower-order bytes. The following table illustrates the difference in the byte arrays that result from passing the integer 1,234,567,890 (0x499602D2) to the method. The bytes are listed in order from the byte at index 0 to the byte at index 3. - -||| -|-|-| -|Little-endian|D2-02-96-49| -|Big-endian|49-96-02-D2| - - Because the return value of some methods depends on system architecture, be careful when transmitting byte data beyond machine boundaries: - -- If all systems sending and receiving data are guaranteed to have the same endianness, nothing has be done to the data. - -- If systems sending and receiving data can have different endianness, always transmit data in a particular order. This means that the order of bytes in the array may have to be reversed either before sending them or after receiving them. A common convention is to transmit data in network byte order (big-endian order). The following example provides an implementation for sending an integer value in network byte order. - + + The order of bytes in the array returned by the method overloads (as well as the order of bits in the integer returned by the method) depends on whether the computer architecture is little-endian or big-endian. Similarly, the order of bytes in the array and returned by the `To`*IntegerValue* methods and the method depends on whether the computer architecture is little-endian or big-endian. The endianness of an architecture is indicated by the property, which returns `true` on little-endian systems and `false` on big-endian systems. On little-endian systems, lower-order bytes precede higher-order bytes. On big-endian system, higher-order bytes precede lower-order bytes. The following table illustrates the difference in the byte arrays that result from passing the integer 1,234,567,890 (0x499602D2) to the method. The bytes are listed in order from the byte at index 0 to the byte at index 3. + +||| +|-|-| +|Little-endian|D2-02-96-49| +|Big-endian|49-96-02-D2| + + Because the return value of some methods depends on system architecture, be careful when transmitting byte data beyond machine boundaries: + +- If all systems sending and receiving data are guaranteed to have the same endianness, nothing has be done to the data. + +- If systems sending and receiving data can have different endianness, always transmit data in a particular order. This means that the order of bytes in the array may have to be reversed either before sending them or after receiving them. A common convention is to transmit data in network byte order (big-endian order). The following example provides an implementation for sending an integer value in network byte order. + :::code language="csharp" source="~/snippets/csharp/System/BitConverter/Overview/networkorder1.cs" interactive="try-dotnet" id="Snippet4"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.BitConverter.Class/FS/networkorder1.fs" id="Snippet4"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.BitConverter.Class/VB/networkorder1.vb" id="Snippet4"::: - + - If systems sending and receiving data can have different endianness and the data to be transmitted consists of signed integers, call the method to convert the data to network byte order and the method to convert it to the order required by the recipient. - -## Examples - The following code example illustrates the use of several class methods. - + +## Examples + The following code example illustrates the use of several class methods. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.BitConverter.Class/CPP/bitconv.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/BitConverter/Overview/bitconv.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.BitConverter.Class/FS/bitconv.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.BitConverter.Class/VB/bitconv.vb" id="Snippet1"::: - + ]]>
@@ -174,14 +174,14 @@ Converts the specified double-precision floating point number to a 64-bit signed integer. A 64-bit signed integer whose value is equivalent to . - method depends on whether the computer architecture is little-endian or big-endian. - -## Examples - The following code example converts the bit patterns of several values to values with the `DoubleToInt64Bits` method. - + +## Examples + The following code example converts the bit patterns of several values to values with the `DoubleToInt64Bits` method. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.BitConverter.DoubleInt64/CPP/dbltobits.cpp" id="Snippet2"::: :::code language="csharp" source="~/snippets/csharp/System/BitConverter/DoubleToInt64Bits/dbltobits.cs" interactive="try-dotnet" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.BitConverter.DoubleInt64/FS/dbltobits.fs" id="Snippet2"::: @@ -293,18 +293,18 @@ Returns the specified Boolean value as a byte array. A byte array with length 1. - value by calling the method. - -## Examples - The following example converts the bit patterns of values to arrays with the `GetBytes` method. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.BitConverter.GetBytes.Others/CPP/bytesbool.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/BitConverter/GetBytes/bytesbool.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.BitConverter.GetBytes.Others/FS/bytesbool.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.BitConverter.GetBytes.Others/VB/bytesbool.vb" id="Snippet1"::: + +## Examples + The following example converts the bit patterns of values to arrays with the `GetBytes` method. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.BitConverter.GetBytes.Others/CPP/bytesbool.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/BitConverter/GetBytes/bytesbool.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.BitConverter.GetBytes.Others/FS/bytesbool.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.BitConverter.GetBytes.Others/VB/bytesbool.vb" id="Snippet1"::: ]]> @@ -358,14 +358,14 @@ Returns the specified Unicode character value as an array of bytes. An array of bytes with length 2. - method depends on whether the computer architecture is little-endian or big-endian. -## Examples - The following code example converts the bit patterns of values (Unicode characters) to arrays with the `GetBytes` method. - +## Examples + The following code example converts the bit patterns of values (Unicode characters) to arrays with the `GetBytes` method. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.BitConverter.GetBytes.Others/CPP/byteschar.cpp" id="Snippet2"::: :::code language="csharp" source="~/snippets/csharp/System/BitConverter/GetBytes/byteschar.cs" interactive="try-dotnet" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.BitConverter.GetBytes.Others/FS/byteschar.fs" id="Snippet2"::: @@ -429,14 +429,14 @@ Returns the specified double-precision floating-point value as an array of bytes. An array of bytes with length 8. - method depends on whether the computer architecture is little-endian or big-endian. - -## Examples - The following code example converts the bit patterns of values to arrays with the `GetBytes` method. - + +## Examples + The following code example converts the bit patterns of values to arrays with the `GetBytes` method. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.BitConverter.GetBytes.Others/CPP/bytesdouble.cpp" id="Snippet4"::: :::code language="csharp" source="~/snippets/csharp/System/BitConverter/GetBytes/bytesdouble.cs" interactive="try-dotnet" id="Snippet4"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.BitConverter.GetBytes.Others/FS/bytesdouble.fs" id="Snippet4"::: @@ -536,14 +536,14 @@ Returns the specified 16-bit signed integer value as an array of bytes. An array of bytes with length 2. - method depends on whether the computer architecture is little-endian or big-endian. - -## Examples - The following code example converts the bit patterns of values to arrays with the `GetBytes` method. - + +## Examples + The following code example converts the bit patterns of values to arrays with the `GetBytes` method. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.BitConverter.GetBytes.SInts/CPP/bytesint16.cpp" id="Snippet3"::: :::code language="csharp" source="~/snippets/csharp/System/BitConverter/GetBytes/bytesint16.cs" interactive="try-dotnet" id="Snippet3"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.BitConverter.GetBytes.SInts/FS/bytesint16.fs" id="Snippet3"::: @@ -607,14 +607,14 @@ Returns the specified 32-bit signed integer value as an array of bytes. An array of bytes with length 4. - method depends on whether the computer architecture is little-endian or big-endian. - -## Examples - The following code example converts the bit patterns of values to arrays with the `GetBytes` method. - + +## Examples + The following code example converts the bit patterns of values to arrays with the `GetBytes` method. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.BitConverter.GetBytes.SInts/CPP/bytesint32.cpp" id="Snippet2"::: :::code language="csharp" source="~/snippets/csharp/System/BitConverter/GetBytes/bytesint32.cs" interactive="try-dotnet" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.BitConverter.GetBytes.SInts/FS/bytesint32.fs" id="Snippet2"::: @@ -678,14 +678,14 @@ Returns the specified 64-bit signed integer value as an array of bytes. An array of bytes with length 8. - method depends on whether the computer architecture is little-endian or big-endian. - -## Examples - The following example calls the method to convert each element in an array to a arrays. - + +## Examples + The following example calls the method to convert each element in an array to a arrays. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.BitConverter.GetBytes.SInts/CPP/bytesint64.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/BitConverter/GetBytes/bytesint64.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.BitConverter.GetBytes.SInts/FS/bytesint64.fs" id="Snippet1"::: @@ -749,14 +749,14 @@ Returns the specified single-precision floating point value as an array of bytes. An array of bytes with length 4. - method depends on whether the computer architecture is little-endian or big-endian. - -## Examples - The following code example converts the bit patterns of values to arrays with the `GetBytes` method. - + +## Examples + The following code example converts the bit patterns of values to arrays with the `GetBytes` method. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.BitConverter.GetBytes.Others/CPP/bytessingle.cpp" id="Snippet3"::: :::code language="csharp" source="~/snippets/csharp/System/BitConverter/GetBytes/bytessingle.cs" interactive="try-dotnet" id="Snippet3"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.BitConverter.GetBytes.Others/FS/bytessingle.fs" id="Snippet3"::: @@ -820,14 +820,14 @@ Returns the specified 16-bit unsigned integer value as an array of bytes. An array of bytes with length 2. - method depends on whether the computer architecture is little-endian or big-endian. - -## Examples - The following code example converts the bit patterns of values to arrays with the `GetBytes` method. - + +## Examples + The following code example converts the bit patterns of values to arrays with the `GetBytes` method. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.BitConverter.GetBytes.UInts/CPP/bytesuint16.cpp" id="Snippet3"::: :::code language="csharp" source="~/snippets/csharp/System/BitConverter/GetBytes/bytesuint16.cs" interactive="try-dotnet" id="Snippet3"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.BitConverter.GetBytes.UInts/FS/bytesuint16.fs" id="Snippet3"::: @@ -891,14 +891,14 @@ Returns the specified 32-bit unsigned integer value as an array of bytes. An array of bytes with length 4. - method depends on whether the computer architecture is little-endian or big-endian. - -## Examples - The following code example converts the bit patterns of values to arrays with the `GetBytes` method. - + +## Examples + The following code example converts the bit patterns of values to arrays with the `GetBytes` method. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.BitConverter.GetBytes.UInts/CPP/bytesuint32.cpp" id="Snippet2"::: :::code language="csharp" source="~/snippets/csharp/System/BitConverter/GetBytes/bytesuint32.cs" interactive="try-dotnet" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.BitConverter.GetBytes.UInts/FS/bytesuint32.fs" id="Snippet2"::: @@ -962,14 +962,14 @@ Returns the specified 64-bit unsigned integer value as an array of bytes. An array of bytes with length 8. - method depends on whether the computer architecture is little-endian or big-endian. - -## Examples - The following code example converts the bit patterns of values to arrays with the `GetBytes` method. - + +## Examples + The following code example converts the bit patterns of values to arrays with the `GetBytes` method. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.BitConverter.GetBytes.UInts/CPP/bytesuint64.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/BitConverter/GetBytes/bytesuint64.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.BitConverter.GetBytes.UInts/FS/bytesuint64.fs" id="Snippet1"::: @@ -1188,19 +1188,19 @@ Reinterprets the specified 64-bit signed integer to a double-precision floating point number. A double-precision floating point number whose value is equivalent to . - method. - -## Examples - The following code example converts the bit patterns of several values to values with the `Int64BitsToDouble` method. - + +## Examples + The following code example converts the bit patterns of several values to values with the `Int64BitsToDouble` method. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.BitConverter.DoubleInt64/CPP/bitstodbl.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/BitConverter/DoubleToInt64Bits/bitstodbl.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.BitConverter.DoubleInt64/FS/bitstodbl.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.BitConverter.DoubleInt64/VB/bitstodbl.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.BitConverter.DoubleInt64/VB/bitstodbl.vb" id="Snippet1"::: + ]]> @@ -1248,17 +1248,17 @@ Indicates the byte order ("endianness") in which data is stored in this computer architecture. - [!NOTE] > You can convert from network byte order to the byte order of the host computer without retrieving the value of the field by passing a 16-bit, 32-bit, or 64 bit integer to the method. - -## Examples - The following code example illustrates the use of the `IsLittleEndian` field. - + +## Examples + The following code example illustrates the use of the `IsLittleEndian` field. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.BitConverter.Class/CPP/littleend.cpp" id="Snippet2"::: :::code language="csharp" source="~/snippets/csharp/System/BitConverter/Overview/littleend.cs" interactive="try-dotnet" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.BitConverter.Class/FS/littleend.fs" id="Snippet2"::: @@ -1448,19 +1448,19 @@ if the byte at in is nonzero; otherwise, . - value to its byte representation, call the method. - -## Examples - The following code example converts elements of arrays to values with the `ToBoolean` method. - + +## Examples + The following code example converts elements of arrays to values with the `ToBoolean` method. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.BitConverter.ToXXX.Others/CPP/batobool.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/BitConverter/ToBoolean/batobool.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.BitConverter.ToXXX.Others/FS/batobool.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.BitConverter.ToXXX.Others/VB/batobool.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.BitConverter.ToXXX.Others/VB/batobool.vb" id="Snippet1"::: + ]]> @@ -1566,19 +1566,19 @@ Returns a Unicode character converted from two bytes at a specified position in a byte array. The character formed by two bytes beginning at . - method converts the bytes from index `startIndex` to `startIndex` + 1 to a value. The order of bytes in the array must reflect the endianness of the computer system's architecture. For more information, see the Remarks section of the class topic. - -## Examples - The following code example converts elements of arrays to values (Unicode characters) with the `ToChar` method. - + +## Examples + The following code example converts elements of arrays to values (Unicode characters) with the `ToChar` method. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.BitConverter.ToXXX.Others/CPP/batochar.cpp" id="Snippet2"::: :::code language="csharp" source="~/snippets/csharp/System/BitConverter/ToBoolean/batochar.cs" interactive="try-dotnet" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.BitConverter.ToXXX.Others/FS/batochar.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.BitConverter.ToXXX.Others/VB/batochar.vb" id="Snippet2"::: - + ]]> @@ -1692,19 +1692,19 @@ Returns a double-precision floating point number converted from eight bytes at a specified position in a byte array. A double-precision floating point number formed by eight bytes beginning at . - method converts the bytes from index `startIndex` to `startIndex` + 7 to a value. The order of bytes in the array must reflect the endianness of the computer system's architecture. For more information, see the Remarks section of the class topic. - -## Examples - The following code example converts elements of arrays to values with the `ToDouble` method. - + +## Examples + The following code example converts elements of arrays to values with the `ToDouble` method. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.BitConverter.ToXXX.Others/CPP/batodouble.cpp" id="Snippet3"::: :::code language="csharp" source="~/snippets/csharp/System/BitConverter/ToBoolean/batodouble.cs" interactive="try-dotnet" id="Snippet3"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.BitConverter.ToXXX.Others/FS/batodouble.fs" id="Snippet3"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.BitConverter.ToXXX.Others/VB/batodouble.vb" id="Snippet3"::: - + ]]> @@ -1905,14 +1905,14 @@ Returns a 16-bit signed integer converted from two bytes at a specified position in a byte array. A 16-bit signed integer formed by two bytes beginning at . - method converts the bytes from index `startIndex` to `startIndex` + 1 to an value. The order of bytes in the array must reflect the endianness of the computer system's architecture. For more information, see the Remarks section of the class topic. - -## Examples - The following code example converts elements of arrays to values with the `ToInt16` method. - + +## Examples + The following code example converts elements of arrays to values with the `ToInt16` method. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.BitConverter.ToXXX.SInts/CPP/batoint16.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/BitConverter/ToInt16/batoint16.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.BitConverter.ToXXX.SInts/FS/batoint16.fs" id="Snippet1"::: @@ -2031,14 +2031,14 @@ Returns a 32-bit signed integer converted from four bytes at a specified position in a byte array. A 32-bit signed integer formed by four bytes beginning at . - method converts the bytes from index `startIndex` to `startIndex` + 3 to an value. The order of bytes in the array must reflect the endianness of the computer system's architecture. For more information, see the Remarks section of . - -## Examples - The following example uses the method to create values from a four-byte array and from the upper four bytes of an eight-byte array. It also uses the and methods to round-trip an value. - + +## Examples + The following example uses the method to create values from a four-byte array and from the upper four bytes of an eight-byte array. It also uses the and methods to round-trip an value. + :::code language="csharp" source="~/snippets/csharp/System/BitConverter/ToInt32/toint32.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.bitconverter.toint32/fs/toint32.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.bitconverter.toint32/vb/toint32.vb" id="Snippet1"::: @@ -2156,14 +2156,14 @@ Returns a 64-bit signed integer converted from eight bytes at a specified position in a byte array. A 64-bit signed integer formed by eight bytes beginning at . - method converts the bytes from index `startIndex` to `startIndex` + 7 to a value. The order of bytes in the array must reflect the endianness of the computer system's architecture. For more information, see the Remarks section of the class topic. - -## Examples - The following code example converts elements of arrays to values with the `ToInt64` method. - + +## Examples + The following code example converts elements of arrays to values with the `ToInt64` method. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.BitConverter.ToXXX.SInts/CPP/batoint64.cpp" id="Snippet3"::: :::code language="csharp" source="~/snippets/csharp/System/BitConverter/ToInt16/batoint64.cs" interactive="try-dotnet" id="Snippet3"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.BitConverter.ToXXX.SInts/FS/batoint64.fs" id="Snippet3"::: @@ -2282,14 +2282,14 @@ Returns a single-precision floating point number converted from four bytes at a specified position in a byte array. A single-precision floating point number formed by four bytes beginning at . - method converts the bytes from index `startIndex` to `startIndex` + 3 to a value. The order of bytes in the array must reflect the endianness of the computer system's architecture. For more information, see the Remarks section of . - -## Examples - The following code example converts elements of arrays to values with the `ToSingle` method. - + +## Examples + The following code example converts elements of arrays to values with the `ToSingle` method. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.BitConverter.ToXXX.Others/CPP/batosingle.cpp" id="Snippet4"::: :::code language="csharp" source="~/snippets/csharp/System/BitConverter/ToBoolean/batosingle.cs" interactive="try-dotnet" id="Snippet4"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.BitConverter.ToXXX.Others/FS/batosingle.fs" id="Snippet4"::: @@ -2365,14 +2365,14 @@ Converts the numeric value of each element of a specified array of bytes to its equivalent hexadecimal string representation. A string of hexadecimal pairs separated by hyphens, where each pair represents the corresponding element in ; for example, "7F-2C-4A-00". - arrays to objects with the `ToString` method. - + +## Examples + The following code example converts arrays to objects with the `ToString` method. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.BitConverter.ToString/CPP/batostring.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/BitConverter/ToString/batostring.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.BitConverter.ToString/FS/batostring.fs" id="Snippet1"::: @@ -2433,14 +2433,14 @@ Converts the numeric value of each element of a specified subarray of bytes to its equivalent hexadecimal string representation. A string of hexadecimal pairs separated by hyphens, where each pair represents the corresponding element in a subarray of ; for example, "7F-2C-4A-00". - array starting at the specified `startIndex` to a with the `ToString` method. - + +## Examples + The following code example converts the part of a array starting at the specified `startIndex` to a with the `ToString` method. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.BitConverter.ToString/CPP/batostringii.cpp" id="Snippet2"::: :::code language="csharp" source="~/snippets/csharp/System/BitConverter/ToString/batostringii.cs" interactive="try-dotnet" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.BitConverter.ToString/FS/batostringii.fs" id="Snippet2"::: @@ -2505,29 +2505,29 @@ Converts the numeric value of each element of a specified subarray of bytes to its equivalent hexadecimal string representation. A string of hexadecimal pairs separated by hyphens, where each pair represents the corresponding element in a subarray of ; for example, "7F-2C-4A-00". - . - -## Examples - The following example uses the method to convert part of a byte array, starting at the specified `startIndex` and with the specified `length`, to a string. - + +## Examples + The following example uses the method to convert part of a byte array, starting at the specified `startIndex` and with the specified `length`, to a string. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.BitConverter.ToString/CPP/batostringii.cpp" id="Snippet2"::: :::code language="csharp" source="~/snippets/csharp/System/BitConverter/ToString/batostringii.cs" interactive="try-dotnet" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.BitConverter.ToString/FS/batostringii.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.BitConverter.ToString/VB/batostringii.vb" id="Snippet2"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.BitConverter.ToString/VB/batostringii.vb" id="Snippet2"::: ]]> is . - or is less than zero. - - -or- - - is greater than zero and is greater than or equal to the length of . + or is less than zero. + +-or- + + is greater than zero and is greater than or equal to the length of . The combination of and does not specify a position within ; that is, the parameter is greater than the length of minus the parameter. @@ -2637,14 +2637,14 @@ Returns a 16-bit unsigned integer converted from two bytes at a specified position in a byte array. A 16-bit unsigned integer formed by two bytes beginning at . - method converts the bytes from index `startIndex` to `startIndex` + 1 to a value. The order of bytes in the array must reflect the endianness of the computer system's architecture. For more information, see the Remarks section of the class topic. - -## Examples - The following code example converts elements of arrays to values with the `ToUInt16` method. - + +## Examples + The following code example converts elements of arrays to values with the `ToUInt16` method. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.BitConverter.ToXXX.UInts/CPP/batouint16.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/BitConverter/ToUInt16/batouint16.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.BitConverter.ToXXX.UInts/FS/batouint16.fs" id="Snippet1"::: @@ -2767,14 +2767,14 @@ Returns a 32-bit unsigned integer converted from four bytes at a specified position in a byte array. A 32-bit unsigned integer formed by four bytes beginning at . - method converts the bytes from index `startIndex` to `startIndex` + 3 to a value. The order of bytes in the array must reflect the endianness of the computer system's architecture. For more information, see the Remarks section of the class topic. - -## Examples - The following code example converts elements of arrays to values with the `ToUInt32` method. - + +## Examples + The following code example converts elements of arrays to values with the `ToUInt32` method. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.BitConverter.ToXXX.UInts/CPP/batouint32.cpp" id="Snippet2"::: :::code language="csharp" source="~/snippets/csharp/System/BitConverter/ToUInt16/batouint32.cs" interactive="try-dotnet" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.BitConverter.ToXXX.UInts/FS/batouint32.fs" id="Snippet2"::: @@ -2897,14 +2897,14 @@ Returns a 64-bit unsigned integer converted from eight bytes at a specified position in a byte array. A 64-bit unsigned integer formed by the eight bytes beginning at . - method converts the bytes from index `startIndex` to `startIndex` + 7 to a value. The order of bytes in the array must reflect the endianness of the computer system's architecture. For more information, see the Remarks section of the class topic. - -## Examples - The following code example converts elements of arrays to values with the `ToUInt64` method. - + +## Examples + The following code example converts elements of arrays to values with the `ToUInt64` method. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.BitConverter.ToXXX.UInts/CPP/batouint64.cpp" id="Snippet3"::: :::code language="csharp" source="~/snippets/csharp/System/BitConverter/ToUInt16/batouint64.cs" interactive="try-dotnet" id="Snippet3"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.BitConverter.ToXXX.UInts/FS/batouint64.fs" id="Snippet3"::: diff --git a/xml/System/Boolean.xml b/xml/System/Boolean.xml index 357cc9adc99..622716c5b50 100644 --- a/xml/System/Boolean.xml +++ b/xml/System/Boolean.xml @@ -97,165 +97,165 @@ Represents a Boolean ( or ) value. - instance can have either of two values: `true` or `false`. - - The structure provides methods that support the following tasks: - -- Converting Boolean values to strings: - -- Parsing strings to convert them to Boolean values: and - -- Comparing values: and - - The following sections explain these tasks and other usage details: - -- [Format Boolean values](#Formatting) -- [Convert to and from Boolean values](#Converting) -- [Parse Boolean values](#Parsing) -- [Compare Boolean values](#Comparing) -- [Work with Booleans as binary values](#Binary) -- [Perform operations with Boolean values](#Operations) -- [Booleans and Interop](#Interop) - - -## Format Boolean values - The string representation of a is either "True" for a `true` value or "False" for a `false` value. The string representation of a value is defined by the read-only and fields. - - You use the method to convert Boolean values to strings. The Boolean structure includes two overloads: the parameterless method and the method, which includes a parameter that controls formatting. However, because this parameter is ignored, the two overloads produce identical strings. The method does not support culture-sensitive formatting. - - The following example illustrates formatting with the method. Note that the C# and VB examples use the [composite formatting](/dotnet/standard/base-types/composite-formatting) feature, while the F# example uses [string interpolation](/dotnet/fsharp/language-reference/interpolated-strings). In both cases the method is called implicitly. - :::code language="csharp" source="~/snippets/csharp/System/Boolean/Overview/tostring1.cs" interactive="try-dotnet" id="Snippet3"::: - :::code language="fsharp" source="~/snippets/fsharp/System/Boolean/Overview/tostring1.fs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.boolean.structure/vb/tostring1.vb" id="Snippet3"::: - - Because the structure can have only two values, it is easy to add custom formatting. For simple custom formatting in which other string literals are substituted for "True" and "False", you can use any conditional evaluation feature supported by your language, such as the [conditional operator](/dotnet/csharp/language-reference/operators/conditional-operator) in C# or the [If operator](/dotnet/visual-basic/language-reference/operators/if-operator) in Visual Basic. The following example uses this technique to format values as "Yes" and "No" rather than "True" and "False". - - :::code language="csharp" source="~/snippets/csharp/System/Boolean/Overview/tostring2.cs" interactive="try-dotnet" id="Snippet4"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.boolean.structure/vb/tostring2.vb" id="Snippet4"::: - :::code language="fsharp" source="~/snippets/fsharp/System/Boolean/Overview/tostring2.fs" id="Snippet4"::: - - For more complex custom formatting operations, including culture-sensitive formatting, you can call the method and provide an implementation. The following example implements the and interfaces to provide culture-sensitive Boolean strings for the English (United States), French (France), and Russian (Russia) cultures. - - :::code language="csharp" source="~/snippets/csharp/System/Boolean/Overview/format3.cs" interactive="try-dotnet" id="Snippet5"::: - :::code language="fsharp" source="~/snippets/fsharp/System/Boolean/Overview/format3.fs" id="Snippet5"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.boolean.structure/vb/format3.vb" id="Snippet5"::: - - Optionally, you can use [resource files](/dotnet/framework/resources/) to define culture-specific Boolean strings. - - -## Convert to and from Boolean values - The structure implements the interface. As a result, you can use the class to perform conversions between a value and any other primitive type in .NET, or you can call the structure's explicit implementations. However, conversions between a and the following types are not supported, so the corresponding conversion methods throw an exception: - -- Conversion between and (the and methods) - -- Conversion between and (the and methods) - - All conversions from integral or floating-point numbers to Boolean values convert non-zero values to `true` and zero values to `false`. The following example illustrates this by calling selected overloads of the class. - - :::code language="csharp" source="~/snippets/csharp/System/Boolean/Overview/conversion1.cs" interactive="try-dotnet" id="Snippet6"::: - :::code language="fsharp" source="~/snippets/fsharp/System/Boolean/Overview/conversion1.fs" id="Snippet6"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.boolean.structure/vb/conversion1.vb" id="Snippet6"::: - - When converting from Boolean to numeric values, the conversion methods of the class convert `true` to 1 and `false` to 0. However, Visual Basic conversion functions convert `true` to either 255 (for conversions to values) or -1 (for all other numeric conversions). The following example converts `true` to numeric values by using a method, and, in the case of the Visual Basic example, by using the Visual Basic language's own conversion operator. - - :::code language="csharp" source="~/snippets/csharp/System/Boolean/Overview/conversion3.cs" interactive="try-dotnet" id="Snippet8"::: - :::code language="fsharp" source="~/snippets/fsharp/System/Boolean/Overview/conversion3.fs" id="Snippet8"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.boolean.structure/vb/conversion3.vb" id="Snippet8"::: - - For conversions from to string values, see the [Formatting Boolean Values](#Formatting) section. For conversions from strings to values, see the [Parsing Boolean Values](#Parsing) section. - - -## Parse Boolean values - The structure includes two static parsing methods, and , that convert a string to a Boolean value. The string representation of a Boolean value is defined by the case-insensitive equivalents of the values of the and fields, which are "True" and "False", respectively. In other words, the only strings that parse successfully are "True", "False", "true", "false", or some mixed-case equivalent. You cannot successfully parse numeric strings such as "0" or "1". Leading or trailing white-space characters are not considered when performing the string comparison. - - The following example uses the and methods to parse a number of strings. Note that only the case-insensitive equivalents of "True" and "False" can be successfully parsed. - - :::code language="csharp" source="~/snippets/csharp/System/Boolean/Overview/parse2.cs" interactive="try-dotnet" id="Snippet2"::: - :::code language="fsharp" source="~/snippets/fsharp/System/Boolean/Overview/parse2.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.boolean.structure/vb/parse2.vb" id="Snippet2"::: - - If you are programming in Visual Basic, you can use the `CBool` function to convert the string representation of a number to a Boolean value. "0" is converted to `false`, and the string representation of any non-zero value is converted to `true`. If you are not programming in Visual Basic, you must convert your numeric string to a number before converting it to a Boolean. The following example illustrates this by converting an array of integers to Boolean values. - - :::code language="csharp" source="~/snippets/csharp/System/Boolean/Overview/parse3.cs" interactive="try-dotnet" id="Snippet9"::: - :::code language="fsharp" source="~/snippets/fsharp/System/Boolean/Overview/parse3.fs" id="Snippet9"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.boolean.structure/vb/parse3.vb" id="Snippet9"::: - - -## Compare Boolean values - Because Boolean values are either `true` or `false`, there is little reason to explicitly call the method, which indicates whether an instance is greater than, less than, or equal to a specified value. Typically, to compare two Boolean variables, you call the method or use your language's equality operator. - - However, when you want to compare a Boolean variable with the literal Boolean value `true` or `false`, it is not necessary to do an explicit comparison, because the result of evaluating a Boolean value is that Boolean value. For example, the expressions - - :::code language="csharp" source="~/snippets/csharp/System/Boolean/Overview/operations1.cs" id="Snippet11"::: - :::code language="fsharp" source="~/snippets/fsharp/System/Boolean/Overview/operations1.fs" id="Snippet11"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.boolean.structure/vb/operations1.vb" id="Snippet11"::: - - and - - :::code language="csharp" source="~/snippets/csharp/System/Boolean/Overview/operations1.cs" id="Snippet12"::: - :::code language="fsharp" source="~/snippets/fsharp/System/Boolean/Overview/operations1.fs" id="Snippet12"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.boolean.structure/vb/operations1.vb" id="Snippet12"::: - - are equivalent, but the second is more compact. However, both techniques offer comparable performance. - - -## Work with Booleans as binary values - A Boolean value occupies one byte of memory, as the following C# or F# example shows. The C# example must be compiled with the `/unsafe` switch. - - :::code language="csharp" source="~/snippets/csharp/System/Boolean/Overview/size1.cs" id="Snippet14"::: - :::code language="fsharp" source="~/snippets/fsharp/System/Boolean/Overview/size1.fs" id="Snippet14"::: - - The byte's low-order bit is used to represent its value. A value of 1 represents `true`; a value of 0 represents `false`. - -> [!TIP] -> You can use the structure to work with sets of Boolean values. - - You can convert a Boolean value to its binary representation by calling the method. The method returns a byte array with a single element. To restore a Boolean value from its binary representation, you can call the method. - - The following example calls the method to convert a Boolean value to its binary representation and displays the individual bits of the value, and then calls the method to restore the value from its binary representation. - - :::code language="csharp" source="~/snippets/csharp/System/Boolean/Overview/binary1.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/Boolean/Overview/binary1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.boolean.structure/vb/binary1.vb" id="Snippet1"::: - - -## Perform operations with Boolean values - This section illustrates how Boolean values are used in apps. The first section discusses its use as a flag. The second illustrates its use for arithmetic operations. - -### Boolean values as flags - Boolean variables are most commonly used as flags, to signal the presence or absence of some condition. For example, in the method, the final parameter, `ignoreCase`, is a flag that indicates whether the comparison of two strings is case-insensitive (`ignoreCase` is `true`) or case-sensitive (`ignoreCase` is `false`). The value of the flag can then be evaluated in a conditional statement. - - The following example uses a simple console app to illustrate the use of Boolean variables as flags. The app accepts command-line parameters that enable output to be redirected to a specified file (the `/f` switch), and that enable output to be sent both to a specified file and to the console (the `/b` switch). The app defines a flag named `isRedirected` to indicate whether output is to be sent to a file, and a flag named `isBoth` to indicate that output should be sent to the console. Note that the F# example uses a [recursive function](/dotnet/fsharp/language-reference/functions/recursive-functions-the-rec-keyword) to parse the arguments. - - :::code language="csharp" source="~/snippets/csharp/System/Boolean/Overview/operations1.cs" id="Snippet10"::: - :::code language="fsharp" source="~/snippets/fsharp/System/Boolean/Overview/operations1.fs" id="Snippet10"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.boolean.structure/vb/operations1.vb" id="Snippet10"::: - -### Booleans and arithmetic operations - A Boolean value is sometimes used to indicate the presence of a condition that triggers a mathematical calculation. For example, a `hasShippingCharge` variable might serve as a flag to indicate whether to add shipping charges to an invoice amount. - - Because an operation with a `false` value has no effect on the result of an operation, it is not necessary to convert the Boolean to an integral value to use in the mathematical operation. Instead, you can use conditional logic. - - The following example computes an amount that consists of a subtotal, a shipping charge, and an optional service charge. The `hasServiceCharge` variable determines whether the service charge is applied. Instead of converting `hasServiceCharge` to a numeric value and multiplying it by the amount of the service charge, the example uses conditional logic to add the service charge amount if it is applicable. - - :::code language="csharp" source="~/snippets/csharp/System/Boolean/Overview/operations2.cs" id="Snippet13"::: - :::code language="fsharp" source="~/snippets/fsharp/System/Boolean/Overview/operations2.fs" id="Snippet13"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.boolean.structure/vb/operations2.vb" id="Snippet13"::: - - -### Booleans and interop - While marshaling base data types to COM is generally straightforward, the data type is an exception. You can apply the attribute to marshal the type to any of the following representations: - -|Enumeration type|Unmanaged format| -|----------------------|----------------------| -||A 4-byte integer value, where any nonzero value represents `true` and 0 represents `false`. This is the default format of a field in a structure and of a parameter in platform invoke calls.| -||A 1-byte integer value, where the 1 represents `true` and 0 represents `false`.| -||A 2-byte integer value, where -1 represents `true` and 0 represents `false`. This is the default format of a parameter in COM interop calls.| - + instance can have either of two values: `true` or `false`. + + The structure provides methods that support the following tasks: + +- Converting Boolean values to strings: + +- Parsing strings to convert them to Boolean values: and + +- Comparing values: and + + The following sections explain these tasks and other usage details: + +- [Format Boolean values](#Formatting) +- [Convert to and from Boolean values](#Converting) +- [Parse Boolean values](#Parsing) +- [Compare Boolean values](#Comparing) +- [Work with Booleans as binary values](#Binary) +- [Perform operations with Boolean values](#Operations) +- [Booleans and Interop](#Interop) + + +## Format Boolean values + The string representation of a is either "True" for a `true` value or "False" for a `false` value. The string representation of a value is defined by the read-only and fields. + + You use the method to convert Boolean values to strings. The Boolean structure includes two overloads: the parameterless method and the method, which includes a parameter that controls formatting. However, because this parameter is ignored, the two overloads produce identical strings. The method does not support culture-sensitive formatting. + + The following example illustrates formatting with the method. Note that the C# and VB examples use the [composite formatting](/dotnet/standard/base-types/composite-formatting) feature, while the F# example uses [string interpolation](/dotnet/fsharp/language-reference/interpolated-strings). In both cases the method is called implicitly. + :::code language="csharp" source="~/snippets/csharp/System/Boolean/Overview/tostring1.cs" interactive="try-dotnet" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Boolean/Overview/tostring1.fs" id="Snippet3"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.boolean.structure/vb/tostring1.vb" id="Snippet3"::: + + Because the structure can have only two values, it is easy to add custom formatting. For simple custom formatting in which other string literals are substituted for "True" and "False", you can use any conditional evaluation feature supported by your language, such as the [conditional operator](/dotnet/csharp/language-reference/operators/conditional-operator) in C# or the [If operator](/dotnet/visual-basic/language-reference/operators/if-operator) in Visual Basic. The following example uses this technique to format values as "Yes" and "No" rather than "True" and "False". + + :::code language="csharp" source="~/snippets/csharp/System/Boolean/Overview/tostring2.cs" interactive="try-dotnet" id="Snippet4"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.boolean.structure/vb/tostring2.vb" id="Snippet4"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Boolean/Overview/tostring2.fs" id="Snippet4"::: + + For more complex custom formatting operations, including culture-sensitive formatting, you can call the method and provide an implementation. The following example implements the and interfaces to provide culture-sensitive Boolean strings for the English (United States), French (France), and Russian (Russia) cultures. + + :::code language="csharp" source="~/snippets/csharp/System/Boolean/Overview/format3.cs" interactive="try-dotnet" id="Snippet5"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Boolean/Overview/format3.fs" id="Snippet5"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.boolean.structure/vb/format3.vb" id="Snippet5"::: + + Optionally, you can use [resource files](/dotnet/framework/resources/) to define culture-specific Boolean strings. + + +## Convert to and from Boolean values + The structure implements the interface. As a result, you can use the class to perform conversions between a value and any other primitive type in .NET, or you can call the structure's explicit implementations. However, conversions between a and the following types are not supported, so the corresponding conversion methods throw an exception: + +- Conversion between and (the and methods) + +- Conversion between and (the and methods) + + All conversions from integral or floating-point numbers to Boolean values convert non-zero values to `true` and zero values to `false`. The following example illustrates this by calling selected overloads of the class. + + :::code language="csharp" source="~/snippets/csharp/System/Boolean/Overview/conversion1.cs" interactive="try-dotnet" id="Snippet6"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Boolean/Overview/conversion1.fs" id="Snippet6"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.boolean.structure/vb/conversion1.vb" id="Snippet6"::: + + When converting from Boolean to numeric values, the conversion methods of the class convert `true` to 1 and `false` to 0. However, Visual Basic conversion functions convert `true` to either 255 (for conversions to values) or -1 (for all other numeric conversions). The following example converts `true` to numeric values by using a method, and, in the case of the Visual Basic example, by using the Visual Basic language's own conversion operator. + + :::code language="csharp" source="~/snippets/csharp/System/Boolean/Overview/conversion3.cs" interactive="try-dotnet" id="Snippet8"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Boolean/Overview/conversion3.fs" id="Snippet8"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.boolean.structure/vb/conversion3.vb" id="Snippet8"::: + + For conversions from to string values, see the [Formatting Boolean Values](#Formatting) section. For conversions from strings to values, see the [Parsing Boolean Values](#Parsing) section. + + +## Parse Boolean values + The structure includes two static parsing methods, and , that convert a string to a Boolean value. The string representation of a Boolean value is defined by the case-insensitive equivalents of the values of the and fields, which are "True" and "False", respectively. In other words, the only strings that parse successfully are "True", "False", "true", "false", or some mixed-case equivalent. You cannot successfully parse numeric strings such as "0" or "1". Leading or trailing white-space characters are not considered when performing the string comparison. + + The following example uses the and methods to parse a number of strings. Note that only the case-insensitive equivalents of "True" and "False" can be successfully parsed. + + :::code language="csharp" source="~/snippets/csharp/System/Boolean/Overview/parse2.cs" interactive="try-dotnet" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Boolean/Overview/parse2.fs" id="Snippet2"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.boolean.structure/vb/parse2.vb" id="Snippet2"::: + + If you are programming in Visual Basic, you can use the `CBool` function to convert the string representation of a number to a Boolean value. "0" is converted to `false`, and the string representation of any non-zero value is converted to `true`. If you are not programming in Visual Basic, you must convert your numeric string to a number before converting it to a Boolean. The following example illustrates this by converting an array of integers to Boolean values. + + :::code language="csharp" source="~/snippets/csharp/System/Boolean/Overview/parse3.cs" interactive="try-dotnet" id="Snippet9"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Boolean/Overview/parse3.fs" id="Snippet9"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.boolean.structure/vb/parse3.vb" id="Snippet9"::: + + +## Compare Boolean values + Because Boolean values are either `true` or `false`, there is little reason to explicitly call the method, which indicates whether an instance is greater than, less than, or equal to a specified value. Typically, to compare two Boolean variables, you call the method or use your language's equality operator. + + However, when you want to compare a Boolean variable with the literal Boolean value `true` or `false`, it is not necessary to do an explicit comparison, because the result of evaluating a Boolean value is that Boolean value. For example, the expressions + + :::code language="csharp" source="~/snippets/csharp/System/Boolean/Overview/operations1.cs" id="Snippet11"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Boolean/Overview/operations1.fs" id="Snippet11"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.boolean.structure/vb/operations1.vb" id="Snippet11"::: + + and + + :::code language="csharp" source="~/snippets/csharp/System/Boolean/Overview/operations1.cs" id="Snippet12"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Boolean/Overview/operations1.fs" id="Snippet12"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.boolean.structure/vb/operations1.vb" id="Snippet12"::: + + are equivalent, but the second is more compact. However, both techniques offer comparable performance. + + +## Work with Booleans as binary values + A Boolean value occupies one byte of memory, as the following C# or F# example shows. The C# example must be compiled with the `/unsafe` switch. + + :::code language="csharp" source="~/snippets/csharp/System/Boolean/Overview/size1.cs" id="Snippet14"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Boolean/Overview/size1.fs" id="Snippet14"::: + + The byte's low-order bit is used to represent its value. A value of 1 represents `true`; a value of 0 represents `false`. + +> [!TIP] +> You can use the structure to work with sets of Boolean values. + + You can convert a Boolean value to its binary representation by calling the method. The method returns a byte array with a single element. To restore a Boolean value from its binary representation, you can call the method. + + The following example calls the method to convert a Boolean value to its binary representation and displays the individual bits of the value, and then calls the method to restore the value from its binary representation. + + :::code language="csharp" source="~/snippets/csharp/System/Boolean/Overview/binary1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Boolean/Overview/binary1.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.boolean.structure/vb/binary1.vb" id="Snippet1"::: + + +## Perform operations with Boolean values + This section illustrates how Boolean values are used in apps. The first section discusses its use as a flag. The second illustrates its use for arithmetic operations. + +### Boolean values as flags + Boolean variables are most commonly used as flags, to signal the presence or absence of some condition. For example, in the method, the final parameter, `ignoreCase`, is a flag that indicates whether the comparison of two strings is case-insensitive (`ignoreCase` is `true`) or case-sensitive (`ignoreCase` is `false`). The value of the flag can then be evaluated in a conditional statement. + + The following example uses a simple console app to illustrate the use of Boolean variables as flags. The app accepts command-line parameters that enable output to be redirected to a specified file (the `/f` switch), and that enable output to be sent both to a specified file and to the console (the `/b` switch). The app defines a flag named `isRedirected` to indicate whether output is to be sent to a file, and a flag named `isBoth` to indicate that output should be sent to the console. Note that the F# example uses a [recursive function](/dotnet/fsharp/language-reference/functions/recursive-functions-the-rec-keyword) to parse the arguments. + + :::code language="csharp" source="~/snippets/csharp/System/Boolean/Overview/operations1.cs" id="Snippet10"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Boolean/Overview/operations1.fs" id="Snippet10"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.boolean.structure/vb/operations1.vb" id="Snippet10"::: + +### Booleans and arithmetic operations + A Boolean value is sometimes used to indicate the presence of a condition that triggers a mathematical calculation. For example, a `hasShippingCharge` variable might serve as a flag to indicate whether to add shipping charges to an invoice amount. + + Because an operation with a `false` value has no effect on the result of an operation, it is not necessary to convert the Boolean to an integral value to use in the mathematical operation. Instead, you can use conditional logic. + + The following example computes an amount that consists of a subtotal, a shipping charge, and an optional service charge. The `hasServiceCharge` variable determines whether the service charge is applied. Instead of converting `hasServiceCharge` to a numeric value and multiplying it by the amount of the service charge, the example uses conditional logic to add the service charge amount if it is applicable. + + :::code language="csharp" source="~/snippets/csharp/System/Boolean/Overview/operations2.cs" id="Snippet13"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Boolean/Overview/operations2.fs" id="Snippet13"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.boolean.structure/vb/operations2.vb" id="Snippet13"::: + + +### Booleans and interop + While marshaling base data types to COM is generally straightforward, the data type is an exception. You can apply the attribute to marshal the type to any of the following representations: + +|Enumeration type|Unmanaged format| +|----------------------|----------------------| +||A 4-byte integer value, where any nonzero value represents `true` and 0 represents `false`. This is the default format of a field in a structure and of a parameter in platform invoke calls.| +||A 1-byte integer value, where the 1 represents `true` and 0 represents `false`.| +||A 2-byte integer value, where -1 represents `true` and 0 represents `false`. This is the default format of a parameter in COM interop calls.| + ]]> All members of this type are thread safe. Members that appear to modify instance state actually return a new instance initialized with the new value. As with any other type, reading and writing to a shared variable that contains an instance of this type must be protected by a lock to guarantee thread safety. @@ -319,47 +319,56 @@ A instance can have either of two values: `true` or `false A object to compare to this instance. Compares this instance to a specified object and returns an integer that indicates their relationship to one another. - A signed integer that indicates the relative values of this instance and . - - Return Value - - Condition - - Less than zero - - This instance is and is . - - Zero - - This instance and are equal (either both are or both are ). - - Greater than zero - - This instance is and is . - - + A signed integer that indicates the relative values of this instance and . + + Return Value + + + Condition + + + + + Less than zero + + + This instance is and is . + + + Zero + + + This instance and are equal (either both are or both are ). + + + Greater than zero + + + This instance is and is . + + - interface and performs slightly better than the method because it does not have to convert the `value` parameter to an object. - - If `value` has fewer bits (is narrower) than the instance type, some programming languages perform an implicit widening conversion that transforms the value of the parameter into a value with more bits. - - For example, suppose the instance type is and the parameter type is . The Microsoft C# compiler generates instructions to represent the value of the parameter as an object, then generates a method to compare the instance and parameter representation. - - Consult your programming language's documentation to determine whether its compiler performs implicit widening conversions on numeric types. - -## Examples - -The following code example demonstrates generic and nongeneric versions of the method for several value and reference types. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/T.CompareTo/CPP/cat.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/Boolean/CompareTo/cat.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/Boolean/CompareTo/cat.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/T.CompareTo/VB/cat.vb" id="Snippet1"::: - + interface and performs slightly better than the method because it does not have to convert the `value` parameter to an object. + + If `value` has fewer bits (is narrower) than the instance type, some programming languages perform an implicit widening conversion that transforms the value of the parameter into a value with more bits. + + For example, suppose the instance type is and the parameter type is . The Microsoft C# compiler generates instructions to represent the value of the parameter as an object, then generates a method to compare the instance and parameter representation. + + Consult your programming language's documentation to determine whether its compiler performs implicit widening conversions on numeric types. + +## Examples + +The following code example demonstrates generic and nongeneric versions of the method for several value and reference types. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/T.CompareTo/CPP/cat.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/Boolean/CompareTo/cat.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Boolean/CompareTo/cat.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/T.CompareTo/VB/cat.vb" id="Snippet1"::: + ]]> @@ -415,38 +424,47 @@ The following code example demonstrates generic and nongeneric versions of the < An object to compare to this instance, or . Compares this instance to a specified object and returns an integer that indicates their relationship to one another. - A signed integer that indicates the relative order of this instance and . - - Return Value - - Condition - - Less than zero - - This instance is and is . - - Zero - - This instance and are equal (either both are or both are ). - - Greater than zero - - This instance is and is . - - -or- - - is . - - + A signed integer that indicates the relative order of this instance and . + + Return Value + + + Condition + + + + + Less than zero + + + This instance is and is . + + + Zero + + + This instance and are equal (either both are or both are ). + + + Greater than zero + + + This instance is and is . + +-or- + + is . + + - interface. - + interface. + ]]> @@ -516,12 +534,12 @@ The following code example demonstrates generic and nongeneric versions of the < if has the same value as this instance; otherwise, . - interface, and performs slightly better than because it does not have to convert the `obj` parameter to an object. - + interface, and performs slightly better than because it does not have to convert the `obj` parameter to an object. + ]]> @@ -588,12 +606,12 @@ This method implements the if is a and has the same value as this instance; otherwise, . - . - + . + ]]> @@ -646,14 +664,14 @@ This method overrides . Represents the Boolean value as a string. This field is read-only. - property defines the string representation of a `false` value in formatting and parsing operations. - + property defines the string representation of a `false` value in formatting and parsing operations. + ]]> @@ -702,12 +720,12 @@ The property defines the string representation Returns the hash code for this instance. A hash code for the current . - class implements `true` as the integer, one, and `false` as the integer, zero. However, a particular programming language might represent `true` and `false` with other values. - + class implements `true` as the integer, one, and `false` as the integer, zero. However, a particular programming language might represent `true` and `false` with other values. + ]]> @@ -846,21 +864,21 @@ The class implements `true` as the integer, one, and `fals if is equivalent to ; if is equivalent to . - or ; otherwise, an exception is thrown. The comparison is case-insensitive. - -## Examples - -The following code example illustrates the use of method. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Boolean/CPP/booleanmembers.cpp" id="Snippet2"::: - :::code language="csharp" source="~/snippets/csharp/System/Boolean/Parse/booleanmembers.cs" interactive="try-dotnet-method" id="Snippet2"::: - :::code language="fsharp" source="~/snippets/fsharp/System/Boolean/Parse/booleanmembers.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Boolean/VB/booleanmembers.vb" id="Snippet2"::: - + or ; otherwise, an exception is thrown. The comparison is case-insensitive. + +## Examples + +The following code example illustrates the use of method. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Boolean/CPP/booleanmembers.cpp" id="Snippet2"::: + :::code language="csharp" source="~/snippets/csharp/System/Boolean/Parse/booleanmembers.cs" interactive="try-dotnet-method" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Boolean/Parse/booleanmembers.fs" id="Snippet2"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Boolean/VB/booleanmembers.vb" id="Snippet2"::: + ]]> @@ -907,20 +925,20 @@ The following code example illustrates the use of Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object. A value that indicates the relative order of the objects being compared. - instance is cast to an interface. - -The return value has these meanings: - -| Value | Meaning | -|-------------------|-------------------------------------------------------------------------| -| Less than zero | This instance precedes `obj` in the sort order. | -| Zero | This instance occurs in the same position in the sort order as `obj`. | -| Greater than zero | This instance follows `obj` in the sort order. | - + instance is cast to an interface. + +The return value has these meanings: + +| Value | Meaning | +|-------------------|-------------------------------------------------------------------------| +| Less than zero | This instance precedes `obj` in the sort order. | +| Zero | This instance occurs in the same position in the sort order as `obj`. | +| Greater than zero | This instance follows `obj` in the sort order. | + ]]> @@ -955,12 +973,12 @@ The return value has these meanings: Returns the for this instance. The enumerated constant that is the of the class or value type that implements this interface. - instance is cast to an interface. - + instance is cast to an interface. + ]]> @@ -1012,12 +1030,12 @@ This member is an explicit interface member implementation. It can be used only or . - instance is cast to an interface. - + instance is cast to an interface. + ]]> @@ -1068,12 +1086,12 @@ This member is an explicit interface member implementation. It can be used only For a description of this member, see . 1 if the value of this instance is ; otherwise, 0. - instance is cast to an interface. The recommended alternative is to call the method. - + instance is cast to an interface. The recommended alternative is to call the method. + ]]> @@ -1223,12 +1241,12 @@ This member is an explicit interface member implementation. It can be used only For a description of this member, see . 1 if this instance is ; otherwise, 0. - instance is cast to an interface. The recommended alternative is to call the method. - + instance is cast to an interface. The recommended alternative is to call the method. + ]]> @@ -1279,12 +1297,12 @@ This member is an explicit interface member implementation. It can be used only For a description of this member, see . 1 if this instance is ; otherwise, 0. - instance is cast to an interface. The recommended alternative is to call the method. - + instance is cast to an interface. The recommended alternative is to call the method. + ]]>
@@ -1335,12 +1353,12 @@ This member is an explicit interface member implementation. It can be used only For a description of this member, see . 1 if this instance is ; otherwise, 0. - instance is cast to an interface. The recommended alternative is to call the method. - + instance is cast to an interface. The recommended alternative is to call the method. + ]]>
@@ -1391,12 +1409,12 @@ This member is an explicit interface member implementation. It can be used only For a description of this member, see . 1 if this instance is ; otherwise, 0. - instance is cast to an interface. The recommended alternative is to call the method. - + instance is cast to an interface. The recommended alternative is to call the method. + ]]> @@ -1447,12 +1465,12 @@ This member is an explicit interface member implementation. It can be used only For a description of this member, see . 1 if this instance is ; otherwise, 0. - instance is cast to an interface. The recommended alternative is to call the method. - + instance is cast to an interface. The recommended alternative is to call the method. + ]]> @@ -1509,12 +1527,12 @@ This member is an explicit interface member implementation. It can be used only For a description of this member, see . 1 if this instance is ; otherwise, 0. - instance is cast to an interface. The recommended alternative is to call the method. - + instance is cast to an interface. The recommended alternative is to call the method. + ]]> @@ -1565,12 +1583,12 @@ This member is an explicit interface member implementation. It can be used only For a description of this member, see . 1 if this instance is ; otherwise, 0. - instance is cast to an interface. The recommended alternative is to call the method. - + instance is cast to an interface. The recommended alternative is to call the method. + ]]> @@ -1608,12 +1626,12 @@ This member is an explicit interface member implementation. It can be used only Converts the value of this instance to an equivalent string using the specified culture-specific formatting information. A string instance equivalent to the value of this instance. - instance is cast to an interface. - + instance is cast to an interface. + ]]> @@ -1666,12 +1684,12 @@ This member is an explicit interface member implementation. It can be used only For a description of this member, see . An object of the specified type, with a value that is equivalent to the value of this object. - instance is cast to an interface. The recommended alternative is to call the method. - + instance is cast to an interface. The recommended alternative is to call the method. + ]]> @@ -1732,12 +1750,12 @@ This member is an explicit interface member implementation. It can be used only For a description of this member, see . 1 if this instance is ; otherwise, 0. - instance is cast to an interface. The recommended alternative is to call the method. - + instance is cast to an interface. The recommended alternative is to call the method. + ]]> @@ -1796,12 +1814,12 @@ This member is an explicit interface member implementation. It can be used only For a description of this member, see . 1 if this instance is ; otherwise, 0. - instance is cast to an interface. The recommended alternative is to call the method. - + instance is cast to an interface. The recommended alternative is to call the method. + ]]> @@ -1860,12 +1878,12 @@ This member is an explicit interface member implementation. It can be used only For a description of this member, see . 1 if this instance is ; otherwise, 0. - instance is cast to an interface. The recommended alternative is to call the method. - + instance is cast to an interface. The recommended alternative is to call the method. + ]]> @@ -2082,23 +2100,23 @@ This member is an explicit interface member implementation. It can be used only Converts the value of this instance to its equivalent string representation (either "True" or "False"). "True" (the value of the property) if the value of this instance is , or "False" (the value of the property) if the value of this instance is . - method is to be written to an XML file, its method should be called first to convert it to lowercase. - -## Examples - -The following example illustrates the method. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Boolean/CPP/booleanmembers.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/Boolean/Parse/booleanmembers.cs" interactive="try-dotnet-method" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/Boolean/Parse/booleanmembers.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Boolean/VB/booleanmembers.vb" id="Snippet1"::: - + method is to be written to an XML file, its method should be called first to convert it to lowercase. + +## Examples + +The following example illustrates the method. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Boolean/CPP/booleanmembers.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/Boolean/Parse/booleanmembers.cs" interactive="try-dotnet-method" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Boolean/Parse/booleanmembers.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Boolean/VB/booleanmembers.vb" id="Snippet1"::: + ]]> @@ -2162,14 +2180,14 @@ The following example illustrates the method. if the value of this instance is , or if the value of this instance is . - method, unlike most methods with a `provider` parameter, does not reflect culture-specific settings. - - This method returns the constants "True" or "False". Note that XML is case-sensitive, and that the XML specification recognizes "true" and "false" as the valid set of Boolean values. If the object returned by the method is to be written to an XML file, its method should be called first to convert it to lowercase. - + method, unlike most methods with a `provider` parameter, does not reflect culture-specific settings. + + This method returns the constants "True" or "False". Note that XML is case-sensitive, and that the XML specification recognizes "true" and "false" as the valid set of Boolean values. If the object returned by the method is to be written to an XML file, its method should be called first to convert it to lowercase. + ]]> @@ -2220,14 +2238,14 @@ The `provider` parameter is reserved. It does not participate in the execution o Represents the Boolean value as a string. This field is read-only. - property defines the string representation of a `true` value in formatting and parsing operations. - + property defines the string representation of a `true` value in formatting and parsing operations. + ]]> @@ -2375,22 +2393,22 @@ The property defines the string representation if was converted successfully; otherwise, . - method is like the method, except the method does not throw an exception if the conversion fails. - - The `value` parameter can be preceded or followed by white space. The comparison is ordinal and case-insensitive. - -## Examples - -The following example calls the method to parse an array of strings. Note that the parse operation succeeds only if the string to be parsed is "True" (the value of the field) or "False" (the value of the field) in a case-insensitive comparison. - - :::code language="csharp" source="~/snippets/csharp/System/Boolean/TryParse/tryparseex.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/Boolean/TryParse/tryparseex.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.boolean.tryparse/vb/tryparseex.vb" id="Snippet1"::: - + method is like the method, except the method does not throw an exception if the conversion fails. + + The `value` parameter can be preceded or followed by white space. The comparison is ordinal and case-insensitive. + +## Examples + +The following example calls the method to parse an array of strings. Note that the parse operation succeeds only if the string to be parsed is "True" (the value of the field) or "False" (the value of the field) in a case-insensitive comparison. + + :::code language="csharp" source="~/snippets/csharp/System/Boolean/TryParse/tryparseex.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Boolean/TryParse/tryparseex.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.boolean.tryparse/vb/tryparseex.vb" id="Snippet1"::: + ]]> diff --git a/xml/System/Buffer.xml b/xml/System/Buffer.xml index a8bc4056dd7..7d7f2f96f73 100644 --- a/xml/System/Buffer.xml +++ b/xml/System/Buffer.xml @@ -63,24 +63,24 @@ Manipulates arrays of primitive types. - only affects arrays of primitive types; this class does not apply to objects. Each primitive type is treated as a series of bytes without regard to any behavior or limitation associated with the primitive type. - - provides methods to copy bytes from one array of primitive types to another array of primitive types, get a byte from an array, set a byte in an array, and obtain the length of an array. This class provides better performance for manipulating primitive types than similar methods in the class. - - is applicable to the following primitive types: , , , , , , , , , , , , , and . - - - -## Examples - The following code example illustrates the use of several `Buffer` class methods. - + only affects arrays of primitive types; this class does not apply to objects. Each primitive type is treated as a series of bytes without regard to any behavior or limitation associated with the primitive type. + + provides methods to copy bytes from one array of primitive types to another array of primitive types, get a byte from an array, set a byte in an array, and obtain the length of an array. This class provides better performance for manipulating primitive types than similar methods in the class. + + is applicable to the following primitive types: , , , , , , , , , , , , , and . + + + +## Examples + The following code example illustrates the use of several `Buffer` class methods. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Buffer.BlockCopy/CPP/buffer.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Buffer/Overview/buffer.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Buffer.BlockCopy/FS/buffer.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Buffer.BlockCopy/VB/buffer.vb" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Buffer.BlockCopy/VB/buffer.vb" id="Snippet1"::: ]]> @@ -144,51 +144,51 @@ The number of bytes to copy. Copies a specified number of bytes from a source array starting at a particular offset to a destination array starting at a particular offset. - method accesses the bytes in the `src` parameter array using offsets into memory, not programming constructs such as indexes or upper and lower array bounds. For example, if in the programming language of your application you declare an array with a zero-based lower bound of -50, and then pass the array and an offset of 5 to the method, the first array element the method will access is the second element of the array, which is at index -49. Furthermore, which byte of array element -49 is accessed first depends on the endianness of the computer that is executing your application. - - As its name suggests, the method copies a block of bytes as a whole, rather than copying one byte at a time. Therefore, if `src` and `dst` reference the same array, and the range from `srcOffset` + `count` -1 overlaps the range from `dstOffset` + `count` - 1, the values of the overlapping bytes are not overwritten before they are copied to the destination. In the following example, the values of bytes 0-16 in an array named `arr` are copied to bytes 12-28. Despite the overlapping range, the values of the source bytes are successfully copied. - + method accesses the bytes in the `src` parameter array using offsets into memory, not programming constructs such as indexes or upper and lower array bounds. For example, if in the programming language of your application you declare an array with a zero-based lower bound of -50, and then pass the array and an offset of 5 to the method, the first array element the method will access is the second element of the array, which is at index -49. Furthermore, which byte of array element -49 is accessed first depends on the endianness of the computer that is executing your application. + + As its name suggests, the method copies a block of bytes as a whole, rather than copying one byte at a time. Therefore, if `src` and `dst` reference the same array, and the range from `srcOffset` + `count` -1 overlaps the range from `dstOffset` + `count` - 1, the values of the overlapping bytes are not overwritten before they are copied to the destination. In the following example, the values of bytes 0-16 in an array named `arr` are copied to bytes 12-28. Despite the overlapping range, the values of the source bytes are successfully copied. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Buffer.BlockCopy/CPP/overlap1.cpp" id="Snippet3"::: :::code language="csharp" source="~/snippets/csharp/System/Buffer/Overview/overlap1.cs" interactive="try-dotnet-method" id="Snippet3"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Buffer.BlockCopy/FS/overlap1.fs" id="Snippet3"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Buffer.BlockCopy/VB/overlap1.vb" id="Snippet3"::: - - In the following example, the values of bytes 12-28 in an array named `arr` are copied to bytes 0-16. Again, despite the overlapping range, the values of the source bytes are successfully copied. - + + In the following example, the values of bytes 12-28 in an array named `arr` are copied to bytes 0-16. Again, despite the overlapping range, the values of the source bytes are successfully copied. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Buffer.BlockCopy/CPP/overlap1.cpp" id="Snippet4"::: :::code language="csharp" source="~/snippets/csharp/System/Buffer/Overview/overlap1.cs" interactive="try-dotnet-method" id="Snippet4"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Buffer.BlockCopy/FS/overlap1.fs" id="Snippet4"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Buffer.BlockCopy/VB/overlap1.vb" id="Snippet4"::: - - - -## Examples - The following example copies regions of arrays by using the method. For each operation, it lists the source and destination arrays as both an array of values and as a sequence of bytes. The example illustrates the importance of considering a system's endianness when working with the method: Because Windows systems are little-endian, the lower-order bytes of a primitive data type's value precede the higher-order bytes. - + + + +## Examples + The following example copies regions of arrays by using the method. For each operation, it lists the source and destination arrays as both an array of values and as a sequence of bytes. The example illustrates the importance of considering a system's endianness when working with the method: Because Windows systems are little-endian, the lower-order bytes of a primitive data type's value precede the higher-order bytes. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Buffer.BlockCopy/CPP/bcopy.cpp" id="Snippet2"::: :::code language="csharp" source="~/snippets/csharp/System/Buffer/Overview/bcopy.cs" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Buffer.BlockCopy/FS/bcopy.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Buffer.BlockCopy/VB/bcopy.vb" id="Snippet2"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Buffer.BlockCopy/VB/bcopy.vb" id="Snippet2"::: + ]]> or is . - or is not an array of primitives. - - -or- - - The number of bytes in is less than plus . - - -or- - - The number of bytes in is less than plus . + or is not an array of primitives. + +-or- + +The number of bytes in is less than plus . + +-or- + +The number of bytes in is less than plus . , , or is less than 0. @@ -244,16 +244,16 @@ Returns the number of bytes in the specified array. The number of bytes in the array. - @@ -317,21 +317,21 @@ Retrieves the byte at the specified location in the specified array. The byte at the specified location in the array. - @@ -412,13 +412,13 @@ The target address. The number of bytes available in the destination memory block. The number of bytes to copy. - Copies a number of bytes specified as a long integer value from one address in memory to another. - - This API is not CLS-compliant. + Copies a number of bytes specified as a long integer value from one address in memory to another. + + This API is not CLS-compliant. - @@ -484,15 +484,15 @@ The target address. The number of bytes available in the destination memory block. The number of bytes to copy. - Copies a number of bytes specified as an unsigned long integer value from one address in memory to another. - - This API is not CLS-compliant. + Copies a number of bytes specified as an unsigned long integer value from one address in memory to another. + + This API is not CLS-compliant. - @@ -553,21 +553,21 @@ A value to assign. Assigns a specified value to a byte at a particular location in a specified array. - diff --git a/xml/System/Byte.xml b/xml/System/Byte.xml index 81b0d73d06d..48a16d08a2f 100644 --- a/xml/System/Byte.xml +++ b/xml/System/Byte.xml @@ -432,25 +432,34 @@ An 8-bit unsigned integer to compare. Compares this instance to a specified 8-bit unsigned integer and returns an indication of their relative values. - A signed integer that indicates the relative order of this instance and . - - Return Value - - Description - - Less than zero - - This instance is less than . - - Zero - - This instance is equal to . - - Greater than zero - - This instance is greater than . - - + A signed integer that indicates the relative order of this instance and . + + Return Value + + + Description + + + + + Less than zero + + + This instance is less than . + + + Zero + + + This instance is equal to . + + + Greater than zero + + + This instance is greater than . + + An object to compare, or . Compares this instance to a specified object and returns an indication of their relative values. - A signed integer that indicates the relative order of this instance and . - - Return Value - - Description - - Less than zero - - This instance is less than . - - Zero - - This instance is equal to . - - Greater than zero - - This instance is greater than , or is . + A signed integer that indicates the relative order of this instance and . + + Return Value + + + Description + + + + + Less than zero + + + This instance is less than . + + + Zero + + + This instance is equal to . + + + Greater than zero + + + This instance is greater than , or is . + + , this method matches the IEEE 754: represents a number less than Byte.MinValue or greater than Byte.MaxValue. - -or- +-or- - includes non-zero, fractional digits. + includes non-zero, fractional digits. is not a value. - -or- +-or- - is not a combination of and values. + is not a combination of and values. @@ -2120,15 +2140,15 @@ For , this method matches the IEEE 754: represents a number less than Byte.MinValue or greater than Byte.MaxValue. - -or- +-or- - includes non-zero, fractional digits. + includes non-zero, fractional digits. is not a value. - -or- +-or- - is not a combination of and values. + is not a combination of and values. @@ -6978,9 +6998,9 @@ This member is an explicit interface member implementation. It can be used only is not a value. - -or- +-or- - is not a combination of and values. + is not a combination of and values.
diff --git a/xml/System/CannotUnloadAppDomainException.xml b/xml/System/CannotUnloadAppDomainException.xml index af2cbef2e4b..7c0d3b8cea8 100644 --- a/xml/System/CannotUnloadAppDomainException.xml +++ b/xml/System/CannotUnloadAppDomainException.xml @@ -66,21 +66,21 @@ The exception that is thrown when an attempt to unload an application domain fails. - is thrown when there is an attempt to unload the following: - -- The default application domain, which must remain loaded during the lifetime of the application. - -- An application domain with a running thread that cannot immediately stop execution. - -- An application domain that has already been unloaded. - - uses the HRESULT COR_E_CANNOTUNLOADAPPDOMAIN, which has the value 0x80131015. - - For a list of initial property values for an instance of , see the constructors. - + is thrown when there is an attempt to unload the following: + +- The default application domain, which must remain loaded during the lifetime of the application. + +- An application domain with a running thread that cannot immediately stop execution. + +- An application domain that has already been unloaded. + + uses the HRESULT COR_E_CANNOTUNLOADAPPDOMAIN, which has the value 0x80131015. + + For a list of initial property values for an instance of , see the constructors. + ]]> @@ -136,18 +136,18 @@ Initializes a new instance of the class. - property of the new instance to a system-supplied message that describes the error, such as "Attempt to unload the AppDomain failed." This message takes into account the current system culture. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The localized error message string.| - + property of the new instance to a system-supplied message that describes the error, such as "Attempt to unload the AppDomain failed." This message takes into account the current system culture. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The localized error message string.| + ]]> @@ -193,18 +193,18 @@ A that describes the error. Initializes a new instance of the class with a specified error message. - . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The error message string.| - + . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The error message string.| + ]]> @@ -269,11 +269,11 @@ The contextual information about the source or destination. Initializes a new instance of the class from serialized data. - XML and SOAP Serialization @@ -322,18 +322,18 @@ The exception that is the cause of the current exception. If the parameter is not a null reference ( in Visual Basic), the current exception is raised in a block that handles the inner exception. Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception. - property. The property returns the same value that is passed into the constructor, or a null reference (`Nothing` in Visual Basic) if the property does not supply the inner exception value to the constructor. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||The inner exception reference.| -||The error message string.| - + property. The property returns the same value that is passed into the constructor, or a null reference (`Nothing` in Visual Basic) if the property does not supply the inner exception value to the constructor. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||The inner exception reference.| +||The error message string.| + ]]> diff --git a/xml/System/Char.xml b/xml/System/Char.xml index 1088c7d8417..7982e02f9cd 100644 --- a/xml/System/Char.xml +++ b/xml/System/Char.xml @@ -419,25 +419,34 @@ When a managed type, which is represented as a Unicode UTF-16 A object to compare. Compares this instance to a specified object and indicates whether this instance precedes, follows, or appears in the same position in the sort order as the specified object. - A signed number indicating the position of this instance in the sort order in relation to the parameter. - - Return Value - - Description - - Less than zero - - This instance precedes . - - Zero - - This instance has the same position in the sort order as . - - Greater than zero - - This instance follows . - - + A signed number indicating the position of this instance in the sort order in relation to the parameter. + + Return Value + + + Description + + + + + Less than zero + + + This instance precedes . + + + Zero + + + This instance has the same position in the sort order as . + + + Greater than zero + + + This instance follows . + + type, which is represented as a Unicode UTF-16 An object to compare this instance to, or . Compares this instance to a specified object and indicates whether this instance precedes, follows, or appears in the same position in the sort order as the specified . - A signed number indicating the position of this instance in the sort order in relation to the parameter. - - Return Value - - Description - - Less than zero - - This instance precedes . - - Zero - - This instance has the same position in the sort order as . - - Greater than zero - - This instance follows . - - -or- - - is . - - + A signed number indicating the position of this instance in the sort order in relation to the parameter. + + Return Value + + + Description + + + + + Less than zero + + + This instance precedes . + + + Zero + + + This instance has the same position in the sort order as . + + + Greater than zero + + + This instance follows . + +-or- + + is . + + The format to use. - -or- - A reference ( in Visual Basic) to use the default format defined for the type of the implementation. + +-or- + +A reference ( in Visual Basic) to use the default format defined for the type of the implementation. The provider to use to format the value. - -or- - A reference ( in Visual Basic) to obtain the numeric format information from the current locale setting of the operating system. + +-or- + +A reference ( in Visual Basic) to obtain the numeric format information from the current locale setting of the operating system. Formats the value of the current instance using the specified format. The value of the current instance in the specified format. To be added. diff --git a/xml/System/CharEnumerator.xml b/xml/System/CharEnumerator.xml index 7b4300f3383..ffc3e70429d 100644 --- a/xml/System/CharEnumerator.xml +++ b/xml/System/CharEnumerator.xml @@ -72,40 +72,40 @@ Supports iterating over a object and reading its individual characters. This class cannot be inherited. - provides read-only access to the characters in a referenced object. For example, the `foreach` statement of the Microsoft Visual Basic and C# programming languages, which iterates through the elements of a collection, retrieves a from a object in order to iterate through the characters in that object. + provides read-only access to the characters in a referenced object. For example, the `foreach` statement of the Microsoft Visual Basic and C# programming languages, which iterates through the elements of a collection, retrieves a from a object in order to iterate through the characters in that object. > [!IMPORTANT] > The `CharEnumerator` class enumerates individual 16-bit instances. It does not consider graphemes (that is, a character followed by one or more combiding characters) or surrogate pairs (that is, characters outside the Unicode Basic Multilingual Plane) as single characters. For an enumerator that handles these types of characters as a single unit, use the class. - There is no public constructor for . Instead, call a object's method to obtain a that is initialized to reference the string. - - A maintains an internal index to the characters in the string the references. The state of the index is invalid when it references a character position logically before the first character or after the last character in the string, and valid when it references a character within the string. The index is initialized to a position logically before the first character, and is set to a position after the last character when the iteration is complete. An exception is thrown if you attempt to access a character while the index is invalid. - - The method increments the index by one, so the first and subsequent characters are accessed in turn. The method sets the index to a position logically before the first character. The property retrieves the character currently referenced by index. The method creates a copy of the . - + There is no public constructor for . Instead, call a object's method to obtain a that is initialized to reference the string. + + A maintains an internal index to the characters in the string the references. The state of the index is invalid when it references a character position logically before the first character or after the last character in the string, and valid when it references a character within the string. The index is initialized to a position logically before the first character, and is set to a position after the last character when the iteration is complete. An exception is thrown if you attempt to access a character while the index is invalid. + + The method increments the index by one, so the first and subsequent characters are accessed in turn. The method sets the index to a position logically before the first character. The property retrieves the character currently referenced by index. The method creates a copy of the . + > [!NOTE] -> Several independent instances of across one or more threads can have access to a single instance of . This class is implemented to support the interface. For more information regarding the use of an enumerator, see the topic. - - - -## Examples - The following example uses the class to enumerate the individual characters in a string. It instantiates a object by calling the method, moves from one character to the next by calling the method, and displays the current character by retrieving the value of the property. - +> Several independent instances of across one or more threads can have access to a single instance of . This class is implemented to support the interface. For more information regarding the use of an enumerator, see the topic. + + + +## Examples + The following example uses the class to enumerate the individual characters in a string. It instantiates a object by calling the method, moves from one character to the next by calling the method, and displays the current character by retrieving the value of the property. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.CharEnumerator.Class/cpp/charenumerator1.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/CharEnumerator/Overview/CharEnumerator1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.CharEnumerator.Class/fs/CharEnumerator1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.CharEnumerator.Class/vb/CharEnumerator1.vb" id="Snippet1"::: - - Note, however, that the same operation can be performed somewhat more intuitively by using `foreach` (in C#) or `For Each` (in Visual Basic), as the following example shows. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.CharEnumerator.Class/vb/CharEnumerator1.vb" id="Snippet1"::: + + Note, however, that the same operation can be performed somewhat more intuitively by using `foreach` (in C#) or `For Each` (in Visual Basic), as the following example shows. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.CharEnumerator.Class/cpp/charenumerator1.cpp" id="Snippet2"::: :::code language="csharp" source="~/snippets/csharp/System/CharEnumerator/Overview/CharEnumerator1.cs" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.CharEnumerator.Class/fs/CharEnumerator1.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.CharEnumerator.Class/vb/CharEnumerator1.vb" id="Snippet2"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.CharEnumerator.Class/vb/CharEnumerator1.vb" id="Snippet2"::: + ]]> @@ -165,18 +165,18 @@ Creates a copy of the current object. An that is a copy of the current object. - and its current state. This is useful for saving your state while iterating through a object. - - For example, suppose your application uses an original instance of to iterate through each character in a . When some unique character is encountered, your application pauses processing and invokes the method. In effect, this saves the object's index in the . - - Your application uses the clone to navigate to another part of the `String` to perform some auxiliary processing. The side-effect of this navigation is the clone loses track of the position where processing stopped. However, when the auxiliary processing is complete, your application discards the clone and uses the original instance to resume working on the where the original processing stopped. - + and its current state. This is useful for saving your state while iterating through a object. + + For example, suppose your application uses an original instance of to iterate through each character in a . When some unique character is encountered, your application pauses processing and invokes the method. In effect, this saves the object's index in the . + + Your application uses the clone to navigate to another part of the `String` to perform some auxiliary processing. The side-effect of this navigation is the clone loses track of the position where processing stopped. However, when the auxiliary processing is complete, your application discards the clone and uses the original instance to resume working on the where the original processing stopped. + > [!NOTE] -> This method is implemented to support the interface. - +> This method is implemented to support the interface. + ]]> @@ -221,32 +221,32 @@ Gets the currently referenced character in the string enumerated by this object. The Unicode character currently referenced by this object. - class maintains an internal index to the enumerated string, and the property returns the character that is currently referenced by the index. This property should be invoked only when the index is valid; otherwise, an exception is thrown. - - The index is always invalid for an empty string (""). The index is also invalid after the or method is called. After either of these methods is called, invoke the method to adjust the index to the first character in the enumerated string. The index is valid whenever the method returns `true`. - - does not move the index, and consecutive calls to return the same character until , , or is called. - - - -## Examples - The following example uses the class to enumerate the individual characters in a string. It instantiates a object by calling the method, moves from one character to the next by calling the method, and displays the current character by retrieving the value of the property. - + class maintains an internal index to the enumerated string, and the property returns the character that is currently referenced by the index. This property should be invoked only when the index is valid; otherwise, an exception is thrown. + + The index is always invalid for an empty string (""). The index is also invalid after the or method is called. After either of these methods is called, invoke the method to adjust the index to the first character in the enumerated string. The index is valid whenever the method returns `true`. + + does not move the index, and consecutive calls to return the same character until , , or is called. + + + +## Examples + The following example uses the class to enumerate the individual characters in a string. It instantiates a object by calling the method, moves from one character to the next by calling the method, and displays the current character by retrieving the value of the property. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.CharEnumerator.Class/cpp/charenumerator1.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/CharEnumerator/Overview/CharEnumerator1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.CharEnumerator.Class/fs/CharEnumerator1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.CharEnumerator.Class/vb/CharEnumerator1.vb" id="Snippet1"::: - - Note, however, that the same operation can be performed somewhat more intuitively by using `foreach` (in C#) or `For Each` (in Visual Basic), as the following example shows. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.CharEnumerator.Class/vb/CharEnumerator1.vb" id="Snippet1"::: + + Note, however, that the same operation can be performed somewhat more intuitively by using `foreach` (in C#) or `For Each` (in Visual Basic), as the following example shows. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.CharEnumerator.Class/cpp/charenumerator1.cpp" id="Snippet2"::: :::code language="csharp" source="~/snippets/csharp/System/CharEnumerator/Overview/CharEnumerator1.cs" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.CharEnumerator.Class/fs/CharEnumerator1.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.CharEnumerator.Class/vb/CharEnumerator1.vb" id="Snippet2"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.CharEnumerator.Class/vb/CharEnumerator1.vb" id="Snippet2"::: + ]]> The index is invalid; that is, it is before the first or after the last character of the enumerated string. @@ -290,16 +290,16 @@ Releases all resources used by the current instance of the class. - when you are finished using the . The method leaves the in an unusable state. After calling , you must release all references to the so the garbage collector can reclaim the memory that the was occupying. - - For more information, see [Cleaning Up Unmanaged Resources](/dotnet/standard/garbage-collection/unmanaged) and [Implementing a Dispose Method](/dotnet/standard/garbage-collection/implementing-dispose). - + when you are finished using the . The method leaves the in an unusable state. After calling , you must release all references to the so the garbage collector can reclaim the memory that the was occupying. + + For more information, see [Cleaning Up Unmanaged Resources](/dotnet/standard/garbage-collection/unmanaged) and [Implementing a Dispose Method](/dotnet/standard/garbage-collection/implementing-dispose). + > [!NOTE] -> Always call before you release your last reference to the . Otherwise, the resources it is using will not be freed until the garbage collector calls the object's `Finalize` method. - +> Always call before you release your last reference to the . Otherwise, the resources it is using will not be freed until the garbage collector calls the object's `Finalize` method. + ]]> @@ -346,32 +346,32 @@ if the index is successfully incremented and within the enumerated string; otherwise, . - class maintains an internal index to the enumerated string, and the method increments the index by one. Call after calling or to increment the current character position to the first character in the enumerated string. Check that the return value is `true` to determine that the current character position is valid. - - If the index is already beyond the last character of the enumerated string, the index is not changed and `false` is returned. - - Notice that if the enumerated string is empty (""), the state of the is always invalid. This is because the internal index for the is initially before the first character of the enumerated string and is therefore invalid. logically sets the index after the last (nonexistent) character of the enumerated string which is also invalid. - - - -## Examples - The following example uses the class to enumerate the individual characters in a string. It instantiates a object by calling the method, moves from one character to the next by calling the method, and displays the current character by retrieving the value of the property. - + class maintains an internal index to the enumerated string, and the method increments the index by one. Call after calling or to increment the current character position to the first character in the enumerated string. Check that the return value is `true` to determine that the current character position is valid. + + If the index is already beyond the last character of the enumerated string, the index is not changed and `false` is returned. + + Notice that if the enumerated string is empty (""), the state of the is always invalid. This is because the internal index for the is initially before the first character of the enumerated string and is therefore invalid. logically sets the index after the last (nonexistent) character of the enumerated string which is also invalid. + + + +## Examples + The following example uses the class to enumerate the individual characters in a string. It instantiates a object by calling the method, moves from one character to the next by calling the method, and displays the current character by retrieving the value of the property. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.CharEnumerator.Class/cpp/charenumerator1.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/CharEnumerator/Overview/CharEnumerator1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.CharEnumerator.Class/fs/CharEnumerator1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.CharEnumerator.Class/vb/CharEnumerator1.vb" id="Snippet1"::: - - Note, however, that the same operation can be performed somewhat more intuitively by using `foreach` (in C#) or `For Each` (in Visual Basic), as the following example shows. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.CharEnumerator.Class/vb/CharEnumerator1.vb" id="Snippet1"::: + + Note, however, that the same operation can be performed somewhat more intuitively by using `foreach` (in C#) or `For Each` (in Visual Basic), as the following example shows. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.CharEnumerator.Class/cpp/charenumerator1.cpp" id="Snippet2"::: :::code language="csharp" source="~/snippets/csharp/System/CharEnumerator/Overview/CharEnumerator1.cs" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.CharEnumerator.Class/fs/CharEnumerator1.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.CharEnumerator.Class/vb/CharEnumerator1.vb" id="Snippet2"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.CharEnumerator.Class/vb/CharEnumerator1.vb" id="Snippet2"::: + ]]> @@ -416,11 +416,11 @@ Initializes the index to a position logically before the first character of the enumerated string. - class maintains an internal index to the enumerated string, and the method sets the index to the invalid state. - + class maintains an internal index to the enumerated string, and the method sets the index to the invalid state. + ]]> @@ -472,18 +472,18 @@ Gets the currently referenced character in the string enumerated by this object. For a description of this member, see . The boxed Unicode character currently referenced by this object. - instance is cast to an interface. - + instance is cast to an interface. + ]]> - Enumeration has not started. - - -or- - - Enumeration has ended. + Enumeration has not started. + + -or- + + Enumeration has ended. @@ -516,7 +516,7 @@ class. The method leaves the class in an unusable state. After calling it, you must release all references to the class so the garbage collector can reclaim the memory that the class was occupying. For more information, see [Cleaning Up Unmanaged Resources](/dotnet/standard/garbage-collection/unmanaged) and [Implementing a Dispose Method](/dotnet/standard/garbage-collection/implementing-dispose). diff --git a/xml/System/Comparison`1.xml b/xml/System/Comparison`1.xml index a12c258054d..768b66b1cba 100644 --- a/xml/System/Comparison`1.xml +++ b/xml/System/Comparison`1.xml @@ -68,47 +68,56 @@ The first object to compare. The second object to compare. Represents the method that compares two objects of the same type. - A signed integer that indicates the relative values of and , as shown in the following table. - - Value - - Meaning - - Less than 0 - - is less than . - - 0 - - equals . - - Greater than 0 - - is greater than . - - + A signed integer that indicates the relative values of and , as shown in the following table. + + Value + + + Meaning + + + + + Less than 0 + + + is less than . + + + 0 + + + equals . + + + Greater than 0 + + + is greater than . + + - method overload of the class and the method overload of the class to sort the elements of an array or list. - - - -## Examples - The following code example demonstrates the use of the delegate with the method overload. - - The code example defines an alternative comparison method for strings, named `CompareDinosByLength`. This method works as follows: First, the comparands are tested for `null`, and a null reference is treated as less than a non-null. Second, the string lengths are compared, and the longer string is deemed to be greater. Third, if the lengths are equal, ordinary string comparison is used. - - A of strings is created and populated with four strings, in no particular order. The list also includes an empty string and a null reference. The list is displayed, sorted using a generic delegate representing the `CompareDinosByLength` method, and displayed again. - + method overload of the class and the method overload of the class to sort the elements of an array or list. + + + +## Examples + The following code example demonstrates the use of the delegate with the method overload. + + The code example defines an alternative comparison method for strings, named `CompareDinosByLength`. This method works as follows: First, the comparands are tested for `null`, and a null reference is treated as less than a non-null. Second, the string lengths are compared, and the longer string is deemed to be greater. Third, if the lengths are equal, ordinary string comparison is used. + + A of strings is created and populated with four strings, in no particular order. The list also includes an empty string and a null reference. The list is displayed, sorted using a generic delegate representing the `CompareDinosByLength` method, and displayed again. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/List`1_SortComparison/cpp/source.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/ComparisonT/Overview/source.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR/List`1_SortComparison/fs/source.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/List`1_SortComparison/vb/source.vb" id="Snippet1"::: - The following example uses the delegate to sort the elements of a collection of `CityInfo` objects. `CityInfo` is an application-defined class that contains information about a city and its population. The example defines three methods, `CompareByName`, `CompareByPopulation`, and `CompareByNames`, that offer three different ways of ordering the `CityInfo` objects. Each method is assigned to the `comparison` argument of the method. - + The following example uses the delegate to sort the elements of a collection of `CityInfo` objects. `CityInfo` is an application-defined class that contains information about a city and its population. The example defines three methods, `CompareByName`, `CompareByPopulation`, and `CompareByNames`, that offer three different ways of ordering the `CityInfo` objects. Each method is assigned to the `comparison` argument of the method. + :::code language="csharp" source="~/snippets/csharp/System/ComparisonT/Overview/comparisont1.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.comparison`1/fs/comparisont1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.comparison`1/vb/comparisont1.vb" id="Snippet1"::: diff --git a/xml/System/Console.xml b/xml/System/Console.xml index d0c42df1481..fba2ae4ba27 100644 --- a/xml/System/Console.xml +++ b/xml/System/Console.xml @@ -459,9 +459,9 @@ is less than 37 or more than 32767 hertz. - -or- +-or- - is less than or equal to zero. + is less than or equal to zero.
This method was executed on a server, such as SQL Server, that does not permit access to the console. The current operating system is not Windows. @@ -553,13 +553,13 @@
The value in a set operation is less than or equal to zero. - -or- +-or- - The value in a set operation is greater than or equal to Int16.MaxValue. +The value in a set operation is greater than or equal to Int16.MaxValue. - -or- +-or- - The value in a set operation is less than + . +The value in a set operation is less than + . The user does not have permission to perform this action. An I/O error occurred. The set operation is invoked on an operating system other than Windows. @@ -651,13 +651,13 @@
The value in a set operation is less than or equal to zero. - -or- +-or- - The value in a set operation is greater than or equal to Int16.MaxValue. +The value in a set operation is greater than or equal to Int16.MaxValue. - -or- +-or- - The value in a set operation is less than + . +The value in a set operation is less than + . The user does not have permission to perform this action. An I/O error occurred. The set operation is invoked on an operating system other than Windows. @@ -985,9 +985,9 @@
The value in a set operation is less than zero. - -or- +-or- - The value in a set operation is greater than or equal to . +The value in a set operation is greater than or equal to . The user does not have permission to perform this action. An I/O error occurred. @@ -1159,9 +1159,9 @@
The value in a set operation is less than zero. - -or- +-or- - The value in a set operation is greater than or equal to . +The value in a set operation is greater than or equal to . The user does not have permission to perform this action. An I/O error occurred. @@ -2073,21 +2073,21 @@ Columns are numbered from left to right starting at 0. Rows are numbered from to
One or more of the parameters is less than zero. - -or- +-or- - or is greater than or equal to . + or is greater than or equal to . - -or- +-or- - or is greater than or equal to . + or is greater than or equal to . - -or- +-or- - + is greater than or equal to . + + is greater than or equal to . - -or- +-or- - + is greater than or equal to . + + is greater than or equal to . The user does not have permission to perform this action. An I/O error occurred. The current operating system is not Windows. @@ -2172,21 +2172,21 @@ Columns are numbered from left to right starting at 0. Rows are numbered from to One or more of the parameters is less than zero. - -or- +-or- - or is greater than or equal to . + or is greater than or equal to . - -or- +-or- - or is greater than or equal to . + or is greater than or equal to . - -or- +-or- - + is greater than or equal to . + + is greater than or equal to . - -or- +-or- - + is greater than or equal to . + + is greater than or equal to . One or both of the color parameters is not a member of the enumeration. The user does not have permission to perform this action. An I/O error occurred. @@ -2801,15 +2801,7 @@ This method can be used to reacquire the standard output stream after it has bee An error occurred during the execution of this operation. Your application does not have permission to perform this operation. - Of the Unicode encodings, the class supports UTF-8 encoding with the class and, starting with the .NET Framework 4.5, it supports UTF-16 encoding with the class. UTF-32 encoding with the class is not supported. Attempting to set the output encoding to UTF-32 throws an . - - Note that successfully displaying Unicode characters to the console requires the following: - -- The console must use a TrueType font, such as Lucida Console or Consolas, to display characters. - -- A font used by the console must define the particular glyph or glyphs to be displayed. The console can take advantage of font linking to display glyphs from linked fonts if the base font does not contain a definition for that glyph. - - For more information about support for Unicode encoding by the console, see the "Unicode Support for the Console" section in the class. + Of the Unicode encodings, the class supports UTF-8 encoding with the class and, starting with the .NET Framework 4.5, it supports UTF-16 encoding with the class. UTF-32 encoding with the class is not supported. Attempting to set the output encoding to UTF-32 throws an . Note that successfully displaying Unicode characters to the console requires the following: - The console must use a TrueType font, such as Lucida Console or Consolas, to display characters. - A font used by the console must define the particular glyph or glyphs to be displayed. The console can take advantage of font linking to display glyphs from linked fonts if the base font does not contain a definition for that glyph. For more information about support for Unicode encoding by the console, see the "Unicode Support for the Console" section in the class. @@ -3359,17 +3351,17 @@ This method can be used to reacquire the standard output stream after it has bee or is less than or equal to zero. - -or- +-or- - or is greater than or equal to Int16.MaxValue. + or is greater than or equal to Int16.MaxValue. - -or- +-or- - is less than + . + is less than + . - -or- +-or- - is less than + . + is less than + . The user does not have permission to perform this action. An I/O error occurred. The current operating system is not Windows. @@ -3461,13 +3453,13 @@ This method can be used to reacquire the standard output stream after it has bee or is less than zero. - -or- +-or- - is greater than or equal to . + is greater than or equal to . - -or- +-or- - is greater than or equal to . + is greater than or equal to . The user does not have permission to perform this action. An I/O error occurred. @@ -3760,7 +3752,7 @@ This method can be used to reacquire the standard output stream after it has bee - The column position of the upper left corner of the console window. + The column position of the upper left corner of the console window. The row position of the upper left corner of the console window. Sets the position of the console window relative to the screen buffer. @@ -3786,13 +3778,13 @@ This method can be used to reacquire the standard output stream after it has bee or is less than zero. - -or- +-or- - + is greater than . + + is greater than . - -or- +-or- - + is greater than . + + is greater than . The user does not have permission to perform this action. An I/O error occurred. The current operating system is not Windows. @@ -3883,13 +3875,13 @@ This method can be used to reacquire the standard output stream after it has bee or is less than or equal to zero. - -or- +-or- - plus or plus is greater than or equal to Int16.MaxValue. + plus or plus is greater than or equal to Int16.MaxValue. - -or- +-or- - or is greater than the largest possible window width or height for the current screen resolution and console font. + or is greater than the largest possible window width or height for the current screen resolution and console font. The user does not have permission to perform this action. An I/O error occurred. The current operating system is not Windows. @@ -4175,13 +4167,13 @@ This method can be used to reacquire the standard output stream after it has bee The value of the property or the value of the property is less than or equal to 0. - -or- +-or- - The value of the property plus the value of the property is greater than or equal to Int16.MaxValue. +The value of the property plus the value of the property is greater than or equal to Int16.MaxValue. - -or- +-or- - The value of the property or the value of the property is greater than the largest possible window width or height for the current screen resolution and console font. +The value of the property or the value of the property is greater than the largest possible window width or height for the current screen resolution and console font. Error reading or writing information. The set operation is invoked on an operating system other than Windows. @@ -4262,9 +4254,9 @@ This method can be used to reacquire the standard output stream after it has bee In a set operation, the value to be assigned is less than zero. - -or- +-or- - As a result of the assignment, plus would exceed . +As a result of the assignment, plus would exceed . Error reading or writing information. The set operation is invoked on an operating system other than Windows. @@ -4341,9 +4333,9 @@ This method can be used to reacquire the standard output stream after it has bee In a set operation, the value to be assigned is less than zero. - -or- +-or- - As a result of the assignment, plus would exceed . +As a result of the assignment, plus would exceed . Error reading or writing information. The set operation is invoked on an operating system other than Windows. @@ -4452,13 +4444,13 @@ This method can be used to reacquire the standard output stream after it has bee The value of the property or the value of the property is less than or equal to 0. - -or- +-or- - The value of the property plus the value of the property is greater than or equal to Int16.MaxValue. +The value of the property plus the value of the property is greater than or equal to Int16.MaxValue. - -or- +-or- - The value of the property or the value of the property is greater than the largest possible window width or height for the current screen resolution and console font. +The value of the property or the value of the property is greater than the largest possible window width or height for the current screen resolution and console font. Error reading or writing information. The set operation is invoked on an operating system other than Windows. diff --git a/xml/System/ConsoleCancelEventHandler.xml b/xml/System/ConsoleCancelEventHandler.xml index 0f978f38afa..867f8b3cc2e 100644 --- a/xml/System/ConsoleCancelEventHandler.xml +++ b/xml/System/ConsoleCancelEventHandler.xml @@ -56,21 +56,21 @@ A object that contains the event data. Represents the method that will handle the event of a . - delegate, you identify the method that will handle the event. To associate the event with your event handler, add an instance of the delegate to the event. The event handler is called whenever the event occurs, unless you remove the delegate. For more information about event-handler delegates, see [Handling and Raising Events](/dotnet/standard/events/). - - - -## Examples - The following code example demonstrates how to use the class to handle an event. - + delegate, you identify the method that will handle the event. To associate the event with your event handler, add an instance of the delegate to the event. The event handler is called whenever the event occurs, unless you remove the delegate. For more information about event-handler delegates, see [Handling and Raising Events](/dotnet/standard/events/). + + + +## Examples + The following code example demonstrates how to use the class to handle an event. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/console.cancelkeypress/cpp/ckp.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Console/CancelKeyPress/ckp.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR/console.cancelkeypress/fs/ckp.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/console.cancelkeypress/vb/ckp.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/console.cancelkeypress/vb/ckp.vb" id="Snippet1"::: + ]]> diff --git a/xml/System/ConsoleColor.xml b/xml/System/ConsoleColor.xml index 7fb421b94d6..c956f83526f 100644 --- a/xml/System/ConsoleColor.xml +++ b/xml/System/ConsoleColor.xml @@ -46,15 +46,15 @@ Specifies constants that define foreground and background colors for the console. - enumeration to an array and stores the current values of the and properties to variables. It then changes the foreground color to each color in the enumeration except to the color that matches the current background, and it changes the background color to each color in the enumeration except to the color that matches the current foreground. (If the foreground color is the same as the background color, the text isn't visible.) Finally, it calls the method to restore the original console colors. - + enumeration to an array and stores the current values of the and properties to variables. It then changes the foreground color to each color in the enumeration except to the color that matches the current background, and it changes the background color to each color in the enumeration except to the color that matches the current foreground. (If the foreground color is the same as the background color, the text isn't visible.) Finally, it calls the method to restore the original console colors. + :::code language="csharp" source="~/snippets/csharp/System/Console/BackgroundColor/foregroundcolor3.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.consolecolor/fs/foregroundcolor3.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.consolecolor/vb/foregroundcolor3.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.consolecolor/vb/foregroundcolor3.vb" id="Snippet1"::: + ]]> diff --git a/xml/System/ConsoleKey.xml b/xml/System/ConsoleKey.xml index b82a1fe6d95..8aa385667a2 100644 --- a/xml/System/ConsoleKey.xml +++ b/xml/System/ConsoleKey.xml @@ -46,21 +46,21 @@ Specifies the standard keys on a console. - enumeration is typically used in the nfo structure, which is returned by the method to indicate which key on the console has been pressed. - - - -## Examples - The following example uses the enumeration to indicate to the user which key the user had pressed. - + enumeration is typically used in the nfo structure, which is returned by the method to indicate which key on the console has been pressed. + + + +## Examples + The following example uses the enumeration to indicate to the user which key the user had pressed. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.ConsoleKey/cpp/consolekey.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/ConsoleKey/Overview/ConsoleKey1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.ConsoleKey/fs/ConsoleKey1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.ConsoleKey/vb/ConsoleKey1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.ConsoleKey/vb/ConsoleKey1.vb" id="Snippet1"::: + ]]> diff --git a/xml/System/ConsoleKeyInfo.xml b/xml/System/ConsoleKeyInfo.xml index 2e426b87948..1c5c874523d 100644 --- a/xml/System/ConsoleKeyInfo.xml +++ b/xml/System/ConsoleKeyInfo.xml @@ -60,23 +60,23 @@ Describes the console key that was pressed, including the character represented by the console key and the state of the SHIFT, ALT, and CTRL modifier keys. - type is not intended to be created by users. Instead, it is returned to the user in response to calling the method. - - The object describes the constant and Unicode character, if any, that correspond to the pressed console key. The object also describes, in a bitwise combination of values, whether one or more SHIFT, ALT, or CTRL modifier keys was pressed simultaneously with the console key. - - - -## Examples - The following example demonstrates using a object in a read operation. - + type is not intended to be created by users. Instead, it is returned to the user in response to calling the method. + + The object describes the constant and Unicode character, if any, that correspond to the pressed console key. The object also describes, in a bitwise combination of values, whether one or more SHIFT, ALT, or CTRL modifier keys was pressed simultaneously with the console key. + + + +## Examples + The following example demonstrates using a object in a read operation. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/console.readkey1/CPP/rk.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Console/ReadKey/rk.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR/console.readkey1/FS/rk.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/console.readkey1/VB/rk.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/console.readkey1/VB/rk.vb" id="Snippet1"::: + ]]> @@ -131,13 +131,13 @@ to indicate that a CTRL key was pressed; otherwise, . Initializes a new instance of the structure using the specified character, console key, and modifier keys. - method. - - The type does not specify whether the left or right SHIFT, ALT, or CTRL modifier key was pressed. - + method. + + The type does not specify whether the left or right SHIFT, ALT, or CTRL modifier key was pressed. + ]]> The numeric value of the parameter is less than 0 or greater than 255. @@ -200,13 +200,13 @@ if is equal to the current object; otherwise, . - objects are equal if their corresponding , , and properties are equal. - - The method performs slightly better than the method because it does not have to convert `obj` to an object. - + objects are equal if their corresponding , , and properties are equal. + + The method performs slightly better than the method because it does not have to convert `obj` to an object. + ]]> @@ -267,21 +267,21 @@ if is a object and is equal to the current object; otherwise, . - objects are equal if their corresponding , , and properties are equal. - - - -## Examples - The following example demonstrates the method. - + objects are equal if their corresponding , , and properties are equal. + + + +## Examples + The following example demonstrates the method. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.ConsoleKeyInfo.Equals/cpp/consolekeyinfo.equals.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/ConsoleKeyInfo/Equals/equals.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.ConsoleKeyInfo.Equals/fs/equals.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.ConsoleKeyInfo.Equals/vb/equals.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.ConsoleKeyInfo.Equals/vb/equals.vb" id="Snippet1"::: + ]]> @@ -324,21 +324,21 @@ Returns the hash code for the current object. A 32-bit signed integer hash code. - method is not suitable for distinguishing one object from another. If your application needs a unique hash code, override the method with your own method. - - - -## Examples - The following example demonstrates the method. - + method is not suitable for distinguishing one object from another. If your application needs a unique hash code, override the method with your own method. + + + +## Examples + The following example demonstrates the method. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.ConsoleKeyInfo.GetHashcode/cpp/hash.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/ConsoleKeyInfo/GetHashCode/hash.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.ConsoleKeyInfo.GetHashcode/fs/hash.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.ConsoleKeyInfo.GetHashcode/vb/hash.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.ConsoleKeyInfo.GetHashcode/vb/hash.vb" id="Snippet1"::: + ]]> @@ -380,16 +380,16 @@ Gets the console key represented by the current object. A value that identifies the console key that was pressed. - property in a read operation. - + property in a read operation. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/console.readkey1/CPP/rk.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Console/ReadKey/rk.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR/console.readkey1/FS/rk.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/console.readkey1/VB/rk.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/console.readkey1/VB/rk.vb" id="Snippet1"::: + ]]> @@ -431,20 +431,20 @@ Gets the Unicode character represented by the current object. An object that corresponds to the console key represented by the current object. - property is \U0000. - - - -## Examples - The following example uses the property to add the characters input by the user into a string. The example ignores special keys other than **ENTER**, **ESC**, and **BACKSPACE**. - + property is \U0000. + + + +## Examples + The following example uses the property to add the characters input by the user into a string. The example ignores special keys other than **ENTER**, **ESC**, and **BACKSPACE**. + :::code language="csharp" source="~/snippets/csharp/System/ConsoleKeyInfo/KeyChar/keychar1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.consolekeyinfo.keychar/fs/keychar1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.consolekeyinfo.keychar/vb/keychar1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.consolekeyinfo.keychar/vb/keychar1.vb" id="Snippet1"::: + ]]> @@ -486,16 +486,16 @@ Gets a bitwise combination of values that specifies one or more modifier keys pressed simultaneously with the console key. A bitwise combination of the enumeration values. There is no default value. - property in a read operation. - + property in a read operation. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/console.readkey1/CPP/rk.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Console/ReadKey/rk.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR/console.readkey1/FS/rk.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/console.readkey1/VB/rk.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/console.readkey1/VB/rk.vb" id="Snippet1"::: + ]]> @@ -544,11 +544,11 @@ if is equal to ; otherwise, . - objects are equal if their corresponding , , and properties are equal. - + objects are equal if their corresponding , , and properties are equal. + The equivalent method for this operator is .]]> @@ -597,11 +597,11 @@ if is not equal to ; otherwise, . - objects are equal if their corresponding , , and properties are equal. - + objects are equal if their corresponding , , and properties are equal. + ]]> diff --git a/xml/System/ConsoleModifiers.xml b/xml/System/ConsoleModifiers.xml index a84a356b860..49ea3ddde2f 100644 --- a/xml/System/ConsoleModifiers.xml +++ b/xml/System/ConsoleModifiers.xml @@ -50,23 +50,23 @@ Represents the SHIFT, ALT, and CTRL modifier keys on a keyboard. - enumeration is used in conjunction with the type. - - - -## Examples - The following code example reads a key and determines whether one or more modifier keys was pressed. - + enumeration is used in conjunction with the type. + + + +## Examples + The following code example reads a key and determines whether one or more modifier keys was pressed. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/console.readkey1/CPP/rk.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Console/ReadKey/rk.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR/console.readkey1/FS/rk.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/console.readkey1/VB/rk.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/console.readkey1/VB/rk.vb" id="Snippet1"::: + ]]> diff --git a/xml/System/ConsoleSpecialKey.xml b/xml/System/ConsoleSpecialKey.xml index cab65915aac..a77ee3f22da 100644 --- a/xml/System/ConsoleSpecialKey.xml +++ b/xml/System/ConsoleSpecialKey.xml @@ -46,23 +46,23 @@ Specifies combinations of modifier and console keys that can interrupt the current process. - property returns the enumeration type. - - Simultaneously pressing certain key combinations signals the operating system to interrupt the currently running process. The two valid key combinations are plus BREAK (CTRL+BREAK) and plus (CTRL+C). - - - -## Examples - The following code example displays the value that invokes the associated event handler. - + property returns the enumeration type. + + Simultaneously pressing certain key combinations signals the operating system to interrupt the currently running process. The two valid key combinations are plus BREAK (CTRL+BREAK) and plus (CTRL+C). + + + +## Examples + The following code example displays the value that invokes the associated event handler. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/console.cancelkeypress/cpp/ckp.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Console/CancelKeyPress/ckp.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR/console.cancelkeypress/fs/ckp.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/console.cancelkeypress/vb/ckp.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/console.cancelkeypress/vb/ckp.vb" id="Snippet1"::: + ]]> diff --git a/xml/System/ContextBoundObject.xml b/xml/System/ContextBoundObject.xml index d84842ac721..e68e81a62d9 100644 --- a/xml/System/ContextBoundObject.xml +++ b/xml/System/ContextBoundObject.xml @@ -58,13 +58,13 @@ Defines the base class for all context-bound classes. - that provides the usage rules. The context properties that can be added include policies regarding synchronization and transactions. - + that provides the usage rules. The context properties that can be added include policies regarding synchronization and transactions. + ]]> diff --git a/xml/System/ContextMarshalException.xml b/xml/System/ContextMarshalException.xml index 544682abfbc..87093a5acd0 100644 --- a/xml/System/ContextMarshalException.xml +++ b/xml/System/ContextMarshalException.xml @@ -70,17 +70,17 @@ The exception that is thrown when an attempt to marshal an object across a context boundary fails. - . - - uses the HRESULT COR_E_CONTEXTMARSHAL which has the value 0x80131504L. - - uses the default implementation, which supports reference equality. - - For a list of initial property values for an instance of , see the constructors. - + . + + uses the HRESULT COR_E_CONTEXTMARSHAL which has the value 0x80131504L. + + uses the default implementation, which supports reference equality. + + For a list of initial property values for an instance of , see the constructors. + ]]> @@ -133,16 +133,16 @@ Initializes a new instance of the class with default properties. - . - -|Property|Value| -|--------------|-----------| -||`null`.| -||The empty string ("").| - + . + +|Property|Value| +|--------------|-----------| +||`null`.| +||The empty string ("").| + ]]> @@ -188,16 +188,16 @@ The error message that explains the reason for the exception. Initializes a new instance of the class with a specified error message. - . - -|Property|Value| -|--------------|-----------| -||`null`.| -||The error message string.| - + . + +|Property|Value| +|--------------|-----------| +||`null`.| +||The error message string.| + ]]> @@ -307,18 +307,18 @@ The exception that is the cause of the current exception. If the parameter is not , the current exception is raised in a block that handles the inner exception. Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception. - property. The property returns the same value that is passed into the constructor, or `null` if the property does not supply the inner exception value to the constructor. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||The inner exception reference.| -||The error message string.| - + property. The property returns the same value that is passed into the constructor, or `null` if the property does not supply the inner exception value to the constructor. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||The inner exception reference.| +||The error message string.| + ]]> diff --git a/xml/System/ContextStaticAttribute.xml b/xml/System/ContextStaticAttribute.xml index ca78e53a975..ebfb8d7fbee 100644 --- a/xml/System/ContextStaticAttribute.xml +++ b/xml/System/ContextStaticAttribute.xml @@ -62,19 +62,19 @@ Indicates that the value of a static field is unique for a particular context. - diff --git a/xml/System/Convert.xml b/xml/System/Convert.xml index db5a8492120..81d29b878c2 100644 --- a/xml/System/Convert.xml +++ b/xml/System/Convert.xml @@ -284,9 +284,9 @@ Returns an object of the specified type and whose value is equivalent to the specified object. An object whose type is and whose value is equivalent to . - -or- +-or- - A null reference ( in Visual Basic), if is and is not a value type. +A null reference ( in Visual Basic), if is and is not a value type. This conversion is not supported. - -or- +-or- - is and is a value type. + is and is a value type. - -or- +-or- - does not implement the interface. + does not implement the interface. is not in a format recognized by . @@ -323,17 +323,7 @@ is . - The method can convert an enumeration value to another type. However, it cannot convert another type to an enumeration value, even if the source type is the underlying type of the enumeration. To convert a type to an enumeration value, use a casting operator (in C#) or a conversion function (in Visual Basic). The following example illustrates the conversion to and from a Continent enumeration value. - - :::code language="csharp" source="~/snippets/csharp/System/Convert/ChangeType/changetype_enum2.cs" interactive="try-dotnet" id="Snippet5"::: - :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ChangeType/changetype_enum2.fs" id="Snippet5"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.changetype/vb/changetype_enum2.vb" id="Snippet5"::: - - The method can convert a nullable type to another type. However, it cannot convert another type to a value of a nullable type, even if is the underlying type of the .To perform the conversion, you can use a casting operator (in C#) or a conversion function (in Visual Basic). The following example illustrates the conversion to and from a nullable type. - - :::code language="csharp" source="~/snippets/csharp/System/Convert/ChangeType/changetype_nullable.cs" interactive="try-dotnet" id="Snippet7"::: - :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ChangeType/changetype_nullable.fs" id="Snippet7"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.changetype/vb/changetype_nullable.vb" id="Snippet7"::: + The method can convert an enumeration value to another type. However, it cannot convert another type to an enumeration value, even if the source type is the underlying type of the enumeration. To convert a type to an enumeration value, use a casting operator (in C#) or a conversion function (in Visual Basic). The following example illustrates the conversion to and from a Continent enumeration value. :::code language="csharp" source="~/snippets/csharp/System/Convert/ChangeType/changetype_enum2.cs" interactive="try-dotnet" id="Snippet5"::: :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ChangeType/changetype_enum2.fs" id="Snippet5"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.changetype/vb/changetype_enum2.vb" id="Snippet5"::: The method can convert a nullable type to another type. However, it cannot convert another type to a value of a nullable type, even if is the underlying type of the .To perform the conversion, you can use a casting operator (in C#) or a conversion function (in Visual Basic). The following example illustrates the conversion to and from a nullable type. :::code language="csharp" source="~/snippets/csharp/System/Convert/ChangeType/changetype_nullable.cs" interactive="try-dotnet" id="Snippet7"::: :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ChangeType/changetype_nullable.fs" id="Snippet7"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.changetype/vb/changetype_nullable.vb" id="Snippet7"::: @@ -390,9 +380,9 @@ Returns an object of the specified type whose value is equivalent to the specified object. An object whose underlying type is and whose value is equivalent to . - -or- +-or- - A null reference ( in Visual Basic), if is and is , , or . +A null reference ( in Visual Basic), if is and is , , or . This conversion is not supported. - -or- +-or- - is and specifies a value type. + is and specifies a value type. - -or- +-or- - does not implement the interface. + does not implement the interface. is not in a format recognized by the type. @@ -489,13 +479,13 @@ Returns an object of the specified type whose value is equivalent to the specified object. A parameter supplies culture-specific formatting information. An object whose type is and whose value is equivalent to . - -or- +-or- - , if the of and are equal. +, if the of and are equal. - -or- +-or- - A null reference ( in Visual Basic), if is and is not a value type. +A null reference ( in Visual Basic), if is and is not a value type. This conversion is not supported. - -or- +-or- - is and is a value type. + is and is a value type. - -or- +-or- - does not implement the interface. + does not implement the interface. is not in a format for recognized by . @@ -543,17 +533,7 @@ is . - The method can convert an enumeration value to another type. However, it cannot convert another type to an enumeration value, even if the source type is the underlying type of the enumeration. To convert a type to an enumeration value, use a casting operator (in C#) or a conversion function (in Visual Basic). The following example illustrates the conversion to and from a Continent enumeration value. - - :::code language="csharp" source="~/snippets/csharp/System/Convert/ChangeType/changetype_enum2.cs" interactive="try-dotnet" id="Snippet5"::: - :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ChangeType/changetype_enum2.fs" id="Snippet5"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.changetype/vb/changetype_enum2.vb" id="Snippet5"::: - - The method can convert a nullable type to another type. However, it cannot convert another type to a value of a nullable type, even if is the underlying type of the . To perform the conversion, you can use a casting operator (in C#) or a conversion function (in Visual Basic). The following example illustrates the conversion to and from a nullable type. - - :::code language="csharp" source="~/snippets/csharp/System/Convert/ChangeType/changetype_nullable_1.cs" interactive="try-dotnet" id="Snippet8"::: - :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ChangeType/changetype_nullable_1.fs" id="Snippet8"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.changetype/vb/changetype_nullable_1.vb" id="Snippet8"::: + The method can convert an enumeration value to another type. However, it cannot convert another type to an enumeration value, even if the source type is the underlying type of the enumeration. To convert a type to an enumeration value, use a casting operator (in C#) or a conversion function (in Visual Basic). The following example illustrates the conversion to and from a Continent enumeration value. :::code language="csharp" source="~/snippets/csharp/System/Convert/ChangeType/changetype_enum2.cs" interactive="try-dotnet" id="Snippet5"::: :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ChangeType/changetype_enum2.fs" id="Snippet5"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.changetype/vb/changetype_enum2.vb" id="Snippet5"::: The method can convert a nullable type to another type. However, it cannot convert another type to a value of a nullable type, even if is the underlying type of the . To perform the conversion, you can use a casting operator (in C#) or a conversion function (in Visual Basic). The following example illustrates the conversion to and from a nullable type. :::code language="csharp" source="~/snippets/csharp/System/Convert/ChangeType/changetype_nullable_1.cs" interactive="try-dotnet" id="Snippet8"::: :::code language="fsharp" source="~/snippets/fsharp/System/Convert/ChangeType/changetype_nullable_1.fs" id="Snippet8"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.convert.changetype/vb/changetype_nullable_1.vb" id="Snippet8"::: @@ -608,9 +588,9 @@ Returns an object of the specified type whose value is equivalent to the specified object. A parameter supplies culture-specific formatting information. An object whose underlying type is and whose value is equivalent to . - -or- +-or- - A null reference ( in Visual Basic), if is and is , , or . +A null reference ( in Visual Basic), if is and is , , or . This conversion is not supported. - -or- +-or- - is and specifies a value type. + is and specifies a value type. - -or- +-or- - does not implement the interface. + does not implement the interface. is not in a format for the type recognized by . @@ -813,14 +793,14 @@ or is less than 0. - -or- +-or- - plus indicates a position not within . + plus indicates a position not within . The length of , ignoring white-space characters, is not zero or a multiple of 4. - -or- +-or- - The format of is invalid. contains a non-base-64 character, more than two padding characters, or a non-white-space character among the padding characters. +The format of is invalid. contains a non-base-64 character, more than two padding characters, or a non-white-space character among the padding characters. @@ -915,9 +895,9 @@ is . The length of , ignoring white-space characters, is not zero or a multiple of 4. - -or- +-or- - The format of is invalid. contains a non-base-64 character, more than two padding characters, or a non-white space-character among the padding characters. +The format of is invalid. contains a non-base-64 character, more than two padding characters, or a non-white space-character among the padding characters. @@ -1246,13 +1226,13 @@ , , or is negative. - -or- +-or- - plus is greater than the length of . + plus is greater than the length of . - -or- +-or- - plus the number of elements to return is greater than the length of . + plus the number of elements to return is greater than the length of . @@ -1358,13 +1338,13 @@ , , or is negative. - -or- +-or- - plus is greater than the length of . + plus is greater than the length of . - -or- +-or- - plus the number of elements to return is greater than the length of . + plus the number of elements to return is greater than the length of . is not a valid value. @@ -1688,9 +1668,9 @@ or is negative. - -or- +-or- - plus is greater than the length of . + plus is greater than the length of . @@ -1792,9 +1772,9 @@ or is negative. - -or- +-or- - plus is greater than the length of . + plus is greater than the length of . is not a valid value. @@ -2422,9 +2402,9 @@ does not implement the interface. - -or- +-or- - The conversion of to a is not supported. +The conversion of to a is not supported. @@ -2927,9 +2907,9 @@ does not implement the interface. - -or- +-or- - The conversion of to a is not supported. +The conversion of to a is not supported. @@ -3621,9 +3601,9 @@ does not implement . - -or- +-or- - Conversion from to the type is not supported. +Conversion from to the type is not supported. represents a number that is less than Byte.MinValue or greater than Byte.MaxValue. @@ -4113,9 +4093,9 @@ does not implement . - -or- +-or- - Conversion from to the type is not supported. +Conversion from to the type is not supported. represents a number that is less than Byte.MinValue or greater than Byte.MaxValue. @@ -4276,9 +4256,9 @@ is not 2, 8, 10, or 16. - -or- +-or- - , which represents a non-base 10 unsigned number, is prefixed with a negative sign. +, which represents a non-base 10 unsigned number, is prefixed with a negative sign. is . @@ -4286,9 +4266,9 @@ , which represents a base 10 unsigned number, is prefixed with a negative sign. - -or- +-or- - represents a number that is less than Byte.MinValue or greater than Byte.MaxValue. + represents a number that is less than Byte.MinValue or greater than Byte.MaxValue. @@ -4864,9 +4844,9 @@ does not implement the interface. - -or- +-or- - The conversion of to a is not supported. +The conversion of to a is not supported. is less than Char.MinValue or greater than Char.MaxValue. @@ -5338,9 +5318,9 @@ does not implement the interface. - -or- +-or- - The conversion of to a is not supported. +The conversion of to a is not supported. is less than Char.MinValue or greater than Char.MaxValue. @@ -5943,9 +5923,9 @@ does not implement the interface. - -or- +-or- - The conversion is not supported. +The conversion is not supported. @@ -6357,9 +6337,9 @@ does not implement the interface. - -or- +-or- - The conversion is not supported. +The conversion is not supported. Parsing Date and Time Strings in .NET @@ -7057,9 +7037,9 @@ does not implement the interface. - -or- +-or- - The conversion is not supported. +The conversion is not supported. represents a number that is less than Decimal.MinValue or greater than Decimal.MaxValue. @@ -7555,9 +7535,9 @@ does not implement the interface. - -or- +-or- - The conversion is not supported. +The conversion is not supported. represents a number that is less than Decimal.MinValue or greater than Decimal.MaxValue. @@ -8230,9 +8210,9 @@ does not implement the interface. - -or- +-or- - The conversion is not supported. +The conversion is not supported. represents a number that is less than Double.MinValue or greater than Double.MaxValue. @@ -8925,7 +8905,7 @@ An offset in . The number of elements of to convert. Converts a subset of an array of 8-bit unsigned integers to its equivalent string representation that is encoded with uppercase hex characters. - Parameters specify the subset as an offset in the input array and the number of elements in the array to convert. + Parameters specify the subset as an offset in the input array and the number of elements in the array to convert. The string representation in hex of elements of , starting at position . To be added. @@ -9551,9 +9531,9 @@ does not implement the interface. - -or- +-or- - The conversion is not supported. +The conversion is not supported. represents a number that is less than Int16.MinValue or greater than Int16.MaxValue. @@ -10201,9 +10181,9 @@ is not 2, 8, 10, or 16. - -or- +-or- - , which represents a non-base 10 signed number, is prefixed with a negative sign. +, which represents a non-base 10 signed number, is prefixed with a negative sign. is . @@ -10211,9 +10191,9 @@ , which represents a non-base 10 signed number, is prefixed with a negative sign. - -or- +-or- - represents a number that is less than Int16.MinValue or greater than Int16.MaxValue. + represents a number that is less than Int16.MinValue or greater than Int16.MaxValue. @@ -10834,11 +10814,11 @@ is not in an appropriate format. - does not implement the interface. + does not implement the interface. - -or- +-or- - The conversion is not supported. +The conversion is not supported. represents a number that is less than Int32.MinValue or greater than Int32.MaxValue. @@ -11477,9 +11457,9 @@ is not 2, 8, 10, or 16. - -or- +-or- - , which represents a non-base 10 signed number, is prefixed with a negative sign. +, which represents a non-base 10 signed number, is prefixed with a negative sign. is . @@ -11487,9 +11467,9 @@ , which represents a non-base 10 signed number, is prefixed with a negative sign. - -or- +-or- - represents a number that is less than Int32.MinValue or greater than Int32.MaxValue. + represents a number that is less than Int32.MinValue or greater than Int32.MaxValue. @@ -12105,9 +12085,9 @@ does not implement the interface. - -or- +-or- - The conversion is not supported. +The conversion is not supported. represents a number that is less than Int64.MinValue or greater than Int64.MaxValue. @@ -12591,9 +12571,9 @@ does not implement the interface. - -or- +-or- - The conversion is not supported. +The conversion is not supported. represents a number that is less than Int64.MinValue or greater than Int64.MaxValue. @@ -12752,9 +12732,9 @@ is not 2, 8, 10, or 16. - -or- +-or- - , which represents a non-base 10 signed number, is prefixed with a negative sign. +, which represents a non-base 10 signed number, is prefixed with a negative sign. is . @@ -12762,9 +12742,9 @@ , which represents a non-base 10 signed number, is prefixed with a negative sign. - -or- +-or- - represents a number that is less than Int64.MinValue or greater than Int64.MaxValue. + represents a number that is less than Int64.MinValue or greater than Int64.MaxValue. @@ -13454,9 +13434,9 @@ does not implement the interface. - -or- +-or- - The conversion is not supported. +The conversion is not supported. represents a number that is less than SByte.MinValue or greater than SByte.MaxValue. @@ -13957,9 +13937,9 @@ does not implement the interface. - -or- +-or- - The conversion is not supported. +The conversion is not supported. represents a number that is less than SByte.MinValue or greater than SByte.MaxValue. @@ -14146,9 +14126,9 @@ is not 2, 8, 10, or 16. - -or- +-or- - , which represents a non-base 10 signed number, is prefixed with a negative sign. +, which represents a non-base 10 signed number, is prefixed with a negative sign. is . @@ -14156,9 +14136,9 @@ , which represents a non-base 10 signed number, is prefixed with a negative sign. - -or- +-or- - represents a number that is less than SByte.MinValue or greater than SByte.MaxValue. + represents a number that is less than SByte.MinValue or greater than SByte.MaxValue. @@ -14433,9 +14413,7 @@ The decimal number to convert. Converts the value of the specified decimal number to an equivalent single-precision floating-point number. - A single-precision floating-point number that is equivalent to . - - is rounded using rounding to nearest. For example, when rounded to two decimals, the value 2.345 becomes 2.34 and the value 2.355 becomes 2.36. + A single-precision floating-point number that is equivalent to . is rounded using rounding to nearest. For example, when rounded to two decimals, the value 2.345 becomes 2.34 and the value 2.355 becomes 2.36. The double-precision floating-point number to convert. Converts the value of the specified double-precision floating-point number to an equivalent single-precision floating-point number. - A single-precision floating-point number that is equivalent to . - - is rounded using rounding to nearest. For example, when rounded to two decimals, the value 2.345 becomes 2.34 and the value 2.355 becomes 2.36. + A single-precision floating-point number that is equivalent to . is rounded using rounding to nearest. For example, when rounded to two decimals, the value 2.345 becomes 2.34 and the value 2.355 becomes 2.36. does not implement the interface. - -or- +-or- - The conversion is not supported. +The conversion is not supported. represents a number that is less than Single.MinValue or greater than Single.MaxValue. @@ -18771,11 +18747,11 @@ is not in an appropriate format. - does not implement the interface. + does not implement the interface. - -or- +-or- - The conversion is not supported. +The conversion is not supported. represents a number that is less than UInt16.MinValue or greater than UInt16.MaxValue. @@ -19274,11 +19250,11 @@ is not in an appropriate format. - does not implement the interface. + does not implement the interface. - -or- +-or- - The conversion is not supported. +The conversion is not supported. represents a number that is less than UInt16.MinValue or greater than UInt16.MaxValue. @@ -19452,9 +19428,9 @@ is not 2, 8, 10, or 16. - -or- +-or- - , which represents a non-base 10 unsigned number, is prefixed with a negative sign. +, which represents a non-base 10 unsigned number, is prefixed with a negative sign. is . @@ -19462,9 +19438,9 @@ , which represents a non-base 10 unsigned number, is prefixed with a negative sign. - -or- +-or- - represents a number that is less than UInt16.MinValue or greater than UInt16.MaxValue. + represents a number that is less than UInt16.MinValue or greater than UInt16.MaxValue. @@ -20150,9 +20126,9 @@ does not implement the interface. - -or- +-or- - The conversion is not supported. +The conversion is not supported. represents a number that is less than UInt32.MinValue or greater than UInt32.MaxValue. @@ -20651,9 +20627,9 @@ does not implement the interface. - -or- +-or- - The conversion is not supported. +The conversion is not supported. represents a number that is less than UInt32.MinValue or greater than UInt32.MaxValue. @@ -20827,9 +20803,9 @@ is not 2, 8, 10, or 16. - -or- +-or- - , which represents a non-base 10 unsigned number, is prefixed with a negative sign. +, which represents a non-base 10 unsigned number, is prefixed with a negative sign. is . @@ -20837,9 +20813,9 @@ , which represents a non-base 10 unsigned number, is prefixed with a negative sign. - -or- +-or- - represents a number that is less than UInt32.MinValue or greater than UInt32.MaxValue. + represents a number that is less than UInt32.MinValue or greater than UInt32.MaxValue. @@ -21529,9 +21505,9 @@ does not implement the interface. - -or- +-or- - The conversion is not supported. +The conversion is not supported. represents a number that is less than UInt64.MinValue or greater than UInt64.MaxValue. @@ -22028,9 +22004,9 @@ does not implement the interface. - -or- +-or- - The conversion is not supported. +The conversion is not supported. represents a number that is less than UInt64.MinValue or greater than UInt64.MaxValue. @@ -22204,9 +22180,9 @@ is not 2, 8, 10, or 16. - -or- +-or- - , which represents a non-base 10 unsigned number, is prefixed with a negative sign. +, which represents a non-base 10 unsigned number, is prefixed with a negative sign. is . @@ -22214,9 +22190,9 @@ , which represents a non-base 10 unsigned number, is prefixed with a negative sign. - -or- +-or- - represents a number that is less than UInt64.MinValue or greater than UInt64.MaxValue. + represents a number that is less than UInt64.MinValue or greater than UInt64.MaxValue. diff --git a/xml/System/Converter`2.xml b/xml/System/Converter`2.xml index d1fbd40c123..02619ab5798 100644 --- a/xml/System/Converter`2.xml +++ b/xml/System/Converter`2.xml @@ -75,28 +75,28 @@ Represents a method that converts an object from one type to another type. The that represents the converted . - method of the class and the method of the class to convert each element of the collection from one type to another. - - - -## Examples - This section contains two code examples. The first demonstrates the delegate with the method of the class, and the second demonstrates the delegate with the method of the generic class. - - Example 1 - - The following code example defines a method named `PointFToPoint` that converts a structure to a structure. The example then creates an array of structures, creates a `Converter` delegate (`Converter(Of PointF, Point)` in Visual Basic) to represent the `PointFToPoint` method, and passes the delegate to the method. The method passes each element of the input list to the `PointFToPoint` method and puts the converted elements into a new list of structures. Both lists are displayed. - + method of the class and the method of the class to convert each element of the collection from one type to another. + + + +## Examples + This section contains two code examples. The first demonstrates the delegate with the method of the class, and the second demonstrates the delegate with the method of the generic class. + + Example 1 + + The following code example defines a method named `PointFToPoint` that converts a structure to a structure. The example then creates an array of structures, creates a `Converter` delegate (`Converter(Of PointF, Point)` in Visual Basic) to represent the `PointFToPoint` method, and passes the delegate to the method. The method passes each element of the input list to the `PointFToPoint` method and puts the converted elements into a new list of structures. Both lists are displayed. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Array_ConvertAll/cpp/source.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Array/ConvertAllTInput,TOutput/source.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Array_ConvertAll/vb/source.vb" id="Snippet1"::: - Example 2 - - The following code example defines a method named `PointFToPoint` that converts a structure to a structure. The example then creates a of structures, creates a `Converter\` delegate (`Converter(Of PointF, Point)` in Visual Basic) to represent the `PointFToPoint` method, and passes the delegate to the method. The method passes each element of the input list to the `PointFToPoint` method and puts the converted elements into a new list of structures. Both lists are displayed. - + Example 2 + + The following code example defines a method named `PointFToPoint` that converts a structure to a structure. The example then creates a of structures, creates a `Converter\` delegate (`Converter(Of PointF, Point)` in Visual Basic) to represent the `PointFToPoint` method, and passes the delegate to the method. The method passes each element of the input list to the `PointFToPoint` method and puts the converted elements into a new list of structures. Both lists are displayed. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/List`1_ConvertAll/cpp/source.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/ConverterTInput,TOutput/Overview/source.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/List`1_ConvertAll/vb/source.vb" id="Snippet1"::: diff --git a/xml/System/CrossAppDomainDelegate.xml b/xml/System/CrossAppDomainDelegate.xml index 053eb7ad53e..23bc3ec648b 100644 --- a/xml/System/CrossAppDomainDelegate.xml +++ b/xml/System/CrossAppDomainDelegate.xml @@ -28,11 +28,11 @@ Used by for cross-application domain calls. - and has a constructor and an `Invoke` method. See the C++ code example given in the description for . - + and has a constructor and an `Invoke` method. See the C++ code example given in the description for . + ]]> diff --git a/xml/System/DBNull.xml b/xml/System/DBNull.xml index 693e2cceb9e..410e020e308 100644 --- a/xml/System/DBNull.xml +++ b/xml/System/DBNull.xml @@ -84,24 +84,24 @@ Represents a nonexistent value. This class cannot be inherited. - class represents a nonexistent value. In a database, for example, a column in a row of a table might not contain any data whatsoever. That is, the column is considered to not exist at all instead of merely not having a value. A object represents the nonexistent column. Additionally, COM interop uses the class to distinguish between a VT_NULL variant, which indicates a nonexistent value, and a VT_EMPTY variant, which indicates an unspecified value. - - The type is a singleton class, which means only one object exists. The member represents the sole object. can be used to explicitly assign a nonexistent value to a database field, although most ADO.NET data providers automatically assign values of when a field does not have a valid value. You can determine whether a value retrieved from a database field is a value by passing the value of that field to the `DBNull.Value.Equals` method. However, some languages and database objects supply methods that make it easier to determine whether the value of a database field is . These include the Visual Basic `IsDBNull` function, the method, the method, and the method. - - Do not confuse the notion of `null` in an object-oriented programming language with a object. In an object-oriented programming language, `null` means the absence of a reference to an object. represents an uninitialized variant or nonexistent database column. - - - -## Examples - The following example calls the `DBNull.Value.Equals` method to determine whether a database field in a contacts database has a valid value. If it does, the field value is appended to the string output in a label. - + class represents a nonexistent value. In a database, for example, a column in a row of a table might not contain any data whatsoever. That is, the column is considered to not exist at all instead of merely not having a value. A object represents the nonexistent column. Additionally, COM interop uses the class to distinguish between a VT_NULL variant, which indicates a nonexistent value, and a VT_EMPTY variant, which indicates an unspecified value. + + The type is a singleton class, which means only one object exists. The member represents the sole object. can be used to explicitly assign a nonexistent value to a database field, although most ADO.NET data providers automatically assign values of when a field does not have a valid value. You can determine whether a value retrieved from a database field is a value by passing the value of that field to the `DBNull.Value.Equals` method. However, some languages and database objects supply methods that make it easier to determine whether the value of a database field is . These include the Visual Basic `IsDBNull` function, the method, the method, and the method. + + Do not confuse the notion of `null` in an object-oriented programming language with a object. In an object-oriented programming language, `null` means the absence of a reference to an object. represents an uninitialized variant or nonexistent database column. + + + +## Examples + The following example calls the `DBNull.Value.Equals` method to determine whether a database field in a contacts database has a valid value. If it does, the field value is appended to the string output in a label. + :::code language="csharp" source="~/snippets/csharp/System/DBNull/Overview/DBNullExamples.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DBNull.Class/fs/DBNullExamples.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DBNull.Class/vb/DBNullExamples.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DBNull.Class/vb/DBNullExamples.vb" id="Snippet1"::: + ]]> @@ -841,11 +841,11 @@ Converts the current object to the specified type. The boxed equivalent of the current object, if that conversion is supported; otherwise, an exception is thrown and no value is returned. - or , the return value is the current object itself. If the `type` parameter specifies , the return value is the string returned by the method. - + or , the return value is the current object itself. If the `type` parameter specifies , the return value is the string returned by the method. + ]]> This conversion is not supported for the type. @@ -1136,11 +1136,11 @@ - The to be used to format the return value. - - -or- - - to obtain the format information from the current locale setting of the operating system. + The to be used to format the return value. + +-or- + + to obtain the format information from the current locale setting of the operating system. Returns an empty string using the specified . An empty string (). To be added. @@ -1188,24 +1188,24 @@ Represents the sole instance of the class. - is a singleton class, which means only this instance of this class can exist. - - If a database field has missing data, you can use the property to explicitly assign a object value to the field. However, most data providers do this automatically. - - To evaluate database fields to determine whether their values are , you can pass the field value to the `DBNull.Value.Equals` method. However, this method is rarely used because there are a number of other ways to evaluate a database field for missing data. These include the Visual Basic `IsDBNull` function, the method, the method, the method, and several other methods. - - - -## Examples - The following example calls the `DBNull.Value.Equals` method to determine whether a database field in a contacts database has a valid value. If it does, the field value is appended to the string output in a label. - + is a singleton class, which means only this instance of this class can exist. + + If a database field has missing data, you can use the property to explicitly assign a object value to the field. However, most data providers do this automatically. + + To evaluate database fields to determine whether their values are , you can pass the field value to the `DBNull.Value.Equals` method. However, this method is rarely used because there are a number of other ways to evaluate a database field for missing data. These include the Visual Basic `IsDBNull` function, the method, the method, the method, and several other methods. + + + +## Examples + The following example calls the `DBNull.Value.Equals` method to determine whether a database field in a contacts database has a valid value. If it does, the field value is appended to the string output in a label. + :::code language="csharp" source="~/snippets/csharp/System/DBNull/Overview/DBNullExamples.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DBNull.Class/fs/DBNullExamples.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DBNull.Class/vb/DBNullExamples.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DBNull.Class/vb/DBNullExamples.vb" id="Snippet1"::: + ]]> diff --git a/xml/System/DataMisalignedException.xml b/xml/System/DataMisalignedException.xml index 8acbb581ebc..7ecc9752d7f 100644 --- a/xml/System/DataMisalignedException.xml +++ b/xml/System/DataMisalignedException.xml @@ -70,13 +70,13 @@ The exception that is thrown when a unit of data is read from or written to an address that is not a multiple of the data size. This class cannot be inherited. - is typically thrown when 16-bit, 32-bit, or 64-bit data is read from or written to an address that is not a multiple of two, four, or eight bytes. - - The exposes the underlying hardware exception, which allows you to respond in an appropriate manner. For example, a routine in your application attempts to copy a sequence of bytes from one location to another in 64-bit units. However, the write operation starts at a misaligned address, which causes the common language runtime to throw a . Your routine responds to the exception by copying the data one byte at a time. - + is typically thrown when 16-bit, 32-bit, or 64-bit data is read from or written to an address that is not a multiple of two, four, or eight bytes. + + The exposes the underlying hardware exception, which allows you to respond in an appropriate manner. For example, a routine in your application attempts to copy a sequence of bytes from one location to another in 64-bit units. However, the write operation starts at a misaligned address, which causes the common language runtime to throw a . Your routine responds to the exception by copying the data one byte at a time. + ]]> diff --git a/xml/System/DateOnly.xml b/xml/System/DateOnly.xml index 52328568d22..2dc9c21f523 100644 --- a/xml/System/DateOnly.xml +++ b/xml/System/DateOnly.xml @@ -151,9 +151,7 @@ Adds the specified number of days to the value of this instance. An instance whose value is the sum of the date represented by this instance and the number of days represented by value. To be added. - - The resulting value is greater than DateOnly.MaxValue. - + The resulting value is greater than DateOnly.MaxValue. @@ -1043,8 +1041,7 @@ A span containing the characters that represent a date to convert. An array of allowable formats of . - Converts the specified span representation of a date to its equivalent using the specified array of formats. - The format of the string representation must match at least one of the specified formats exactly or an exception is thrown. + Converts the specified span representation of a date to its equivalent using the specified array of formats. The format of the string representation must match at least one of the specified formats exactly or an exception is thrown. An object that is equivalent to the date contained in , as specified by format, provider, and style. To be added. @@ -1088,16 +1085,15 @@ A string containing the characters that represent a date to convert. A string that represent a format specifier that defines the required format of . - Converts the specified string representation of a date to its equivalent using the specified format. - The format of the string representation must match the specified format exactly or an exception is thrown. + Converts the specified string representation of a date to its equivalent using the specified format. The format of the string representation must match the specified format exactly or an exception is thrown. An object that is equivalent to the date contained in , as specified by format. - method parses the string representation of a date, which must be in the format defined by the `format` parameter. It also requires that the \ element of the string representation of a date appear in the order specified by `format`, and that `s` have no white space other than that permitted by `format`. - The `format` parameter is a string that contains either a single standard format specifier, or one or more custom format specifiers that define the required format of `s`. For details about valid formatting codes, see [Standard Date and Time Format Strings](/dotnet/standard/base-types/standard-date-and-time-format-strings) or [Custom Date and Time Format Strings](/dotnet/standard/base-types/custom-date-and-time-format-strings). -> [!NOTE] -> If `format` is a custom format pattern that does not include date separators (such as "yyyyMMdd"), use the widest form of each custom format specifier. For example, if you want to specify months in the format pattern, specify the wider form, "MM", instead of the narrower form, "M". + method parses the string representation of a date, which must be in the format defined by the `format` parameter. It also requires that the \ element of the string representation of a date appear in the order specified by `format`, and that `s` have no white space other than that permitted by `format`. + The `format` parameter is a string that contains either a single standard format specifier, or one or more custom format specifiers that define the required format of `s`. For details about valid formatting codes, see [Standard Date and Time Format Strings](/dotnet/standard/base-types/standard-date-and-time-format-strings) or [Custom Date and Time Format Strings](/dotnet/standard/base-types/custom-date-and-time-format-strings). +> [!NOTE] +> If `format` is a custom format pattern that does not include date separators (such as "yyyyMMdd"), use the widest form of each custom format specifier. For example, if you want to specify months in the format pattern, specify the wider form, "MM", instead of the narrower form, "M". ]]> @@ -1143,8 +1139,7 @@ A span containing the characters that represent a date to convert. An array of allowable formats of . - Converts the specified span representation of a date to its equivalent using the specified array of formats. - The format of the string representation must match at least one of the specified formats exactly or an exception is thrown. + Converts the specified span representation of a date to its equivalent using the specified array of formats. The format of the string representation must match at least one of the specified formats exactly or an exception is thrown. An object that is equivalent to the date contained in , as specified by format, provider, and style. To be added. @@ -1194,8 +1189,7 @@ A span containing the characters that represent a format specifier that defines the required format of . An object that supplies culture-specific formatting information about . A bitwise combination of enumeration values that indicates the permitted format of . A typical value to specify is . - Converts the specified span representation of a date to its equivalent using the specified format, culture-specific format information, and style. - The format of the string representation must match the specified format exactly or an exception is thrown. + Converts the specified span representation of a date to its equivalent using the specified format, culture-specific format information, and style. The format of the string representation must match the specified format exactly or an exception is thrown. An object that is equivalent to the date contained in , as specified by format, provider, and style. To be added. @@ -1247,8 +1241,7 @@ An array of allowable formats of . An object that supplies culture-specific formatting information about . A bitwise combination of enumeration values that indicates the permitted format of . A typical value to specify is . - Converts the specified span representation of a date to its equivalent using the specified array of formats, culture-specific format information, and style. - The format of the string representation must match at least one of the specified formats exactly or an exception is thrown. + Converts the specified span representation of a date to its equivalent using the specified array of formats, culture-specific format information, and style. The format of the string representation must match at least one of the specified formats exactly or an exception is thrown. An object that is equivalent to the date contained in , as specified by format, provider, and style. To be added. @@ -1300,8 +1293,7 @@ A string containing the characters that represent a format specifier that defines the required format of . An object that supplies culture-specific formatting information about . A bitwise combination of the enumeration values that provides additional information about , about style elements that may be present in , or about the conversion from to a value. A typical value to specify is . - Converts the specified string representation of a date to its equivalent using the specified format, culture-specific format information, and style. - The format of the string representation must match the specified format exactly or an exception is thrown. + Converts the specified string representation of a date to its equivalent using the specified format, culture-specific format information, and style. The format of the string representation must match the specified format exactly or an exception is thrown. An object that is equivalent to the date contained in , as specified by format, provider, and style. To be added. @@ -1357,8 +1349,7 @@ An array of allowable formats of . An object that supplies culture-specific formatting information about . A bitwise combination of enumeration values that indicates the permitted format of . A typical value to specify is . - Converts the specified string representation of a date to its equivalent using the specified array of formats, culture-specific format information, and style. - The format of the string representation must match at least one of the specified formats exactly or an exception is thrown. + Converts the specified string representation of a date to its equivalent using the specified array of formats, culture-specific format information, and style. The format of the string representation must match at least one of the specified formats exactly or an exception is thrown. An object that is equivalent to the date contained in , as specified by format, provider, and style. To be added. @@ -1508,8 +1499,7 @@ - Converts the value of the current object to its equivalent string representation using the formatting conventions of the current culture. - The object will be formatted in short form. + Converts the value of the current object to its equivalent string representation using the formatting conventions of the current culture. The object will be formatted in short form. A string that contains the short date string representation of the current object. To be added. @@ -2019,8 +2009,7 @@ A span containing the characters representing a date to convert. The required format of . When this method returns, contains the value equivalent to the date contained in , if the conversion succeeded, or DateOnly.MinValue if the conversion failed. The conversion fails if the is an empty string, or does not contain a date that correspond to the pattern specified in format. This parameter is passed uninitialized. - Converts the specified span representation of a date to its equivalent using the specified format and style. - The format of the string representation must match the specified format exactly. The method returns a value that indicates whether the conversion succeeded. + Converts the specified span representation of a date to its equivalent using the specified format and style. The format of the string representation must match the specified format exactly. The method returns a value that indicates whether the conversion succeeded. if was converted successfully; otherwise, . To be added. @@ -2123,8 +2112,7 @@ A string containing the characters representing a date to convert. The required format of . When this method returns, contains the value equivalent to the date contained in , if the conversion succeeded, or DateOnly.MinValue if the conversion failed. The conversion fails if is an empty string, or does not contain a date that correspond to the pattern specified in format. This parameter is passed uninitialized. - Converts the specified string representation of a date to its equivalent using the specified format and style. - The format of the string representation must match the specified format exactly. The method returns a value that indicates whether the conversion succeeded. + Converts the specified string representation of a date to its equivalent using the specified format and style. The format of the string representation must match the specified format exactly. The method returns a value that indicates whether the conversion succeeded. if was converted successfully; otherwise, . To be added. @@ -2230,8 +2218,7 @@ An object that supplies culture-specific formatting information about . A bitwise combination of one or more enumeration values that indicate the permitted format of . When this method returns, contains the value equivalent to the date contained in , if the conversion succeeded, or DateOnly.MinValue if the conversion failed. The conversion fails if the is an empty string, or does not contain a date that correspond to the pattern specified in format. This parameter is passed uninitialized. - Converts the specified span representation of a date to its equivalent using the specified format, culture-specific format information, and style. - The format of the string representation must match the specified format exactly. The method returns a value that indicates whether the conversion succeeded. + Converts the specified span representation of a date to its equivalent using the specified format, culture-specific format information, and style. The format of the string representation must match the specified format exactly. The method returns a value that indicates whether the conversion succeeded. if was converted successfully; otherwise, . To be added. @@ -2351,8 +2338,7 @@ An object that supplies culture-specific formatting information about . A bitwise combination of one or more enumeration values that indicate the permitted format of . When this method returns, contains the value equivalent to the date contained in , if the conversion succeeded, or DateOnly.MinValue if the conversion failed. The conversion fails if is an empty string, or does not contain a date that correspond to the pattern specified in format. This parameter is passed uninitialized. - Converts the specified span representation of a date to its equivalent using the specified format, culture-specific format information, and style. - The format of the string representation must match the specified format exactly. The method returns a value that indicates whether the conversion succeeded. + Converts the specified span representation of a date to its equivalent using the specified format, culture-specific format information, and style. The format of the string representation must match the specified format exactly. The method returns a value that indicates whether the conversion succeeded. if was converted successfully; otherwise, . To be added. diff --git a/xml/System/DateTime.xml b/xml/System/DateTime.xml index faa283da9a8..b49b5fe6214 100644 --- a/xml/System/DateTime.xml +++ b/xml/System/DateTime.xml @@ -656,8 +656,7 @@ The behavior of the .NET Framework and COM means that if your application round- The date part. The time part. - Initializes a new instance of the structure to the specified and . - The new instance will have the kind. + Initializes a new instance of the structure to the specified and . The new instance will have the kind. To be added. @@ -813,13 +812,13 @@ The behavior of the .NET Framework and COM means that if your application round- is less than 1 or greater than 9999. - -or- +-or- - is less than 1 or greater than 12. + is less than 1 or greater than 12. - -or- +-or- - is less than 1 or greater than the number of days in . + is less than 1 or greater than the number of days in . @@ -892,13 +891,13 @@ The behavior of the .NET Framework and COM means that if your application round- is not in the range supported by . - -or- +-or- - is less than 1 or greater than the number of months in . + is less than 1 or greater than the number of months in . - -or- +-or- - is less than 1 or greater than the number of days in . + is less than 1 or greater than the number of days in . @@ -977,25 +976,25 @@ The behavior of the .NET Framework and COM means that if your application round- is less than 1 or greater than 9999. - -or- +-or- - is less than 1 or greater than 12. + is less than 1 or greater than 12. - -or- +-or- - is less than 1 or greater than the number of days in . + is less than 1 or greater than the number of days in . - -or- +-or- - is less than 0 or greater than 23. + is less than 0 or greater than 23. - -or- +-or- - is less than 0 or greater than 59. + is less than 0 or greater than 59. - -or- +-or- - is less than 0 or greater than 59. + is less than 0 or greater than 59. @@ -1071,25 +1070,25 @@ The behavior of the .NET Framework and COM means that if your application round- is less than 1 or greater than 9999. - -or- +-or- - is less than 1 or greater than 12. + is less than 1 or greater than 12. - -or- +-or- - is less than 1 or greater than the number of days in . + is less than 1 or greater than the number of days in . - -or- +-or- - is less than 0 or greater than 23. + is less than 0 or greater than 23. - -or- +-or- - is less than 0 or greater than 59. + is less than 0 or greater than 59. - -or- +-or- - is less than 0 or greater than 59. + is less than 0 or greater than 59. is not one of the values. @@ -1170,25 +1169,25 @@ The behavior of the .NET Framework and COM means that if your application round- is not in the range supported by . - -or- +-or- - is less than 1 or greater than the number of months in . + is less than 1 or greater than the number of months in . - -or- +-or- - is less than 1 or greater than the number of days in . + is less than 1 or greater than the number of days in . - -or- +-or- - is less than 0 or greater than 23 + is less than 0 or greater than 23 - -or- +-or- - is less than 0 or greater than 59. + is less than 0 or greater than 59. - -or- +-or- - is less than 0 or greater than 59. + is less than 0 or greater than 59. @@ -1269,29 +1268,29 @@ The behavior of the .NET Framework and COM means that if your application round- is less than 1 or greater than 9999. - -or- +-or- - is less than 1 or greater than 12. + is less than 1 or greater than 12. - -or- +-or- - is less than 1 or greater than the number of days in . + is less than 1 or greater than the number of days in . - -or- +-or- - is less than 0 or greater than 23. + is less than 0 or greater than 23. - -or- +-or- - is less than 0 or greater than 59. + is less than 0 or greater than 59. - -or- +-or- - is less than 0 or greater than 59. + is less than 0 or greater than 59. - -or- +-or- - is less than 0 or greater than 999. + is less than 0 or greater than 999. @@ -1370,29 +1369,29 @@ The behavior of the .NET Framework and COM means that if your application round- is less than 1 or greater than 9999. - -or- +-or- - is less than 1 or greater than 12. + is less than 1 or greater than 12. - -or- +-or- - is less than 1 or greater than the number of days in . + is less than 1 or greater than the number of days in . - -or- +-or- - is less than 0 or greater than 23. + is less than 0 or greater than 23. - -or- +-or- - is less than 0 or greater than 59. + is less than 0 or greater than 59. - -or- +-or- - is less than 0 or greater than 59. + is less than 0 or greater than 59. - -or- +-or- - is less than 0 or greater than 999. + is less than 0 or greater than 999. is not one of the values. @@ -1477,29 +1476,29 @@ The behavior of the .NET Framework and COM means that if your application round- is not in the range supported by . - -or- +-or- - is less than 1 or greater than the number of months in . + is less than 1 or greater than the number of months in . - -or- +-or- - is less than 1 or greater than the number of days in . + is less than 1 or greater than the number of days in . - -or- +-or- - is less than 0 or greater than 23. + is less than 0 or greater than 23. - -or- +-or- - is less than 0 or greater than 59. + is less than 0 or greater than 59. - -or- +-or- - is less than 0 or greater than 59. + is less than 0 or greater than 59. - -or- +-or- - is less than 0 or greater than 999. + is less than 0 or greater than 999. @@ -1670,29 +1669,29 @@ For applications in which portability of date and time data or a limited degree is not in the range supported by . - -or- +-or- - is less than 1 or greater than the number of months in . + is less than 1 or greater than the number of months in . - -or- +-or- - is less than 1 or greater than the number of days in . + is less than 1 or greater than the number of days in . - -or- +-or- - is less than 0 or greater than 23. + is less than 0 or greater than 23. - -or- +-or- - is less than 0 or greater than 59. + is less than 0 or greater than 59. - -or- +-or- - is less than 0 or greater than 59. + is less than 0 or greater than 59. - -or- +-or- - is less than 0 or greater than 999. + is less than 0 or greater than 999. is not one of the values. @@ -2206,9 +2205,7 @@ For applications in which portability of date and time data or a limited degree - A number of whole and fractional microseconds. - The parameter can be negative or positive. - Note that this value is rounded to the nearest integer. + A number of whole and fractional microseconds. The parameter can be negative or positive. Note that this value is rounded to the nearest integer. Returns a new that adds the specified number of microseconds to the value of this instance. An object whose value is the sum of the date and time represented by this instance and the number of microseconds represented by . @@ -2433,9 +2430,9 @@ The value parameter is rounded to the nearest integer. The resulting is less than DateTime.MinValue or greater than DateTime.MaxValue. - -or- +-or- - is less than -120,000 or greater than 120,000. + is less than -120,000 or greater than 120,000. @@ -2679,25 +2676,34 @@ The value parameter is rounded to the nearest integer. The first object to compare. The second object to compare. Compares two instances of and returns an integer that indicates whether the first instance is earlier than, the same as, or later than the second instance. - A signed number indicating the relative values of and . - - Value Type - - Condition - - Less than zero - - is earlier than . - - Zero - - is the same as . - - Greater than zero - - is later than . - - + A signed number indicating the relative values of and . + + Value Type + + + Condition + + + + + Less than zero + + + is earlier than . + + + Zero + + + is the same as . + + + Greater than zero + + + is later than . + + The object to compare to the current instance. Compares the value of this instance to a specified value and returns an integer that indicates whether this instance is earlier than, the same as, or later than the specified value. - A signed number indicating the relative values of this instance and the parameter. - - Value - - Description - - Less than zero - - This instance is earlier than . - - Zero - - This instance is the same as . - - Greater than zero - - This instance is later than . - - + A signed number indicating the relative values of this instance and the parameter. + + Value + + + Description + + + + + Less than zero + + + This instance is earlier than . + + + Zero + + + This instance is the same as . + + + Greater than zero + + + This instance is later than . + + A boxed object to compare, or . Compares the value of this instance to a specified object that contains a specified value, and returns an integer that indicates whether this instance is earlier than, the same as, or later than the specified value. - A signed number indicating the relative values of this instance and . - - Value - - Description - - Less than zero - - This instance is earlier than . - - Zero - - This instance is the same as . - - Greater than zero - - This instance is later than , or is . - - + A signed number indicating the relative values of this instance and . + + Value + + + Description + + + + + Less than zero + + + This instance is earlier than . + + + Zero + + + This instance is the same as . + + + Greater than zero + + + This instance is later than , or is . + + The year. The month (a number ranging from 1 to 12). Returns the number of days in the specified month and year. - The number of days in for the specified . - - For example, if equals 2 for February, the return value is 28 or 29 depending upon whether is a leap year. + The number of days in for the specified . For example, if equals 2 for February, the return value is 28 or 29 depending upon whether is a leap year. is less than 1 or greater than 12. - -or- +-or- - is less than 1 or greater than 9999. + is less than 1 or greater than 9999. @@ -3556,7 +3578,7 @@ The value parameter is rounded to the nearest integer. The first object to compare. The second object to compare. - Returns a value indicating whether two instances have the same date and time value. + Returns a value indicating whether two instances have the same date and time value. if the two values are equal; otherwise, . @@ -3730,17 +3752,7 @@ The value parameter is rounded to the nearest integer. is less than 0 or represents a time greater than DateTime.MaxValue. - Ordinarily, the method restores a value that was saved by the method. However, the two values may differ under the following conditions: - -- If the serialization and deserialization of the value occur in different time zones. For example, if a value with a time of 12:30 P.M. in the U.S. Eastern Time zone is serialized, and then deserialized in the U.S. Pacific Time zone, the original value of 12:30 P.M. is adjusted to 9:30 A.M. to reflect the difference between the two time zones. - -- If the value that is serialized represents an invalid time in the local time zone. In this case, the method adjusts the restored value so that it represents a valid time in the local time zone. - - For example, the transition from standard time to daylight saving time occurs in the U.S. Pacific Time zone on March 14, 2010, at 2:00 A.M., when the time advances by one hour, to 3:00 A.M. This hour interval is an invalid time, that is, a time interval that does not exist in this time zone. The following example shows that when a time that falls within this range is converted to a long integer value by the method and is then restored by the method, the original value is adjusted to become a valid time. You can determine whether a particular date and time value may be subject to modification by passing it to the method, as the example illustrates. - - :::code language="csharp" source="~/snippets/csharp/System/DateTime/FromFileTime/fromfiletime1.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.fromfiletime/fs/fromfiletime1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.fromfiletime/vb/fromfiletime1.vb" id="Snippet1"::: + Ordinarily, the method restores a value that was saved by the method. However, the two values may differ under the following conditions: - If the serialization and deserialization of the value occur in different time zones. For example, if a value with a time of 12:30 P.M. in the U.S. Eastern Time zone is serialized, and then deserialized in the U.S. Pacific Time zone, the original value of 12:30 P.M. is adjusted to 9:30 A.M. to reflect the difference between the two time zones. - If the value that is serialized represents an invalid time in the local time zone. In this case, the method adjusts the restored value so that it represents a valid time in the local time zone. For example, the transition from standard time to daylight saving time occurs in the U.S. Pacific Time zone on March 14, 2010, at 2:00 A.M., when the time advances by one hour, to 3:00 A.M. This hour interval is an invalid time, that is, a time interval that does not exist in this time zone. The following example shows that when a time that falls within this range is converted to a long integer value by the method and is then restored by the method, the original value is adjusted to become a valid time. You can determine whether a particular date and time value may be subject to modification by passing it to the method, as the example illustrates. :::code language="csharp" source="~/snippets/csharp/System/DateTime/FromFileTime/fromfiletime1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.fromfiletime/fs/fromfiletime1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.fromfiletime/vb/fromfiletime1.vb" id="Snippet1"::: @@ -6248,7 +6260,7 @@ It handles the exception that is thrown when the m A string that contains a date and time to convert. See [The string to parse](#StringToParse) for more information. - An object that supplies culture-specific format information about . See [Parsing and cultural conventions](#Culture) + An object that supplies culture-specific format information about . See [Parsing and cultural conventions](#Culture) Converts the string representation of a date and time to its equivalent by using culture-specific format information. An object that is equivalent to the date and time contained in as specified by . @@ -6329,7 +6341,7 @@ The following example parses an array of date strings by using the conventions o The memory span that contains the string to parse. See [The string to parse](#StringToParse) for more information. - An object that supplies culture-specific format information about . See [Parsing and cultural conventions](#Culture) + An object that supplies culture-specific format information about . See [Parsing and cultural conventions](#Culture) A bitwise combination of the enumeration values that indicates the style elements that can be present in for the parse operation to succeed, and that defines how to interpret the parsed date in relation to the current time zone or the current date. A typical value to specify is . Converts a memory span that contains string representation of a date and time to its equivalent by using culture-specific format information and a formatting style. An object that is equivalent to the date and time contained in , as specified by and . @@ -6398,7 +6410,7 @@ The following example parses an array of date strings by using the conventions o A string that contains a date and time to convert. See [The string to parse](#StringToParse) for more information. - An object that supplies culture-specific formatting information about . See [Parsing and cultural conventions](#Culture) + An object that supplies culture-specific formatting information about . See [Parsing and cultural conventions](#Culture) A bitwise combination of the enumeration values that indicates the style elements that can be present in for the parse operation to succeed, and that defines how to interpret the parsed date in relation to the current time zone or the current date. A typical value to specify is . Converts the string representation of a date and time to its equivalent by using culture-specific format information and a formatting style. An object that is equivalent to the date and time contained in , as specified by and . @@ -6564,13 +6576,13 @@ The following example demonstrates the or is an empty string. - -or- +-or- - does not contain a date and time that corresponds to the pattern specified in . + does not contain a date and time that corresponds to the pattern specified in . - -or- +-or- - The hour component and the AM/PM designator in do not agree. +The hour component and the AM/PM designator in do not agree. In the .NET Framework 4, the method throws a if the string to be parsed contains an hour component and an AM/PM designator that are not in agreement. In the .NET Framework 3.5 and earlier versions, the AM/PM designator is ignored. @@ -6835,13 +6847,13 @@ The following example demonstrates the or is an empty string. - -or- +-or- - does not contain a date and time that corresponds to the pattern specified in . + does not contain a date and time that corresponds to the pattern specified in . - -or- +-or- - The hour component and the AM/PM designator in do not agree. +The hour component and the AM/PM designator in do not agree. contains an invalid combination of values. For example, both and . @@ -6975,17 +6987,17 @@ The following example demonstrates the is an empty string. - -or- +-or- - an element of is an empty string. +an element of is an empty string. - -or- +-or- - does not contain a date and time that corresponds to any element of . + does not contain a date and time that corresponds to any element of . - -or- +-or- - The hour component and the AM/PM designator in do not agree. +The hour component and the AM/PM designator in do not agree. contains an invalid combination of values. For example, both and . @@ -8580,17 +8592,7 @@ In general, the ticks represent the time according to the time zone specified by The resulting file time would represent a date and time before 12:00 midnight January 1, 1601 C.E. UTC. - Ordinarily, the method restores a value that was saved by the method. However, the two values may differ under the following conditions: - -- If the serialization and deserialization of the value occur in different time zones. For example, if a value with a time of 12:30 P.M. in the U.S. Eastern Time zone is serialized, and then deserialized in the U.S. Pacific Time zone, the original value of 12:30 P.M. is adjusted to 9:30 A.M. to reflect the difference between the two time zones. - -- If the value that is serialized represents an invalid time in the local time zone. In this case, the method adjusts the restored value so that it represents a valid time in the local time zone. - - For example, the transition from standard time to daylight saving time occurs in the U.S. Pacific Time zone on March 14, 2010, at 2:00 A.M., when the time advances by one hour, to 3:00 A.M. This hour interval is an invalid time, that is, a time interval that does not exist in this time zone. The following example shows that when a time that falls within this range is converted to a long integer value by the method and is then restored by the method, the original value is adjusted to become a valid time. You can determine whether a particular date and time value may be subject to modification by passing it to the method, as the example illustrates. - - :::code language="csharp" source="~/snippets/csharp/System/DateTime/FromFileTime/fromfiletime1.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.fromfiletime/fs/fromfiletime1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.fromfiletime/vb/fromfiletime1.vb" id="Snippet1"::: + Ordinarily, the method restores a value that was saved by the method. However, the two values may differ under the following conditions: - If the serialization and deserialization of the value occur in different time zones. For example, if a value with a time of 12:30 P.M. in the U.S. Eastern Time zone is serialized, and then deserialized in the U.S. Pacific Time zone, the original value of 12:30 P.M. is adjusted to 9:30 A.M. to reflect the difference between the two time zones. - If the value that is serialized represents an invalid time in the local time zone. In this case, the method adjusts the restored value so that it represents a valid time in the local time zone. For example, the transition from standard time to daylight saving time occurs in the U.S. Pacific Time zone on March 14, 2010, at 2:00 A.M., when the time advances by one hour, to 3:00 A.M. This hour interval is an invalid time, that is, a time interval that does not exist in this time zone. The following example shows that when a time that falls within this range is converted to a long integer value by the method and is then restored by the method, the original value is adjusted to become a valid time. You can determine whether a particular date and time value may be subject to modification by passing it to the method, as the example illustrates. :::code language="csharp" source="~/snippets/csharp/System/DateTime/FromFileTime/fromfiletime1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.fromfiletime/fs/fromfiletime1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.fromfiletime/vb/fromfiletime1.vb" id="Snippet1"::: @@ -8741,13 +8743,7 @@ In general, the ticks represent the time according to the time zone specified by ]]> - You can use the method to restore a local date and time value that was converted to UTC by the or method. However, if the original time represents an invalid time in the local time zone, it will not match the restored value. When the method converts a time from UTC to the local time zone, it also adjusts the time so that is valid in the local time zone. - - For example, the transition from standard time to daylight saving time occurs in the U.S. Pacific Time zone on March 14, 2010, at 2:00 A.M., when the time advances by one hour, to 3:00 A.M. This hour interval is an invalid time, that is, a time interval that does not exist in this time zone. The following example shows that when a time that falls within this range is converted to UTC by the method and is then restored by the method, the original value is adjusted to become a valid time. You can determine whether a particular date and time value may be subject to modification by passing it to the method, as the example illustrates. - - :::code language="csharp" source="~/snippets/csharp/System/DateTime/ToLocalTime/tolocaltime1.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.tolocaltime/fs/tolocaltime1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.tolocaltime/vb/tolocaltime1.vb" id="Snippet1"::: + You can use the method to restore a local date and time value that was converted to UTC by the or method. However, if the original time represents an invalid time in the local time zone, it will not match the restored value. When the method converts a time from UTC to the local time zone, it also adjusts the time so that is valid in the local time zone. For example, the transition from standard time to daylight saving time occurs in the U.S. Pacific Time zone on March 14, 2010, at 2:00 A.M., when the time advances by one hour, to 3:00 A.M. This hour interval is an invalid time, that is, a time interval that does not exist in this time zone. The following example shows that when a time that falls within this range is converted to UTC by the method and is then restored by the method, the original value is adjusted to become a valid time. You can determine whether a particular date and time value may be subject to modification by passing it to the method, as the example illustrates. :::code language="csharp" source="~/snippets/csharp/System/DateTime/ToLocalTime/tolocaltime1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.tolocaltime/fs/tolocaltime1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.tolocaltime/vb/tolocaltime1.vb" id="Snippet1"::: @@ -9178,13 +9174,7 @@ The following example illustrates how the string representation of a 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 Arabic (Syria). - - :::code language="csharp" source="~/snippets/csharp/System/DateTime/ToString/datetime.tostring.argumentoutofrangeexception2.cs" id="Snippet2"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/fs/datetime.tostring.argumentoutofrangeexception2.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/vb/datetime.tostring.argumentoutofrangeexception2.vb" id="Snippet2"::: - - + 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 Arabic (Syria). :::code language="csharp" source="~/snippets/csharp/System/DateTime/ToString/datetime.tostring.argumentoutofrangeexception2.cs" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/fs/datetime.tostring.argumentoutofrangeexception2.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/vb/datetime.tostring.argumentoutofrangeexception2.vb" id="Snippet2"::: @@ -9286,13 +9276,7 @@ The following example illustrates how the string representation of a 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 language="csharp" source="~/snippets/csharp/System/DateTime/ToString/datetime.tostring.argumentoutofrangeexception1.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/fs/datetime.tostring.argumentoutofrangeexception1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/vb/datetime.tostring.argumentoutofrangeexception1.vb" id="Snippet1"::: - - + 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 language="csharp" source="~/snippets/csharp/System/DateTime/ToString/datetime.tostring.argumentoutofrangeexception1.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/fs/datetime.tostring.argumentoutofrangeexception1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/vb/datetime.tostring.argumentoutofrangeexception1.vb" id="Snippet1"::: @@ -9395,18 +9379,12 @@ The following example illustrates how the string representation of a The length of is 1, and it is not one of the format specifier characters defined for . - -or- +-or- - does not contain a valid custom format pattern. + does not contain a valid custom format pattern. 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 language="csharp" source="~/snippets/csharp/System/DateTime/ToString/datetime.tostring.argumentoutofrangeexception3.cs" interactive="try-dotnet" id="Snippet3"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/fs/datetime.tostring.argumentoutofrangeexception3.fs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/vb/datetime.tostring.argumentoutofrangeexception3.vb" id="Snippet3"::: - - + 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 language="csharp" source="~/snippets/csharp/System/DateTime/ToString/datetime.tostring.argumentoutofrangeexception3.cs" interactive="try-dotnet" id="Snippet3"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/fs/datetime.tostring.argumentoutofrangeexception3.fs" id="Snippet3"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/vb/datetime.tostring.argumentoutofrangeexception3.vb" id="Snippet3"::: @@ -9518,18 +9496,12 @@ The following example illustrates how the string representation of a The length of is 1, and it is not one of the format specifier characters defined for . - -or- +-or- - does not contain a valid custom format pattern. + does not contain a valid custom format pattern. 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 language="csharp" source="~/snippets/csharp/System/DateTime/ToString/datetime.tostring.argumentoutofrangeexception4.cs" interactive="try-dotnet" id="Snippet4"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/fs/datetime.tostring.argumentoutofrangeexception4.fs" id="Snippet4"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/vb/datetime.tostring.argumentoutofrangeexception4.vb" id="Snippet4"::: - - + 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 language="csharp" source="~/snippets/csharp/System/DateTime/ToString/datetime.tostring.argumentoutofrangeexception4.cs" interactive="try-dotnet" id="Snippet4"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/fs/datetime.tostring.argumentoutofrangeexception4.fs" id="Snippet4"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/vb/datetime.tostring.argumentoutofrangeexception4.vb" id="Snippet4"::: @@ -9622,15 +9594,7 @@ The following example illustrates how the string representation of a - The method is sometimes used to convert a local time to UTC. The method is then called to restore the original local time. However, if the original time represents an invalid time in the local time zone, the two local time values will not be equal. For additional information and an example, see the method. - - On Windows XP systems, the method recognizes only the current adjustment rule for the local time zone, which it applies to all dates, including down-level dates (that is, dates that are earlier than the starting date of the current adjustment rule). Applications running on Windows XP that require historically accurate local date and time calculations must work around this behavior by using the method to retrieve a object that corresponds to the local time zone and calling its method. - - The following example illustrates the difference between the and methods on a Windows XP system in the U.S. Pacific Time zone. The first two method calls apply the current time zone adjustment rule (which went into effect in 2007) to a date in 2006. The current adjustment rule provides for the transition to daylight saving time on the second Sunday of March; the previous rule, which was in effect in 2006, provided for the transition to daylight saving time to occur on the first Sunday of April. Only the third method call accurately performs this historical date and time conversion. - - :::code language="csharp" source="~/snippets/csharp/System/DateTime/ToUniversalTime/touniversaltime.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.touniversaltime/fs/touniversaltime.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.touniversaltime/vb/touniversaltime.vb" id="Snippet1"::: + The method is sometimes used to convert a local time to UTC. The method is then called to restore the original local time. However, if the original time represents an invalid time in the local time zone, the two local time values will not be equal. For additional information and an example, see the method. On Windows XP systems, the method recognizes only the current adjustment rule for the local time zone, which it applies to all dates, including down-level dates (that is, dates that are earlier than the starting date of the current adjustment rule). Applications running on Windows XP that require historically accurate local date and time calculations must work around this behavior by using the method to retrieve a object that corresponds to the local time zone and calling its method. The following example illustrates the difference between the and methods on a Windows XP system in the U.S. Pacific Time zone. The first two method calls apply the current time zone adjustment rule (which went into effect in 2007) to a date in 2006. The current adjustment rule provides for the transition to daylight saving time on the second Sunday of March; the previous rule, which was in effect in 2006, provided for the transition to daylight saving time to occur on the first Sunday of April. Only the third method call accurately performs this historical date and time conversion. :::code language="csharp" source="~/snippets/csharp/System/DateTime/ToUniversalTime/touniversaltime.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.touniversaltime/fs/touniversaltime.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.touniversaltime/vb/touniversaltime.vb" id="Snippet1"::: @@ -10223,9 +10187,9 @@ The following example illustrates how the string representation of a is not a valid value. - -or- +-or- - contains an invalid combination of values (for example, both and ). + contains an invalid combination of values (for example, both and ). is a neutral culture and cannot be used in a parsing operation. @@ -10531,9 +10495,9 @@ The following example illustrates how the string representation of a is not a valid value. - -or- +-or- - contains an invalid combination of values (for example, both and ). + contains an invalid combination of values (for example, both and ). In the .NET Framework 4, the method returns if the string to be parsed contains an hour component and an AM/PM designator that are not in agreement. In the .NET Framework 3.5 and earlier versions, the AM/PM designator is ignored. @@ -10675,9 +10639,9 @@ The following example illustrates how the string representation of a is not a valid value. - -or- +-or- - contains an invalid combination of values (for example, both and ). + contains an invalid combination of values (for example, both and ). In the .NET Framework 4, the method returns if the string to be parsed contains an hour component and an AM/PM designator that are not in agreement. In the .NET Framework 3.5 and earlier versions, the AM/PM designator is ignored. diff --git a/xml/System/DateTimeKind.xml b/xml/System/DateTimeKind.xml index aabd2b9578d..1aff27aaf7c 100644 --- a/xml/System/DateTimeKind.xml +++ b/xml/System/DateTimeKind.xml @@ -54,13 +54,13 @@ Specifies whether a object represents a local time, a Coordinated Universal Time (UTC), or is not specified as either local time or UTC. - enumeration is returned by the property. - - The members of the enumeration are used in conversion operations between local time and Coordinated Universal Time (UTC), but not in comparison or arithmetic operations. For more information about time conversions, see [Converting Times Between Time Zones](/dotnet/standard/datetime/converting-between-time-zones). - + enumeration is returned by the property. + + The members of the enumeration are used in conversion operations between local time and Coordinated Universal Time (UTC), but not in comparison or arithmetic operations. For more information about time conversions, see [Converting Times Between Time Zones](/dotnet/standard/datetime/converting-between-time-zones). + ]]> diff --git a/xml/System/DateTimeOffset.xml b/xml/System/DateTimeOffset.xml index 164d85f5200..fb605968465 100644 --- a/xml/System/DateTimeOffset.xml +++ b/xml/System/DateTimeOffset.xml @@ -111,51 +111,51 @@ Represents a point in time, typically expressed as a date and time of day, relative to Coordinated Universal Time (UTC). - structure includes a value, together with an property that defines the difference between the current instance's date and time and Coordinated Universal Time (UTC). Because it exactly defines a date and time relative to UTC, the structure does not include a `Kind` member, as the structure does. It represents dates and times with values whose UTC ranges from 12:00:00 midnight, January 1, 0001 Anno Domini (Common Era), to 11:59:59 P.M., December 31, 9999 A.D. (C.E.). - -[!INCLUDE[japanese-era-note](~/includes/calendar-era.md)] - - The time component of a value is measured in 100-nanosecond units called ticks, and a particular date is the number of ticks since 12:00 midnight, January 1, 0001 A.D. (C.E.) in the calendar. A value is always expressed in the context of an explicit or default calendar. Ticks that are attributable to leap seconds are not included in the total number of ticks. - - Although a value includes an offset, it is not a fully time zone-aware data structure. While an offset from UTC is one characteristic of a time zone, it does not unambiguously identify a time zone. Not only do multiple time zones share the same offset from UTC, but the offset of a single time zone changes if it observes daylight saving time. This means that, as soon as a value is disassociated from its time zone, it can no longer be unambiguously linked back to its original time zone. - - Because is a structure, a object that has been declared but not otherwise initialized contains the default values for each of its member fields. This means that its property is set to and its property is set to . - - You can create a new value by calling any of the overloads of its constructor, which are similar to the overloaded constructors for the structure. You can also create a new value by assigning it a value. This is an implicit conversion; it does not require a casting operator (in C#) or call to a conversion method (in Visual Basic). You can also initialize a value from the string representation of a date and time by calling a number of static string parsing methods, which include , , , and . - - The members of the structure provide functionality in the following areas: - -- Date and time arithmetic. - - You can add or subtract either dates or time intervals from a particular value. Arithmetic operations with values, unlike those with values, adjust for differences in time offsets when returning a result. For example, the following code uses variables to subtract the current local time from the current UTC time. The code then uses variables to perform the same operation. The subtraction with values returns the local time zone's difference from UTC, while the subtraction with values returns . - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Overview/Type.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Type/fs/Type.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Type/vb/Type.vb" id="Snippet1"::: - -- Type conversion operations. - - You can convert values to values and vice versa. - -- Time manipulation and extraction operations. - - You can extract either the date or the time of a value. You can also retrieve the value of a particular component, such as its year or its month. - - > [!NOTE] - > If you are working with a ticks value that you want to convert to some other time interval, such as minutes or seconds, you should use the , , , , or constant to perform the conversion. For example, to add the number of seconds represented by a specified number of ticks to the component of a value, you can use the expression `dateValue.Second + nTicks/Timespan.TicksPerSecond`. - - -- Date and time conversion. - - You can convert any value to another value that represents the same point in time in another time zone. However, a time zone's adjustment rules are applied only in the case of the method, which converts a value to the date and time in the local system zone. - -- Date and time comparison. - - You can determine whether any particular value is earlier than, the same as, or later than another value. Before the comparison is performed, all values are converted to UTC. - + structure includes a value, together with an property that defines the difference between the current instance's date and time and Coordinated Universal Time (UTC). Because it exactly defines a date and time relative to UTC, the structure does not include a `Kind` member, as the structure does. It represents dates and times with values whose UTC ranges from 12:00:00 midnight, January 1, 0001 Anno Domini (Common Era), to 11:59:59 P.M., December 31, 9999 A.D. (C.E.). + +[!INCLUDE[japanese-era-note](~/includes/calendar-era.md)] + + The time component of a value is measured in 100-nanosecond units called ticks, and a particular date is the number of ticks since 12:00 midnight, January 1, 0001 A.D. (C.E.) in the calendar. A value is always expressed in the context of an explicit or default calendar. Ticks that are attributable to leap seconds are not included in the total number of ticks. + + Although a value includes an offset, it is not a fully time zone-aware data structure. While an offset from UTC is one characteristic of a time zone, it does not unambiguously identify a time zone. Not only do multiple time zones share the same offset from UTC, but the offset of a single time zone changes if it observes daylight saving time. This means that, as soon as a value is disassociated from its time zone, it can no longer be unambiguously linked back to its original time zone. + + Because is a structure, a object that has been declared but not otherwise initialized contains the default values for each of its member fields. This means that its property is set to and its property is set to . + + You can create a new value by calling any of the overloads of its constructor, which are similar to the overloaded constructors for the structure. You can also create a new value by assigning it a value. This is an implicit conversion; it does not require a casting operator (in C#) or call to a conversion method (in Visual Basic). You can also initialize a value from the string representation of a date and time by calling a number of static string parsing methods, which include , , , and . + + The members of the structure provide functionality in the following areas: + +- Date and time arithmetic. + + You can add or subtract either dates or time intervals from a particular value. Arithmetic operations with values, unlike those with values, adjust for differences in time offsets when returning a result. For example, the following code uses variables to subtract the current local time from the current UTC time. The code then uses variables to perform the same operation. The subtraction with values returns the local time zone's difference from UTC, while the subtraction with values returns . + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Overview/Type.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Type/fs/Type.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Type/vb/Type.vb" id="Snippet1"::: + +- Type conversion operations. + + You can convert values to values and vice versa. + +- Time manipulation and extraction operations. + + You can extract either the date or the time of a value. You can also retrieve the value of a particular component, such as its year or its month. + + > [!NOTE] + > If you are working with a ticks value that you want to convert to some other time interval, such as minutes or seconds, you should use the , , , , or constant to perform the conversion. For example, to add the number of seconds represented by a specified number of ticks to the component of a value, you can use the expression `dateValue.Second + nTicks/Timespan.TicksPerSecond`. + + +- Date and time conversion. + + You can convert any value to another value that represents the same point in time in another time zone. However, a time zone's adjustment rules are applied only in the case of the method, which converts a value to the date and time in the local system zone. + +- Date and time comparison. + + You can determine whether any particular value is earlier than, the same as, or later than another value. Before the comparison is performed, all values are converted to UTC. + ]]> Choosing Between DateTime, DateTimeOffset, TimeSpan, and TimeZoneInfo @@ -216,31 +216,31 @@ A date and time. Initializes a new instance of the structure using the specified value. - property of the `dateTime` parameter: - -- If the value of is , the property of the new instance is set equal to `dateTime`, and the property is set equal to . - -- If the value of is or , the property of the new instance is set equal to `dateTime`, and the property is set equal to the offset of the local system's current time zone. - - - -## Examples - The following example illustrates how the value of the property of the `dateTime` parameter affects the date and time value that is returned by this constructor. - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/.ctor/Constructors.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Constructors/fs/Constructors.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Constructors/vb/Constructors.vb" id="Snippet1"::: - + property of the `dateTime` parameter: + +- If the value of is , the property of the new instance is set equal to `dateTime`, and the property is set equal to . + +- If the value of is or , the property of the new instance is set equal to `dateTime`, and the property is set equal to the offset of the local system's current time zone. + + + +## Examples + The following example illustrates how the value of the property of the `dateTime` parameter affects the date and time value that is returned by this constructor. + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/.ctor/Constructors.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Constructors/fs/Constructors.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Constructors/vb/Constructors.vb" id="Snippet1"::: + ]]> - The Coordinated Universal Time (UTC) date and time that results from applying the offset is earlier than DateTimeOffset.MinValue. - - -or- - - The UTC date and time that results from applying the offset is later than DateTimeOffset.MaxValue. + The Coordinated Universal Time (UTC) date and time that results from applying the offset is earlier than DateTimeOffset.MinValue. + +-or- + +The UTC date and time that results from applying the offset is later than DateTimeOffset.MaxValue. Instantiating a DateTimeOffset Object @@ -286,44 +286,44 @@ The time's offset from Coordinated Universal Time (UTC). Initializes a new instance of the structure using the specified value and offset. - property of the `dateTime` parameter: - -- If the value of is , the value of the `offset` parameter must be 0 or an is thrown. - -- If the value of is , the value of the `offset` parameter must be equal to the local time zone's offset from Coordinated Universal Time (UTC) for that particular date or an is thrown. - -- If the value of is , the `offset` parameter can have any valid value. - - - -## Examples - The following example shows how to initialize a object with a date and time and the offset of the local time zone when that time zone is not known in advance. - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/.ctor/Constructors.cs" id="Snippet3"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Constructors/fs/Constructors.fs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Constructors/vb/Constructors.vb" id="Snippet3"::: - + property of the `dateTime` parameter: + +- If the value of is , the value of the `offset` parameter must be 0 or an is thrown. + +- If the value of is , the value of the `offset` parameter must be equal to the local time zone's offset from Coordinated Universal Time (UTC) for that particular date or an is thrown. + +- If the value of is , the `offset` parameter can have any valid value. + + + +## Examples + The following example shows how to initialize a object with a date and time and the offset of the local time zone when that time zone is not known in advance. + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/.ctor/Constructors.cs" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Constructors/fs/Constructors.fs" id="Snippet3"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Constructors/vb/Constructors.vb" id="Snippet3"::: + ]]> - equals and does not equal zero. - - -or- - - equals and does not equal the offset of the system's local time zone. - - -or- - - is not specified in whole minutes. + equals and does not equal zero. + +-or- + + equals and does not equal the offset of the system's local time zone. + +-or- + + is not specified in whole minutes. - is less than -14 hours or greater than 14 hours. - - -or- - - is less than DateTimeOffset.MinValue or greater than DateTimeOffset.MaxValue. + is less than -14 hours or greater than 14 hours. + +-or- + + is less than DateTimeOffset.MinValue or greater than DateTimeOffset.MaxValue. Instantiating a DateTimeOffset Object @@ -369,37 +369,37 @@ The time's offset from Coordinated Universal Time (UTC). Initializes a new instance of the structure using the specified number of ticks and offset. - constructor to instantiate a value with a local time and an offset other than that of the local time zone throws an . You can use this overload of the constructor to work around this limitation. The following example uses the local time's number of ticks to instantiate a value whose offset does not necessarily represent that of the local time: - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/.ctor/Constructors.cs" id="Snippet4"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Constructors/fs/Constructors.fs" id="Snippet4"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Constructors/vb/Constructors.vb" id="Snippet4"::: - - - -## Examples - The following example initializes a object by using the number of ticks in an arbitrary date (in this case, July 16, 2007, at 1:32 PM) with an offset of -5. - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/.ctor/Constructors.cs" id="Snippet2"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Constructors/fs/Constructors.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Constructors/vb/Constructors.vb" id="Snippet2"::: - + constructor to instantiate a value with a local time and an offset other than that of the local time zone throws an . You can use this overload of the constructor to work around this limitation. The following example uses the local time's number of ticks to instantiate a value whose offset does not necessarily represent that of the local time: + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/.ctor/Constructors.cs" id="Snippet4"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Constructors/fs/Constructors.fs" id="Snippet4"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Constructors/vb/Constructors.vb" id="Snippet4"::: + + + +## Examples + The following example initializes a object by using the number of ticks in an arbitrary date (in this case, July 16, 2007, at 1:32 PM) with an offset of -5. + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/.ctor/Constructors.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Constructors/fs/Constructors.fs" id="Snippet2"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Constructors/vb/Constructors.vb" id="Snippet2"::: + ]]> is not specified in whole minutes. - The property is earlier than DateTimeOffset.MinValue or later than DateTimeOffset.MaxValue. - - -or- - - is less than or greater than . - - -or- - - s less than -14 hours or greater than 14 hours. + The property is earlier than DateTimeOffset.MinValue or later than DateTimeOffset.MaxValue. + +-or- + + is less than or greater than . + +-or- + + s less than -14 hours or greater than 14 hours. Instantiating a DateTimeOffset Object @@ -486,54 +486,54 @@ The time's offset from Coordinated Universal Time (UTC). Initializes a new instance of the structure using the specified year, month, day, hour, minute, second, and offset. - value by using the year, month, and day in another calendar, call the constructor. - - - -## Examples - The following example instantiates a object by using the constructor overload. - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/.ctor/Constructors.cs" id="Snippet5"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Constructors/fs/Constructors.fs" id="Snippet5"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Constructors/vb/Constructors.vb" id="Snippet5"::: - + value by using the year, month, and day in another calendar, call the constructor. + + + +## Examples + The following example instantiates a object by using the constructor overload. + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/.ctor/Constructors.cs" id="Snippet5"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Constructors/fs/Constructors.fs" id="Snippet5"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Constructors/vb/Constructors.vb" id="Snippet5"::: + ]]> does not represent whole minutes. - is less than one or greater than 9999. - - -or- - - is less than one or greater than 12. - - -or- - - is less than one or greater than the number of days in . - - -or- - - is less than zero or greater than 23. - - -or- - - is less than 0 or greater than 59. - - -or- - - is less than 0 or greater than 59. - - -or- - - is less than -14 hours or greater than 14 hours. - - -or- - - The property is earlier than DateTimeOffset.MinValue or later than DateTimeOffset.MaxValue. + is less than one or greater than 9999. + +-or- + + is less than one or greater than 12. + +-or- + + is less than one or greater than the number of days in . + +-or- + + is less than zero or greater than 23. + +-or- + + is less than 0 or greater than 59. + +-or- + + is less than 0 or greater than 59. + +-or- + + is less than -14 hours or greater than 14 hours. + +-or- + +The property is earlier than DateTimeOffset.MinValue or later than DateTimeOffset.MaxValue. Instantiating a DateTimeOffset Object @@ -591,58 +591,58 @@ The time's offset from Coordinated Universal Time (UTC). Initializes a new instance of the structure using the specified year, month, day, hour, minute, second, millisecond, and offset. - value by using the year, month, and day in another calendar, call the constructor. - - - -## Examples - The following example instantiates a object by using the constructor overload. - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/.ctor/Constructors.cs" id="Snippet7"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Constructors/fs/Constructors.fs" id="Snippet7"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Constructors/vb/Constructors.vb" id="Snippet7"::: - + value by using the year, month, and day in another calendar, call the constructor. + + + +## Examples + The following example instantiates a object by using the constructor overload. + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/.ctor/Constructors.cs" id="Snippet7"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Constructors/fs/Constructors.fs" id="Snippet7"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Constructors/vb/Constructors.vb" id="Snippet7"::: + ]]> does not represent whole minutes. - is less than one or greater than 9999. - - -or- - - is less than one or greater than 12. - - -or- - - is less than one or greater than the number of days in . - - -or- - - is less than zero or greater than 23. - - -or- - - is less than 0 or greater than 59. - - -or- - - is less than 0 or greater than 59. - - -or- - - is less than 0 or greater than 999. - - -or- - - is less than -14 or greater than 14. - - -or- - - The property is earlier than DateTimeOffset.MinValue or later than DateTimeOffset.MaxValue. + is less than one or greater than 9999. + +-or- + + is less than one or greater than 12. + +-or- + + is less than one or greater than the number of days in . + +-or- + + is less than zero or greater than 23. + +-or- + + is less than 0 or greater than 59. + +-or- + + is less than 0 or greater than 59. + +-or- + + is less than 0 or greater than 999. + +-or- + + is less than -14 or greater than 14. + +-or- + +The property is earlier than DateTimeOffset.MinValue or later than DateTimeOffset.MaxValue. Instantiating a DateTimeOffset Object @@ -704,20 +704,20 @@ The time's offset from Coordinated Universal Time (UTC). Initializes a new instance of the structure using the specified year, month, day, hour, minute, second, millisecond, and offset of a specified calendar. - class and the class to instantiate a value. That date is then displayed to the console using the respective calendars and the Gregorian calendar. - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/.ctor/Constructors.cs" id="Snippet8"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Constructors/fs/Constructors.fs" id="Snippet8"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Constructors/vb/Constructors.vb" id="Snippet8"::: - + class and the class to instantiate a value. That date is then displayed to the console using the respective calendars and the Gregorian calendar. + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/.ctor/Constructors.cs" id="Snippet8"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Constructors/fs/Constructors.fs" id="Snippet8"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Constructors/vb/Constructors.vb" id="Snippet8"::: + ]]> @@ -725,43 +725,43 @@ cannot be . - is less than the parameter's or greater than . - - -or- - - is either less than or greater than the number of months in in the . - - -or- - - is less than one or greater than the number of days in . - - -or- - - is less than zero or greater than 23. - - -or- - - is less than 0 or greater than 59. - - -or- - - is less than 0 or greater than 59. - - -or- - - is less than 0 or greater than 999. - - -or- - - is less than -14 hours or greater than 14 hours. - - -or- - - The , , and parameters cannot be represented as a date and time value. - - -or- - - The property is earlier than DateTimeOffset.MinValue or later than DateTimeOffset.MaxValue. + is less than the parameter's or greater than . + +-or- + + is either less than or greater than the number of months in in the . + +-or- + + is less than one or greater than the number of days in . + +-or- + + is less than zero or greater than 23. + +-or- + + is less than 0 or greater than 59. + +-or- + + is less than 0 or greater than 59. + +-or- + + is less than 0 or greater than 999. + +-or- + + is less than -14 hours or greater than 14 hours. + +-or- + +The , , and parameters cannot be represented as a date and time value. + +-or- + +The property is earlier than DateTimeOffset.MinValue or later than DateTimeOffset.MaxValue. Instantiating a DateTimeOffset Object @@ -807,47 +807,47 @@ The time's offset from Coordinated Universal Time (UTC). Initializes a new instance of the structure using the specified , , , , , , , and . - value by using the year, month and day in another calendar, call - the constructor. - + value by using the year, month and day in another calendar, call + the constructor. + ]]> does not represent whole minutes. - is less than 1 or greater than 9999. - --or- - - is less than 1 or greater than 12. - --or- - - is less than 1 or greater than the number of days in . - --or- - - is less than 0 or greater than 23. - --or- - - is less than 0 or greater than 59. - --or- - - is less than 0 or greater than 59. - --or- - - is less than 0 or greater than 999. - --or- - + is less than 1 or greater than 9999. + +-or- + + is less than 1 or greater than 12. + +-or- + + is less than 1 or greater than the number of days in . + +-or- + + is less than 0 or greater than 23. + +-or- + + is less than 0 or greater than 59. + +-or- + + is less than 0 or greater than 59. + +-or- + + is less than 0 or greater than 999. + +-or- + is less than 0 or greater than 999. @@ -901,60 +901,59 @@ This constructor interprets `year`, `month` and `day` as a year, month and day The time's offset from Coordinated Universal Time (UTC). Initializes a new instance of the structure using the specified , , , , , , , and . - value by using the year, month and day in another calendar, call - the constructor. - + value by using the year, month and day in another calendar, call + the constructor. + ]]> does not represent whole minutes. - is not in the range supported by . - --or- - - is less than 1 or greater than the number of months in . - --or- - - is less than 1 or greater than the number of days in . - --or- - - is less than 0 or greater than 23. - --or- - - is less than 0 or greater than 59. - --or- - - is less than 0 or greater than 59. - --or- - - is less than 0 or greater than 999. - --or- - - is less than 0 or greater than 999. - --or- - - is less than -14 hours or greater than 14 hours. - --or- - -The , , and parameters - cannot be represented as a date and time value. - --or- - + is not in the range supported by . + +-or- + + is less than 1 or greater than the number of months in . + +-or- + + is less than 1 or greater than the number of days in . + +-or- + + is less than 0 or greater than 23. + +-or- + + is less than 0 or greater than 59. + +-or- + + is less than 0 or greater than 59. + +-or- + + is less than 0 or greater than 999. + +-or- + + is less than 0 or greater than 999. + +-or- + + is less than -14 hours or greater than 14 hours. + +-or- + +The , , and parameters cannot be represented as a date and time value. + +-or- + The property is earlier than or later than . @@ -1002,36 +1001,36 @@ The property is earlier than Returns a new object that adds a specified time interval to the value of this instance. An object whose value is the sum of the date and time represented by the current object and the time interval represented by . - method to add more than one kind of time interval (days, hours, minutes, seconds, or milliseconds) in a single operation. This method's behavior is identical to the addition operator. The structure also supports specialized addition methods (such as , , and ) for each time interval. - -> [!NOTE] -> This method returns a new object. It does not modify the value of the current object by adding `timeSpan` to its date and time. - - The method does not affect the value of the current object's property. - - Because a object does not represent the date and time in a specific time zone, the method does not consider a particular time zone's adjustment rules when it performs date and time arithmetic. - - If the `timeSpan` parameter is `null`, this method returns the value of the original object unchanged. - - - -## Examples - The following example creates an array of objects that represent the flight times between destinations. The method then adds these times to a object that represents a flight's initial takeoff time. The result reflects the scheduled arrival time at each destination. - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Add/Methods.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/fs/Methods.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/vb/Methods.vb" id="Snippet1"::: - + method to add more than one kind of time interval (days, hours, minutes, seconds, or milliseconds) in a single operation. This method's behavior is identical to the addition operator. The structure also supports specialized addition methods (such as , , and ) for each time interval. + +> [!NOTE] +> This method returns a new object. It does not modify the value of the current object by adding `timeSpan` to its date and time. + + The method does not affect the value of the current object's property. + + Because a object does not represent the date and time in a specific time zone, the method does not consider a particular time zone's adjustment rules when it performs date and time arithmetic. + + If the `timeSpan` parameter is `null`, this method returns the value of the original object unchanged. + + + +## Examples + The following example creates an array of objects that represent the flight times between destinations. The method then adds these times to a object that represents a flight's initial takeoff time. The result reflects the scheduled arrival time at each destination. + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Add/Methods.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/fs/Methods.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/vb/Methods.vb" id="Snippet1"::: + ]]> - The resulting value is less than DateTimeOffset.MinValue. - - -or- - - The resulting value is greater than DateTimeOffset.MaxValue. + The resulting value is less than DateTimeOffset.MinValue. + +-or- + +The resulting value is greater than DateTimeOffset.MaxValue. Performing Arithmetic Operations with Dates and Times @@ -1080,37 +1079,37 @@ The property is earlier than Returns a new object that adds a specified number of whole and fractional days to the value of this instance. An object whose value is the sum of the date and time represented by the current object and the number of days represented by . - precision of the `days` parameter is used. However, due to the inherent imprecision of floating point math, the resulting precision will vary. - -> [!NOTE] -> This method returns a new object. It does not modify the value of the current object by adding `days` to its date and time. - - Because a object does not represent the date and time in a specific time zone, the method does not consider a particular time zone's adjustment rules when it performs date and time arithmetic. - - Converting time intervals of less than a day to a fraction can involve a loss of precision. If this is problematic, you can use the method, which enables you to specify more than one kind of time interval in a single method call and eliminates the need to convert time intervals to fractional parts of a day. - - - -## Examples - The following example uses the method to list the dates that fall on Monday, the start of the work week, in March 2008. - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Add/Methods.cs" interactive="try-dotnet-method" id="Snippet2"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/fs/Methods.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/vb/Methods.vb" id="Snippet2"::: - + precision of the `days` parameter is used. However, due to the inherent imprecision of floating point math, the resulting precision will vary. + +> [!NOTE] +> This method returns a new object. It does not modify the value of the current object by adding `days` to its date and time. + + Because a object does not represent the date and time in a specific time zone, the method does not consider a particular time zone's adjustment rules when it performs date and time arithmetic. + + Converting time intervals of less than a day to a fraction can involve a loss of precision. If this is problematic, you can use the method, which enables you to specify more than one kind of time interval in a single method call and eliminates the need to convert time intervals to fractional parts of a day. + + + +## Examples + The following example uses the method to list the dates that fall on Monday, the start of the work week, in March 2008. + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Add/Methods.cs" interactive="try-dotnet-method" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/fs/Methods.fs" id="Snippet2"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/vb/Methods.vb" id="Snippet2"::: + ]]> - The resulting value is less than DateTimeOffset.MinValue. - - -or- - - The resulting value is greater than DateTimeOffset.MaxValue. + The resulting value is less than DateTimeOffset.MinValue. + +-or- + +The resulting value is greater than DateTimeOffset.MaxValue. @@ -1157,35 +1156,35 @@ In .NET 6 and earlier versions, the `days` parameter is rounded to the nearest m Returns a new object that adds a specified number of whole and fractional hours to the value of this instance. An object whose value is the sum of the date and time represented by the current object and the number of hours represented by . - precision of the `hours` parameter is used. However, due to the inherent imprecision of floating point math, the resulting precision will vary. - -> [!NOTE] -> This method returns a new object. It does not modify the value of the current object by adding `hours` to its date and time. - - Because a object does not represent the date and time in a specific time zone, the method does not consider a particular time zone's adjustment rules when it performs date and time arithmetic. - - Converting time intervals of less than an hour to a fraction can involve a loss of precision. (For example, one minute is 0.01666 of an hour.) If this is problematic, you can use the method, which enables you to specify more than one kind of time interval in a single method call and eliminates the need to convert time intervals to fractional parts of an hour. - -## Examples - The following example uses the method to list the start times of work shifts for a particular week at an office that has two eight-hour shifts per day. - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Add/Methods.cs" id="Snippet3"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/fs/Methods.fs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/vb/Methods.vb" id="Snippet3"::: - + precision of the `hours` parameter is used. However, due to the inherent imprecision of floating point math, the resulting precision will vary. + +> [!NOTE] +> This method returns a new object. It does not modify the value of the current object by adding `hours` to its date and time. + + Because a object does not represent the date and time in a specific time zone, the method does not consider a particular time zone's adjustment rules when it performs date and time arithmetic. + + Converting time intervals of less than an hour to a fraction can involve a loss of precision. (For example, one minute is 0.01666 of an hour.) If this is problematic, you can use the method, which enables you to specify more than one kind of time interval in a single method call and eliminates the need to convert time intervals to fractional parts of an hour. + +## Examples + The following example uses the method to list the start times of work shifts for a particular week at an office that has two eight-hour shifts per day. + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Add/Methods.cs" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/fs/Methods.fs" id="Snippet3"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/vb/Methods.vb" id="Snippet3"::: + ]]> - The resulting value is less than DateTimeOffset.MinValue. - - -or- - - The resulting value is greater than DateTimeOffset.MaxValue. + The resulting value is less than DateTimeOffset.MinValue. + +-or- + +The resulting value is greater than DateTimeOffset.MaxValue. Performing Arithmetic Operations with Dates and Times @@ -1219,24 +1218,24 @@ In .NET 6 and earlier versions, the `hours` parameter is rounded to the nearest Returns a new object that adds a specified number of microseconds to the value of this instance. An object whose value is the sum of the date and time represented by the current object and the number of whole microseconds represented by . - object does not represent the date and time in a specific time zone, - the method does not consider a particular time zone's adjustment rules - when it performs date and time arithmetic. - + object does not represent the date and time in a specific time zone, + the method does not consider a particular time zone's adjustment rules + when it performs date and time arithmetic. + ]]> - The resulting value is less than DateTimeOffset.MinValue. - --or- - + The resulting value is less than DateTimeOffset.MinValue. + +-or- + The resulting value is greater than DateTimeOffset.MaxValue. @@ -1284,24 +1283,24 @@ The resulting value is greater than Returns a new object that adds a specified number of milliseconds to the value of this instance. An object whose value is the sum of the date and time represented by the current object and the number of whole milliseconds represented by . - precision of the `milliseconds` parameter is used. However, due to the inherent imprecision of floating point math, the resulting precision will vary. - -> [!NOTE] -> This method returns a new object. It does not modify the value of the current object by adding `milliseconds` to its date and time. - - Because a object does not represent the date and time in a specific time zone, the method does not consider a particular time zone's adjustment rules when it performs date and time arithmetic. - + precision of the `milliseconds` parameter is used. However, due to the inherent imprecision of floating point math, the resulting precision will vary. + +> [!NOTE] +> This method returns a new object. It does not modify the value of the current object by adding `milliseconds` to its date and time. + + Because a object does not represent the date and time in a specific time zone, the method does not consider a particular time zone's adjustment rules when it performs date and time arithmetic. + ]]> - The resulting value is less than DateTimeOffset.MinValue. - - -or- - - The resulting value is greater than DateTimeOffset.MaxValue. + The resulting value is less than DateTimeOffset.MinValue. + +-or- + +The resulting value is greater than DateTimeOffset.MaxValue. Performing Arithmetic Operations with Dates and Times @@ -1349,28 +1348,28 @@ The fractional part of the `milliseconds` parameter is the fractional part of a Returns a new object that adds a specified number of whole and fractional minutes to the value of this instance. An object whose value is the sum of the date and time represented by the current object and the number of minutes represented by . - precision of the `minutes` parameter is used. However, due to the inherent imprecision of floating point math, the resulting precision will vary. - -> [!NOTE] -> This method returns a new object. It does not modify the value of the current object by adding `minutes` to its date and time. - - Because a object does not represent the date and time in a specific time zone, the method does not consider a particular time zone's adjustment rules when it performs date and time arithmetic. - - Converting time intervals of less than a minute to a fraction can involve a loss of precision. (For example, one second is 0.01666 of a minute.) If this is problematic, you can use the method, which enables you to specify more than one kind of time interval in a single method call and eliminates the need to convert time intervals to fractional parts of a minute. - + precision of the `minutes` parameter is used. However, due to the inherent imprecision of floating point math, the resulting precision will vary. + +> [!NOTE] +> This method returns a new object. It does not modify the value of the current object by adding `minutes` to its date and time. + + Because a object does not represent the date and time in a specific time zone, the method does not consider a particular time zone's adjustment rules when it performs date and time arithmetic. + + Converting time intervals of less than a minute to a fraction can involve a loss of precision. (For example, one second is 0.01666 of a minute.) If this is problematic, you can use the method, which enables you to specify more than one kind of time interval in a single method call and eliminates the need to convert time intervals to fractional parts of a minute. + ]]> - The resulting value is less than DateTimeOffset.MinValue. - - -or- - - The resulting value is greater than DateTimeOffset.MaxValue. + The resulting value is less than DateTimeOffset.MinValue. + +-or- + +The resulting value is greater than DateTimeOffset.MaxValue. Performing Arithmetic Operations with Dates and Times @@ -1418,30 +1417,30 @@ In .NET 6 and earlier versions, the `minutes` parameter is rounded to the neares Returns a new object that adds a specified number of months to the value of this instance. An object whose value is the sum of the date and time represented by the current object and the number of months represented by . - does not enable you to add fractional parts of a month. To add a time that consists of other time units in addition to months to a object, use the method. - -> [!NOTE] -> This method returns a new object. It does not modify the value of the current object by adding `months` to its date and time. - - - -## Examples - The following example uses the method to display the start date of each quarter of the year 2007. - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Add/Methods.cs" id="Snippet4"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/fs/Methods.fs" id="Snippet4"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/vb/Methods.vb" id="Snippet4"::: - + does not enable you to add fractional parts of a month. To add a time that consists of other time units in addition to months to a object, use the method. + +> [!NOTE] +> This method returns a new object. It does not modify the value of the current object by adding `months` to its date and time. + + + +## Examples + The following example uses the method to display the start date of each quarter of the year 2007. + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Add/Methods.cs" id="Snippet4"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/fs/Methods.fs" id="Snippet4"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/vb/Methods.vb" id="Snippet4"::: + ]]> - The resulting value is less than DateTimeOffset.MinValue. - - -or- - - The resulting value is greater than DateTimeOffset.MaxValue. + The resulting value is less than DateTimeOffset.MinValue. + +-or- + +The resulting value is greater than DateTimeOffset.MaxValue. @@ -1488,31 +1487,31 @@ In .NET 6 and earlier versions, the `minutes` parameter is rounded to the neares Returns a new object that adds a specified number of whole and fractional seconds to the value of this instance. An object whose value is the sum of the date and time represented by the current object and the number of seconds represented by . - precision of the `seconds` parameter is used. However, due to the inherent imprecision of floating point math, the resulting precision will vary. - -> [!NOTE] -> This method returns a new object. It does not modify the value of the current object by adding `seconds` to its date and time. - - Because a object does not represent the date and time in a specific time zone, the method does not consider a particular time zone's adjustment rules when it performs date and time arithmetic. - + precision of the `seconds` parameter is used. However, due to the inherent imprecision of floating point math, the resulting precision will vary. + +> [!NOTE] +> This method returns a new object. It does not modify the value of the current object by adding `seconds` to its date and time. + + Because a object does not represent the date and time in a specific time zone, the method does not consider a particular time zone's adjustment rules when it performs date and time arithmetic. + ]]> - The resulting value is less than DateTimeOffset.MinValue. - - -or- - - The resulting value is greater than DateTimeOffset.MaxValue. + The resulting value is less than DateTimeOffset.MinValue. + +-or- + +The resulting value is greater than DateTimeOffset.MaxValue. Performing Arithmetic Operations with Dates and Times @@ -1560,36 +1559,36 @@ In .NET 6 and earlier versions, the `seconds` parameter is rounded to the neares Returns a new object that adds a specified number of ticks to the value of this instance. An object whose value is the sum of the date and time represented by the current object and the number of ticks represented by . - [!NOTE] -> This method returns a new object. It does not modify the value of the current object by adding `ticks` to its date and time. - - The following table lists the number of ticks in a particular time interval. - -|Time interval|Number of ticks| -|-------------------|---------------------| -|Second|10,000,000| -|Minute|600,000,000| -|Hour|36,000,000,000| -|Day|864,000,000,000| -|Week|6,048,000,000,000| -|Month|Depends on number of days in the month.| -|Non-leap year|315,360,000,000,000| -|Leap year|316,224,000,000,000| - - Because a object does not represent the date and time in a specific time zone, the method does not consider a particular time zone's adjustment rules when it performs date and time arithmetic. - + [!NOTE] +> This method returns a new object. It does not modify the value of the current object by adding `ticks` to its date and time. + + The following table lists the number of ticks in a particular time interval. + +|Time interval|Number of ticks| +|-------------------|---------------------| +|Second|10,000,000| +|Minute|600,000,000| +|Hour|36,000,000,000| +|Day|864,000,000,000| +|Week|6,048,000,000,000| +|Month|Depends on number of days in the month.| +|Non-leap year|315,360,000,000,000| +|Leap year|316,224,000,000,000| + + Because a object does not represent the date and time in a specific time zone, the method does not consider a particular time zone's adjustment rules when it performs date and time arithmetic. + ]]> - The resulting value is less than DateTimeOffset.MinValue. - - -or- - - The resulting value is greater than DateTimeOffset.MaxValue. + The resulting value is less than DateTimeOffset.MinValue. + +-or- + +The resulting value is greater than DateTimeOffset.MaxValue. Performing Arithmetic Operations with Dates and Times @@ -1637,28 +1636,28 @@ In .NET 6 and earlier versions, the `seconds` parameter is rounded to the neares Returns a new object that adds a specified number of years to the value of this instance. An object whose value is the sum of the date and time represented by the current object and the number of years represented by . - does not enable you to add fractional parts of a year. To add a time that consists of other time units in addition to years to a object, use the method. - -> [!NOTE] -> This method returns a new object. It does not modify the value of the current object by adding `years` to its date and time. - -## Examples - In the United States, driver's licenses cannot be issued to persons under 16 years of age. The following example displays the latest possible date on which a person must be born in order to legally be issued a driver's license. - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Add/Methods.cs" id="Snippet6"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/fs/Methods.fs" id="Snippet6"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/vb/Methods.vb" id="Snippet6"::: - + does not enable you to add fractional parts of a year. To add a time that consists of other time units in addition to years to a object, use the method. + +> [!NOTE] +> This method returns a new object. It does not modify the value of the current object by adding `years` to its date and time. + +## Examples + In the United States, driver's licenses cannot be issued to persons under 16 years of age. The following example displays the latest possible date on which a person must be born in order to legally be issued a driver's license. + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Add/Methods.cs" id="Snippet6"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/fs/Methods.fs" id="Snippet6"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/vb/Methods.vb" id="Snippet6"::: + ]]> - The resulting value is less than DateTimeOffset.MinValue. - - -or- - - The resulting value is greater than DateTimeOffset.MaxValue. + The resulting value is less than DateTimeOffset.MinValue. + +-or- + +The resulting value is greater than DateTimeOffset.MaxValue. @@ -1705,46 +1704,55 @@ In .NET 6 and earlier versions, the `seconds` parameter is rounded to the neares The first object to compare. The second object to compare. Compares two objects and indicates whether the first is earlier than the second, equal to the second, or later than the second. - A signed integer that indicates whether the value of the parameter is earlier than, later than, or the same time as the value of the parameter, as the following table shows. - - Return value - - Meaning - - Less than zero - - is earlier than . - - Zero - - is equal to . - - Greater than zero - - is later than . - - + A signed integer that indicates whether the value of the parameter is earlier than, later than, or the same time as the value of the parameter, as the following table shows. + + Return value + + + Meaning + + + + + Less than zero + + + is earlier than . + + + Zero + + + is equal to . + + + Greater than zero + + + is later than . + + - method determines whether two objects represent a single point in time. It directly compares neither dates and times nor offsets. - - - -## Examples - The following example illustrates calls to the method to compare objects. - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Add/Methods2.cs" id="Snippet7"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/fs/Methods2.fs" id="Snippet7"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/vb/Methods2.vb" id="Snippet7"::: - + method determines whether two objects represent a single point in time. It directly compares neither dates and times nor offsets. + + + +## Examples + The following example illustrates calls to the method to compare objects. + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Add/Methods2.cs" id="Snippet7"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/fs/Methods2.fs" id="Snippet7"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/vb/Methods2.vb" id="Snippet7"::: + ]]> @@ -1794,40 +1802,49 @@ In .NET 6 and earlier versions, the `seconds` parameter is rounded to the neares An object to compare with the current object. Compares the current object to a specified object and indicates whether the current object is earlier than, the same as, or later than the second object. - A signed integer that indicates the relationship between the current object and , as the following table shows. - - Return Value - - Description - - Less than zero - - The current object is earlier than . - - Zero - - The current object is the same as . - - Greater than zero. - - The current object is later than . - - + A signed integer that indicates the relationship between the current object and , as the following table shows. + + Return Value + + + Description + + + + + Less than zero + + + The current object is earlier than . + + + Zero + + + The current object is the same as . + + + Greater than zero. + + + The current object is later than . + + - objects by comparing their values; that is, it determines whether the two objects represent a single point in time, and indicates whether the current object is earlier than, later than, or the same as the `other` parameter. - - - -## Examples - The following example illustrates calls to the method to compare objects. - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Add/Methods3.cs" id="Snippet8"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/fs/Methods3.fs" id="Snippet8"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/vb/Methods3.vb" id="Snippet8"::: - + objects by comparing their values; that is, it determines whether the two objects represent a single point in time, and indicates whether the current object is earlier than, later than, or the same as the `other` parameter. + + + +## Examples + The following example illustrates calls to the method to compare objects. + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Add/Methods3.cs" id="Snippet8"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/fs/Methods3.fs" id="Snippet8"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/vb/Methods3.vb" id="Snippet8"::: + ]]> @@ -1872,24 +1889,24 @@ In .NET 6 and earlier versions, the `seconds` parameter is rounded to the neares Gets a value that represents the date component of the current object. A value that represents the date component of the current object. - object and returns only its significant date component. For example, if the object has a date and time value of "1/12/07 4:01pm +7:30", the property returns a value of "1/12/07 12:00:00 AM". The value can then be displayed by using any of the standard or custom format specifiers that display dates only. (See the Example section for an illustration.) - - The value of the property of the returned object is always . It is not affected by the value of the property. - - To display a date without its time component, you can also use the "D" or "d" format specifiers; for an illustration, see the Example section. - - - -## Examples - The following example retrieves the value of the property for a specific date. It then displays that value to the console using some standard and custom date-only format specifiers. - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Date/Properties.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/Properties.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/vb/Properties.vb" id="Snippet1"::: - + object and returns only its significant date component. For example, if the object has a date and time value of "1/12/07 4:01pm +7:30", the property returns a value of "1/12/07 12:00:00 AM". The value can then be displayed by using any of the standard or custom format specifiers that display dates only. (See the Example section for an illustration.) + + The value of the property of the returned object is always . It is not affected by the value of the property. + + To display a date without its time component, you can also use the "D" or "d" format specifiers; for an illustration, see the Example section. + + + +## Examples + The following example retrieves the value of the property for a specific date. It then displays that value to the console using some standard and custom date-only format specifiers. + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Date/Properties.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/Properties.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/vb/Properties.vb" id="Snippet1"::: + ]]> Standard DateTime Format Strings @@ -1936,24 +1953,24 @@ In .NET 6 and earlier versions, the `seconds` parameter is rounded to the neares Gets a value that represents the date and time of the current object. The date and time of the current object. - property is not affected by the value of the property. - - This property returns both the date and the time component of a object, which makes it useful for performing to conversion. For example, if the object has a date and time value of "1/12/07 4:01pm + 7:30", the property returns a date of "1/12/07 4:01pm". - - The value of the property of the returned object is . - - - -## Examples - The following example illustrates the use of the property to convert the time returned by the and properties to values. - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Date/Properties.cs" id="Snippet2"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/Properties.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/vb/Properties.vb" id="Snippet2"::: - + property is not affected by the value of the property. + + This property returns both the date and the time component of a object, which makes it useful for performing to conversion. For example, if the object has a date and time value of "1/12/07 4:01pm + 7:30", the property returns a date of "1/12/07 4:01pm". + + The value of the property of the returned object is . + + + +## Examples + The following example illustrates the use of the property to convert the time returned by the and properties to values. + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Date/Properties.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/Properties.fs" id="Snippet2"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/vb/Properties.vb" id="Snippet2"::: + ]]> @@ -2000,28 +2017,28 @@ In .NET 6 and earlier versions, the `seconds` parameter is rounded to the neares Gets the day of the month represented by the current object. The day component of the current object, expressed as a value between 1 and 31. - property is not affected by the value of the property. - - You can also create a string representation of a object's day component by calling the method with the "d" or "dd" custom format specifiers. - - - -## Examples - The following example displays the day component of a object in three different ways: - -- By retrieving the value of the property. - -- By calling the method with the "d" format specifier. - -- By calling the method with the "dd" format specifier. - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Date/Properties.cs" id="Snippet10"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/Properties.fs" id="Snippet10"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/vb/Properties.vb" id="Snippet10"::: - + property is not affected by the value of the property. + + You can also create a string representation of a object's day component by calling the method with the "d" or "dd" custom format specifiers. + + + +## Examples + The following example displays the day component of a object in three different ways: + +- By retrieving the value of the property. + +- By calling the method with the "d" format specifier. + +- By calling the method with the "dd" format specifier. + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Date/Properties.cs" id="Snippet10"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/Properties.fs" id="Snippet10"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/vb/Properties.vb" id="Snippet10"::: + ]]> @@ -2066,32 +2083,32 @@ In .NET 6 and earlier versions, the `seconds` parameter is rounded to the neares Gets the day of the week represented by the current object. One of the enumeration values that indicates the day of the week of the current object. - enumeration ranges from to . If cast to an integer, its value ranges from zero (which indicates ) to six (which indicates ). - - You can also display the weekday name of a particular date by using the "D" format specifier or the "dddd" custom format specifier. For example: - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Date/Properties.cs" id="Snippet4"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/Properties.fs" id="Snippet4"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/vb/Properties.vb" id="Snippet4"::: - - Note that the string returned by calling the `ToString` method of the enumeration member that is returned by this property is not localized. To extract a string that contains the weekday name of the current culture or of a specific culture, call the method with the "dddd" custom format specifier. For example, the following code displays the weekday name for a date using the `fr-fr` culture. - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Date/Properties.cs" id="Snippet5"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/Properties.fs" id="Snippet5"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/vb/Properties.vb" id="Snippet5"::: - - - -## Examples - The following example displays the weekday name of the first day of each month of the year 2008. - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Date/Properties.cs" id="Snippet3"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/Properties.fs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/vb/Properties.vb" id="Snippet3"::: - + enumeration ranges from to . If cast to an integer, its value ranges from zero (which indicates ) to six (which indicates ). + + You can also display the weekday name of a particular date by using the "D" format specifier or the "dddd" custom format specifier. For example: + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Date/Properties.cs" id="Snippet4"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/Properties.fs" id="Snippet4"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/vb/Properties.vb" id="Snippet4"::: + + Note that the string returned by calling the `ToString` method of the enumeration member that is returned by this property is not localized. To extract a string that contains the weekday name of the current culture or of a specific culture, call the method with the "dddd" custom format specifier. For example, the following code displays the weekday name for a date using the `fr-fr` culture. + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Date/Properties.cs" id="Snippet5"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/Properties.fs" id="Snippet5"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/vb/Properties.vb" id="Snippet5"::: + + + +## Examples + The following example displays the weekday name of the first day of each month of the year 2008. + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Date/Properties.cs" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/Properties.fs" id="Snippet3"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/vb/Properties.vb" id="Snippet3"::: + ]]> @@ -2239,30 +2256,30 @@ In .NET 6 and earlier versions, the `seconds` parameter is rounded to the neares if both objects have the same value; otherwise, . - objects to Coordinated Universal Time (UTC). The method is equivalent to the following: - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Compare/Syntax.cs" id="Snippet2"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/fs/Syntax.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/vb/Syntax.vb" id="Snippet2"::: - - In other words, the method determines whether two objects represent a single point in time. It directly compares neither dates and times nor offsets. To determine whether two objects represent the same time and have the same offset value, use the method. - - A object that is not `null` is considered to be later (or greater) than one that is `null`. - - This overload of the method implements the method. It offers slightly better performance than the overload because the `other` parameter does not have to be converted from an object. - - - -## Examples - The following example illustrates calls to the method to test objects for equality with the current object. - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Add/Methods.cs" id="Snippet9"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/fs/Methods.fs" id="Snippet9"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/vb/Methods.vb" id="Snippet9"::: - + objects to Coordinated Universal Time (UTC). The method is equivalent to the following: + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Compare/Syntax.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/fs/Syntax.fs" id="Snippet2"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/vb/Syntax.vb" id="Snippet2"::: + + In other words, the method determines whether two objects represent a single point in time. It directly compares neither dates and times nor offsets. To determine whether two objects represent the same time and have the same offset value, use the method. + + A object that is not `null` is considered to be later (or greater) than one that is `null`. + + This overload of the method implements the method. It offers slightly better performance than the overload because the `other` parameter does not have to be converted from an object. + + + +## Examples + The following example illustrates calls to the method to test objects for equality with the current object. + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Add/Methods.cs" id="Snippet9"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/fs/Methods.fs" id="Snippet9"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/vb/Methods.vb" id="Snippet9"::: + ]]> @@ -2327,28 +2344,28 @@ In .NET 6 and earlier versions, the `seconds` parameter is rounded to the neares if the parameter is a object and represents the same point in time as the current object; otherwise, . - object and the `obj` parameter to Coordinated Universal Time (UTC). The method is equivalent to the following: - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Compare/Syntax.cs" id="Snippet3"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/fs/Syntax.fs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/vb/Syntax.vb" id="Snippet3"::: - - In other words, the method determines whether the current object and a specified object represent a single point in time. It directly compares neither dates and times nor offsets. To determine whether two objects represent the same time and have the same offset value, use the method. - - If `obj` is `null`, or if the run-time type of `obj` is not , the method returns `false`. - - - -## Examples - The following example indicates whether the current object is equal to several other objects, as well as to a null reference and a object. - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Add/Methods.cs" id="Snippet10"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/fs/Methods.fs" id="Snippet10"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/vb/Methods.vb" id="Snippet10"::: - + object and the `obj` parameter to Coordinated Universal Time (UTC). The method is equivalent to the following: + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Compare/Syntax.cs" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/fs/Syntax.fs" id="Snippet3"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/vb/Syntax.vb" id="Snippet3"::: + + In other words, the method determines whether the current object and a specified object represent a single point in time. It directly compares neither dates and times nor offsets. To determine whether two objects represent the same time and have the same offset value, use the method. + + If `obj` is `null`, or if the run-time type of `obj` is not , the method returns `false`. + + + +## Examples + The following example indicates whether the current object is equal to several other objects, as well as to a null reference and a object. + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Add/Methods.cs" id="Snippet10"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/fs/Methods.fs" id="Snippet10"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/vb/Methods.vb" id="Snippet10"::: + ]]> @@ -2401,26 +2418,26 @@ In .NET 6 and earlier versions, the `seconds` parameter is rounded to the neares if the two objects have the same value; otherwise, . - objects to Coordinated Universal Time (UTC). The method is equivalent to the following: - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Compare/Syntax.cs" id="Snippet4"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/fs/Syntax.fs" id="Snippet4"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/vb/Syntax.vb" id="Snippet4"::: - - In other words, the method determines whether the two objects represent a single point in time. It directly compares neither dates and times nor offsets. To determine whether two objects represent the same time and have the same offset value, use the method. - - - -## Examples - The following example illustrates calls to the method to test various pairs of objects for equality. - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Add/Methods.cs" id="Snippet11"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/fs/Methods.fs" id="Snippet11"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/vb/Methods.vb" id="Snippet11"::: - + objects to Coordinated Universal Time (UTC). The method is equivalent to the following: + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Compare/Syntax.cs" id="Snippet4"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/fs/Syntax.fs" id="Snippet4"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/vb/Syntax.vb" id="Snippet4"::: + + In other words, the method determines whether the two objects represent a single point in time. It directly compares neither dates and times nor offsets. To determine whether two objects represent the same time and have the same offset value, use the method. + + + +## Examples + The following example illustrates calls to the method to test various pairs of objects for equality. + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Add/Methods.cs" id="Snippet11"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/fs/Methods.fs" id="Snippet11"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/vb/Methods.vb" id="Snippet11"::: + ]]> @@ -2471,22 +2488,22 @@ In .NET 6 and earlier versions, the `seconds` parameter is rounded to the neares if the current object and have the same date and time value and the same value; otherwise, . - method, the overloads of the method determine only whether two values represent a single point in time. They do not indicate that two values have the same date and time as well as the same offset. - - - -## Examples - The following example illustrates the use of the method to compare similar objects. - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Add/Methods.cs" id="Snippet12"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/fs/Methods.fs" id="Snippet12"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/vb/Methods.vb" id="Snippet12"::: - + method, the overloads of the method determine only whether two values represent a single point in time. They do not indicate that two values have the same date and time as well as the same offset. + + + +## Examples + The following example illustrates the use of the method to compare similar objects. + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Add/Methods.cs" id="Snippet12"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/fs/Methods.fs" id="Snippet12"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/vb/Methods.vb" id="Snippet12"::: + ]]> @@ -2536,32 +2553,32 @@ In .NET 6 and earlier versions, the `seconds` parameter is rounded to the neares Converts the specified Windows file time to an equivalent local time. An object that represents the date and time of with the offset set to the local time offset. - values. - - Windows file time values can also be created from values by calling the and methods, and from values by calling the method. - - - -## Examples - The following example uses the Windows API to retrieve the Windows file times for the WordPad executable. - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/FromFileTime/FileTime.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.FromFileTime/fs/FileTime.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.FromFileTime/vb/FileTime.vb" id="Snippet1"::: - + values. + + Windows file time values can also be created from values by calling the and methods, and from values by calling the method. + + + +## Examples + The following example uses the Windows API to retrieve the Windows file times for the WordPad executable. + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/FromFileTime/FileTime.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.FromFileTime/fs/FileTime.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.FromFileTime/vb/FileTime.vb" id="Snippet1"::: + ]]> - is less than zero. - - -or- - - is greater than . + is less than zero. + +-or- + + is greater than . @@ -2605,19 +2622,19 @@ In .NET 6 and earlier versions, the `seconds` parameter is rounded to the neares Converts a Unix time expressed as the number of milliseconds that have elapsed since 1970-01-01T00:00:00Z to a value. A date and time value that represents the same moment in time as the Unix time. - property value of the returned instance is , which represents Coordinated Universal Time. You can convert it to the time in a specific time zone by calling the method. - + property value of the returned instance is , which represents Coordinated Universal Time. You can convert it to the time in a specific time zone by calling the method. + ]]> - is less than -62,135,596,800,000. - - -or- - - is greater than 253,402,300,799,999. + is less than -62,135,596,800,000. + +-or- + + is greater than 253,402,300,799,999. @@ -2663,19 +2680,19 @@ In .NET 6 and earlier versions, the `seconds` parameter is rounded to the neares Converts a Unix time expressed as the number of seconds that have elapsed since 1970-01-01T00:00:00Z to a value. A date and time value that represents the same moment in time as the Unix time. - property value of the returned instance is , which represents Coordinated Universal Time. You can convert it to the time in a specific time zone by calling the method. - + property value of the returned instance is , which represents Coordinated Universal Time. You can convert it to the time in a specific time zone by calling the method. + ]]> - is less than -62,135,596,800. - - -or- - - is greater than 253,402,300,799. + is less than -62,135,596,800. + +-or- + + is greater than 253,402,300,799. @@ -2763,28 +2780,28 @@ In .NET 6 and earlier versions, the `seconds` parameter is rounded to the neares Gets the hour component of the time represented by the current object. The hour component of the current object. This property uses a 24-hour clock; the value ranges from 0 to 23. - property is not affected by the value of the property. - - You can also create a string representation of a object's hour component by calling the method with the "H", or "HH" custom format specifiers. - - - -## Examples - The following example displays the hour component of a object in three different ways: - -- By retrieving the value of the property. - -- By calling the method with the "H" format specifier. - -- By calling the method with the "HH" format specifier. - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Date/Properties.cs" id="Snippet6"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/Properties.fs" id="Snippet6"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/vb/Properties.vb" id="Snippet6"::: - + property is not affected by the value of the property. + + You can also create a string representation of a object's hour component by calling the method with the "H", or "HH" custom format specifiers. + + + +## Examples + The following example displays the hour component of a object in three different ways: + +- By retrieving the value of the property. + +- By calling the method with the "H" format specifier. + +- By calling the method with the "HH" format specifier. + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Date/Properties.cs" id="Snippet6"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/Properties.fs" id="Snippet6"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/vb/Properties.vb" id="Snippet6"::: + ]]> @@ -2829,28 +2846,28 @@ In .NET 6 and earlier versions, the `seconds` parameter is rounded to the neares Gets a value that represents the local date and time of the current object. The local date and time of the current object. - property converts the current object's date and time to the local system's date and time. The conversion is a two-step operation: - -1. The property converts the current object's time to Coordinated Universal Time (UTC). - -2. The property then converts UTC to local time. - - There are no invalid times and ambiguous times are mapped to the local zone's standard time. (However, the conversion can create an anomaly: if a value that is derived from the local computer reflects an ambiguous date and time, that value can be converted to UTC and then back to a local time that differs from the original time.) The property applies any adjustment rules in the local time zone when it performs this conversion. - - This property returns both the date and the time component of a object, which makes it useful for to conversion. In addition to performing any necessary time conversion, this property differs from the property by setting the value of the property of the returned object to . - - - -## Examples - The following example illustrates several conversions of values to local times in the U.S. Pacific Standard Time zone. Note that the last three times are all ambiguous; the property maps all of them to a single date and time in the Pacific Standard Time zone. - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Date/Properties.cs" id="Snippet7"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/Properties.fs" id="Snippet7"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/vb/Properties.vb" id="Snippet7"::: - + property converts the current object's date and time to the local system's date and time. The conversion is a two-step operation: + +1. The property converts the current object's time to Coordinated Universal Time (UTC). + +2. The property then converts UTC to local time. + + There are no invalid times and ambiguous times are mapped to the local zone's standard time. (However, the conversion can create an anomaly: if a value that is derived from the local computer reflects an ambiguous date and time, that value can be converted to UTC and then back to a local time that differs from the original time.) The property applies any adjustment rules in the local time zone when it performs this conversion. + + This property returns both the date and the time component of a object, which makes it useful for to conversion. In addition to performing any necessary time conversion, this property differs from the property by setting the value of the property of the returned object to . + + + +## Examples + The following example illustrates several conversions of values to local times in the U.S. Pacific Standard Time zone. Note that the last three times are all ambiguous; the property maps all of them to a single date and time in the Pacific Standard Time zone. + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Date/Properties.cs" id="Snippet7"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/Properties.fs" id="Snippet7"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/vb/Properties.vb" id="Snippet7"::: + ]]> @@ -2895,15 +2912,15 @@ In .NET 6 and earlier versions, the `seconds` parameter is rounded to the neares Represents the greatest possible value of . This field is read-only. - property is used to determine whether the value of a new object or the value returned by an arithmetic operation is the same as or earlier than this maximum range value. If it is not, the method throws an . Any value is converted to Coordinated Universal Time (UTC) before the method compares it with . This means that a value whose date and time are close to the maximum range, but whose offset is negative, may throw an exception. For example, the value 12/31/9999 11:00 PM -02:00 is out of range because it is one hour later than when it is converted to UTC. - - Some calendars, such as the , support an upper date range that is earlier than . In these cases, trying to access in variable assignments or formatting and parsing operations can throw an . Instead of retrieving the value of , you can retrieve the value of the specified culture's latest valid date value from the property. - + property is used to determine whether the value of a new object or the value returned by an arithmetic operation is the same as or earlier than this maximum range value. If it is not, the method throws an . Any value is converted to Coordinated Universal Time (UTC) before the method compares it with . This means that a value whose date and time are close to the maximum range, but whose offset is negative, may throw an exception. For example, the value 12/31/9999 11:00 PM -02:00 is out of range because it is one hour later than when it is converted to UTC. + + Some calendars, such as the , support an upper date range that is earlier than . In these cases, trying to access in variable assignments or formatting and parsing operations can throw an . Instead of retrieving the value of , you can retrieve the value of the specified culture's latest valid date value from the property. + ]]> @@ -2936,14 +2953,14 @@ In .NET 6 and earlier versions, the `seconds` parameter is rounded to the neares Gets the microsecond component of the time represented by the current object. To be added. - or to accurately track the number of elapsed microseconds, - the precision of the time's microseconds component depends on the resolution of the system clock. - On Windows NT 3.5 and later, and Windows Vista operating systems, the clock's resolution is approximately 10000-15000 microseconds. - + or to accurately track the number of elapsed microseconds, + the precision of the time's microseconds component depends on the resolution of the system clock. + On Windows NT 3.5 and later, and Windows Vista operating systems, the clock's resolution is approximately 10000-15000 microseconds. + ]]> @@ -2988,22 +3005,22 @@ If you rely on properties such as or Gets the millisecond component of the time represented by the current object. The millisecond component of the current object, expressed as an integer between 0 and 999. - object's millisecond component by calling the method with the "fff" custom format specifier. - - If you rely on properties such as or to accurately track the number of elapsed milliseconds, the precision of the time's millisecond component depends on the resolution of the system clock. On Windows NT 3.5 and later, and Windows Vista operating systems, the clock's resolution is approximately 10-15 milliseconds. - - - -## Examples - The following example displays the number of milliseconds of a object by using a custom format specifier and by directly accessing the property. - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Date/Properties.cs" id="Snippet12"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/Properties.fs" id="Snippet12"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/vb/Properties.vb" id="Snippet12"::: - + object's millisecond component by calling the method with the "fff" custom format specifier. + + If you rely on properties such as or to accurately track the number of elapsed milliseconds, the precision of the time's millisecond component depends on the resolution of the system clock. On Windows NT 3.5 and later, and Windows Vista operating systems, the clock's resolution is approximately 10-15 milliseconds. + + + +## Examples + The following example displays the number of milliseconds of a object by using a custom format specifier and by directly accessing the property. + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Date/Properties.cs" id="Snippet12"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/Properties.fs" id="Snippet12"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/vb/Properties.vb" id="Snippet12"::: + ]]> @@ -3048,28 +3065,28 @@ If you rely on properties such as or Gets the minute component of the time represented by the current object. The minute component of the current object, expressed as an integer between 0 and 59. - property is not affected by the value of the property. - - You can also create a string representation of a object's minute component by calling the method with the "m", or "mm" custom format specifiers. - - - -## Examples - The following example displays the minute component of a object in three different ways: - -- By retrieving the value of the property. - -- By calling the method with the "m" format specifier. - -- By calling the method with the "mm" format specifier. - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Date/Properties.cs" id="Snippet8"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/Properties.fs" id="Snippet8"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/vb/Properties.vb" id="Snippet8"::: - + property is not affected by the value of the property. + + You can also create a string representation of a object's minute component by calling the method with the "m", or "mm" custom format specifiers. + + + +## Examples + The following example displays the minute component of a object in three different ways: + +- By retrieving the value of the property. + +- By calling the method with the "m" format specifier. + +- By calling the method with the "mm" format specifier. + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Date/Properties.cs" id="Snippet8"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/Properties.fs" id="Snippet8"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/vb/Properties.vb" id="Snippet8"::: + ]]> @@ -3113,13 +3130,13 @@ If you rely on properties such as or Represents the earliest possible value. This field is read-only. - property is used to determine whether the value of a new object or the value returned by an arithmetic operation is the same as or later than this minimum range value. If it is not, the method throws an . Any value is converted to Coordinated Universal Time (UTC) before the method performs the comparison with . This means that a value whose date and time are close to the minimum range, but whose offset is positive, may throw an exception. For example, the value 1/1/0001 1:00:00 AM +02:00 is out of range because it is one hour earlier than when it is converted to UTC. - + property is used to determine whether the value of a new object or the value returned by an arithmetic operation is the same as or later than this minimum range value. If it is not, the method throws an . Any value is converted to Coordinated Universal Time (UTC) before the method performs the comparison with . This means that a value whose date and time are close to the minimum range, but whose offset is positive, may throw an exception. For example, the value 1/1/0001 1:00:00 AM +02:00 is out of range because it is one hour earlier than when it is converted to UTC. + ]]> @@ -3165,28 +3182,28 @@ If you rely on properties such as or Gets the month component of the date represented by the current object. The month component of the current object, expressed as an integer between 1 and 12. - property is not affected by the value of the property. - - You can also create a string representation of a object's month component by calling the method with the "M" or "MM" custom format specifiers. - - - -## Examples - The following example displays the month component of a value in three different ways: - -- By retrieving the value of the property. - -- By calling the method with the "M" format specifier. - -- By calling the method with the "MM" format specifier. - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Date/Properties.cs" id="Snippet9"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/Properties.fs" id="Snippet9"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/vb/Properties.vb" id="Snippet9"::: - + property is not affected by the value of the property. + + You can also create a string representation of a object's month component by calling the method with the "M" or "MM" custom format specifiers. + + + +## Examples + The following example displays the month component of a value in three different ways: + +- By retrieving the value of the property. + +- By calling the method with the "M" format specifier. + +- By calling the method with the "MM" format specifier. + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Date/Properties.cs" id="Snippet9"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/Properties.fs" id="Snippet9"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/vb/Properties.vb" id="Snippet9"::: + ]]> @@ -3217,14 +3234,14 @@ If you rely on properties such as or Gets the nanosecond component of the time represented by the current object. To be added. - or to accurately track the number of elapsed nanosecond, - the precision of the time's nanosecond component depends on the resolution of the system clock. - On Windows NT 3.5 and later, and Windows Vista operating systems, the clock's resolution is approximately 10000000-15000000 nanoseconds. - + or to accurately track the number of elapsed nanosecond, + the precision of the time's nanosecond component depends on the resolution of the system clock. + On Windows NT 3.5 and later, and Windows Vista operating systems, the clock's resolution is approximately 10000000-15000000 nanoseconds. + ]]> @@ -3269,26 +3286,26 @@ If you rely on properties such as or Gets a object that is set to the current date and time on the current computer, with the offset set to the local time's offset from Coordinated Universal Time (UTC). A object whose date and time is the current local time and whose offset is the local time zone's offset from Coordinated Universal Time (UTC). - property to retrieve the current date and time and displays it by using each of the [standard date and time format strings](/dotnet/standard/base-types/standard-date-and-time-format-strings) supported by the type. - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Now/now1.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.datetimeoffset.now/fs/now1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.datetimeoffset.now/vb/now1.vb" id="Snippet1"::: - - The following example uses the and properties to determine the resolution of the system clock. It displays the time only when the value of its millisecond component has changed. - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Date/Properties.cs" id="Snippet11"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/Properties.fs" id="Snippet11"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/vb/Properties.vb" id="Snippet11"::: - + property to retrieve the current date and time and displays it by using each of the [standard date and time format strings](/dotnet/standard/base-types/standard-date-and-time-format-strings) supported by the type. + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Now/now1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.datetimeoffset.now/fs/now1.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.datetimeoffset.now/vb/now1.vb" id="Snippet1"::: + + The following example uses the and properties to determine the resolution of the system clock. It displays the time only when the value of its millisecond component has changed. + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Date/Properties.cs" id="Snippet11"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/Properties.fs" id="Snippet11"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/vb/Properties.vb" id="Snippet11"::: + ]]> @@ -3334,22 +3351,22 @@ If you rely on properties such as or Gets the time's offset from Coordinated Universal Time (UTC). The difference between the current object's time value and Coordinated Universal Time (UTC). - property of the returned object can range from -14 hours to 14 hours. - - The value of the property is precise to the minute. - - - -## Examples - The following example uses the property to display the local time's difference from Coordinated Universal Time (UTC). - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Date/Properties.cs" id="Snippet13"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/Properties.fs" id="Snippet13"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/vb/Properties.vb" id="Snippet13"::: - + property of the returned object can range from -14 hours to 14 hours. + + The value of the property is precise to the minute. + + + +## Examples + The following example uses the property to display the local time's difference from Coordinated Universal Time (UTC). + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Date/Properties.cs" id="Snippet13"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/Properties.fs" id="Snippet13"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/vb/Properties.vb" id="Snippet13"::: + ]]> @@ -3407,24 +3424,24 @@ If you rely on properties such as or Adds a specified time interval to a object that has a specified date and time, and yields a object that has new a date and time. An object whose value is the sum of the values of and . - method defines the addition operation for values. It enables code such as the following: - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/op_Addition/Operators.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/fs/Operators.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/vb/Operators.vb" id="Snippet1"::: - - Languages that do not support custom operators and operator overloading can call the method instead. - + method defines the addition operation for values. It enables code such as the following: + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/op_Addition/Operators.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/fs/Operators.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/vb/Operators.vb" id="Snippet1"::: + + Languages that do not support custom operators and operator overloading can call the method instead. + The equivalent method for this operator is .]]> - The resulting value is less than DateTimeOffset.MinValue. - - -or- - - The resulting value is greater than DateTimeOffset.MaxValue. + The resulting value is less than DateTimeOffset.MinValue. + +-or- + +The resulting value is greater than DateTimeOffset.MaxValue. Performing Arithmetic Operations with Dates and Times @@ -3476,23 +3493,23 @@ If you rely on properties such as or if both objects have the same value; otherwise, . - method defines the operation of the equality operator for objects. It enables code such as the following: - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/op_Addition/Operators.cs" id="Snippet2"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/fs/Operators.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/vb/Operators.vb" id="Snippet2"::: - - Before evaluating the `left` and `right` operands for equality, the operator converts both values to Coordinated Universal Time (UTC). The operation is equivalent to the following: - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Compare/Syntax.cs" id="Snippet4"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/fs/Syntax.fs" id="Snippet4"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/vb/Syntax.vb" id="Snippet4"::: - - In other words, the method determines whether the two objects represent a single point in time. It directly compares neither dates and times nor offsets. To determine whether two objects represent the same time and have the same offset value, use the method. - + method defines the operation of the equality operator for objects. It enables code such as the following: + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/op_Addition/Operators.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/fs/Operators.fs" id="Snippet2"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/vb/Operators.vb" id="Snippet2"::: + + Before evaluating the `left` and `right` operands for equality, the operator converts both values to Coordinated Universal Time (UTC). The operation is equivalent to the following: + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Compare/Syntax.cs" id="Snippet4"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/fs/Syntax.fs" id="Snippet4"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/vb/Syntax.vb" id="Snippet4"::: + + In other words, the method determines whether the two objects represent a single point in time. It directly compares neither dates and times nor offsets. To determine whether two objects represent the same time and have the same offset value, use the method. + The equivalent method for this operator is ]]> @@ -3545,25 +3562,25 @@ If you rely on properties such as or if the value of is later than the value of ; otherwise, . - method defines the operation of the greater than operator for objects. It enables code such as the following: - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/op_Addition/Operators.cs" id="Snippet3"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/fs/Operators.fs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/vb/Operators.vb" id="Snippet3"::: - - Languages that do not support custom operators can call the method instead. They can also call the method directly, as the following example shows. - - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/vb/Operators.vb" id="Snippet4"::: - - Before evaluating the `left` and `right` operands, the operator converts both values to Coordinated Universal Time (UTC). The operation is equivalent to the following: - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Compare/Syntax.cs" id="Snippet5"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/fs/Syntax.fs" id="Snippet5"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/vb/Syntax.vb" id="Snippet5"::: - + method defines the operation of the greater than operator for objects. It enables code such as the following: + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/op_Addition/Operators.cs" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/fs/Operators.fs" id="Snippet3"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/vb/Operators.vb" id="Snippet3"::: + + Languages that do not support custom operators can call the method instead. They can also call the method directly, as the following example shows. + + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/vb/Operators.vb" id="Snippet4"::: + + Before evaluating the `left` and `right` operands, the operator converts both values to Coordinated Universal Time (UTC). The operation is equivalent to the following: + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Compare/Syntax.cs" id="Snippet5"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/fs/Syntax.fs" id="Snippet5"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/vb/Syntax.vb" id="Snippet5"::: + The equivalent method for this operator is ]]> @@ -3616,25 +3633,25 @@ If you rely on properties such as or if the value of is the same as or later than the value of ; otherwise, . - method defines the operation of the greater than or equal to operator for objects. It enables code such as the following: - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/op_Addition/Operators.cs" id="Snippet5"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/fs/Operators.fs" id="Snippet5"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/vb/Operators.vb" id="Snippet5"::: - - Languages that do not support custom operators can call the method instead. Some languages can also call the method directly, as the following example shows. - - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/vb/Operators.vb" id="Snippet6"::: - - Before evaluating the `left` and `right` operands, the operator converts both values to Coordinated Universal Time (UTC). The operation is equivalent to the following: - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Compare/Syntax.cs" id="Snippet6"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/fs/Syntax.fs" id="Snippet6"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/vb/Syntax.vb" id="Snippet6"::: - + method defines the operation of the greater than or equal to operator for objects. It enables code such as the following: + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/op_Addition/Operators.cs" id="Snippet5"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/fs/Operators.fs" id="Snippet5"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/vb/Operators.vb" id="Snippet5"::: + + Languages that do not support custom operators can call the method instead. Some languages can also call the method directly, as the following example shows. + + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/vb/Operators.vb" id="Snippet6"::: + + Before evaluating the `left` and `right` operands, the operator converts both values to Coordinated Universal Time (UTC). The operation is equivalent to the following: + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Compare/Syntax.cs" id="Snippet6"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/fs/Syntax.fs" id="Snippet6"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/vb/Syntax.vb" id="Snippet6"::: + The equivalent method for this operator is ]]> @@ -3684,28 +3701,28 @@ If you rely on properties such as or Defines an implicit conversion of a object to a object. The converted object. - method enables the compiler to automatically convert a object to a object without an explicit casting operator (in C#) or a call to a conversion function (in Visual Basic). It defines a widening conversion that does not involve data loss and does not throw an . The method makes code such as the following possible: - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/op_Addition/Operators.cs" id="Snippet7"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/fs/Operators.fs" id="Snippet7"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/vb/Operators.vb" id="Snippet7"::: - - This method is equivalent to the constructor. The offset of the resulting object depends on the value of the property of the `dateTime` parameter: - -- If the value of the property is , the date and time of the object is set equal to `dateTime`, and its property is set equal to 0. - -- If the value of the property is or , the date and time of the object is set equal to `dateTime`, and its property is set equal to the offset of the local system's current time zone. - + method enables the compiler to automatically convert a object to a object without an explicit casting operator (in C#) or a call to a conversion function (in Visual Basic). It defines a widening conversion that does not involve data loss and does not throw an . The method makes code such as the following possible: + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/op_Addition/Operators.cs" id="Snippet7"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/fs/Operators.fs" id="Snippet7"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/vb/Operators.vb" id="Snippet7"::: + + This method is equivalent to the constructor. The offset of the resulting object depends on the value of the property of the `dateTime` parameter: + +- If the value of the property is , the date and time of the object is set equal to `dateTime`, and its property is set equal to 0. + +- If the value of the property is or , the date and time of the object is set equal to `dateTime`, and its property is set equal to the offset of the local system's current time zone. + The equivalent method for this operator is ]]> - The Coordinated Universal Time (UTC) date and time that results from applying the offset is earlier than DateTimeOffset.MinValue. - - -or- - - The UTC date and time that results from applying the offset is later than DateTimeOffset.MaxValue. + The Coordinated Universal Time (UTC) date and time that results from applying the offset is earlier than DateTimeOffset.MinValue. + +-or- + +The UTC date and time that results from applying the offset is later than DateTimeOffset.MaxValue. @@ -3755,27 +3772,27 @@ If you rely on properties such as or if and do not have the same value; otherwise, . - method defines the operation of the inequality operator for objects. It always returns the opposite result from . The method enables code such as the following: - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/op_Addition/Operators.cs" id="Snippet8"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/fs/Operators.fs" id="Snippet8"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/vb/Operators.vb" id="Snippet8"::: - - Before evaluating the `left` and `right` operands for equality, the operator converts both values to Coordinated Universal Time (UTC). The operation is equivalent to the following: - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Compare/Syntax.cs" id="Snippet4"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/fs/Syntax.fs" id="Snippet4"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/vb/Syntax.vb" id="Snippet4"::: - - In other words, the method determines whether the two objects represent different points in time. It directly compares neither dates and times nor offsets. - - Languages that do not support custom operators can call the method instead. In addition, some languages can also call the method directly, as the following example shows. - - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/vb/Operators.vb" id="Snippet9"::: - + method defines the operation of the inequality operator for objects. It always returns the opposite result from . The method enables code such as the following: + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/op_Addition/Operators.cs" id="Snippet8"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/fs/Operators.fs" id="Snippet8"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/vb/Operators.vb" id="Snippet8"::: + + Before evaluating the `left` and `right` operands for equality, the operator converts both values to Coordinated Universal Time (UTC). The operation is equivalent to the following: + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Compare/Syntax.cs" id="Snippet4"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/fs/Syntax.fs" id="Snippet4"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/vb/Syntax.vb" id="Snippet4"::: + + In other words, the method determines whether the two objects represent different points in time. It directly compares neither dates and times nor offsets. + + Languages that do not support custom operators can call the method instead. In addition, some languages can also call the method directly, as the following example shows. + + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/vb/Operators.vb" id="Snippet9"::: + The equivalent method for this operator is ]]> @@ -3827,25 +3844,25 @@ If you rely on properties such as or if the value of is earlier than the value of ; otherwise, . - method defines the operation of the less than operator for objects. It enables code such as the following: - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/op_Addition/Operators.cs" id="Snippet10"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/fs/Operators.fs" id="Snippet10"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/vb/Operators.vb" id="Snippet10"::: - - Before evaluating the `left` and `right` operands, the operator converts both operands to Coordinated Universal Time (UTC). The operation is equivalent to the following: - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Compare/Syntax.cs" id="Snippet8"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/fs/Syntax.fs" id="Snippet8"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/vb/Syntax.vb" id="Snippet8"::: - - Languages that do not support custom operators can call the method instead. In addition, some languages can also call the method directly, as the following example shows. - - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/vb/Operators.vb" id="Snippet11"::: - + method defines the operation of the less than operator for objects. It enables code such as the following: + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/op_Addition/Operators.cs" id="Snippet10"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/fs/Operators.fs" id="Snippet10"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/vb/Operators.vb" id="Snippet10"::: + + Before evaluating the `left` and `right` operands, the operator converts both operands to Coordinated Universal Time (UTC). The operation is equivalent to the following: + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Compare/Syntax.cs" id="Snippet8"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/fs/Syntax.fs" id="Snippet8"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/vb/Syntax.vb" id="Snippet8"::: + + Languages that do not support custom operators can call the method instead. In addition, some languages can also call the method directly, as the following example shows. + + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/vb/Operators.vb" id="Snippet11"::: + The equivalent method for this operator is ]]> @@ -3898,25 +3915,25 @@ If you rely on properties such as or if the value of is earlier than the value of ; otherwise, . - method defines the operation of the less than or equal to operator for objects. It enables code such as the following: - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/op_Addition/Operators.cs" id="Snippet12"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/fs/Operators.fs" id="Snippet12"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/vb/Operators.vb" id="Snippet12"::: - - Languages that do not support custom operators can call the method instead. Some languages can also call the method directly, as the following example shows. - - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/vb/Operators.vb" id="Snippet13"::: - - Before evaluating the `left` and `right` operands, the operator converts both values to Coordinated Universal Time (UTC). The operation is equivalent to the following: - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Compare/Syntax.cs" id="Snippet9"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/fs/Syntax.fs" id="Snippet9"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/vb/Syntax.vb" id="Snippet9"::: - + method defines the operation of the less than or equal to operator for objects. It enables code such as the following: + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/op_Addition/Operators.cs" id="Snippet12"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/fs/Operators.fs" id="Snippet12"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/vb/Operators.vb" id="Snippet12"::: + + Languages that do not support custom operators can call the method instead. Some languages can also call the method directly, as the following example shows. + + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/vb/Operators.vb" id="Snippet13"::: + + Before evaluating the `left` and `right` operands, the operator converts both values to Coordinated Universal Time (UTC). The operation is equivalent to the following: + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Compare/Syntax.cs" id="Snippet9"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/fs/Syntax.fs" id="Snippet9"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/vb/Syntax.vb" id="Snippet9"::: + The equivalent method for this operator is ]]> @@ -3981,17 +3998,17 @@ If you rely on properties such as or Subtracts one object from another and yields a time interval. An object that represents the difference between and . - method defines the subtraction operation for objects. It enables code such as the following: - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/op_Addition/Operators.cs" id="Snippet14"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/fs/Operators.fs" id="Snippet14"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/vb/Operators.vb" id="Snippet14"::: - - Languages that do not support custom operators and operator overloading can call the method instead. - + method defines the subtraction operation for objects. It enables code such as the following: + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/op_Addition/Operators.cs" id="Snippet14"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/fs/Operators.fs" id="Snippet14"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/vb/Operators.vb" id="Snippet14"::: + + Languages that do not support custom operators and operator overloading can call the method instead. + The equivalent method for this operator is .]]> @@ -4051,17 +4068,17 @@ If you rely on properties such as or Subtracts a specified time interval from a specified date and time, and yields a new date and time. An object that is equal to the value of minus . - method defines the subtraction operation for objects. It enables code such as the following: - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/op_Addition/Operators.cs" id="Snippet15"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/fs/Operators.fs" id="Snippet15"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/vb/Operators.vb" id="Snippet15"::: - - Languages that do not support custom operators and operator overloading can call the method instead. - + method defines the subtraction operation for objects. It enables code such as the following: + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/op_Addition/Operators.cs" id="Snippet15"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/fs/Operators.fs" id="Snippet15"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/vb/Operators.vb" id="Snippet15"::: + + Languages that do not support custom operators and operator overloading can call the method instead. + The equivalent method for this operator is .]]> The resulting value is less than DateTimeOffset.MinValue or greater than DateTimeOffset.MaxValue. @@ -4081,10 +4098,10 @@ If you rely on properties such as or Converts the specified string representation of a date and time to its equivalent. - @@ -4143,41 +4160,41 @@ If you rely on properties such as or Converts the specified string representation of a date, time, and offset to its equivalent. An object that is equivalent to the date and time that is contained in . - parses a string with three elements that can appear in any order and are delimited by white space. These three elements are as shown in the following table. - -|Element|Example| -|-------------|-------------| -|\|"2/10/2007"| -|\ The offset is greater than 14 hours or less than -14 hours. is . - does not contain a valid string representation of a date and time. - - -or- - - contains the string representation of an offset value without a date or time. + does not contain a valid string representation of a date and time. + +-or- + + contains the string representation of an offset value without a date or time. @@ -4291,49 +4308,49 @@ If you rely on properties such as or Converts the specified string representation of a date and time to its equivalent using the specified culture-specific format information. An object that is equivalent to the date and time that is contained in , as specified by . - |"2/10/2007"| -|\ The offset is greater than 14 hours or less than -14 hours. is . - does not contain a valid string representation of a date and time. - - -or- - - contains the string representation of an offset value without a date or time. + does not contain a valid string representation of a date and time. + +-or- + + contains the string representation of an offset value without a date or time. @@ -4452,79 +4469,79 @@ If you rely on properties such as or Converts the specified string representation of a date and time to its equivalent using the specified culture-specific format information and formatting style. An object that is equivalent to the date and time that is contained in as specified by and . - |"2/10/2007"| -|\ - The offset is greater than 14 hours or less than -14 hours. - - -or- - - is not a valid value. - - -or- - - includes an unsupported value. - - -or- - - includes values that cannot be used together. + The offset is greater than 14 hours or less than -14 hours. + +-or- + + is not a valid value. + +-or- + + includes an unsupported value. + +-or- + + includes values that cannot be used together. is . - does not contain a valid string representation of a date and time. - - -or- - - contains the string representation of an offset value without a date or time. + does not contain a valid string representation of a date and time. + +-or- + + contains the string representation of an offset value without a date or time. @@ -4540,10 +4557,10 @@ If you rely on properties such as or Converts the specified string representation of a date and time to its equivalent. The format of the string representation must match a specified format exactly. -
@@ -4616,62 +4633,62 @@ If you rely on properties such as or Converts the specified string representation of a date and time to its equivalent using the specified format and culture-specific format information. The format of the string representation must match the specified format exactly. An object that is equivalent to the date and time that is contained in as specified by and . - method parses the string representation of a date, which must be in the format defined by the `format` parameter. It also requires that the \, \ The offset is greater than 14 hours or less than -14 hours. - is . - - -or- - - is . + is . + +-or- + + is . - is an empty string (""). - - -or- - - does not contain a valid string representation of a date and time. - - -or- - - is an empty string. - - -or- - - The hour component and the AM/PM designator in do not agree. + is an empty string (""). + +-or- + + does not contain a valid string representation of a date and time. + +-or- + + is an empty string. + +-or- + +The hour component and the AM/PM designator in do not agree. In the .NET Framework 4, the method throws a if the string to be parsed contains an hour component and an AM/PM designator that are not in agreement. In the .NET Framework 3.5 and earlier versions, the AM/PM designator is ignored. @@ -4735,39 +4752,49 @@ The following example parses an array of strings that are expected to conform to Converts a character span that represents a date and time to its equivalent using the specified format, culture-specific format information, and style. The format of the date and time representation must match the specified format exactly. An object that is equivalent to the date and time that is contained in the parameter, as specified by the , , and parameters. - , \ - The offset is greater than 14 hours or less than -14 hours. --or- -The parameter includes an unsupported value. --or- + The offset is greater than 14 hours or less than -14 hours. + +-or- + +The parameter includes an unsupported value. + +-or- + The parameter contains values that cannot be used together. - is an empty character span. - -or- - does not contain a valid string representation of a date and time. - -or- - is an empty character span. - -or- - The hour component and the AM/PM designator in do not agree. + is an empty character span. + +-or- + + does not contain a valid string representation of a date and time. + +-or- + + is an empty character span. + +-or- + +The hour component and the AM/PM designator in do not agree. @@ -4829,55 +4856,65 @@ The parameter contains equivalent using the specified formats, culture-specific format information, and style. The format of the date and time representation must match one of the specified formats exactly. An object that is equivalent to the date and time that is contained in the parameter, as specified by the , , and parameters. - . Aside from comparing `input` to multiple formatting patterns, this overload behaves identically to the method. - - The `formats` parameter is a string array whose elements contain either a single standard format specifier or one or more custom format specifiers that define the possible pattern of the `input` parameter. When the method is called, `input` must match one of these patterns. For details about valid formatting codes, see [Standard Date and Time Format Strings](/dotnet/standard/base-types/standard-date-and-time-format-strings) and [Custom Date and Time Format Strings](/dotnet/standard/base-types/custom-date-and-time-format-strings). If the matched element in `formats` includes the `z`, `zz`, or `zzz` custom format specifiers to indicate that an offset must be present in `input`, that offset must include either a negative sign or a positive sign. If the sign is missing, the method throws a . - -> [!IMPORTANT] -> Using the `formats` parameter of this overload to specify multiple formats can help reduce the frustration many users experience when they enter dates and times. In particular, the ability to define multiple input patterns enables an application to handle date and time representations that can either include or lack leading zeros in months, days, hours, minutes, and seconds. - - If the matched element in `formats` requires that `input` contain a date but not a time, the resulting object is assigned a time of midnight (0:00:00). If the matched element in `formats` requires that `input` contain a time but not a date, the resulting object is assigned the current date on the local system. If the matched element in `formats` does not require that `input` contain an offset, the offset of the resulting object depends on the value of the `styles` parameter. If `styles` includes , the offset of the local time zone is assigned to the object. If `styles` includes , the Coordinated Universal Time (UTC) offset, or +00:00, is assigned to the object. If neither value is specified, the offset of the local time zone is used. - - The particular date and time symbols and strings used in `input` are defined by the `formatProvider` parameter. The same is true for the precise format of `input`, if the matching element of `formats` is a standard format specifier string. The `formatProvider` parameter can be either of the following: - -- A object that represents the culture based on which `input` is interpreted. The object returned by the property defines the symbols and formatting in `input`. - -- A object that defines the format of date and time data. - - If `formatprovider` is `null`, the object that corresponds to the current culture is used. - - The `styles` parameter defines whether white space is permitted in the input string, indicates how strings without an explicit offset component are parsed, and supports UTC conversion as part of the parsing operation. All members of the enumeration are supported except . The following table lists the effect of each supported member. - -|`DateTimeStyles` member|Behavior| -|-----------------------------|--------------| -||Parses `input` and, if necessary, converts it to UTC. It is equivalent to parsing a string, and then calling the method of the returned object.| -||If the matched element in `formats` does not require that `input` contain an offset value, the returned object is given the offset of the local time zone. This is the default value.| -||If the matched element in `formats` does not require that `input` contain an offset value, the returned object is given the UTC offset (+00:00).| -||Allows `input` to include inner white space not specified by `format`. Extra white space can appear between date and time components and within individual components (except the offset), and is ignored when parsing the string.| -||Allows `input` to include leading spaces not specified by `formats`. These are ignored when parsing the string.| -||Allows `input` to include trailing spaces not specified by `formats`. These are ignored when parsing the string.| -||Allows `input` to include leading, trailing, and inner spaces not specified by `formats`. All extra white-space characters not specified in the matched element in `formats` are ignored when parsing the string.| -||Indicates that additional white space is not permitted in `input`. White space must appear exactly as specified in a particular element of `formats` for a match to occur. This is the default behavior.| -||Has no effect because the structure does not include a `Kind` property.| - + . Aside from comparing `input` to multiple formatting patterns, this overload behaves identically to the method. + + The `formats` parameter is a string array whose elements contain either a single standard format specifier or one or more custom format specifiers that define the possible pattern of the `input` parameter. When the method is called, `input` must match one of these patterns. For details about valid formatting codes, see [Standard Date and Time Format Strings](/dotnet/standard/base-types/standard-date-and-time-format-strings) and [Custom Date and Time Format Strings](/dotnet/standard/base-types/custom-date-and-time-format-strings). If the matched element in `formats` includes the `z`, `zz`, or `zzz` custom format specifiers to indicate that an offset must be present in `input`, that offset must include either a negative sign or a positive sign. If the sign is missing, the method throws a . + +> [!IMPORTANT] +> Using the `formats` parameter of this overload to specify multiple formats can help reduce the frustration many users experience when they enter dates and times. In particular, the ability to define multiple input patterns enables an application to handle date and time representations that can either include or lack leading zeros in months, days, hours, minutes, and seconds. + + If the matched element in `formats` requires that `input` contain a date but not a time, the resulting object is assigned a time of midnight (0:00:00). If the matched element in `formats` requires that `input` contain a time but not a date, the resulting object is assigned the current date on the local system. If the matched element in `formats` does not require that `input` contain an offset, the offset of the resulting object depends on the value of the `styles` parameter. If `styles` includes , the offset of the local time zone is assigned to the object. If `styles` includes , the Coordinated Universal Time (UTC) offset, or +00:00, is assigned to the object. If neither value is specified, the offset of the local time zone is used. + + The particular date and time symbols and strings used in `input` are defined by the `formatProvider` parameter. The same is true for the precise format of `input`, if the matching element of `formats` is a standard format specifier string. The `formatProvider` parameter can be either of the following: + +- A object that represents the culture based on which `input` is interpreted. The object returned by the property defines the symbols and formatting in `input`. + +- A object that defines the format of date and time data. + + If `formatprovider` is `null`, the object that corresponds to the current culture is used. + + The `styles` parameter defines whether white space is permitted in the input string, indicates how strings without an explicit offset component are parsed, and supports UTC conversion as part of the parsing operation. All members of the enumeration are supported except . The following table lists the effect of each supported member. + +|`DateTimeStyles` member|Behavior| +|-----------------------------|--------------| +||Parses `input` and, if necessary, converts it to UTC. It is equivalent to parsing a string, and then calling the method of the returned object.| +||If the matched element in `formats` does not require that `input` contain an offset value, the returned object is given the offset of the local time zone. This is the default value.| +||If the matched element in `formats` does not require that `input` contain an offset value, the returned object is given the UTC offset (+00:00).| +||Allows `input` to include inner white space not specified by `format`. Extra white space can appear between date and time components and within individual components (except the offset), and is ignored when parsing the string.| +||Allows `input` to include leading spaces not specified by `formats`. These are ignored when parsing the string.| +||Allows `input` to include trailing spaces not specified by `formats`. These are ignored when parsing the string.| +||Allows `input` to include leading, trailing, and inner spaces not specified by `formats`. All extra white-space characters not specified in the matched element in `formats` are ignored when parsing the string.| +||Indicates that additional white space is not permitted in `input`. White space must appear exactly as specified in a particular element of `formats` for a match to occur. This is the default behavior.| +||Has no effect because the structure does not include a `Kind` property.| + ]]> - The offset is greater than 14 hours or less than -14 hours. --or- - includes an unsupported value. --or- + The offset is greater than 14 hours or less than -14 hours. + +-or- + + includes an unsupported value. + +-or- + The parameter contains values that cannot be used together. - is an empty character span. --or- - does not contain a valid string representation of a date and time. --or- -No element of contains a valid format specifier. --or- + is an empty character span. + +-or- + + does not contain a valid string representation of a date and time. + +-or- + +No element of contains a valid format specifier. + +-or- + The hour component and the AM/PM designator in do not agree. @@ -4952,90 +4989,90 @@ The hour component and the AM/PM designator in do not Converts the specified string representation of a date and time to its equivalent using the specified format, culture-specific format information, and style. The format of the string representation must match the specified format exactly. An object that is equivalent to the date and time that is contained in the parameter, as specified by the , , and parameters. - method parses the string representation of a date, which must be in the format defined by the `format` parameter. It also requires that the \, \ - The offset is greater than 14 hours or less than -14 hours. - - -or- - - The parameter includes an unsupported value. - - -or- - - The parameter contains values that cannot be used together. + The offset is greater than 14 hours or less than -14 hours. + +-or- + +The parameter includes an unsupported value. + +-or- + +The parameter contains values that cannot be used together. - is . - - -or- - - is . + is . + +-or- + + is . - is an empty string (""). - - -or- - - does not contain a valid string representation of a date and time. - - -or- - - is an empty string. - - -or- - - The hour component and the AM/PM designator in do not agree. + is an empty string (""). + +-or- + + does not contain a valid string representation of a date and time. + +-or- + + is an empty string. + +-or- + +The hour component and the AM/PM designator in do not agree. In the .NET Framework 4, the method throws a if the string to be parsed contains an hour component and an AM/PM designator that are not in agreement. In the .NET Framework 3.5 and earlier versions, the AM/PM designator is ignored. @@ -5115,76 +5152,76 @@ Strings that do not specify a UTC offset are assumed to have the offset of the l Converts the specified string representation of a date and time to its equivalent using the specified formats, culture-specific format information, and style. The format of the string representation must match one of the specified formats exactly. An object that is equivalent to the date and time that is contained in the parameter, as specified by the , , and parameters. - method parses the string representation of a date that matches any one of the patterns assigned to the `formats` parameter. If the `input` string does not match any one of these patterns with any of the variations defined by the `styles` parameter, the method throws a . Aside from comparing `input` to multiple formatting patterns, this overload behaves identically to the method. - - The `formats` parameter is a string array whose elements contain either a single standard format specifier or one or more custom format specifiers that define the possible pattern of the `input` parameter. When the method is called, `input` must match one of these patterns. For details about valid formatting codes, see [Standard Date and Time Format Strings](/dotnet/standard/base-types/standard-date-and-time-format-strings) and [Custom Date and Time Format Strings](/dotnet/standard/base-types/custom-date-and-time-format-strings). If the matched element in `formats` includes the `z`, `zz`, or `zzz` custom format specifiers to indicate that an offset must be present in `input`, that offset must include either a negative sign or a positive sign. If the sign is missing, the method throws a . - -> [!IMPORTANT] -> Using the `formats` parameter of this overload to specify multiple formats can help reduce the frustration many users experience when they enter dates and times. In particular, the ability to define multiple input patterns enables an application to handle date and time representations that can either include or lack leading zeros in months, days, hours, minutes, and seconds. The example provides an illustration of this. - - If the matched element in `formats` requires that `input` contain a date but not a time, the resulting object is assigned a time of midnight (0:00:00). If the matched element in `formats` requires that `input` contain a time but not a date, the resulting object is assigned the current date on the local system. If the matched element in `formats` does not require that `input` contain an offset, the offset of the resulting object depends on the value of the `styles` parameter. If `styles` includes , the offset of the local time zone is assigned to the object. If `styles` includes , the Coordinated Universal Time (UTC) offset, or +00:00, is assigned to the object. If neither value is specified, the offset of the local time zone is used. - - The particular date and time symbols and strings used in `input` are defined by the `formatProvider` parameter. The same is true for the precise format of `input`, if the matching element of `formats` is a standard format specifier string. The `formatProvider` parameter can be either of the following: - -- A object that represents the culture based on which `input` is interpreted. The object returned by the property defines the symbols and formatting in `input`. - -- A object that defines the format of date and time data. - - If `formatprovider` is `null`, the object that corresponds to the current culture is used. - - The `styles` parameter defines whether white space is permitted in the input string, indicates how strings without an explicit offset component are parsed, and supports UTC conversion as part of the parsing operation. All members of the enumeration are supported except . The following table lists the effect of each supported member. - -|`DateTimeStyles` member|Behavior| -|-----------------------------|--------------| -||Parses `input` and, if necessary, converts it to UTC. It is equivalent to parsing a string, and then calling the method of the returned object.| -||If the matched element in `formats` does not require that `input` contain an offset value, the returned object is given the offset of the local time zone. This is the default value.| -||If the matched element in `formats` does not require that `input` contain an offset value, the returned object is given the UTC offset (+00:00).| -||Allows `input` to include inner white space not specified by `format`. Extra white space can appear between date and time components and within individual components (except the offset), and is ignored when parsing the string.| -||Allows `input` to include leading spaces not specified by `formats`. These are ignored when parsing the string.| -||Allows `input` to include trailing spaces not specified by `formats`. These are ignored when parsing the string.| -||Allows `input` to include leading, trailing, and inner spaces not specified by `formats`. All extra white-space characters not specified in the matched element in `formats` are ignored when parsing the string.| -||Indicates that additional white space is not permitted in `input`. White space must appear exactly as specified in a particular element of `formats` for a match to occur. This is the default behavior.| -||Has no effect because the structure does not include a `Kind` property.| - - - -## Examples - The following example defines multiple input formats for the string representation of a date and time and offset value, and then passes the string that is entered by the user to the method. - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/ParseExact/ParseExact.cs" id="Snippet3"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.ParseExact/fs/ParseExact.fs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.ParseExact/vb/ParseExact.vb" id="Snippet3"::: - + method parses the string representation of a date that matches any one of the patterns assigned to the `formats` parameter. If the `input` string does not match any one of these patterns with any of the variations defined by the `styles` parameter, the method throws a . Aside from comparing `input` to multiple formatting patterns, this overload behaves identically to the method. + + The `formats` parameter is a string array whose elements contain either a single standard format specifier or one or more custom format specifiers that define the possible pattern of the `input` parameter. When the method is called, `input` must match one of these patterns. For details about valid formatting codes, see [Standard Date and Time Format Strings](/dotnet/standard/base-types/standard-date-and-time-format-strings) and [Custom Date and Time Format Strings](/dotnet/standard/base-types/custom-date-and-time-format-strings). If the matched element in `formats` includes the `z`, `zz`, or `zzz` custom format specifiers to indicate that an offset must be present in `input`, that offset must include either a negative sign or a positive sign. If the sign is missing, the method throws a . + +> [!IMPORTANT] +> Using the `formats` parameter of this overload to specify multiple formats can help reduce the frustration many users experience when they enter dates and times. In particular, the ability to define multiple input patterns enables an application to handle date and time representations that can either include or lack leading zeros in months, days, hours, minutes, and seconds. The example provides an illustration of this. + + If the matched element in `formats` requires that `input` contain a date but not a time, the resulting object is assigned a time of midnight (0:00:00). If the matched element in `formats` requires that `input` contain a time but not a date, the resulting object is assigned the current date on the local system. If the matched element in `formats` does not require that `input` contain an offset, the offset of the resulting object depends on the value of the `styles` parameter. If `styles` includes , the offset of the local time zone is assigned to the object. If `styles` includes , the Coordinated Universal Time (UTC) offset, or +00:00, is assigned to the object. If neither value is specified, the offset of the local time zone is used. + + The particular date and time symbols and strings used in `input` are defined by the `formatProvider` parameter. The same is true for the precise format of `input`, if the matching element of `formats` is a standard format specifier string. The `formatProvider` parameter can be either of the following: + +- A object that represents the culture based on which `input` is interpreted. The object returned by the property defines the symbols and formatting in `input`. + +- A object that defines the format of date and time data. + + If `formatprovider` is `null`, the object that corresponds to the current culture is used. + + The `styles` parameter defines whether white space is permitted in the input string, indicates how strings without an explicit offset component are parsed, and supports UTC conversion as part of the parsing operation. All members of the enumeration are supported except . The following table lists the effect of each supported member. + +|`DateTimeStyles` member|Behavior| +|-----------------------------|--------------| +||Parses `input` and, if necessary, converts it to UTC. It is equivalent to parsing a string, and then calling the method of the returned object.| +||If the matched element in `formats` does not require that `input` contain an offset value, the returned object is given the offset of the local time zone. This is the default value.| +||If the matched element in `formats` does not require that `input` contain an offset value, the returned object is given the UTC offset (+00:00).| +||Allows `input` to include inner white space not specified by `format`. Extra white space can appear between date and time components and within individual components (except the offset), and is ignored when parsing the string.| +||Allows `input` to include leading spaces not specified by `formats`. These are ignored when parsing the string.| +||Allows `input` to include trailing spaces not specified by `formats`. These are ignored when parsing the string.| +||Allows `input` to include leading, trailing, and inner spaces not specified by `formats`. All extra white-space characters not specified in the matched element in `formats` are ignored when parsing the string.| +||Indicates that additional white space is not permitted in `input`. White space must appear exactly as specified in a particular element of `formats` for a match to occur. This is the default behavior.| +||Has no effect because the structure does not include a `Kind` property.| + + + +## Examples + The following example defines multiple input formats for the string representation of a date and time and offset value, and then passes the string that is entered by the user to the method. + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/ParseExact/ParseExact.cs" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.ParseExact/fs/ParseExact.fs" id="Snippet3"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.ParseExact/vb/ParseExact.vb" id="Snippet3"::: + ]]> - The offset is greater than 14 hours or less than -14 hours. - - -or- - - includes an unsupported value. - - -or- - - The parameter contains values that cannot be used together. + The offset is greater than 14 hours or less than -14 hours. + +-or- + + includes an unsupported value. + +-or- + +The parameter contains values that cannot be used together. is . - is an empty string (""). - - -or- - - does not contain a valid string representation of a date and time. - - -or- - - No element of contains a valid format specifier. - - -or- - - The hour component and the AM/PM designator in do not agree. + is an empty string (""). + +-or- + + does not contain a valid string representation of a date and time. + +-or- + +No element of contains a valid format specifier. + +-or- + +The hour component and the AM/PM designator in do not agree. In the .NET Framework 4, the method throws a if the string to be parsed contains an hour component and an AM/PM designator that are not in agreement. In the .NET Framework 3.5 and earlier versions, the AM/PM designator is ignored. @@ -5233,28 +5270,28 @@ Strings that do not specify a UTC offset are assumed to have the offset of the l Gets the second component of the clock time represented by the current object. The second component of the object, expressed as an integer value between 0 and 59. - property is not affected by the value of the property. - - You can also create a string representation of a object's second component by calling the method with the "s", or "ss" custom format specifiers. - - - -## Examples - The following example displays the second component of a object in three different ways: - -- By retrieving the value of the property. - -- By calling the method with the "s" format specifier. - -- By calling the method with the "ss" format specifier. - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Date/Properties.cs" id="Snippet14"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/Properties.fs" id="Snippet14"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/vb/Properties.vb" id="Snippet14"::: - + property is not affected by the value of the property. + + You can also create a string representation of a object's second component by calling the method with the "s", or "ss" custom format specifiers. + + + +## Examples + The following example displays the second component of a object in three different ways: + +- By retrieving the value of the property. + +- By calling the method with the "s" format specifier. + +- By calling the method with the "ss" format specifier. + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Date/Properties.cs" id="Snippet14"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/Properties.fs" id="Snippet14"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/vb/Properties.vb" id="Snippet14"::: + ]]> @@ -5316,25 +5353,25 @@ Strings that do not specify a UTC offset are assumed to have the offset of the l Subtracts a value that represents a specific date and time from the current object. An object that specifies the interval between the two objects. - objects to Coordinated Universal Time (UTC) before calculating the time interval that separates them. This removes any effect that different offsets from UTC may have on the comparison. - -> [!NOTE] -> For languages that support custom operators, you can also perform date and time subtraction by using the subtraction operator. For details, see the method. - - Because neither the current object nor the `value` parameter represent the date and time in a specific time zone, the method does not consider a particular time zone's adjustment rules when it subtracts dates and times. - - - -## Examples - The following example illustrates subtraction that uses the method. - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Add/Methods.cs" id="Snippet13"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/fs/Methods.fs" id="Snippet13"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/vb/Methods.vb" id="Snippet13"::: - + objects to Coordinated Universal Time (UTC) before calculating the time interval that separates them. This removes any effect that different offsets from UTC may have on the comparison. + +> [!NOTE] +> For languages that support custom operators, you can also perform date and time subtraction by using the subtraction operator. For details, see the method. + + Because neither the current object nor the `value` parameter represent the date and time in a specific time zone, the method does not consider a particular time zone's adjustment rules when it subtracts dates and times. + + + +## Examples + The following example illustrates subtraction that uses the method. + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Add/Methods.cs" id="Snippet13"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/fs/Methods.fs" id="Snippet13"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/vb/Methods.vb" id="Snippet13"::: + ]]> Performing Arithmetic Operations with Dates and Times @@ -5384,32 +5421,32 @@ Strings that do not specify a UTC offset are assumed to have the offset of the l Subtracts a specified time interval from the current object. An object that is equal to the date and time represented by the current object, minus the time interval represented by . - method to subtract more than one kind of time interval (days, hours, minutes, seconds, or milliseconds) in a single operation. Its behavior is identical to the method, which defines the subtraction operator. The structure also supports specialized addition methods (such as , , and ) that allow you to perform subtraction by assigning a negative value to the method parameter. - -> [!NOTE] -> This method returns a new object. It does not modify the value of the current object by subtracting `value` from its date and time. - - The method does not affect the value of the object's property. The returned object has the same offset as the original object. - - Because the current object does not represent the date and time in a specific time zone, the method does not consider a particular time zone's adjustment rules when it performs the subtraction. - -## Examples - The following example illustrates subtraction that uses the method. - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Add/Methods.cs" id="Snippet14"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/fs/Methods.fs" id="Snippet14"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/vb/Methods.vb" id="Snippet14"::: - + method to subtract more than one kind of time interval (days, hours, minutes, seconds, or milliseconds) in a single operation. Its behavior is identical to the method, which defines the subtraction operator. The structure also supports specialized addition methods (such as , , and ) that allow you to perform subtraction by assigning a negative value to the method parameter. + +> [!NOTE] +> This method returns a new object. It does not modify the value of the current object by subtracting `value` from its date and time. + + The method does not affect the value of the object's property. The returned object has the same offset as the original object. + + Because the current object does not represent the date and time in a specific time zone, the method does not consider a particular time zone's adjustment rules when it performs the subtraction. + +## Examples + The following example illustrates subtraction that uses the method. + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Add/Methods.cs" id="Snippet14"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/fs/Methods.fs" id="Snippet14"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/vb/Methods.vb" id="Snippet14"::: + ]]> - The resulting value is less than DateTimeOffset.MinValue. - - -or- - - The resulting value is greater than DateTimeOffset.MaxValue. + The resulting value is less than DateTimeOffset.MinValue. + +-or- + +The resulting value is greater than DateTimeOffset.MaxValue. Performing Arithmetic Operations with Dates and Times @@ -5458,25 +5495,34 @@ Strings that do not specify a UTC offset are assumed to have the offset of the l The object to compare with the current object. Compares the value of the current object with another object of the same type. - A 32-bit signed integer that indicates whether the current object is less than, equal to, or greater than . The return values of the method are interpreted as follows: - - Return Value - - Description - - Less than zero - - The current object is less than (earlier than) . - - Zero - - The current object is equal to (the same point in time as) . - - Greater than zero - - The current object is greater than (later than) . - - + A 32-bit signed integer that indicates whether the current object is less than, equal to, or greater than . The return values of the method are interpreted as follows: + + Return Value + + + Description + + + + + Less than zero + + + The current object is less than (earlier than) . + + + Zero + + + The current object is equal to (the same point in time as) . + + + Greater than zero + + + The current object is greater than (later than) . + + To be added. @@ -5617,24 +5663,24 @@ Strings that do not specify a UTC offset are assumed to have the offset of the l Gets the number of ticks that represents the date and time of the current object in clock time. The number of ticks in the object's clock time. - property is not affected by the value of the property. - - The value of the property represents the number of 100-nanosecond intervals that have elapsed since 12:00:00 midnight on January 1, 0001 (the value of ). It does not include ticks that would be added by leap seconds. A nanosecond is one billionth of a second; there are ten million ticks in a second. The value of the property ranges from `DateTimeOffset.MinValue.Ticks` to `DateTimeOffset.MaxValue.Ticks`. - - You can assign the number of ticks to a object by using the constructor overload. - - - -## Examples - The following example initializes a object by approximating the number of ticks in the date July 1, 2008 1:23:07. It then displays the date and the number of ticks represented by that date to the console. - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Date/Properties.cs" id="Snippet15"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/Properties.fs" id="Snippet15"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/vb/Properties.vb" id="Snippet15"::: - + property is not affected by the value of the property. + + The value of the property represents the number of 100-nanosecond intervals that have elapsed since 12:00:00 midnight on January 1, 0001 (the value of ). It does not include ticks that would be added by leap seconds. A nanosecond is one billionth of a second; there are ten million ticks in a second. The value of the property ranges from `DateTimeOffset.MinValue.Ticks` to `DateTimeOffset.MaxValue.Ticks`. + + You can assign the number of ticks to a object by using the constructor overload. + + + +## Examples + The following example initializes a object by approximating the number of ticks in the date July 1, 2008 1:23:07. It then displays the date and the number of ticks represented by that date to the console. + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Date/Properties.cs" id="Snippet15"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/Properties.fs" id="Snippet15"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/vb/Properties.vb" id="Snippet15"::: + ]]> @@ -5680,22 +5726,22 @@ Strings that do not specify a UTC offset are assumed to have the offset of the l Gets the time of day for the current object. The time interval of the current date that has elapsed since midnight. - property is not affected by the value of the property. - - The property returns the time component of a object in the form of a object. It is equivalent to the property. - - - -## Examples - The following example uses the property to extract the time and display it to the console. - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Date/Properties.cs" id="Snippet16"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/Properties.fs" id="Snippet16"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/vb/Properties.vb" id="Snippet16"::: - + property is not affected by the value of the property. + + The property returns the time component of a object in the form of a object. It is equivalent to the property. + + + +## Examples + The following example uses the property to extract the time and display it to the console. + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Date/Properties.cs" id="Snippet16"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/Properties.fs" id="Snippet16"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/vb/Properties.vb" id="Snippet16"::: + ]]> @@ -5741,21 +5787,21 @@ Strings that do not specify a UTC offset are assumed to have the offset of the l Converts the value of the current object to a Windows file time. The value of the current object, expressed as a Windows file time. - method converts the current object's date and time to UTC before it performs the conversion. In other words, calling the method is equivalent to the following method call: - -```csharp -this.ToUtcDateTime().ToFileTime(); -``` - -```vb -Me.ToUtcDateTime().ToFileTime() -``` - + method converts the current object's date and time to UTC before it performs the conversion. In other words, calling the method is equivalent to the following method call: + +```csharp +this.ToUtcDateTime().ToFileTime(); +``` + +```vb +Me.ToUtcDateTime().ToFileTime() +``` + ]]> The resulting file time would represent a date and time before midnight on January 1, 1601 C.E. Coordinated Universal Time (UTC). @@ -5803,24 +5849,24 @@ Me.ToUtcDateTime().ToFileTime() Converts the current object to a object that represents the local time. An object that represents the date and time of the current object converted to local time. - object's date and time to Coordinated Universal Time (UTC) by subtracting the offset from the time. It then converts the UTC date and time to local time by adding the local time zone offset. In doing this, it takes account of any adjustment rules for the local time zone. - - Both the value of the current object and the value of the object returned by the method call represent the same point in time. That is, if both are passed to the method, the method will return `true`. - - If the conversion causes a time that is out of range of the type, the method returns a object that has the date and time set to either or and the offset set to the local time zone offset. - - - -## Examples - The following example uses the method to convert a value to local time in the Pacific Standard Time zone. It also illustrates the method's support for the local time zone's adjustment rules. - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Add/Methods.cs" id="Snippet15"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/fs/Methods.fs" id="Snippet15"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/vb/Methods.vb" id="Snippet15"::: - + object's date and time to Coordinated Universal Time (UTC) by subtracting the offset from the time. It then converts the UTC date and time to local time by adding the local time zone offset. In doing this, it takes account of any adjustment rules for the local time zone. + + Both the value of the current object and the value of the object returned by the method call represent the same point in time. That is, if both are passed to the method, the method will return `true`. + + If the conversion causes a time that is out of range of the type, the method returns a object that has the date and time set to either or and the offset set to the local time zone offset. + + + +## Examples + The following example uses the method to convert a value to local time in the Pacific Standard Time zone. It also illustrates the method's support for the local time zone's adjustment rules. + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Add/Methods.cs" id="Snippet15"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/fs/Methods.fs" id="Snippet15"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/vb/Methods.vb" id="Snippet15"::: + ]]> @@ -5870,33 +5916,33 @@ Me.ToUtcDateTime().ToFileTime() Converts the value of the current object to the date and time specified by an offset value. An object that is equal to the original object (that is, their methods return identical points in time) but whose property is set to . - method is an alternative to calling the method. It can be useful for performing simple conversions from one time zone to another when the time zones' offsets from Coordinated Universal Time (UTC) are known. However, because neither the original object nor the new object returned by the method call are unambiguously related to a particular time zone, the method does not apply any time zone adjustment rules in the conversion. - - - -## Examples - The following example illustrates how to use the method to convert a object to a object with a different offset. - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/ToOffset/ToOffset.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.ToOffset/fs/ToOffset.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.ToOffset/vb/ToOffset.vb" id="Snippet1"::: - + method is an alternative to calling the method. It can be useful for performing simple conversions from one time zone to another when the time zones' offsets from Coordinated Universal Time (UTC) are known. However, because neither the original object nor the new object returned by the method call are unambiguously related to a particular time zone, the method does not apply any time zone adjustment rules in the conversion. + + + +## Examples + The following example illustrates how to use the method to convert a object to a object with a different offset. + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/ToOffset/ToOffset.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.ToOffset/fs/ToOffset.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.ToOffset/vb/ToOffset.vb" id="Snippet1"::: + ]]> - The resulting object has a value earlier than DateTimeOffset.MinValue. - - -or- - - The resulting object has a value later than DateTimeOffset.MaxValue. + The resulting object has a value earlier than DateTimeOffset.MinValue. + +-or- + +The resulting object has a value later than DateTimeOffset.MaxValue. - is less than -14 hours. - - -or- - - is greater than 14 hours. + is less than -14 hours. + +-or- + + is greater than 14 hours. @@ -5910,10 +5956,10 @@ Me.ToUtcDateTime().ToFileTime() Converts the value of the current object to its equivalent string representation. - @@ -5968,31 +6014,27 @@ Me.ToUtcDateTime().ToFileTime() Converts the value of the current object to its equivalent string representation. A string representation of a object that includes the offset appended at the end of the string. - method, except that it includes a space followed by the offset appended at the end of the string. In other words, it formats output using the short date pattern, the long time pattern, and the `zzz` custom format string, with each element separated from the previous element by a space. For example, if returns a value of 1/12/2008 6:15:50 PM, returns a value of 1/12/2008 6:15:50 PM -08:00 for a time that is eight hours behind Coordinated Universal Time (UTC). - - This method uses formatting information derived from the current culture. For more information, see . Other overloads of the method enable you to specify the culture whose formatting to use, and to define the output pattern of the value. - - - -## Examples - The following example illustrates calls to the method and displays its output on a system whose current culture is en-us. - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/ToString/ToString.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.ToString/fs/ToString.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.ToString/vb/ToString.vb" id="Snippet1"::: - + method, except that it includes a space followed by the offset appended at the end of the string. In other words, it formats output using the short date pattern, the long time pattern, and the `zzz` custom format string, with each element separated from the previous element by a space. For example, if returns a value of 1/12/2008 6:15:50 PM, returns a value of 1/12/2008 6:15:50 PM -08:00 for a time that is eight hours behind Coordinated Universal Time (UTC). + + This method uses formatting information derived from the current culture. For more information, see . Other overloads of the method enable you to specify the culture whose formatting to use, and to define the output pattern of the value. + + + +## Examples + The following example illustrates calls to the method and displays its output on a system whose current culture is en-us. + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/ToString/ToString.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.ToString/fs/ToString.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.ToString/vb/ToString.vb" id="Snippet1"::: + ]]> 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 Arabic (Syria). - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/ToString/datetimeoffset.tostring.argumentoutofrangeexception2.cs" id="Snippet2"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.datetimeoffset.tostring.argumentoutofrangeexception/fs/datetimeoffset.tostring.argumentoutofrangeexception2.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.datetimeoffset.tostring.argumentoutofrangeexception/vb/datetimeoffset.tostring.argumentoutofrangeexception2.vb" id="Snippet2"::: + 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 Arabic (Syria). :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/ToString/datetimeoffset.tostring.argumentoutofrangeexception2.cs" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.datetimeoffset.tostring.argumentoutofrangeexception/fs/datetimeoffset.tostring.argumentoutofrangeexception2.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.datetimeoffset.tostring.argumentoutofrangeexception/vb/datetimeoffset.tostring.argumentoutofrangeexception2.vb" id="Snippet2"::: @@ -6058,37 +6100,33 @@ Me.ToUtcDateTime().ToFileTime() Converts the value of the current object to its equivalent string representation using the specified culture-specific formatting information. A string representation of the value of the current object, as specified by . - method, except that it includes a space followed by the offset appended at the end of the string. In other words, it formats output using the short date pattern, the long time pattern, and the `zzz` custom format string, with each element separated from the previous element by a space. - - The format of these three elements is defined by the `formatProvider` parameter. The `formatProvider` parameter can be either of the following: - -- A object that represents the culture whose formatting conventions are applied to the returned string. The object returned by the property defines the formatting of the returned string. - -- A object that defines the format of date and time data. - - If `formatProvider` is `null`, the object associated with the current culture is used (see ). - - - -## Examples - The following example displays a object using objects that represent the invariant culture, as well as four other cultures. - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/ToString/ToString.cs" interactive="try-dotnet-method" id="Snippet2"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.ToString/fs/ToString.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.ToString/vb/ToString.vb" id="Snippet2"::: - + method, except that it includes a space followed by the offset appended at the end of the string. In other words, it formats output using the short date pattern, the long time pattern, and the `zzz` custom format string, with each element separated from the previous element by a space. + + The format of these three elements is defined by the `formatProvider` parameter. The `formatProvider` parameter can be either of the following: + +- A object that represents the culture whose formatting conventions are applied to the returned string. The object returned by the property defines the formatting of the returned string. + +- A object that defines the format of date and time data. + + If `formatProvider` is `null`, the object associated with the current culture is used (see ). + + + +## Examples + The following example displays a object using objects that represent the invariant culture, as well as four other cultures. + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/ToString/ToString.cs" interactive="try-dotnet-method" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.ToString/fs/ToString.fs" id="Snippet2"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.ToString/vb/ToString.vb" id="Snippet2"::: + ]]> 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 language="csharp" source="~/snippets/csharp/System/DateTimeOffset/ToString/datetimeoffset.tostring.argumentoutofrangeexception1.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.datetimeoffset.tostring.argumentoutofrangeexception/fs/datetimeoffset.tostring.argumentoutofrangeexception1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.datetimeoffset.tostring.argumentoutofrangeexception/vb/datetimeoffset.tostring.argumentoutofrangeexception1.vb" id="Snippet1"::: + 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 language="csharp" source="~/snippets/csharp/System/DateTimeOffset/ToString/datetimeoffset.tostring.argumentoutofrangeexception1.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.datetimeoffset.tostring.argumentoutofrangeexception/fs/datetimeoffset.tostring.argumentoutofrangeexception1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.datetimeoffset.tostring.argumentoutofrangeexception/vb/datetimeoffset.tostring.argumentoutofrangeexception1.vb" id="Snippet1"::: @@ -6158,47 +6196,43 @@ Me.ToUtcDateTime().ToFileTime() Converts the value of the current object to its equivalent string representation using the specified format. A string representation of the value of the current object, as specified by . - value is output using the default format. - - The following table shows the exact operation of certain format specifiers when used with , which differs from their behavior when used with . - -|Existing format specifier|New behavior| -|-------------------------------|------------------| -|"K"|Designed to round-trip a date and time. With , maps to "zzz" (the offset is always displayed with hours and minutes). Note that "K" is a custom format specifier; it cannot appear as the single character in `format`.| -|"U"|Not supported.| -|"r"|Converts the object to Coordinated Universal Time (UTC) and outputs it using the custom format string `ddd, dd MMM yyyy HH:mm:ss GMT`.| -|"u"|Converts the object to UTC and outputs it using the format `yyyy-MM-dd HH:mm:ssZ`.| - - The remaining standard date and time format specifiers behave the same with the method as they do with the method. - - This method uses formatting information derived from the current culture. For more information, see . - - - -## Examples - The following example displays a object to the console using each of the standard date and time format specifiers. The output is formatted by using the en-us culture. - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/ToString/ToString.cs" id="Snippet3"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.ToString/fs/ToString.fs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.ToString/vb/ToString.vb" id="Snippet3"::: - + value is output using the default format. + + The following table shows the exact operation of certain format specifiers when used with , which differs from their behavior when used with . + +|Existing format specifier|New behavior| +|-------------------------------|------------------| +|"K"|Designed to round-trip a date and time. With , maps to "zzz" (the offset is always displayed with hours and minutes). Note that "K" is a custom format specifier; it cannot appear as the single character in `format`.| +|"U"|Not supported.| +|"r"|Converts the object to Coordinated Universal Time (UTC) and outputs it using the custom format string `ddd, dd MMM yyyy HH:mm:ss GMT`.| +|"u"|Converts the object to UTC and outputs it using the format `yyyy-MM-dd HH:mm:ssZ`.| + + The remaining standard date and time format specifiers behave the same with the method as they do with the method. + + This method uses formatting information derived from the current culture. For more information, see . + + + +## Examples + The following example displays a object to the console using each of the standard date and time format specifiers. The output is formatted by using the en-us culture. + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/ToString/ToString.cs" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.ToString/fs/ToString.fs" id="Snippet3"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.ToString/vb/ToString.vb" id="Snippet3"::: + ]]> - The length of is one, and it is not one of the standard format specifier characters defined for . - - -or- - - does not contain a valid custom format pattern. + The length of is one, and it is not one of the standard format specifier characters defined for . + +-or- + + does not contain a valid custom format pattern. 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 language="csharp" source="~/snippets/csharp/System/DateTimeOffset/ToString/datetimeoffset.tostring.argumentoutofrangeexception3.cs" interactive="try-dotnet" id="Snippet3"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.datetimeoffset.tostring.argumentoutofrangeexception/fs/datetimeoffset.tostring.argumentoutofrangeexception3.fs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.datetimeoffset.tostring.argumentoutofrangeexception/vb/datetimeoffset.tostring.argumentoutofrangeexception3.vb" id="Snippet3"::: + 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 language="csharp" source="~/snippets/csharp/System/DateTimeOffset/ToString/datetimeoffset.tostring.argumentoutofrangeexception3.cs" interactive="try-dotnet" id="Snippet3"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.datetimeoffset.tostring.argumentoutofrangeexception/fs/datetimeoffset.tostring.argumentoutofrangeexception3.fs" id="Snippet3"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.datetimeoffset.tostring.argumentoutofrangeexception/vb/datetimeoffset.tostring.argumentoutofrangeexception3.vb" id="Snippet3"::: Standard Date and Time Format Strings Custom Date and Time Format Strings @@ -6271,53 +6305,49 @@ Me.ToUtcDateTime().ToFileTime() Converts the value of the current object to its equivalent string representation using the specified format and culture-specific format information. A string representation of the value of the current object, as specified by and . - object is output using the default format. - - The following table shows the exact operation of certain format specifiers when used with , which differs from their behavior when used with . - -|Existing format specifier|New behavior| -|-------------------------------|------------------| -|"K"|Designed to round-trip a date and time. With , maps to "zzz" (the offset is always displayed with hours and minutes). Note that "K" is a custom format specifier; it cannot appear as the single character in `format`.| -|"U"|Not supported.| -|"r"|Converts the object to Coordinated Universal Time (UTC) and outputs it using the custom format string `ddd, dd MMM yyyy HH:mm:ss GMT`.| -|"u"|Converts the value to UTC and outputs it using the format `yyyy-MM-dd HH:mm:ssZ`.| - - The remaining standard date and time format specifiers behave the same with the method as they do with the method. - - The pattern that corresponds to standard format specifiers, as well as the symbols and names of date and time components, is defined by the `formatProvider` parameter. The `formatProvider` parameter can be either of the following: - -- A object that represents the culture whose formatting is used in `input`. The object returned by the property defines the formatting used in `input`. - -- A object that defines the format of date and time data. - - If `formatProvider` is `null`, the object associated with the current culture is used (see ). - - - -## Examples - The following example uses the method to display a object using a custom format string for several different cultures. - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/ToString/ToString.cs" interactive="try-dotnet-method" id="Snippet4"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.ToString/fs/ToString.fs" id="Snippet4"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.ToString/vb/ToString.vb" id="Snippet4"::: - + object is output using the default format. + + The following table shows the exact operation of certain format specifiers when used with , which differs from their behavior when used with . + +|Existing format specifier|New behavior| +|-------------------------------|------------------| +|"K"|Designed to round-trip a date and time. With , maps to "zzz" (the offset is always displayed with hours and minutes). Note that "K" is a custom format specifier; it cannot appear as the single character in `format`.| +|"U"|Not supported.| +|"r"|Converts the object to Coordinated Universal Time (UTC) and outputs it using the custom format string `ddd, dd MMM yyyy HH:mm:ss GMT`.| +|"u"|Converts the value to UTC and outputs it using the format `yyyy-MM-dd HH:mm:ssZ`.| + + The remaining standard date and time format specifiers behave the same with the method as they do with the method. + + The pattern that corresponds to standard format specifiers, as well as the symbols and names of date and time components, is defined by the `formatProvider` parameter. The `formatProvider` parameter can be either of the following: + +- A object that represents the culture whose formatting is used in `input`. The object returned by the property defines the formatting used in `input`. + +- A object that defines the format of date and time data. + + If `formatProvider` is `null`, the object associated with the current culture is used (see ). + + + +## Examples + The following example uses the method to display a object using a custom format string for several different cultures. + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/ToString/ToString.cs" interactive="try-dotnet-method" id="Snippet4"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.ToString/fs/ToString.fs" id="Snippet4"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.ToString/vb/ToString.vb" id="Snippet4"::: + ]]> - The length of is one, and it is not one of the standard format specifier characters defined for . - - -or- - - does not contain a valid custom format pattern. + The length of is one, and it is not one of the standard format specifier characters defined for . + +-or- + + does not contain a valid custom format pattern. 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 language="csharp" source="~/snippets/csharp/System/DateTimeOffset/ToString/datetimeoffset.tostring.argumentoutofrangeexception4.cs" id="Snippet4"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.datetimeoffset.tostring.argumentoutofrangeexception/fs/datetimeoffset.tostring.argumentoutofrangeexception4.fs" id="Snippet4"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.datetimeoffset.tostring.argumentoutofrangeexception/vb/datetimeoffset.tostring.argumentoutofrangeexception4.vb" id="Snippet4"::: + 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 language="csharp" source="~/snippets/csharp/System/DateTimeOffset/ToString/datetimeoffset.tostring.argumentoutofrangeexception4.cs" id="Snippet4"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.datetimeoffset.tostring.argumentoutofrangeexception/fs/datetimeoffset.tostring.argumentoutofrangeexception4.fs" id="Snippet4"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.datetimeoffset.tostring.argumentoutofrangeexception/vb/datetimeoffset.tostring.argumentoutofrangeexception4.vb" id="Snippet4"::: Standard Date and Time Format Strings Custom Date and Time Format Strings @@ -6393,22 +6423,22 @@ Me.ToUtcDateTime().ToFileTime() Converts the current object to a value that represents the Coordinated Universal Time (UTC). An object that represents the date and time of the current object converted to Coordinated Universal Time (UTC). - object whose property is set to zero. - - Both the value of the current object and the value of the object returned by the method call represent the same point in time. That is, if both are passed to the method, the method will return `true`. - - - -## Examples - The following example calls the method to convert a local time and several other times to Coordinated Universal Time (UTC). - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Add/Methods.cs" id="Snippet16"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/fs/Methods.fs" id="Snippet16"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/vb/Methods.vb" id="Snippet16"::: - + object whose property is set to zero. + + Both the value of the current object and the value of the object returned by the method call represent the same point in time. That is, if both are passed to the method, the method will return `true`. + + + +## Examples + The following example calls the method to convert a local time and several other times to Coordinated Universal Time (UTC). + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Add/Methods.cs" id="Snippet16"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/fs/Methods.fs" id="Snippet16"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/vb/Methods.vb" id="Snippet16"::: + ]]> @@ -6453,13 +6483,13 @@ Me.ToUtcDateTime().ToFileTime() Returns the number of milliseconds that have elapsed since 1970-01-01T00:00:00.000Z. The number of milliseconds that have elapsed since 1970-01-01T00:00:00.000Z. - @@ -6504,22 +6534,22 @@ Me.ToUtcDateTime().ToFileTime() Returns the number of seconds that have elapsed since 1970-01-01T00:00:00Z. The number of seconds that have elapsed since 1970-01-01T00:00:00Z. - method to return the Unix time of values that are equal to, shortly before, and shortly after 1970-01-01T00:00:00Z. - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/ToUnixTimeSeconds/tounixtimeseconds1.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.datetimeoffset.tounixtimeseconds/fs/tounixtimeseconds1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.datetimeoffset.tounixtimeseconds/vb/tounixtimeseconds1.vb" id="Snippet1"::: - + method to return the Unix time of values that are equal to, shortly before, and shortly after 1970-01-01T00:00:00Z. + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/ToUnixTimeSeconds/tounixtimeseconds1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.datetimeoffset.tounixtimeseconds/fs/tounixtimeseconds1.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.datetimeoffset.tounixtimeseconds/vb/tounixtimeseconds1.vb" id="Snippet1"::: + ]]> @@ -6654,10 +6684,10 @@ Me.ToUtcDateTime().ToFileTime() Converts a specified string representation of a date and time to its equivalent. -
@@ -6766,30 +6796,30 @@ Me.ToUtcDateTime().ToFileTime() if the parameter is successfully converted; otherwise, . - method is like the method, except that it does not throw an exception if the conversion fails. It parses a string with three elements that can appear in any order and are delimited by white space. These three elements are shown in the following table. - -|Element|Example| -|-------------|-------------| -|\|"2/10/2007"| -|\ @@ -7014,68 +7044,68 @@ Me.ToUtcDateTime().ToFileTime() if the parameter is successfully converted; otherwise, . - method is like the method, except that it does not throw an exception if the conversion fails. The method parses a string with three elements that can appear in any order and are delimited by white space. These three elements are shown in the following table. - -|Element|Example| -|-------------|-------------| -|\|"2/10/2007"| -|\ - includes an undefined value. - - -or- - - is not supported. - - -or- - - includes mutually exclusive values. + includes an undefined value. + +-or- + + is not supported. + +-or- + + includes mutually exclusive values. @@ -7090,10 +7120,10 @@ Me.ToUtcDateTime().ToFileTime() Converts the specified string representation of a date and time to its equivalent. The format of the string representation must match a specified format exactly. - @@ -7156,45 +7186,49 @@ Me.ToUtcDateTime().ToFileTime() if the parameter is successfully converted; otherwise, . - method, except that this method does not throw an exception if the conversion fails. It parses the representation of a date and time that must exactly match the pattern specified by the `format` parameter. If `input` does not match this pattern, with some possible variations in white space defined by the `styles` parameter, the parsing operation fails and the method returns `false`. - -The `format` parameter is a character span that contains either a single standard format specifier or one or more custom format specifiers that define the required pattern of `input`. For details about valid formatting codes, see [Standard Date and Time Format Strings](/dotnet/standard/base-types/standard-date-and-time-format-strings) and [Custom Date and Time Format Strings](/dotnet/standard/base-types/custom-date-and-time-format-strings). If `format` includes the `z`, `zz`, or `zzz` custom format specifiers to indicate that an offset must be present in `input`, that offset must include either a negative sign or a positive sign. If the sign is missing, the parsing operation fails and the method returns `false`. - -If `format` requires that `input` contain a date but not a time, the resulting object is assigned a time of midnight (0:00:00). If `format` requires that `input` contain a time but not a date, the resulting object is assigned the current date on the local system. If `format` does not require that `input` contain an offset, the offset of the resulting object depends on the value of the `styles` parameter. If `styles` includes , the offset of the local time zone is assigned to the object. If `styles` includes , the Coordinated Universal Time (UTC) offset, or +00:00, is assigned to the object. If neither value is specified, the offset of the local time zone is used. - -The particular date and time symbols and strings used in `input` are defined by the `formatProvider` parameter. The same is true for the precise pattern of `input` if `format` is a standard format specifier string. The `formatProvider` parameter can be either of the following: - -- A object that represents the culture based on which `input` is interpreted. The object returned by the property defines the symbols and standard formats allowed in `input`. - -- A object that defines the format of date and time data. - - If `formatprovider` is `null`, the object that corresponds to the current culture is used. - - The `styles` parameter defines whether white space is allowed in the input string, indicates how strings without an explicit offset component are parsed, and supports UTC conversion as part of the parsing operation. All members of the enumeration are supported except . The following table lists the effect of each supported member. - -|`DateTimeStyles` member|Behavior| -|-----------------------------|--------------| -||Parses `input` and, if necessary, converts it to UTC. It is equivalent to parsing a date and time representation, and then calling the method of the returned object.| -||If `format` does not require that `input` contain an offset value, the returned object is given the offset of the local time zone. This is the default behavior.| -||If `format` does not require that `input` contain an offset value, the returned object is given the UTC offset (+00:00).| -||Allows `input` to include inner white space not specified by format. Extra white space can appear between date and time components and within individual components, other than the offset, and is ignored when parsing the string.| -||Allows `input` to include leading spaces not specified by `format`. These are ignored when parsing the string.| -||Allows `input` to include trailing spaces not specified by `format`. These are ignored when parsing the string.| -||Allows `input` to include leading, trailing, and inner spaces not specified by `format`. All extra white-space characters not specified in `format` are ignored when parsing the string.| -||Indicates that additional white space is not permitted in `input`. White space must appear exactly as specified in `format`. This is the default behavior.| -||Has no effect, because the structure does not include a `Kind` property.| - + method, except that this method does not throw an exception if the conversion fails. It parses the representation of a date and time that must exactly match the pattern specified by the `format` parameter. If `input` does not match this pattern, with some possible variations in white space defined by the `styles` parameter, the parsing operation fails and the method returns `false`. + +The `format` parameter is a character span that contains either a single standard format specifier or one or more custom format specifiers that define the required pattern of `input`. For details about valid formatting codes, see [Standard Date and Time Format Strings](/dotnet/standard/base-types/standard-date-and-time-format-strings) and [Custom Date and Time Format Strings](/dotnet/standard/base-types/custom-date-and-time-format-strings). If `format` includes the `z`, `zz`, or `zzz` custom format specifiers to indicate that an offset must be present in `input`, that offset must include either a negative sign or a positive sign. If the sign is missing, the parsing operation fails and the method returns `false`. + +If `format` requires that `input` contain a date but not a time, the resulting object is assigned a time of midnight (0:00:00). If `format` requires that `input` contain a time but not a date, the resulting object is assigned the current date on the local system. If `format` does not require that `input` contain an offset, the offset of the resulting object depends on the value of the `styles` parameter. If `styles` includes , the offset of the local time zone is assigned to the object. If `styles` includes , the Coordinated Universal Time (UTC) offset, or +00:00, is assigned to the object. If neither value is specified, the offset of the local time zone is used. + +The particular date and time symbols and strings used in `input` are defined by the `formatProvider` parameter. The same is true for the precise pattern of `input` if `format` is a standard format specifier string. The `formatProvider` parameter can be either of the following: + +- A object that represents the culture based on which `input` is interpreted. The object returned by the property defines the symbols and standard formats allowed in `input`. + +- A object that defines the format of date and time data. + + If `formatprovider` is `null`, the object that corresponds to the current culture is used. + + The `styles` parameter defines whether white space is allowed in the input string, indicates how strings without an explicit offset component are parsed, and supports UTC conversion as part of the parsing operation. All members of the enumeration are supported except . The following table lists the effect of each supported member. + +|`DateTimeStyles` member|Behavior| +|-----------------------------|--------------| +||Parses `input` and, if necessary, converts it to UTC. It is equivalent to parsing a date and time representation, and then calling the method of the returned object.| +||If `format` does not require that `input` contain an offset value, the returned object is given the offset of the local time zone. This is the default behavior.| +||If `format` does not require that `input` contain an offset value, the returned object is given the UTC offset (+00:00).| +||Allows `input` to include inner white space not specified by format. Extra white space can appear between date and time components and within individual components, other than the offset, and is ignored when parsing the string.| +||Allows `input` to include leading spaces not specified by `format`. These are ignored when parsing the string.| +||Allows `input` to include trailing spaces not specified by `format`. These are ignored when parsing the string.| +||Allows `input` to include leading, trailing, and inner spaces not specified by `format`. All extra white-space characters not specified in `format` are ignored when parsing the string.| +||Indicates that additional white space is not permitted in `input`. White space must appear exactly as specified in `format`. This is the default behavior.| +||Has no effect, because the structure does not include a `Kind` property.| + ]]> - includes an undefined value. --or- - is not supported. --or- + includes an undefined value. + +-or- + + is not supported. + +-or- + includes mutually exclusive values. @@ -7267,48 +7301,52 @@ The particular date and time symbols and strings used in `input` are defined by if the parameter is successfully converted; otherwise, . - method. - - The `formats` parameter is a string array whose elements contain either a single standard format specifier or one or more custom format specifiers that define the possible pattern of `input`. For details about valid formatting codes, see [Standard Date and Time Format Strings](/dotnet/standard/base-types/standard-date-and-time-format-strings) and [Custom Date and Time Format Strings](/dotnet/standard/base-types/custom-date-and-time-format-strings). If the matched element in `formats` includes the `z`, `zz`, or `zzz` custom format specifiers to indicate that an offset must be present in `input`, that offset must include either a negative sign or a positive sign. If the sign is missing, the parse operation fails and the method returns `false`. - -> [!IMPORTANT] -> Using the `formats` parameter of this overload to specify multiple formats can help reduce the frustration many users experience when they enter dates and times. In particular, the ability to define multiple input patterns enables an application to handle date and time representations that can either include or lack leading zeros in months, days, hours, minutes, and seconds. The example provides an illustration of this. - - If the matched element in `formats` requires that `input` contain a date but not a time, the resulting object is assigned a time of midnight (0:00:00). If the matched element in `formats` requires that input contain a time but not a date, the resulting object is assigned the current date on the local system. If the matched element in `formats` does not require that `input` contain an offset, the offset of the resulting object depends on the value of the `styles` parameter. If `styles` includes , the offset of the local time zone is assigned to the object. If `styles` includes , the Coordinated Universal Time (UTC) offset, or +00:00, is assigned to the object. If neither value is specified, the offset of the local time zone is used. - - The particular date and time symbols used in `input` are defined by the `formatProvider` parameter. The same is true for the precise pattern of `input` if the matching element of `formats` is a standard format specifier string. The `formatProvider` parameter can be either of the following: - -- A object that represents the culture based on which `input` is interpreted. The object returned by the property defines the symbols and formatting in `input`. - -- A object that defines the format of date and time data. - - If `formatprovider` is `null`, the object that corresponds to the current culture is used. - - The `styles` parameter defines whether white space is permitted in the input string, indicates how strings without an explicit offset component are parsed, and supports UTC conversion as part of the parsing operation. All members of the enumeration are supported except . The following table lists the effect of each supported member. - -|`DateTimeStyles` member|Behavior| -|-----------------------------|--------------| -||Parses `input` and, if necessary, converts it to UTC. It is equivalent to parsing a string, and then calling the method of the returned object.| -||If the matched element in `formats` does not require that `input` contain an offset value, the returned object is given the offset of the local time zone. This is the default value.| -||If the matched element in `formats` does not require that `input` contain an offset value, the returned object is given the UTC offset (+00:00).| -||Allows `input` to include inner white space not specified by the elements in `formats`. Extra white space can appear between date and time components and within individual components (except for the offset) and is ignored when parsing the string.| -||Allows `input` to include leading spaces not specified by the elements in `formats`. These are ignored when parsing the string.| -||Allows `input` to include trailing spaces not specified by the elements in `formats`. These are ignored when parsing the string.| -||Allows `input` to include leading, trailing, and inner spaces not specified by the elements in `formats`. All extra white-space characters not specified in the matched element in `formats` are ignored when parsing the string.| -||Indicates that additional white space is not permitted in `input`. White space must appear exactly as specified in a particular element in `formats` for a successful match to occur. This is the default behavior.| -||Has no effect because the structure does not include a `Kind` property.| - + method. + + The `formats` parameter is a string array whose elements contain either a single standard format specifier or one or more custom format specifiers that define the possible pattern of `input`. For details about valid formatting codes, see [Standard Date and Time Format Strings](/dotnet/standard/base-types/standard-date-and-time-format-strings) and [Custom Date and Time Format Strings](/dotnet/standard/base-types/custom-date-and-time-format-strings). If the matched element in `formats` includes the `z`, `zz`, or `zzz` custom format specifiers to indicate that an offset must be present in `input`, that offset must include either a negative sign or a positive sign. If the sign is missing, the parse operation fails and the method returns `false`. + +> [!IMPORTANT] +> Using the `formats` parameter of this overload to specify multiple formats can help reduce the frustration many users experience when they enter dates and times. In particular, the ability to define multiple input patterns enables an application to handle date and time representations that can either include or lack leading zeros in months, days, hours, minutes, and seconds. The example provides an illustration of this. + + If the matched element in `formats` requires that `input` contain a date but not a time, the resulting object is assigned a time of midnight (0:00:00). If the matched element in `formats` requires that input contain a time but not a date, the resulting object is assigned the current date on the local system. If the matched element in `formats` does not require that `input` contain an offset, the offset of the resulting object depends on the value of the `styles` parameter. If `styles` includes , the offset of the local time zone is assigned to the object. If `styles` includes , the Coordinated Universal Time (UTC) offset, or +00:00, is assigned to the object. If neither value is specified, the offset of the local time zone is used. + + The particular date and time symbols used in `input` are defined by the `formatProvider` parameter. The same is true for the precise pattern of `input` if the matching element of `formats` is a standard format specifier string. The `formatProvider` parameter can be either of the following: + +- A object that represents the culture based on which `input` is interpreted. The object returned by the property defines the symbols and formatting in `input`. + +- A object that defines the format of date and time data. + + If `formatprovider` is `null`, the object that corresponds to the current culture is used. + + The `styles` parameter defines whether white space is permitted in the input string, indicates how strings without an explicit offset component are parsed, and supports UTC conversion as part of the parsing operation. All members of the enumeration are supported except . The following table lists the effect of each supported member. + +|`DateTimeStyles` member|Behavior| +|-----------------------------|--------------| +||Parses `input` and, if necessary, converts it to UTC. It is equivalent to parsing a string, and then calling the method of the returned object.| +||If the matched element in `formats` does not require that `input` contain an offset value, the returned object is given the offset of the local time zone. This is the default value.| +||If the matched element in `formats` does not require that `input` contain an offset value, the returned object is given the UTC offset (+00:00).| +||Allows `input` to include inner white space not specified by the elements in `formats`. Extra white space can appear between date and time components and within individual components (except for the offset) and is ignored when parsing the string.| +||Allows `input` to include leading spaces not specified by the elements in `formats`. These are ignored when parsing the string.| +||Allows `input` to include trailing spaces not specified by the elements in `formats`. These are ignored when parsing the string.| +||Allows `input` to include leading, trailing, and inner spaces not specified by the elements in `formats`. All extra white-space characters not specified in the matched element in `formats` are ignored when parsing the string.| +||Indicates that additional white space is not permitted in `input`. White space must appear exactly as specified in a particular element in `formats` for a successful match to occur. This is the default behavior.| +||Has no effect because the structure does not include a `Kind` property.| + ]]> - includes an undefined value. --or- - is not supported. --or- + includes an undefined value. + +-or- + + is not supported. + +-or- + includes mutually exclusive values. @@ -7390,69 +7428,69 @@ This method parses the string representation of a date that matches any one of t if the parameter is successfully converted; otherwise, . - method is like the method, except that this method does not throw an exception if the conversion fails. It parses the string representation of a date and time that must exactly match the pattern specified by the `format` parameter. If the `input` string does not match this pattern, with some possible variations in white space defined by the `styles` parameter, the parsing operation fails and the method returns `false`. - - The `format` parameter is a string that contains either a single standard format specifier or one or more custom format specifiers that define the required pattern of `input`. For details about valid formatting codes, see [Standard Date and Time Format Strings](/dotnet/standard/base-types/standard-date-and-time-format-strings) and [Custom Date and Time Format Strings](/dotnet/standard/base-types/custom-date-and-time-format-strings). If `format` includes the `z`, `zz`, or `zzz` custom format specifiers to indicate that an offset must be present in `input`, that offset must include either a negative sign or a positive sign. If the sign is missing, the parsing operation fails and the method returns `false`. - - If `format` requires that `input` contain a date but not a time, the resulting object is assigned a time of midnight (0:00:00). If `format` requires that `input` contain a time but not a date, the resulting object is assigned the current date on the local system. If `format` does not require that `input` contain an offset, the offset of the resulting object depends on the value of the `styles` parameter. If `styles` includes , the offset of the local time zone is assigned to the object. If `styles` includes , the Coordinated Universal Time (UTC) offset, or +00:00, is assigned to the object. If neither value is specified, the offset of the local time zone is used. - - The particular date and time symbols and strings used in `input` are defined by the `formatProvider` parameter. The same is true for the precise pattern of `input` if `format` is a standard format specifier string. The `formatProvider` parameter can be either of the following: - -- A object that represents the culture based on which `input` is interpreted. The object returned by the property defines the symbols and standard formats allowed in `input`. - -- A object that defines the format of date and time data. - - If `formatprovider` is `null`, the object that corresponds to the current culture is used. - - The `styles` parameter defines whether white space is allowed in the input string, indicates how strings without an explicit offset component are parsed, and supports UTC conversion as part of the parsing operation. All members of the enumeration are supported except . The following table lists the effect of each supported member. - -|`DateTimeStyles` member|Behavior| -|-----------------------------|--------------| -||Parses `input` and, if necessary, converts it to UTC. It is equivalent to parsing a string, and then calling the method of the returned object.| -||If `format` does not require that `input` contain an offset value, the returned object is given the offset of the local time zone. This is the default behavior.| -||If `format` does not require that `input` contain an offset value, the returned object is given the UTC offset (+00:00).| -||Allows `input` to include inner white space not specified by format. Extra white space can appear between date and time components and within individual components, other than the offset, and is ignored when parsing the string.| -||Allows `input` to include leading spaces not specified by `format`. These are ignored when parsing the string.| -||Allows `input` to include trailing spaces not specified by `format`. These are ignored when parsing the string.| -||Allows `input` to include leading, trailing, and inner spaces not specified by `format`. All extra white-space characters not specified in `format` are ignored when parsing the string.| -||Indicates that additional white space is not permitted in `input`. White space must appear exactly as specified in `format`. This is the default behavior.| -||Has no effect, because the structure does not include a `Kind` property.| - -## Examples - - The following example uses the method with standard and custom format specifiers, the invariant culture, and various values to parse several date and time strings. - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/TryParseExact/TryParseExact.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.TryParseExact/fs/TryParseExact.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.TryParseExact/vb/TryParseExact.vb" id="Snippet1"::: - -The following example uses a variety of values to parse an array of strings that are expected to conform to [ISO 8601](/dotnet/standard/base-types/standard-date-and-time-format-strings#the-round-trip-o-o-format-specifier). As the output from the example shows, strings that are in the proper format fail to parse if: - -- they contain white space, and an appropriate flag (such as has not been supplied in the method call. - -- they contain date and time elements that are out of range. - -Strings that do not specify a UTC offset are assumed to have the offset of the local time zone (in this case, -07:00, which reflects the offset of the Pacific Daylight Time zone) unless the flag is supplied in the method call. In that case, they are assumed to be Universal Coordinated Time. - -:::code language="fsharp" source="~/snippets/fsharp/System/DateTimeOffset.TryParseExact/tryparseexacto8601-2.fs"::: -:::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/TryParseExact/tryparseexacto8601-2.cs"::: -:::code language="vb" source="~/snippets/visualbasic/api/system/datetimeoffset/tryparseexact/tryparseexacto8601-2.vb"::: - + method is like the method, except that this method does not throw an exception if the conversion fails. It parses the string representation of a date and time that must exactly match the pattern specified by the `format` parameter. If the `input` string does not match this pattern, with some possible variations in white space defined by the `styles` parameter, the parsing operation fails and the method returns `false`. + + The `format` parameter is a string that contains either a single standard format specifier or one or more custom format specifiers that define the required pattern of `input`. For details about valid formatting codes, see [Standard Date and Time Format Strings](/dotnet/standard/base-types/standard-date-and-time-format-strings) and [Custom Date and Time Format Strings](/dotnet/standard/base-types/custom-date-and-time-format-strings). If `format` includes the `z`, `zz`, or `zzz` custom format specifiers to indicate that an offset must be present in `input`, that offset must include either a negative sign or a positive sign. If the sign is missing, the parsing operation fails and the method returns `false`. + + If `format` requires that `input` contain a date but not a time, the resulting object is assigned a time of midnight (0:00:00). If `format` requires that `input` contain a time but not a date, the resulting object is assigned the current date on the local system. If `format` does not require that `input` contain an offset, the offset of the resulting object depends on the value of the `styles` parameter. If `styles` includes , the offset of the local time zone is assigned to the object. If `styles` includes , the Coordinated Universal Time (UTC) offset, or +00:00, is assigned to the object. If neither value is specified, the offset of the local time zone is used. + + The particular date and time symbols and strings used in `input` are defined by the `formatProvider` parameter. The same is true for the precise pattern of `input` if `format` is a standard format specifier string. The `formatProvider` parameter can be either of the following: + +- A object that represents the culture based on which `input` is interpreted. The object returned by the property defines the symbols and standard formats allowed in `input`. + +- A object that defines the format of date and time data. + + If `formatprovider` is `null`, the object that corresponds to the current culture is used. + + The `styles` parameter defines whether white space is allowed in the input string, indicates how strings without an explicit offset component are parsed, and supports UTC conversion as part of the parsing operation. All members of the enumeration are supported except . The following table lists the effect of each supported member. + +|`DateTimeStyles` member|Behavior| +|-----------------------------|--------------| +||Parses `input` and, if necessary, converts it to UTC. It is equivalent to parsing a string, and then calling the method of the returned object.| +||If `format` does not require that `input` contain an offset value, the returned object is given the offset of the local time zone. This is the default behavior.| +||If `format` does not require that `input` contain an offset value, the returned object is given the UTC offset (+00:00).| +||Allows `input` to include inner white space not specified by format. Extra white space can appear between date and time components and within individual components, other than the offset, and is ignored when parsing the string.| +||Allows `input` to include leading spaces not specified by `format`. These are ignored when parsing the string.| +||Allows `input` to include trailing spaces not specified by `format`. These are ignored when parsing the string.| +||Allows `input` to include leading, trailing, and inner spaces not specified by `format`. All extra white-space characters not specified in `format` are ignored when parsing the string.| +||Indicates that additional white space is not permitted in `input`. White space must appear exactly as specified in `format`. This is the default behavior.| +||Has no effect, because the structure does not include a `Kind` property.| + +## Examples + + The following example uses the method with standard and custom format specifiers, the invariant culture, and various values to parse several date and time strings. + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/TryParseExact/TryParseExact.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.TryParseExact/fs/TryParseExact.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.TryParseExact/vb/TryParseExact.vb" id="Snippet1"::: + +The following example uses a variety of values to parse an array of strings that are expected to conform to [ISO 8601](/dotnet/standard/base-types/standard-date-and-time-format-strings#the-round-trip-o-o-format-specifier). As the output from the example shows, strings that are in the proper format fail to parse if: + +- they contain white space, and an appropriate flag (such as has not been supplied in the method call. + +- they contain date and time elements that are out of range. + +Strings that do not specify a UTC offset are assumed to have the offset of the local time zone (in this case, -07:00, which reflects the offset of the Pacific Daylight Time zone) unless the flag is supplied in the method call. In that case, they are assumed to be Universal Coordinated Time. + +:::code language="fsharp" source="~/snippets/fsharp/System/DateTimeOffset.TryParseExact/tryparseexacto8601-2.fs"::: +:::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/TryParseExact/tryparseexacto8601-2.cs"::: +:::code language="vb" source="~/snippets/visualbasic/api/system/datetimeoffset/tryparseexact/tryparseexacto8601-2.vb"::: + ]]> - includes an undefined value. - - -or- - - is not supported. - - -or- - - includes mutually exclusive values. + includes an undefined value. + +-or- + + is not supported. + +-or- + + includes mutually exclusive values. In the .NET Framework 4, the returns if the string to be parsed contains an hour component and an AM/PM designator that are not in agreement. In the .NET Framework 3.5 and earlier versions, the AM/PM designator is ignored. @@ -7537,61 +7575,61 @@ Strings that do not specify a UTC offset are assumed to have the offset of the l if the parameter is successfully converted; otherwise, . - method parses the string representation of a date that matches any one of the patterns assigned to the `formats` array. If the `input` string does not match any one of these patterns with any variations defined by the `styles` parameter, the parsing operation fails and the method returns `false`. Aside from comparing `input` to multiple strings that contain format specifiers, this overload behaves identically to the method. - - The `formats` parameter is a string array whose elements contain either a single standard format specifier or one or more custom format specifiers that define the possible pattern of `input`. For details about valid formatting codes, see [Standard Date and Time Format Strings](/dotnet/standard/base-types/standard-date-and-time-format-strings) and [Custom Date and Time Format Strings](/dotnet/standard/base-types/custom-date-and-time-format-strings). If the matched element in `formats` includes the `z`, `zz`, or `zzz` custom format specifiers to indicate that an offset must be present in `input`, that offset must include either a negative sign or a positive sign. If the sign is missing, the parse operation fails and the method returns `false`. - -> [!IMPORTANT] -> Using the `formats` parameter of this overload to specify multiple formats can help reduce the frustration many users experience when they enter dates and times. In particular, the ability to define multiple input patterns enables an application to handle date and time representations that can either include or lack leading zeros in months, days, hours, minutes, and seconds. The example provides an illustration of this. - - If the matched element in `formats` requires that `input` contain a date but not a time, the resulting object is assigned a time of midnight (0:00:00). If the matched element in `formats` requires that input contain a time but not a date, the resulting object is assigned the current date on the local system. If the matched element in `formats` does not require that `input` contain an offset, the offset of the resulting object depends on the value of the `styles` parameter. If `styles` includes , the offset of the local time zone is assigned to the object. If `styles` includes , the Coordinated Universal Time (UTC) offset, or +00:00, is assigned to the object. If neither value is specified, the offset of the local time zone is used. - - The particular date and time symbols and strings used in `input` are defined by the `formatProvider` parameter. The same is true for the precise pattern of `input` if the matching element of `formats` is a standard format specifier string. The `formatProvider` parameter can be either of the following: - -- A object that represents the culture based on which `input` is interpreted. The object returned by the property defines the symbols and formatting in `input`. - -- A object that defines the format of date and time data. - - If `formatprovider` is `null`, the object that corresponds to the current culture is used. - - The `styles` parameter defines whether white space is permitted in the input string, indicates how strings without an explicit offset component are parsed, and supports UTC conversion as part of the parsing operation. All members of the enumeration are supported except . The following table lists the effect of each supported member. - -|`DateTimeStyles` member|Behavior| -|-----------------------------|--------------| -||Parses `input` and, if necessary, converts it to UTC. It is equivalent to parsing a string, and then calling the method of the returned object.| -||If the matched element in `formats` does not require that `input` contain an offset value, the returned object is given the offset of the local time zone. This is the default value.| -||If the matched element in `formats` does not require that `input` contain an offset value, the returned object is given the UTC offset (+00:00).| -||Allows `input` to include inner white space not specified by the elements in `formats`. Extra white space can appear between date and time components and within individual components (except for the offset) and is ignored when parsing the string.| -||Allows `input` to include leading spaces not specified by the elements in `formats`. These are ignored when parsing the string.| -||Allows `input` to include trailing spaces not specified by the elements in `formats`. These are ignored when parsing the string.| -||Allows `input` to include leading, trailing, and inner spaces not specified by the elements in `formats`. All extra white-space characters not specified in the matched element in `formats` are ignored when parsing the string.| -||Indicates that additional white space is not permitted in `input`. White space must appear exactly as specified in a particular element in `formats` for a successful match to occur. This is the default behavior.| -||Has no effect because the structure does not include a `Kind` property.| - - - -## Examples - The following example defines multiple input formats for the string representation of a date and time and offset value, and then passes the string that is entered by the user to the method. - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/TryParseExact/TryParseExact.cs" id="Snippet2"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.TryParseExact/fs/TryParseExact.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.TryParseExact/vb/TryParseExact.vb" id="Snippet2"::: - + method parses the string representation of a date that matches any one of the patterns assigned to the `formats` array. If the `input` string does not match any one of these patterns with any variations defined by the `styles` parameter, the parsing operation fails and the method returns `false`. Aside from comparing `input` to multiple strings that contain format specifiers, this overload behaves identically to the method. + + The `formats` parameter is a string array whose elements contain either a single standard format specifier or one or more custom format specifiers that define the possible pattern of `input`. For details about valid formatting codes, see [Standard Date and Time Format Strings](/dotnet/standard/base-types/standard-date-and-time-format-strings) and [Custom Date and Time Format Strings](/dotnet/standard/base-types/custom-date-and-time-format-strings). If the matched element in `formats` includes the `z`, `zz`, or `zzz` custom format specifiers to indicate that an offset must be present in `input`, that offset must include either a negative sign or a positive sign. If the sign is missing, the parse operation fails and the method returns `false`. + +> [!IMPORTANT] +> Using the `formats` parameter of this overload to specify multiple formats can help reduce the frustration many users experience when they enter dates and times. In particular, the ability to define multiple input patterns enables an application to handle date and time representations that can either include or lack leading zeros in months, days, hours, minutes, and seconds. The example provides an illustration of this. + + If the matched element in `formats` requires that `input` contain a date but not a time, the resulting object is assigned a time of midnight (0:00:00). If the matched element in `formats` requires that input contain a time but not a date, the resulting object is assigned the current date on the local system. If the matched element in `formats` does not require that `input` contain an offset, the offset of the resulting object depends on the value of the `styles` parameter. If `styles` includes , the offset of the local time zone is assigned to the object. If `styles` includes , the Coordinated Universal Time (UTC) offset, or +00:00, is assigned to the object. If neither value is specified, the offset of the local time zone is used. + + The particular date and time symbols and strings used in `input` are defined by the `formatProvider` parameter. The same is true for the precise pattern of `input` if the matching element of `formats` is a standard format specifier string. The `formatProvider` parameter can be either of the following: + +- A object that represents the culture based on which `input` is interpreted. The object returned by the property defines the symbols and formatting in `input`. + +- A object that defines the format of date and time data. + + If `formatprovider` is `null`, the object that corresponds to the current culture is used. + + The `styles` parameter defines whether white space is permitted in the input string, indicates how strings without an explicit offset component are parsed, and supports UTC conversion as part of the parsing operation. All members of the enumeration are supported except . The following table lists the effect of each supported member. + +|`DateTimeStyles` member|Behavior| +|-----------------------------|--------------| +||Parses `input` and, if necessary, converts it to UTC. It is equivalent to parsing a string, and then calling the method of the returned object.| +||If the matched element in `formats` does not require that `input` contain an offset value, the returned object is given the offset of the local time zone. This is the default value.| +||If the matched element in `formats` does not require that `input` contain an offset value, the returned object is given the UTC offset (+00:00).| +||Allows `input` to include inner white space not specified by the elements in `formats`. Extra white space can appear between date and time components and within individual components (except for the offset) and is ignored when parsing the string.| +||Allows `input` to include leading spaces not specified by the elements in `formats`. These are ignored when parsing the string.| +||Allows `input` to include trailing spaces not specified by the elements in `formats`. These are ignored when parsing the string.| +||Allows `input` to include leading, trailing, and inner spaces not specified by the elements in `formats`. All extra white-space characters not specified in the matched element in `formats` are ignored when parsing the string.| +||Indicates that additional white space is not permitted in `input`. White space must appear exactly as specified in a particular element in `formats` for a successful match to occur. This is the default behavior.| +||Has no effect because the structure does not include a `Kind` property.| + + + +## Examples + The following example defines multiple input formats for the string representation of a date and time and offset value, and then passes the string that is entered by the user to the method. + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/TryParseExact/TryParseExact.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.TryParseExact/fs/TryParseExact.fs" id="Snippet2"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.TryParseExact/vb/TryParseExact.vb" id="Snippet2"::: + ]]> - includes an undefined value. - - -or- - - is not supported. - - -or- - - includes mutually exclusive values. + includes an undefined value. + +-or- + + is not supported. + +-or- + + includes mutually exclusive values. In the .NET Framework 4, the returns if the string to be parsed contains an hour component and an AM/PM designator that are not in agreement. In the .NET Framework 3.5 and earlier versions, the AM/PM designator is ignored. @@ -7669,28 +7707,28 @@ Strings that do not specify a UTC offset are assumed to have the offset of the l Gets a value that represents the Coordinated Universal Time (UTC) date and time of the current object. The Coordinated Universal Time (UTC) date and time of the current object. - property performs a dual conversion: - -- It converts the date and time of the current object to Coordinated Universal Time (UTC). The conversion is performed by subtracting the value of the property from the date and time of the current object. - -- It converts the value to a value. - - The property of the returned value is set to . - - Retrieving the value of the property is equivalent to calling the current object's `ToUniversalTime.DateTime` property, except that the property of the latter value is . - - - -## Examples - The following example shows how to use of the property to display a value and its corresponding UTC time. - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Date/Properties.cs" id="Snippet17"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/Properties.fs" id="Snippet17"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/vb/Properties.vb" id="Snippet17"::: - + property performs a dual conversion: + +- It converts the date and time of the current object to Coordinated Universal Time (UTC). The conversion is performed by subtracting the value of the property from the date and time of the current object. + +- It converts the value to a value. + + The property of the returned value is set to . + + Retrieving the value of the property is equivalent to calling the current object's `ToUniversalTime.DateTime` property, except that the property of the latter value is . + + + +## Examples + The following example shows how to use of the property to display a value and its corresponding UTC time. + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Date/Properties.cs" id="Snippet17"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/Properties.fs" id="Snippet17"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/vb/Properties.vb" id="Snippet17"::: + ]]> @@ -7735,22 +7773,22 @@ Strings that do not specify a UTC offset are assumed to have the offset of the l Gets a object whose date and time are set to the current Coordinated Universal Time (UTC) date and time and whose offset is . An object whose date and time is the current Coordinated Universal Time (UTC) and whose offset is . - property computes the current Universal Coordinated Time (UTC) based on the local system's clock time and an offset defined by the local system's time zone. - - The precision of the current UTC time's millisecond component depends on the resolution of the system clock. On Windows NT 3.5 and later, and Windows Vista operating systems, the clock's resolution is approximately 10-15 milliseconds. - - - -## Examples - The following example illustrates the relationship between Coordinated Universal Time (UTC) and local time. - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Date/Properties.cs" id="Snippet18"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/Properties.fs" id="Snippet18"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/vb/Properties.vb" id="Snippet18"::: - + property computes the current Universal Coordinated Time (UTC) based on the local system's clock time and an offset defined by the local system's time zone. + + The precision of the current UTC time's millisecond component depends on the resolution of the system clock. On Windows NT 3.5 and later, and Windows Vista operating systems, the clock's resolution is approximately 10-15 milliseconds. + + + +## Examples + The following example illustrates the relationship between Coordinated Universal Time (UTC) and local time. + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Date/Properties.cs" id="Snippet18"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/Properties.fs" id="Snippet18"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/vb/Properties.vb" id="Snippet18"::: + ]]> @@ -7796,11 +7834,11 @@ Strings that do not specify a UTC offset are assumed to have the offset of the l Gets the number of ticks that represents the date and time of the current object in Coordinated Universal Time (UTC). The number of ticks in the object's Coordinated Universal Time (UTC). - property represents the number of 100-nanosecond intervals that have elapsed since 12:00:00 midnight on January 1, 0001 (the value of ). It does not include ticks that would be added by leap seconds. A nanosecond is one billionth of a second; there are ten million ticks in a second. The value of the property ranges from `DateTimeOffset.MinValue.Ticks` to `DateTimeOffset.MaxValue.Ticks`. - + property represents the number of 100-nanosecond intervals that have elapsed since 12:00:00 midnight on January 1, 0001 (the value of ). It does not include ticks that would be added by leap seconds. A nanosecond is one billionth of a second; there are ten million ticks in a second. The value of the property ranges from `DateTimeOffset.MinValue.Ticks` to `DateTimeOffset.MaxValue.Ticks`. + ]]> @@ -7845,30 +7883,30 @@ Strings that do not specify a UTC offset are assumed to have the offset of the l Gets the year component of the date represented by the current object. The year component of the current object, expressed as an integer value between 0 and 9999. - property is not affected by the value of the property. - - You can also create a string representation of a object's year component by calling the method with the "y", "yy", or "yyyy" custom format specifiers. - - - -## Examples - The following example displays the year component of a value in four different ways: - -- By retrieving the value of the property. - -- By calling the method with the "y" format specifier. - -- By calling the method with the "yy" format specifier. - -- By calling the method with the "yyyy" format specifier. - - :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Date/Properties.cs" id="Snippet19"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/Properties.fs" id="Snippet19"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/vb/Properties.vb" id="Snippet19"::: - + property is not affected by the value of the property. + + You can also create a string representation of a object's year component by calling the method with the "y", "yy", or "yyyy" custom format specifiers. + + + +## Examples + The following example displays the year component of a value in four different ways: + +- By retrieving the value of the property. + +- By calling the method with the "y" format specifier. + +- By calling the method with the "yy" format specifier. + +- By calling the method with the "yyyy" format specifier. + + :::code language="csharp" source="~/snippets/csharp/System/DateTimeOffset/Date/Properties.cs" id="Snippet19"::: + :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/Properties.fs" id="Snippet19"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/vb/Properties.vb" id="Snippet19"::: + ]]> diff --git a/xml/System/DayOfWeek.xml b/xml/System/DayOfWeek.xml index 7149d087414..d278b7455a2 100644 --- a/xml/System/DayOfWeek.xml +++ b/xml/System/DayOfWeek.xml @@ -55,23 +55,23 @@ Specifies the day of the week. - enumeration represents the day of the week in calendars that have seven days per week. The value of the constants in this enumeration ranges from Sunday to Saturday. If cast to an integer, its value ranges from zero (which indicates Sunday) to six (which indicates Saturday). - - This enumeration is useful when it is desirable to have a strongly typed specification of the day of the week. For example, this enumeration is the type of the property value for the and properties. - - The members of the enumeration are not localized. To return the localized name of the day of the week, call the or the method with either the "ddd" or "dddd" format strings. The former format string produces the abbreviated weekday name; the latter produces the full weekday name. - -## Examples - The following example demonstrates the property and the enumeration. - + enumeration represents the day of the week in calendars that have seven days per week. The value of the constants in this enumeration ranges from Sunday to Saturday. If cast to an integer, its value ranges from zero (which indicates Sunday) to six (which indicates Saturday). + + This enumeration is useful when it is desirable to have a strongly typed specification of the day of the week. For example, this enumeration is the type of the property value for the and properties. + + The members of the enumeration are not localized. To return the localized name of the day of the week, call the or the method with either the "ddd" or "dddd" format strings. The former format string produces the abbreviated weekday name; the latter produces the full weekday name. + +## Examples + The following example demonstrates the property and the enumeration. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/DateTime.DayOfWeek/CPP/dow.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/DateTime/DayOfWeek/dow.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR/DateTime.DayOfWeek/FS/dow.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/DateTime.DayOfWeek/VB/dow.vb" id="Snippet1"::: - + ]]> diff --git a/xml/System/Decimal.xml b/xml/System/Decimal.xml index 425a45d65a6..4a71a7a2bc2 100644 --- a/xml/System/Decimal.xml +++ b/xml/System/Decimal.xml @@ -406,9 +406,9 @@ is greater than Decimal.MaxValue or less than Decimal.MinValue. - -or- +-or- - is , , or . + is , , or . @@ -550,9 +550,9 @@ is . The length of the is not 4. - -or- +-or- - The representation of the decimal value in is not valid. +The representation of the decimal value in is not valid. @@ -709,9 +709,9 @@ is greater than Decimal.MaxValue or less than Decimal.MinValue. - -or- +-or- - is , , or . + is , , or . @@ -1183,25 +1183,34 @@ The first value to compare. The second value to compare. Compares two specified values. - A signed number indicating the relative values of and . - - Return value - - Meaning - - Less than zero - - is less than . - - Zero - - and are equal. - - Greater than zero - - is greater than . - - + A signed number indicating the relative values of and . + + Return value + + + Meaning + + + + + Less than zero + + + is less than . + + + Zero + + + and are equal. + + + Greater than zero + + + is greater than . + + The object to compare with this instance. Compares this instance to a specified object and returns a comparison of their relative values. - A signed number indicating the relative values of this instance and . - - Return value - - Meaning - - Less than zero - - This instance is less than . - - Zero - - This instance is equal to . - - Greater than zero - - This instance is greater than . - - + A signed number indicating the relative values of this instance and . + + Return value + + + Meaning + + + + + Less than zero + + + This instance is less than . + + + Zero + + + This instance is equal to . + + + Greater than zero + + + This instance is greater than . + + The object to compare with this instance, or . Compares this instance to a specified object and returns a comparison of their relative values. - A signed number indicating the relative values of this instance and . - - Return value - - Meaning - - Less than zero - - This instance is less than . - - Zero - - This instance is equal to . - - Greater than zero - - This instance is greater than , or is . - - + A signed number indicating the relative values of this instance and . + + Return value + + + Meaning + + + + + Less than zero + + + This instance is less than . + + + Zero + + + This instance is equal to . + + + Greater than zero + + + This instance is greater than , or is . + + - 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 a is defined and the argument is not typed as an , compilers may perform an implicit conversion and call the method. Otherwise, they call the method, which always returns if its argument is not a value. The following example illustrates the difference in behavior between the two method overloads. In the case of all primitive integral types, including both signed and unsigned types, 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 language="csharp" source="~/snippets/csharp/System/Decimal/Equals/equalsoverl.cs" interactive="try-dotnet" id="Snippet2"::: - :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/Equals/equalsoverl.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.decimal.equals/vb/equalsoverl.vb" id="Snippet2"::: + 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 a is defined and the argument is not typed as an , compilers may perform an implicit conversion and call the method. Otherwise, they call the method, which always returns if its argument is not a value. The following example illustrates the difference in behavior between the two method overloads. In the case of all primitive integral types, including both signed and unsigned types, 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 language="csharp" source="~/snippets/csharp/System/Decimal/Equals/equalsoverl.cs" interactive="try-dotnet" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/Equals/equalsoverl.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.decimal.equals/vb/equalsoverl.vb" id="Snippet2"::: @@ -1873,11 +1896,7 @@ ]]> - 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 a is defined and the argument is not typed as an , compilers may perform an implicit conversion and call the method. Otherwise, they call the method, which always returns if its argument is not a value. The following example illustrates the difference in behavior between the two method overloads. In the case of all primitive integral types, including both signed and unsigned types, 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 language="csharp" source="~/snippets/csharp/System/Decimal/Equals/equalsoverl.cs" interactive="try-dotnet" id="Snippet2"::: - :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/Equals/equalsoverl.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.decimal.equals/vb/equalsoverl.vb" id="Snippet2"::: + 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 a is defined and the argument is not typed as an , compilers may perform an implicit conversion and call the method. Otherwise, they call the method, which always returns if its argument is not a value. The following example illustrates the difference in behavior between the two method overloads. In the case of all primitive integral types, including both signed and unsigned types, 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 language="csharp" source="~/snippets/csharp/System/Decimal/Equals/equalsoverl.cs" interactive="try-dotnet" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/Equals/equalsoverl.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.decimal.equals/vb/equalsoverl.vb" id="Snippet2"::: @@ -2008,9 +2027,9 @@ Rounds a specified number to the closest integer toward negative infinity. If has a fractional part, the next whole number toward negative infinity that is less than . - -or- +-or- - If doesn't have a fractional part, is returned unchanged. Note that the method returns an integral value of type . +If doesn't have a fractional part, is returned unchanged. Note that the method returns an integral value of type . , this method matches the IE Returns the result of multiplying the specified value by negative one. A decimal number with the value of , but the opposite sign. - -or- +-or- - Zero, if is zero. +Zero, if is zero. , this method matches the IE The value to convert. - Defines an explicit conversion of a to an 8-bit signed integer. - - This API is not CLS-compliant. + Defines an explicit conversion of a to an 8-bit signed integer. This API is not CLS-compliant. An 8-bit signed integer that represents the converted . , this method matches the IE The value to convert. - Defines an explicit conversion of a to a 16-bit unsigned integer. - - This API is not CLS-compliant. + Defines an explicit conversion of a to a 16-bit unsigned integer. This API is not CLS-compliant. A 16-bit unsigned integer that represents the converted . , this method matches the IE The value to convert. - Defines an explicit conversion of a to a 32-bit unsigned integer. - - This API is not CLS-compliant. + Defines an explicit conversion of a to a 32-bit unsigned integer. This API is not CLS-compliant. A 32-bit unsigned integer that represents the converted . , this method matches the IE The value to convert. - Defines an explicit conversion of a to a 64-bit unsigned integer. - - This API is not CLS-compliant. + Defines an explicit conversion of a to a 64-bit unsigned integer. This API is not CLS-compliant. A 64-bit unsigned integer that represents the converted . , this method matches the IE is greater than Decimal.MaxValue or less than Decimal.MinValue. - -or- +-or- - is , , or . + is , , or . @@ -4356,9 +4367,9 @@ For , this method matches the IE is greater than Decimal.MaxValue or less than Decimal.MinValue. - -or- +-or- - is , , or . + is , , or . @@ -4904,9 +4915,7 @@ For , this method matches the IE The 8-bit signed integer to convert. - Defines an implicit conversion of an 8-bit signed integer to a . - - This API is not CLS-compliant. + Defines an implicit conversion of an 8-bit signed integer to a . This API is not CLS-compliant. The converted 8-bit signed integer. , this method matches the IE The 16-bit unsigned integer to convert. - Defines an implicit conversion of a 16-bit unsigned integer to a . - - This API is not CLS-compliant. + Defines an implicit conversion of a 16-bit unsigned integer to a . This API is not CLS-compliant. The converted 16-bit unsigned integer. , this method matches the IE The 32-bit unsigned integer to convert. - Defines an implicit conversion of a 32-bit unsigned integer to a . - - This API is not CLS-compliant. + Defines an implicit conversion of a 32-bit unsigned integer to a . This API is not CLS-compliant. The converted 32-bit unsigned integer. , this method matches the IE The 64-bit unsigned integer to convert. - Defines an implicit conversion of a 64-bit unsigned integer to a . - - This API is not CLS-compliant. + Defines an implicit conversion of a 64-bit unsigned integer to a . This API is not CLS-compliant. The converted 64-bit unsigned integer. , this method matches the IE is not a value. - -or- +-or- - is the value. + is the value. is not in the correct format. @@ -6480,9 +6483,9 @@ For , this method matches the IE is not a value. - -or- +-or- - is the value. + is the value. Parsing Numeric Strings in .NET @@ -11514,9 +11517,9 @@ This member is an explicit interface member implementation. It can be used only is not a value. - -or- +-or- - is the value. + is the value. Parsing Numeric Strings in .NET diff --git a/xml/System/Delegate.xml b/xml/System/Delegate.xml index c7a177e5e00..4e5aae543d2 100644 --- a/xml/System/Delegate.xml +++ b/xml/System/Delegate.xml @@ -81,59 +81,59 @@ Represents a delegate, which is a data structure that refers to a static method or to a class instance and an instance method of that class. - class is the base class for delegate types. However, only the system and compilers can derive explicitly from the class or from the class. It is also not permissible to derive a new type from a delegate type. The class is not considered a delegate type; it is a class used to derive delegate types. - - Most languages implement a `delegate` keyword, and compilers for those languages are able to derive from the class; therefore, users should use the `delegate` keyword provided by the language. - + class is the base class for delegate types. However, only the system and compilers can derive explicitly from the class or from the class. It is also not permissible to derive a new type from a delegate type. The class is not considered a delegate type; it is a class used to derive delegate types. + + Most languages implement a `delegate` keyword, and compilers for those languages are able to derive from the class; therefore, users should use the `delegate` keyword provided by the language. + > [!NOTE] -> The common language runtime provides an `Invoke` method for each delegate type, with the same signature as the delegate. You do not have to call this method explicitly from C#, Visual Basic, or Visual C++, because the compilers call it automatically. The `Invoke` method is useful in [reflection](/dotnet/framework/reflection-and-codedom/reflection) when you want to find the signature of the delegate type. - - The common language runtime provides each delegate type with `BeginInvoke` and `EndInvoke` methods, to enable asynchronous invocation of the delegate. For more information about these methods, see [Calling Synchronous Methods Asynchronously](/dotnet/standard/asynchronous-programming-patterns/calling-synchronous-methods-asynchronously). - - The declaration of a delegate type establishes a contract that specifies the signature of one or more methods. A delegate is an instance of a delegate type that has references to: - -- An instance method of a type and a target object assignable to that type. - -- An instance method of a type, with the hidden `this` parameter exposed in the formal parameter list. The delegate is said to be an open instance delegate. - -- A static method. - -- A static method and a target object assignable to the first parameter of the method. The delegate is said to be closed over its first argument. - - For more information on delegate binding, see the method overload. - - When a delegate represents an instance method closed over its first argument (the most common case), the delegate stores a reference to the method's entry point and a reference to an object, called the target, which is of a type assignable to the type that defined the method. When a delegate represents an open instance method, it stores a reference to the method's entry point. The delegate signature must include the hidden `this` parameter in its formal parameter list; in this case, the delegate does not have a reference to a target object, and a target object must be supplied when the delegate is invoked. - +> The common language runtime provides an `Invoke` method for each delegate type, with the same signature as the delegate. You do not have to call this method explicitly from C#, Visual Basic, or Visual C++, because the compilers call it automatically. The `Invoke` method is useful in [reflection](/dotnet/framework/reflection-and-codedom/reflection) when you want to find the signature of the delegate type. + + The common language runtime provides each delegate type with `BeginInvoke` and `EndInvoke` methods, to enable asynchronous invocation of the delegate. For more information about these methods, see [Calling Synchronous Methods Asynchronously](/dotnet/standard/asynchronous-programming-patterns/calling-synchronous-methods-asynchronously). + + The declaration of a delegate type establishes a contract that specifies the signature of one or more methods. A delegate is an instance of a delegate type that has references to: + +- An instance method of a type and a target object assignable to that type. + +- An instance method of a type, with the hidden `this` parameter exposed in the formal parameter list. The delegate is said to be an open instance delegate. + +- A static method. + +- A static method and a target object assignable to the first parameter of the method. The delegate is said to be closed over its first argument. + + For more information on delegate binding, see the method overload. + + When a delegate represents an instance method closed over its first argument (the most common case), the delegate stores a reference to the method's entry point and a reference to an object, called the target, which is of a type assignable to the type that defined the method. When a delegate represents an open instance method, it stores a reference to the method's entry point. The delegate signature must include the hidden `this` parameter in its formal parameter list; in this case, the delegate does not have a reference to a target object, and a target object must be supplied when the delegate is invoked. + When a delegate represents a static method, the delegate stores a reference to the method's entry point. When a delegate represents a static method closed over its first argument, the delegate stores a reference to the method's entry point and a reference to a target object assignable to the type of the method's first argument. When the delegate is invoked, the first argument of the static method receives the target object. This first argument must be a reference type. - - The invocation list of a delegate is an ordered set of delegates in which each element of the list invokes exactly one of the methods represented by the delegate. An invocation list can contain duplicate methods. During an invocation, methods are invoked in the order in which they appear in the invocation list. A delegate attempts to invoke every method in its invocation list; duplicates are invoked once for each time they appear in the invocation list. Delegates are immutable; once created, the invocation list of a delegate does not change. - - Delegates are referred to as multicast, or combinable, because a delegate can invoke one or more methods and can be used in combining operations. - - Combining operations, such as and , do not alter existing delegates. Instead, such an operation returns a new delegate that contains the results of the operation, an unchanged delegate, or `null`. A combining operation returns `null` when the result of the operation is a delegate that does not reference at least one method. A combining operation returns an unchanged delegate when the requested operation has no effect. - + + The invocation list of a delegate is an ordered set of delegates in which each element of the list invokes exactly one of the methods represented by the delegate. An invocation list can contain duplicate methods. During an invocation, methods are invoked in the order in which they appear in the invocation list. A delegate attempts to invoke every method in its invocation list; duplicates are invoked once for each time they appear in the invocation list. Delegates are immutable; once created, the invocation list of a delegate does not change. + + Delegates are referred to as multicast, or combinable, because a delegate can invoke one or more methods and can be used in combining operations. + + Combining operations, such as and , do not alter existing delegates. Instead, such an operation returns a new delegate that contains the results of the operation, an unchanged delegate, or `null`. A combining operation returns `null` when the result of the operation is a delegate that does not reference at least one method. A combining operation returns an unchanged delegate when the requested operation has no effect. + > [!NOTE] -> Managed languages use the and methods to implement delegate operations. Examples include the `AddHandler` and `RemoveHandler` statements in Visual Basic and the += and -= operators on delegate types in C#. - - Starting with the .NET Framework 4, generic delegate types can have variant type parameters. Contravariant type parameters can be used as parameter types of the delegate, and a covariant type parameter can be used as the return type. This feature allows generic delegate types that are constructed from the same generic type definition to be assignment-compatible if their type arguments are reference types with an inheritance relationship, as explained in [Covariance and Contravariance](/dotnet/standard/generics/covariance-and-contravariance). - +> Managed languages use the and methods to implement delegate operations. Examples include the `AddHandler` and `RemoveHandler` statements in Visual Basic and the += and -= operators on delegate types in C#. + + Starting with the .NET Framework 4, generic delegate types can have variant type parameters. Contravariant type parameters can be used as parameter types of the delegate, and a covariant type parameter can be used as the return type. This feature allows generic delegate types that are constructed from the same generic type definition to be assignment-compatible if their type arguments are reference types with an inheritance relationship, as explained in [Covariance and Contravariance](/dotnet/standard/generics/covariance-and-contravariance). + > [!NOTE] -> Generic delegates that are assignment-compatible because of variance are not necessarily combinable. To be combinable, the types must match exactly. For example, suppose that a class named `Derived` is derived from a class named `Base`. A delegate of type `Action` (`Action(Of Base)` in Visual Basic) can be assigned to a variable of type `Action`, but the two delegates cannot be combined because the types do not match exactly. - - If an invoked method throws an exception, the method stops executing, the exception is passed back to the caller of the delegate, and remaining methods in the invocation list are not invoked. Catching the exception in the caller does not alter this behavior. - - When the signature of the methods invoked by a delegate includes a return value, the delegate returns the return value of the last element in the invocation list. When the signature includes a parameter that is passed by reference, the final value of the parameter is the result of every method in the invocation list executing sequentially and updating the parameter's value. - - The closest equivalent of a delegate in C is a function pointer. A delegate can represent a static method or an instance method. When the delegate represents an instance method, the delegate stores not only a reference to the method's entry point, but also a reference to the class instance. Unlike function pointers, delegates are object oriented and type safe. - - - -## Examples - The following example shows how to define a delegate named `myMethodDelegate`. Instances of this delegate are created for an instance method and a static method of the nested `mySampleClass` class. The delegate for the instance method requires an instance of `mySampleClass`. The `mySampleClass` instance is saved in a variable named `mySC`. - +> Generic delegates that are assignment-compatible because of variance are not necessarily combinable. To be combinable, the types must match exactly. For example, suppose that a class named `Derived` is derived from a class named `Base`. A delegate of type `Action` (`Action(Of Base)` in Visual Basic) can be assigned to a variable of type `Action`, but the two delegates cannot be combined because the types do not match exactly. + + If an invoked method throws an exception, the method stops executing, the exception is passed back to the caller of the delegate, and remaining methods in the invocation list are not invoked. Catching the exception in the caller does not alter this behavior. + + When the signature of the methods invoked by a delegate includes a return value, the delegate returns the return value of the last element in the invocation list. When the signature includes a parameter that is passed by reference, the final value of the parameter is the result of every method in the invocation list executing sequentially and updating the parameter's value. + + The closest equivalent of a delegate in C is a function pointer. A delegate can represent a static method or an instance method. When the delegate represents an instance method, the delegate stores not only a reference to the method's entry point, but also a reference to the class instance. Unlike function pointers, delegates are object oriented and type safe. + + + +## Examples + The following example shows how to define a delegate named `myMethodDelegate`. Instances of this delegate are created for an instance method and a static method of the nested `mySampleClass` class. The delegate for the instance method requires an instance of `mySampleClass`. The `mySampleClass` instance is saved in a variable named `mySC`. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_Classic/classic Delegate Example/CPP/source.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Delegate/Overview/source.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Delegate/Overview/source.fs" id="Snippet1"::: @@ -208,21 +208,21 @@ The name of the instance method that the delegate represents. Initializes a delegate that invokes the specified instance method on the specified class instance. - method that specifies a method name and a target object. For example, the method overload creates a delegate for an instance method with a specified name. - - This constructor creates delegates for instance methods only. An instance method is a method that is associated with an instance of a class; a static method is a method that is associated with the class itself. - + method that specifies a method name and a target object. For example, the method overload creates a delegate for an instance method with a specified name. + + This constructor creates delegates for instance methods only. An instance method is a method that is associated with an instance of a class; a static method is a method that is associated with the class itself. + ]]> - is . - - -or- - - is . + is . + +-or- + + is . There was an error binding to the target method. @@ -280,27 +280,27 @@ The name of the static method that the delegate represents. Initializes a delegate that invokes the specified static method from the specified class. - method that specifies a method name but does not specify a target object. For example, the method overload creates a static delegate for a method with a specified name. - - This constructor creates delegates for static methods only. An instance method is a method that is associated with an instance of a class; a static method is a method that is associated with the class itself. - + method that specifies a method name but does not specify a target object. For example, the method overload creates a static delegate for a method with a specified name. + + This constructor creates delegates for static methods only. An instance method is a method that is associated with an instance of a class; a static method is a method that is associated with the class itself. + ]]> - is . - - -or- - - is . + is . + +-or- + + is . - is not a . See [Runtime Types in Reflection](/previous-versions/dotnet/netframework-4.0/ms172329(v=vs.100)). - - -or- - - represents an open generic type. + is not a . See [Runtime Types in Reflection](/previous-versions/dotnet/netframework-4.0/ms172329(v=vs.100)). + +-or- + + represents an open generic type. @@ -352,13 +352,13 @@ Creates a shallow copy of the delegate. A shallow copy of the delegate. - , target, method, and invocation list as the original delegate. - - A shallow copy creates a new instance of the same type as the original object, and then copies the nonstatic fields of the original object. If the field is a value type, a bit-by-bit copy of the field is performed. If the field is a reference type, the reference is copied but the referred object is not; therefore, the reference in the original object and the reference in the clone point to the same object. In contrast, a deep copy of an object duplicates everything directly or indirectly referenced by the fields in the object. - + , target, method, and invocation list as the original delegate. + + A shallow copy creates a new instance of the same type as the original object, and then copies the nonstatic fields of the original object. If the field is a value type, a bit-by-bit copy of the field is performed. If the field is a reference type, the reference is copied but the referred object is not; therefore, the reference in the original object and the reference in the clone point to the same object. In contrast, a deep copy of an object duplicates everything directly or indirectly referenced by the fields in the object. + ]]> @@ -442,18 +442,18 @@ Concatenates the invocation lists of an array of delegates. A new delegate with an invocation list that concatenates the invocation lists of the delegates in the array. Returns if is , if contains zero elements, or if every entry in is . - [!NOTE] -> Generic delegates that are assignment-compatible because of variance are not necessarily combinable. To be combinable, the types must match exactly. For example, suppose that a class named `Derived` is derived from a class named `Base`. A delegate of type `Action` (`Action(Of Base)` in Visual Basic) can be assigned to a variable of type `Action`, as explained in [Covariance and Contravariance](/dotnet/standard/generics/covariance-and-contravariance), but the two delegates cannot be combined because the types do not match exactly. - - is useful for creating event handlers that call multiple methods each time an event occurs. - +> Generic delegates that are assignment-compatible because of variance are not necessarily combinable. To be combinable, the types must match exactly. For example, suppose that a class named `Derived` is derived from a class named `Base`. A delegate of type `Action` (`Action(Of Base)` in Visual Basic) can be assigned to a variable of type `Action`, as explained in [Covariance and Contravariance](/dotnet/standard/generics/covariance-and-contravariance), but the two delegates cannot be combined because the types do not match exactly. + + is useful for creating event handlers that call multiple methods each time an event occurs. + ]]> Not all the non-null entries in are instances of the same delegate type. @@ -523,16 +523,16 @@ Concatenates the invocation lists of two delegates. A new delegate with an invocation list that concatenates the invocation lists of and in that order. Returns if is , returns if is a null reference, and returns a null reference if both and are null references. - [!NOTE] -> Generic delegates that are assignment-compatible because of variance are not necessarily combinable. To be combinable, the types must match exactly. For example, suppose that a class named `Derived` is derived from a class named `Base`. A delegate of type `Action` (`Action(Of Base)` in Visual Basic) can be assigned to a variable of type `Action`, as explained in [Covariance and Contravariance](/dotnet/standard/generics/covariance-and-contravariance), but the two delegates cannot be combined because the types do not match exactly. - - is useful for creating event handlers that call multiple methods each time an event occurs. - +> Generic delegates that are assignment-compatible because of variance are not necessarily combinable. To be combinable, the types must match exactly. For example, suppose that a class named `Derived` is derived from a class named `Base`. A delegate of type `Action` (`Action(Of Base)` in Visual Basic) can be assigned to a variable of type `Action`, as explained in [Covariance and Contravariance](/dotnet/standard/generics/covariance-and-contravariance), but the two delegates cannot be combined because the types do not match exactly. + + is useful for creating event handlers that call multiple methods each time an event occurs. + ]]> Both and are not , and and are not instances of the same delegate type. @@ -589,15 +589,15 @@ Concatenates the invocation lists of the specified multicast (combinable) delegate and the current multicast (combinable) delegate. A new multicast (combinable) delegate with an invocation list that concatenates the invocation list of the current multicast (combinable) delegate and the invocation list of , or the current multicast (combinable) delegate if is . - . - - The invocation list can contain duplicate entries; that is, entries that refer to the same method on the same object. - + . + + The invocation list can contain duplicate entries; that is, entries that refer to the same method on the same object. + ]]> Always thrown. @@ -657,97 +657,97 @@ Creates a delegate of the specified type to represent the specified method. A delegate of the specified type to represent the specified method. - method overload, which allows you to create all combinations of open or closed delegates for instance or static methods, and optionally to specify a first argument. - + method overload, which allows you to create all combinations of open or closed delegates for instance or static methods, and optionally to specify a first argument. + > [!NOTE] -> This method overload should be used when the delegate is not closed over its first argument, because it is somewhat faster in that case. - - This method overload is equivalent to calling the method overload and specifying `true` for `throwOnBindFailure`. - +> This method overload should be used when the delegate is not closed over its first argument, because it is somewhat faster in that case. + + This method overload is equivalent to calling the method overload and specifying `true` for `throwOnBindFailure`. + > [!NOTE] -> Starting with the .NET Framework 2.0 Service Pack 1, this method can be used to access non-public methods if the caller has been granted with the flag and if the grant set of the non-public methods is restricted to the caller's grant set, or a subset thereof. (See [Security Considerations for Reflection](/dotnet/framework/reflection-and-codedom/security-considerations-for-reflection).) -> -> To use this functionality, your application should target the .NET Framework 3.5 or later. - -## Compatible Parameter Types and Return Type - In the .NET Framework version 2.0, the parameter types and return type of a delegate created using this method overload must be compatible with the parameter types and return type of the method the delegate represents; the types do not have to match exactly. This represents a relaxation of the binding behavior in the .NET Framework version 1.0 and 1.1, where the types must match exactly. - - A parameter of a delegate is compatible with the corresponding parameter of a method if the type of the delegate parameter is more restrictive than the type of the method parameter, because this guarantees that an argument passed to the delegate can be passed safely to the method. - - Similarly, the return type of a delegate is compatible with the return type of a method if the return type of the method is more restrictive than the return type of the delegate, because this guarantees that the return value of the method can be cast safely to the return type of the delegate. - - For example, a delegate with a parameter of type and a return type of can represent a method with a parameter of type and a return value of type . - - - -## Examples - This section contains two code examples. The first example demonstrates the two kinds of delegates that can be created with this method overload: open over an instance method and open over a static method. - - The second code example demonstrates compatible parameter types and return types. - - **Example 1** - - The following code example demonstrates the two ways a delegate can be created using this overload of the method. - +> Starting with the .NET Framework 2.0 Service Pack 1, this method can be used to access non-public methods if the caller has been granted with the flag and if the grant set of the non-public methods is restricted to the caller's grant set, or a subset thereof. (See [Security Considerations for Reflection](/dotnet/framework/reflection-and-codedom/security-considerations-for-reflection).) +> +> To use this functionality, your application should target the .NET Framework 3.5 or later. + +## Compatible Parameter Types and Return Type + In the .NET Framework version 2.0, the parameter types and return type of a delegate created using this method overload must be compatible with the parameter types and return type of the method the delegate represents; the types do not have to match exactly. This represents a relaxation of the binding behavior in the .NET Framework version 1.0 and 1.1, where the types must match exactly. + + A parameter of a delegate is compatible with the corresponding parameter of a method if the type of the delegate parameter is more restrictive than the type of the method parameter, because this guarantees that an argument passed to the delegate can be passed safely to the method. + + Similarly, the return type of a delegate is compatible with the return type of a method if the return type of the method is more restrictive than the return type of the delegate, because this guarantees that the return value of the method can be cast safely to the return type of the delegate. + + For example, a delegate with a parameter of type and a return type of can represent a method with a parameter of type and a return value of type . + + + +## Examples + This section contains two code examples. The first example demonstrates the two kinds of delegates that can be created with this method overload: open over an instance method and open over a static method. + + The second code example demonstrates compatible parameter types and return types. + + **Example 1** + + The following code example demonstrates the two ways a delegate can be created using this overload of the method. + > [!NOTE] -> There are two overloads of the method that specify a but not a first argument; their functionality is the same except that one allows you to specify whether to throw on failure to bind, and the other always throws. This code example uses both overloads. - - The example declares a class `C` with a static method `M2` and an instance method `M1`, and two delegate types: `D1` takes an instance of `C` and a string, and `D2` takes a string. - - A second class named `Example` contains the code that creates the delegates. - -- A delegate of type `D1`, representing an open instance method, is created for the instance method `M1`. An instance must be passed when the delegate is invoked. - -- A delegate of type `D2`, representing an open static method, is created for the static method `M2`. - +> There are two overloads of the method that specify a but not a first argument; their functionality is the same except that one allows you to specify whether to throw on failure to bind, and the other always throws. This code example uses both overloads. + + The example declares a class `C` with a static method `M2` and an instance method `M1`, and two delegate types: `D1` takes an instance of `C` and a string, and `D2` takes a string. + + A second class named `Example` contains the code that creates the delegates. + +- A delegate of type `D1`, representing an open instance method, is created for the instance method `M1`. An instance must be passed when the delegate is invoked. + +- A delegate of type `D2`, representing an open static method, is created for the static method `M2`. + :::code language="csharp" source="~/snippets/csharp/System/Delegate/CreateDelegate/openClosedOver.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Delegate/CreateDelegate/openClosedOver.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Delegate.CreateDelegateTOM/VB/openClosedOver.vb" id="Snippet1"::: - **Example 2** - - The following code example demonstrates compatibility of parameter types and return types. - - The code example defines a base class named `Base` and a class named `Derived` that derives from `Base`. The derived class has a `static` (`Shared` in Visual Basic) method named `MyMethod` with one parameter of type `Base` and a return type of `Derived`. The code example also defines a delegate named `Example` that has one parameter of type `Derived` and a return type of `Base`. - - The code example demonstrates that the delegate named `Example` can be used to represent the method `MyMethod`. The method can be bound to the delegate because: - -- The parameter type of the delegate (`Derived`) is more restrictive than the parameter type of `MyMethod` (`Base`), so that it is always safe to pass the argument of the delegate to `MyMethod`. - -- The return type of `MyMethod` (`Derived`) is more restrictive than the parameter type of the delegate (`Base`), so that it is always safe to cast the return type of the method to the return type of the delegate. - - The code example produces no output. - + **Example 2** + + The following code example demonstrates compatibility of parameter types and return types. + + The code example defines a base class named `Base` and a class named `Derived` that derives from `Base`. The derived class has a `static` (`Shared` in Visual Basic) method named `MyMethod` with one parameter of type `Base` and a return type of `Derived`. The code example also defines a delegate named `Example` that has one parameter of type `Derived` and a return type of `Base`. + + The code example demonstrates that the delegate named `Example` can be used to represent the method `MyMethod`. The method can be bound to the delegate because: + +- The parameter type of the delegate (`Derived`) is more restrictive than the parameter type of `MyMethod` (`Base`), so that it is always safe to pass the argument of the delegate to `MyMethod`. + +- The return type of `MyMethod` (`Derived`) is more restrictive than the parameter type of the delegate (`Base`), so that it is always safe to cast the return type of the method to the return type of the delegate. + + The code example produces no output. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Delegate.CreateDelegate_RelaxedFit/cpp/source.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Delegate/CreateDelegate/source1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Delegate/CreateDelegate/source1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Delegate.CreateDelegate_RelaxedFit/vb/source.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Delegate.CreateDelegate_RelaxedFit/vb/source.vb" id="Snippet1"::: + ]]> - is . - - -or- - - is . + is . + +-or- + + is . - does not inherit . - - -or- - - is not a . See [Runtime Types in Reflection](/previous-versions/dotnet/netframework-4.0/ms172329(v=vs.100)). - - -or- - - cannot be bound. - - -or- - - is not a . See [Runtime Types in Reflection](/previous-versions/dotnet/netframework-4.0/ms172329(v=vs.100)). + does not inherit . + +-or- + + is not a . See [Runtime Types in Reflection](/previous-versions/dotnet/netframework-4.0/ms172329(v=vs.100)). + +-or- + + cannot be bound. + +-or- + + is not a . See [Runtime Types in Reflection](/previous-versions/dotnet/netframework-4.0/ms172329(v=vs.100)). The method of is not found. The caller does not have the permissions necessary to access . @@ -808,133 +808,133 @@ Creates a delegate of the specified type that represents the specified static or instance method, with the specified first argument. A delegate of the specified type that represents the specified static or instance method. - method overload and specifying `true` for `throwOnBindFailure`. These two overloads provide the most flexible way to create delegates. You can use them to create delegates for either static or instance methods, and optionally to specify the first argument. - + method overload and specifying `true` for `throwOnBindFailure`. These two overloads provide the most flexible way to create delegates. You can use them to create delegates for either static or instance methods, and optionally to specify the first argument. + > [!NOTE] -> If you do not supply a first argument, use the method overload for better performance. - - The delegate type and the method must have compatible return types. That is, the return type of `method` must be assignable to the return type of `type`. - - If `firstArgument` is supplied, it is passed to `method` every time the delegate is invoked; `firstArgument` is said to be bound to the delegate, and the delegate is said to be closed over its first argument. If `method` is `static` (`Shared` in Visual Basic), the argument list supplied when invoking the delegate includes all parameters except the first; if `method` is an instance method, then `firstArgument` is passed to the hidden instance parameter (represented by `this` in C#, or by `Me` in Visual Basic). - - If `firstArgument` is supplied, the first parameter of `method` must be a reference type, and `firstArgument` must be compatible with that type. - +> If you do not supply a first argument, use the method overload for better performance. + + The delegate type and the method must have compatible return types. That is, the return type of `method` must be assignable to the return type of `type`. + + If `firstArgument` is supplied, it is passed to `method` every time the delegate is invoked; `firstArgument` is said to be bound to the delegate, and the delegate is said to be closed over its first argument. If `method` is `static` (`Shared` in Visual Basic), the argument list supplied when invoking the delegate includes all parameters except the first; if `method` is an instance method, then `firstArgument` is passed to the hidden instance parameter (represented by `this` in C#, or by `Me` in Visual Basic). + + If `firstArgument` is supplied, the first parameter of `method` must be a reference type, and `firstArgument` must be compatible with that type. + > [!IMPORTANT] -> If `method` is `static` (`Shared` in Visual Basic) and its first parameter is of type or , then `firstArgument` can be a value type. In this case `firstArgument` is automatically boxed. Automatic boxing does not occur for any other arguments, as it would in a C# or Visual Basic function call. - - If `firstArgument` is a null reference and `method` is an instance method, the result depends on the signatures of the delegate type `type` and of `method`: - -- If the signature of `type` explicitly includes the hidden first parameter of `method`, the delegate is said to represent an open instance method. When the delegate is invoked, the first argument in the argument list is passed to the hidden instance parameter of `method`. - -- If the signatures of `method` and `type` match (that is, all parameter types are compatible), then the delegate is said to be closed over a null reference. Invoking the delegate is like calling an instance method on a null instance, which is not a particularly useful thing to do. - - If `firstArgument` is a null reference and `method` is static, the result depends on the signatures of the delegate type `type` and of `method`: - -- If the signature of `method` and `type` match (that is, all parameter types are compatible), the delegate is said to represent an open static method. This is the most common case for static methods. In this case, you can get slightly better performance by using the method overload. - -- If the signature of `type` begins with the second parameter of `method` and the rest of the parameter types are compatible, then the delegate is said to be closed over a null reference. When the delegate is invoked, a null reference is passed to the first parameter of `method`. - +> If `method` is `static` (`Shared` in Visual Basic) and its first parameter is of type or , then `firstArgument` can be a value type. In this case `firstArgument` is automatically boxed. Automatic boxing does not occur for any other arguments, as it would in a C# or Visual Basic function call. + + If `firstArgument` is a null reference and `method` is an instance method, the result depends on the signatures of the delegate type `type` and of `method`: + +- If the signature of `type` explicitly includes the hidden first parameter of `method`, the delegate is said to represent an open instance method. When the delegate is invoked, the first argument in the argument list is passed to the hidden instance parameter of `method`. + +- If the signatures of `method` and `type` match (that is, all parameter types are compatible), then the delegate is said to be closed over a null reference. Invoking the delegate is like calling an instance method on a null instance, which is not a particularly useful thing to do. + + If `firstArgument` is a null reference and `method` is static, the result depends on the signatures of the delegate type `type` and of `method`: + +- If the signature of `method` and `type` match (that is, all parameter types are compatible), the delegate is said to represent an open static method. This is the most common case for static methods. In this case, you can get slightly better performance by using the method overload. + +- If the signature of `type` begins with the second parameter of `method` and the rest of the parameter types are compatible, then the delegate is said to be closed over a null reference. When the delegate is invoked, a null reference is passed to the first parameter of `method`. + > [!NOTE] -> Starting with the .NET Framework 2.0 Service Pack 1, this method can be used to access non-public methods if the caller has been granted with the flag and if the grant set of the non-public methods is restricted to the caller's grant set, or a subset thereof. (See [Security Considerations for Reflection](/dotnet/framework/reflection-and-codedom/security-considerations-for-reflection).) -> -> To use this functionality, your application should target the .NET Framework 3.5 or later. - -## Compatible Parameter Types and Return Type - The parameter types and return type of a delegate must be compatible with the parameter types and return type of the method the delegate represents; the types do not have to match exactly. - - A parameter of a delegate is compatible with the corresponding parameter of a method if the type of the delegate parameter is more restrictive than the type of the method parameter, because this guarantees that an argument passed to the delegate can be passed safely to the method. - - Similarly, the return type of a delegate is compatible with the return type of a method if the return type of the method is more restrictive than the return type of the delegate, because this guarantees that the return value of the method can be cast safely to the return type of the delegate. - - For example, a delegate with a parameter of type and a return type of can represent a method with a parameter of type and a return value of type . - -## Determining the Methods a Delegate Can Represent - Another useful way to think of the flexibility provided by this overload of is that any given delegate can represent four different combinations of method signature and method kind (static versus instance). Consider a delegate type `D` with one argument of type `C`. The following describes the methods `D` can represent, ignoring the return type since it must match in all cases: - -- `D` can represent any instance method that has exactly one argument of type `C`, regardless of what type the instance method belongs to. When is called, `firstArgument` is an instance of the type `method` belongs to, and the resulting delegate is said to be closed over that instance. (Trivially, `D` can also be closed over a null reference if `firstArgument` is a null reference.) - -- `D` can represent an instance method of `C` that has no arguments. When is called, `firstArgument` is a null reference. The resulting delegate represents an open instance method, and an instance of `C` must be supplied each time it is invoked. - -- `D` can represent a static method that takes one argument of type `C`, and that method can belong to any type. When is called, `firstArgument` is a null reference. The resulting delegate represents an open static method, and an instance of `C` must be supplied each time it is invoked. - -- `D` can represent a static method that belongs to type `F` and has two arguments, of type `F` and type `C`. When is called, `firstArgument` is an instance of `F`. The resulting delegate represents a static method that is closed over that instance of `F`. Note that in the case where `F` and `C` are the same type, the static method has two arguments of that type. (In this case, `D` is closed over a null reference if `firstArgument` is a null reference.) - - - -## Examples - This section contains three code examples. The first example demonstrates the four kinds of delegates that can be created: closed over an instance method, open over an instance method, open over a static method, and closed over a static method. - - The second code example demonstrates compatible parameter types and return types. - - The third code example defines a single delegate type, and shows all the methods that delegate type can represent. - - **Example 1** - - The following code example demonstrates the four ways a delegate can be created using this overload of the method. - +> Starting with the .NET Framework 2.0 Service Pack 1, this method can be used to access non-public methods if the caller has been granted with the flag and if the grant set of the non-public methods is restricted to the caller's grant set, or a subset thereof. (See [Security Considerations for Reflection](/dotnet/framework/reflection-and-codedom/security-considerations-for-reflection).) +> +> To use this functionality, your application should target the .NET Framework 3.5 or later. + +## Compatible Parameter Types and Return Type + The parameter types and return type of a delegate must be compatible with the parameter types and return type of the method the delegate represents; the types do not have to match exactly. + + A parameter of a delegate is compatible with the corresponding parameter of a method if the type of the delegate parameter is more restrictive than the type of the method parameter, because this guarantees that an argument passed to the delegate can be passed safely to the method. + + Similarly, the return type of a delegate is compatible with the return type of a method if the return type of the method is more restrictive than the return type of the delegate, because this guarantees that the return value of the method can be cast safely to the return type of the delegate. + + For example, a delegate with a parameter of type and a return type of can represent a method with a parameter of type and a return value of type . + +## Determining the Methods a Delegate Can Represent + Another useful way to think of the flexibility provided by this overload of is that any given delegate can represent four different combinations of method signature and method kind (static versus instance). Consider a delegate type `D` with one argument of type `C`. The following describes the methods `D` can represent, ignoring the return type since it must match in all cases: + +- `D` can represent any instance method that has exactly one argument of type `C`, regardless of what type the instance method belongs to. When is called, `firstArgument` is an instance of the type `method` belongs to, and the resulting delegate is said to be closed over that instance. (Trivially, `D` can also be closed over a null reference if `firstArgument` is a null reference.) + +- `D` can represent an instance method of `C` that has no arguments. When is called, `firstArgument` is a null reference. The resulting delegate represents an open instance method, and an instance of `C` must be supplied each time it is invoked. + +- `D` can represent a static method that takes one argument of type `C`, and that method can belong to any type. When is called, `firstArgument` is a null reference. The resulting delegate represents an open static method, and an instance of `C` must be supplied each time it is invoked. + +- `D` can represent a static method that belongs to type `F` and has two arguments, of type `F` and type `C`. When is called, `firstArgument` is an instance of `F`. The resulting delegate represents a static method that is closed over that instance of `F`. Note that in the case where `F` and `C` are the same type, the static method has two arguments of that type. (In this case, `D` is closed over a null reference if `firstArgument` is a null reference.) + + + +## Examples + This section contains three code examples. The first example demonstrates the four kinds of delegates that can be created: closed over an instance method, open over an instance method, open over a static method, and closed over a static method. + + The second code example demonstrates compatible parameter types and return types. + + The third code example defines a single delegate type, and shows all the methods that delegate type can represent. + + **Example 1** + + The following code example demonstrates the four ways a delegate can be created using this overload of the method. + > [!NOTE] -> There are two overloads of the method that specify `firstArgument` and a ; their functionality is the same except that one allows you to specify whether to throw on failure to bind, and the other always throws. This code example uses both overloads. - - The example declares a class `C` with a static method `M2` and an instance method `M1`, and three delegate types: `D1` takes an instance of `C` and a string, `D2` takes a string, and `D3` has no arguments. - - A second class named `Example` contains the code that creates the delegates. - -- A delegate of type `D2`, closed over an instance of `C`, is created for the instance method `M1`. It is invoked with different strings, to show that the bound instance of `C` is always used. - -- A delegate of type `D1`, representing an open instance method, is created for the instance method `M1`. An instance must be passed when the delegate is invoked. - -- A delegate of type `D2`, representing an open static method, is created for the static method `M2`. - -- Finally, a delegate of type `D3`, closed over a string, is created for the static method `M2`. The method is invoked to show that it uses the bound string. - +> There are two overloads of the method that specify `firstArgument` and a ; their functionality is the same except that one allows you to specify whether to throw on failure to bind, and the other always throws. This code example uses both overloads. + + The example declares a class `C` with a static method `M2` and an instance method `M1`, and three delegate types: `D1` takes an instance of `C` and a string, `D2` takes a string, and `D3` has no arguments. + + A second class named `Example` contains the code that creates the delegates. + +- A delegate of type `D2`, closed over an instance of `C`, is created for the instance method `M1`. It is invoked with different strings, to show that the bound instance of `C` is always used. + +- A delegate of type `D1`, representing an open instance method, is created for the instance method `M1`. An instance must be passed when the delegate is invoked. + +- A delegate of type `D2`, representing an open static method, is created for the static method `M2`. + +- Finally, a delegate of type `D3`, closed over a string, is created for the static method `M2`. The method is invoked to show that it uses the bound string. + :::code language="csharp" source="~/snippets/csharp/System/Delegate/CreateDelegate/openClosedOver.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Delegate/CreateDelegate/openClosedOver.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Delegate.CreateDelegateTOM/VB/openClosedOver.vb" id="Snippet1"::: - **Example 2** - - The following code example demonstrates compatibility of parameter types and return types. - + **Example 2** + + The following code example demonstrates compatibility of parameter types and return types. + > [!NOTE] -> This code example uses the method overload. The use of other overloads that take is similar. - - The code example defines a base class named `Base` and a class named `Derived` that derives from `Base`. The derived class has a `static` (`Shared` in Visual Basic) method named `MyMethod` with one parameter of type `Base` and a return type of `Derived`. The code example also defines a delegate named `Example` that has one parameter of type `Derived` and a return type of `Base`. - - The code example demonstrates that the delegate named `Example` can be used to represent the method `MyMethod`. The method can be bound to the delegate because: - -- The parameter type of the delegate (`Derived`) is more restrictive than the parameter type of `MyMethod` (`Base`), so that it is always safe to pass the argument of the delegate to `MyMethod`. - -- The return type of `MyMethod` (`Derived`) is more restrictive than the parameter type of the delegate (`Base`), so that it is always safe to cast the return type of the method to the return type of the delegate. - - The code example produces no output. - +> This code example uses the method overload. The use of other overloads that take is similar. + + The code example defines a base class named `Base` and a class named `Derived` that derives from `Base`. The derived class has a `static` (`Shared` in Visual Basic) method named `MyMethod` with one parameter of type `Base` and a return type of `Derived`. The code example also defines a delegate named `Example` that has one parameter of type `Derived` and a return type of `Base`. + + The code example demonstrates that the delegate named `Example` can be used to represent the method `MyMethod`. The method can be bound to the delegate because: + +- The parameter type of the delegate (`Derived`) is more restrictive than the parameter type of `MyMethod` (`Base`), so that it is always safe to pass the argument of the delegate to `MyMethod`. + +- The return type of `MyMethod` (`Derived`) is more restrictive than the parameter type of the delegate (`Base`), so that it is always safe to cast the return type of the method to the return type of the delegate. + + The code example produces no output. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Delegate.CreateDelegate_RelaxedFit/cpp/source.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Delegate/CreateDelegate/source1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Delegate/CreateDelegate/source1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Delegate.CreateDelegate_RelaxedFit/vb/source.vb" id="Snippet1"::: - - **Example 3** - - The following code example shows all the methods a single delegate type can represent, using the method to create the delegates. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Delegate.CreateDelegate_RelaxedFit/vb/source.vb" id="Snippet1"::: + + **Example 3** + + The following code example shows all the methods a single delegate type can represent, using the method to create the delegates. + > [!NOTE] -> There are two overloads of the method that specify `firstArgument` and a ; their functionality is the same except that one allows you to specify whether to throw on failure to bind, and the other always throws. This code example uses both overloads. - - The code example defines two classes, `C` and `F`, and a delegate type `D` with one argument of type `C`. The classes have matching static and instance methods `M1`, `M3`, and `M4`, and class `C` also has an instance method `M2` that has no arguments. - - A third class named `Example` contains the code that creates the delegates. - -- Delegates are created for instance method `M1` of type `C` and type `F`; each is closed over an instance of the respective type. Method `M1` of type `C` displays the `ID` properties of the bound instance and of the argument. - -- A delegate is created for method `M2` of type `C`. This is an open instance delegate, in which the argument of the delegate represents the hidden first argument on the instance method. The method has no other arguments. It is called as if it were a static method. - -- Delegates are created for static method `M3` of type `C` and type `F`; these are open static delegates. - -- Finally, delegates are created for static method `M4` of type `C` and type `F`; each method has the declaring type as its first argument, and an instance of the type is supplied, so the delegates are closed over their first arguments. Method `M4` of type `C` displays the `ID` properties of the bound instance and of the argument. - +> There are two overloads of the method that specify `firstArgument` and a ; their functionality is the same except that one allows you to specify whether to throw on failure to bind, and the other always throws. This code example uses both overloads. + + The code example defines two classes, `C` and `F`, and a delegate type `D` with one argument of type `C`. The classes have matching static and instance methods `M1`, `M3`, and `M4`, and class `C` also has an instance method `M2` that has no arguments. + + A third class named `Example` contains the code that creates the delegates. + +- Delegates are created for instance method `M1` of type `C` and type `F`; each is closed over an instance of the respective type. Method `M1` of type `C` displays the `ID` properties of the bound instance and of the argument. + +- A delegate is created for method `M2` of type `C`. This is an open instance delegate, in which the argument of the delegate represents the hidden first argument on the instance method. The method has no other arguments. It is called as if it were a static method. + +- Delegates are created for static method `M3` of type `C` and type `F`; these are open static delegates. + +- Finally, delegates are created for static method `M4` of type `C` and type `F`; each method has the declaring type as its first argument, and an instance of the type is supplied, so the delegates are closed over their first arguments. Method `M4` of type `C` displays the `ID` properties of the bound instance and of the argument. + :::code language="csharp" source="~/snippets/csharp/System/Delegate/CreateDelegate/source.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Delegate/CreateDelegate/source.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Delegate.CreateDelegateTOM_2/vb/source.vb" id="Snippet1"::: @@ -942,25 +942,25 @@ ]]> - is . - - -or- - - is . + is . + +-or- + + is . - does not inherit . - - -or- - - is not a . See [Runtime Types in Reflection](/previous-versions/dotnet/netframework-4.0/ms172329(v=vs.100)). - - -or- - - cannot be bound. - - -or- - - is not a . See [Runtime Types in Reflection](/previous-versions/dotnet/netframework-4.0/ms172329(v=vs.100)). + does not inherit . + +-or- + + is not a . See [Runtime Types in Reflection](/previous-versions/dotnet/netframework-4.0/ms172329(v=vs.100)). + +-or- + + cannot be bound. + +-or- + + is not a . See [Runtime Types in Reflection](/previous-versions/dotnet/netframework-4.0/ms172329(v=vs.100)). The method of is not found. The caller does not have the permissions necessary to access . @@ -1020,44 +1020,44 @@ Creates a delegate of the specified type that represents the specified instance method to invoke on the specified class instance. A delegate of the specified type that represents the specified instance method to invoke on the specified class instance. - method overload, specifying `false` for `ignoreCase` and `true` for `throwOnBindFailure`. - + method overload, specifying `false` for `ignoreCase` and `true` for `throwOnBindFailure`. + > [!NOTE] -> Starting with the .NET Framework 2.0 Service Pack 1, this method can be used to access non-public methods if the caller has been granted with the flag and if the grant set of the non-public methods is restricted to the caller's grant set, or a subset thereof. (See [Security Considerations for Reflection](/dotnet/framework/reflection-and-codedom/security-considerations-for-reflection).) -> -> To use this functionality, your application should target the .NET Framework 3.5 or later. - +> Starting with the .NET Framework 2.0 Service Pack 1, this method can be used to access non-public methods if the caller has been granted with the flag and if the grant set of the non-public methods is restricted to the caller's grant set, or a subset thereof. (See [Security Considerations for Reflection](/dotnet/framework/reflection-and-codedom/security-considerations-for-reflection).) +> +> To use this functionality, your application should target the .NET Framework 3.5 or later. + ]]> - is . - - -or- - - is . - - -or- - - is . + is . + +-or- + + is . + +-or- + + is . - does not inherit . - - -or- - - is not a . See [Runtime Types in Reflection](/previous-versions/dotnet/netframework-4.0/ms172329(v=vs.100)). - - -or- - - is not an instance method. - - -or- - - cannot be bound, for example because it cannot be found. + does not inherit . + +-or- + + is not a . See [Runtime Types in Reflection](/previous-versions/dotnet/netframework-4.0/ms172329(v=vs.100)). + +-or- + + is not an instance method. + +-or- + + cannot be bound, for example because it cannot be found. The method of is not found. The caller does not have the permissions necessary to access . @@ -1118,98 +1118,98 @@ Creates a delegate of the specified type to represent the specified static method, with the specified behavior on failure to bind. A delegate of the specified type to represent the specified static method. - method overload, which allows you to create all combinations of open or closed delegates for instance or static methods. - + method overload, which allows you to create all combinations of open or closed delegates for instance or static methods. + > [!NOTE] -> This method overload should be used when the delegate is not closed over its first argument, because it is somewhat faster in that case. - +> This method overload should be used when the delegate is not closed over its first argument, because it is somewhat faster in that case. + > [!NOTE] -> Starting with the .NET Framework 2.0 Service Pack 1, this method can be used to access non-public methods if the caller has been granted with the flag and if the grant set of the non-public methods is restricted to the caller's grant set, or a subset thereof. (See [Security Considerations for Reflection](/dotnet/framework/reflection-and-codedom/security-considerations-for-reflection).) -> -> To use this functionality, your application should target the .NET Framework 3.5 or later. - -## Compatible Parameter Types and Return Type - The parameter types and return type of a delegate must be compatible with the parameter types and return type of the method the delegate represents; the types do not have to match exactly. - - A parameter of a delegate is compatible with the corresponding parameter of a method if the type of the delegate parameter is more restrictive than the type of the method parameter, because this guarantees that an argument passed to the delegate can be passed safely to the method. - - Similarly, the return type of a delegate is compatible with the return type of a method if the return type of the method is more restrictive than the return type of the delegate, because this guarantees that the return value of the method can be cast safely to the return type of the delegate. - - For example, a delegate with a parameter of type and a return type of can represent a method with a parameter of type and a return value of type . - - - -## Examples - This section contains two code examples. The first example demonstrates the two kinds of delegates that can be created with this method overload: open over an instance method and open over a static method. - - The second code example demonstrates compatible parameter types and return types. - - **Example 1** - - The following code example demonstrates the two ways a delegate can be created using this overload of the method. - +> Starting with the .NET Framework 2.0 Service Pack 1, this method can be used to access non-public methods if the caller has been granted with the flag and if the grant set of the non-public methods is restricted to the caller's grant set, or a subset thereof. (See [Security Considerations for Reflection](/dotnet/framework/reflection-and-codedom/security-considerations-for-reflection).) +> +> To use this functionality, your application should target the .NET Framework 3.5 or later. + +## Compatible Parameter Types and Return Type + The parameter types and return type of a delegate must be compatible with the parameter types and return type of the method the delegate represents; the types do not have to match exactly. + + A parameter of a delegate is compatible with the corresponding parameter of a method if the type of the delegate parameter is more restrictive than the type of the method parameter, because this guarantees that an argument passed to the delegate can be passed safely to the method. + + Similarly, the return type of a delegate is compatible with the return type of a method if the return type of the method is more restrictive than the return type of the delegate, because this guarantees that the return value of the method can be cast safely to the return type of the delegate. + + For example, a delegate with a parameter of type and a return type of can represent a method with a parameter of type and a return value of type . + + + +## Examples + This section contains two code examples. The first example demonstrates the two kinds of delegates that can be created with this method overload: open over an instance method and open over a static method. + + The second code example demonstrates compatible parameter types and return types. + + **Example 1** + + The following code example demonstrates the two ways a delegate can be created using this overload of the method. + > [!NOTE] -> There are two overloads of the method that specify a but not a first argument; their functionality is the same except that one allows you to specify whether to throw on failure to bind, and the other always throws. This code example uses both overloads. - - The example declares a class `C` with a static method `M2` and an instance method `M1`, and two delegate types: `D1` takes an instance of `C` and a string, and `D2` takes a string. - - A second class named `Example` contains the code that creates the delegates. - -- A delegate of type `D1`, representing an open instance method, is created for the instance method `M1`. An instance must be passed when the delegate is invoked. - -- A delegate of type `D2`, representing an open static method, is created for the static method `M2`. - +> There are two overloads of the method that specify a but not a first argument; their functionality is the same except that one allows you to specify whether to throw on failure to bind, and the other always throws. This code example uses both overloads. + + The example declares a class `C` with a static method `M2` and an instance method `M1`, and two delegate types: `D1` takes an instance of `C` and a string, and `D2` takes a string. + + A second class named `Example` contains the code that creates the delegates. + +- A delegate of type `D1`, representing an open instance method, is created for the instance method `M1`. An instance must be passed when the delegate is invoked. + +- A delegate of type `D2`, representing an open static method, is created for the static method `M2`. + :::code language="csharp" source="~/snippets/csharp/System/Delegate/CreateDelegate/openClosedOver.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Delegate/CreateDelegate/openClosedOver.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Delegate.CreateDelegateTOM/VB/openClosedOver.vb" id="Snippet1"::: - **Example 2** - - The following code example demonstrates compatibility of parameter types and return types. - + **Example 2** + + The following code example demonstrates compatibility of parameter types and return types. + > [!NOTE] -> This code example uses the method overload. The use of other overloads that take is similar. - - The code example defines a base class named `Base` and a class named `Derived` that derives from `Base`. The derived class has a `static` (`Shared` in Visual Basic) method named `MyMethod` with one parameter of type `Base` and a return type of `Derived`. The code example also defines a delegate named `Example` that has one parameter of type `Derived` and a return type of `Base`. - - The code example demonstrates that the delegate named `Example` can be used to represent the method `MyMethod`. The method can be bound to the delegate because: - -- The parameter type of the delegate (`Derived`) is more restrictive than the parameter type of `MyMethod` (`Base`), so that it is always safe to pass the argument of the delegate to `MyMethod`. - -- The return type of `MyMethod` (`Derived`) is more restrictive than the parameter type of the delegate (`Base`), so that it is always safe to cast the return type of the method to the return type of the delegate. - - The code example produces no output. - +> This code example uses the method overload. The use of other overloads that take is similar. + + The code example defines a base class named `Base` and a class named `Derived` that derives from `Base`. The derived class has a `static` (`Shared` in Visual Basic) method named `MyMethod` with one parameter of type `Base` and a return type of `Derived`. The code example also defines a delegate named `Example` that has one parameter of type `Derived` and a return type of `Base`. + + The code example demonstrates that the delegate named `Example` can be used to represent the method `MyMethod`. The method can be bound to the delegate because: + +- The parameter type of the delegate (`Derived`) is more restrictive than the parameter type of `MyMethod` (`Base`), so that it is always safe to pass the argument of the delegate to `MyMethod`. + +- The return type of `MyMethod` (`Derived`) is more restrictive than the parameter type of the delegate (`Base`), so that it is always safe to cast the return type of the method to the return type of the delegate. + + The code example produces no output. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Delegate.CreateDelegate_RelaxedFit/cpp/source.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Delegate/CreateDelegate/source1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Delegate/CreateDelegate/source1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Delegate.CreateDelegate_RelaxedFit/vb/source.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Delegate.CreateDelegate_RelaxedFit/vb/source.vb" id="Snippet1"::: + ]]> - is . - - -or- - - is . + is . + +-or- + + is . - does not inherit . - - -or- - - is not a . See [Runtime Types in Reflection](/previous-versions/dotnet/netframework-4.0/ms172329(v=vs.100)). - - -or- - - cannot be bound, and is . - - -or- - - is not a . See [Runtime Types in Reflection](/previous-versions/dotnet/netframework-4.0/ms172329(v=vs.100)). + does not inherit . + +-or- + + is not a . See [Runtime Types in Reflection](/previous-versions/dotnet/netframework-4.0/ms172329(v=vs.100)). + +-or- + + cannot be bound, and is . + +-or- + + is not a . See [Runtime Types in Reflection](/previous-versions/dotnet/netframework-4.0/ms172329(v=vs.100)). The method of is not found. The caller does not have the permissions necessary to access . @@ -1276,52 +1276,52 @@ Creates a delegate of the specified type that represents the specified static method of the specified class. A delegate of the specified type that represents the specified static method of the specified class. - method overload, specifying `false` for `ignoreCase` and `true` for `throwOnBindFailure`. - + method overload, specifying `false` for `ignoreCase` and `true` for `throwOnBindFailure`. + > [!NOTE] -> Starting with the .NET Framework 2.0 Service Pack 1, this method can be used to access non-public methods if the caller has been granted with the flag and if the grant set of the non-public methods is restricted to the caller's grant set, or a subset thereof. (See [Security Considerations for Reflection](/dotnet/framework/reflection-and-codedom/security-considerations-for-reflection).) -> -> To use this functionality, your application should target the .NET Framework 3.5 or later. - +> Starting with the .NET Framework 2.0 Service Pack 1, this method can be used to access non-public methods if the caller has been granted with the flag and if the grant set of the non-public methods is restricted to the caller's grant set, or a subset thereof. (See [Security Considerations for Reflection](/dotnet/framework/reflection-and-codedom/security-considerations-for-reflection).) +> +> To use this functionality, your application should target the .NET Framework 3.5 or later. + ]]> - is . - - -or- - - is . - - -or- - - is . + is . + +-or- + + is . + +-or- + + is . - does not inherit . - - -or- - - is not a . See [Runtime Types in Reflection](/previous-versions/dotnet/netframework-4.0/ms172329(v=vs.100)). - - -or- - - is not a . - - -or- - - is an open generic type. That is, its property is . - - -or- - - is not a method ( method in Visual Basic). - - -or- - - cannot be bound, for example because it cannot be found, and is . + does not inherit . + +-or- + + is not a . See [Runtime Types in Reflection](/previous-versions/dotnet/netframework-4.0/ms172329(v=vs.100)). + +-or- + + is not a . + +-or- + + is an open generic type. That is, its property is . + +-or- + + is not a method ( method in Visual Basic). + +-or- + + cannot be bound, for example because it cannot be found, and is . The method of is not found. The caller does not have the permissions necessary to access . @@ -1391,133 +1391,133 @@ Creates a delegate of the specified type that represents the specified static or instance method, with the specified first argument and the specified behavior on failure to bind. A delegate of the specified type that represents the specified static or instance method, or if is and the delegate cannot be bound to . - method overload, which always throws on failure to bind, provide the most flexible way to create delegates. You can use them to create delegates for either static or instance methods, with or without a first argument. - + method overload, which always throws on failure to bind, provide the most flexible way to create delegates. You can use them to create delegates for either static or instance methods, with or without a first argument. + > [!NOTE] -> If you do not supply a first argument, use the method overload for better performance. - - The delegate type and the method must have compatible return types. That is, the return type of `method` must be assignable to the return type of `type`. - - If `firstArgument` is supplied, it is passed to `method` every time the delegate is invoked; `firstArgument` is said to be bound to the delegate, and the delegate is said to be closed over its first argument. If `method` is `static` (`Shared` in Visual Basic), the argument list supplied when invoking the delegate includes all parameters except the first; if `method` is an instance method, then `firstArgument` is passed to the hidden instance parameter (represented by `this` in C#, or by `Me` in Visual Basic). - - If `firstArgument` is supplied, the first parameter of `method` must be a reference type, and `firstArgument` must be compatible with that type. - +> If you do not supply a first argument, use the method overload for better performance. + + The delegate type and the method must have compatible return types. That is, the return type of `method` must be assignable to the return type of `type`. + + If `firstArgument` is supplied, it is passed to `method` every time the delegate is invoked; `firstArgument` is said to be bound to the delegate, and the delegate is said to be closed over its first argument. If `method` is `static` (`Shared` in Visual Basic), the argument list supplied when invoking the delegate includes all parameters except the first; if `method` is an instance method, then `firstArgument` is passed to the hidden instance parameter (represented by `this` in C#, or by `Me` in Visual Basic). + + If `firstArgument` is supplied, the first parameter of `method` must be a reference type, and `firstArgument` must be compatible with that type. + > [!IMPORTANT] -> If `method` is `static` (`Shared` in Visual Basic) and its first parameter is of type or , then `firstArgument` can be a value type. In this case `firstArgument` is automatically boxed. Automatic boxing does not occur for any other arguments, as it would in a C# or Visual Basic function call. - - If `firstArgument` is a null reference and `method` is an instance method, the result depends on the signatures of the delegate type `type` and of `method`: - -- If the signature of `type` explicitly includes the hidden first parameter of `method`, the delegate is said to represent an open instance method. When the delegate is invoked, the first argument in the argument list is passed to the hidden instance parameter of `method`. - -- If the signatures of `method` and `type` match (that is, all parameter types are compatible), then the delegate is said to be closed over a null reference. Invoking the delegate is like calling an instance method on a null instance, which is not a particularly useful thing to do. - - If `firstArgument` is a null reference and `method` is static, the result depends on the signatures of the delegate type `type` and of `method`: - -- If the signature of `method` and `type` match (that is, all parameter types are compatible), the delegate is said to represent an open static method. This is the most common case for static methods. In this case, you can get slightly better performance by using the method overload. - -- If the signature of `type` begins with the second parameter of `method` and the rest of the parameter types are compatible, then the delegate is said to be closed over a null reference. When the delegate is invoked, a null reference is passed to the first parameter of `method`. - +> If `method` is `static` (`Shared` in Visual Basic) and its first parameter is of type or , then `firstArgument` can be a value type. In this case `firstArgument` is automatically boxed. Automatic boxing does not occur for any other arguments, as it would in a C# or Visual Basic function call. + + If `firstArgument` is a null reference and `method` is an instance method, the result depends on the signatures of the delegate type `type` and of `method`: + +- If the signature of `type` explicitly includes the hidden first parameter of `method`, the delegate is said to represent an open instance method. When the delegate is invoked, the first argument in the argument list is passed to the hidden instance parameter of `method`. + +- If the signatures of `method` and `type` match (that is, all parameter types are compatible), then the delegate is said to be closed over a null reference. Invoking the delegate is like calling an instance method on a null instance, which is not a particularly useful thing to do. + + If `firstArgument` is a null reference and `method` is static, the result depends on the signatures of the delegate type `type` and of `method`: + +- If the signature of `method` and `type` match (that is, all parameter types are compatible), the delegate is said to represent an open static method. This is the most common case for static methods. In this case, you can get slightly better performance by using the method overload. + +- If the signature of `type` begins with the second parameter of `method` and the rest of the parameter types are compatible, then the delegate is said to be closed over a null reference. When the delegate is invoked, a null reference is passed to the first parameter of `method`. + > [!NOTE] -> Starting with the .NET Framework 2.0 Service Pack 1, this method can be used to access non-public methods if the caller has been granted with the flag and if the grant set of the non-public methods is restricted to the caller's grant set, or a subset thereof. (See [Security Considerations for Reflection](/dotnet/framework/reflection-and-codedom/security-considerations-for-reflection).) -> -> To use this functionality, your application should target the .NET Framework 3.5 or later. - -## Compatible Parameter Types and Return Type - The parameter types and return type of a delegate must be compatible with the parameter types and return type of the method the delegate represents; the types do not have to match exactly. - - A parameter of a delegate is compatible with the corresponding parameter of a method if the type of the delegate parameter is more restrictive than the type of the method parameter, because this guarantees that an argument passed to the delegate can be passed safely to the method. - - Similarly, the return type of a delegate is compatible with the return type of a method if the return type of the method is more restrictive than the return type of the delegate, because this guarantees that the return value of the method can be cast safely to the return type of the delegate. - - For example, a delegate with a parameter of type and a return type of can represent a method with a parameter of type and a return value of type . - -## Determining the Methods a Delegate Can Represent - Another useful way to think of the flexibility provided by this overload of is that any given delegate can represent four different combinations of method signature and method kind (static versus instance). Consider a delegate type `D` with one argument of type `C`. The following describes the methods `D` can represent, ignoring the return type since it must match in all cases: - -- `D` can represent any instance method that has exactly one argument of type `C`, regardless of what type the instance method belongs to. When is called, `firstArgument` is an instance of the type `method` belongs to, and the resulting delegate is said to be closed over that instance. (Trivially, `D` can also be closed over a null reference if `firstArgument` is `null`.) - -- `D` can represent an instance method of `C` that has no arguments. When is called, `firstArgument` is a null reference. The resulting delegate represents an open instance method, and an instance of `C` must be supplied each time it is invoked. - -- `D` can represent a static method that takes one argument of type `C`, and that method can belong to any type. When is called, `firstArgument` is a null reference. The resulting delegate represents an open static method, and an instance of `C` must be supplied each time it is invoked. - -- `D` can represent a static method that belongs to type `F` and has two arguments, of type `F` and type `C`. When is called, `firstArgument` is an instance of `F`. The resulting delegate represents a static method that is closed over that instance of `F`. Note that in the case where `F` and `C` are the same type, the static method has two arguments of that type. (In this case, `D` is closed over a null reference if `firstArgument` is `null`.) - - - -## Examples - This section contains three code examples. The first example demonstrates the four kinds of delegates that can be created: closed over an instance method, open over an instance method, open over a static method, and closed over a static method. - - The second code example demonstrates compatible parameter types and return types. - - The third code example defines a single delegate type, and shows all the methods that delegate type can represent. - - **Example 1** - - The following code example demonstrates the four ways a delegate can be created using this overload of the method. - +> Starting with the .NET Framework 2.0 Service Pack 1, this method can be used to access non-public methods if the caller has been granted with the flag and if the grant set of the non-public methods is restricted to the caller's grant set, or a subset thereof. (See [Security Considerations for Reflection](/dotnet/framework/reflection-and-codedom/security-considerations-for-reflection).) +> +> To use this functionality, your application should target the .NET Framework 3.5 or later. + +## Compatible Parameter Types and Return Type + The parameter types and return type of a delegate must be compatible with the parameter types and return type of the method the delegate represents; the types do not have to match exactly. + + A parameter of a delegate is compatible with the corresponding parameter of a method if the type of the delegate parameter is more restrictive than the type of the method parameter, because this guarantees that an argument passed to the delegate can be passed safely to the method. + + Similarly, the return type of a delegate is compatible with the return type of a method if the return type of the method is more restrictive than the return type of the delegate, because this guarantees that the return value of the method can be cast safely to the return type of the delegate. + + For example, a delegate with a parameter of type and a return type of can represent a method with a parameter of type and a return value of type . + +## Determining the Methods a Delegate Can Represent + Another useful way to think of the flexibility provided by this overload of is that any given delegate can represent four different combinations of method signature and method kind (static versus instance). Consider a delegate type `D` with one argument of type `C`. The following describes the methods `D` can represent, ignoring the return type since it must match in all cases: + +- `D` can represent any instance method that has exactly one argument of type `C`, regardless of what type the instance method belongs to. When is called, `firstArgument` is an instance of the type `method` belongs to, and the resulting delegate is said to be closed over that instance. (Trivially, `D` can also be closed over a null reference if `firstArgument` is `null`.) + +- `D` can represent an instance method of `C` that has no arguments. When is called, `firstArgument` is a null reference. The resulting delegate represents an open instance method, and an instance of `C` must be supplied each time it is invoked. + +- `D` can represent a static method that takes one argument of type `C`, and that method can belong to any type. When is called, `firstArgument` is a null reference. The resulting delegate represents an open static method, and an instance of `C` must be supplied each time it is invoked. + +- `D` can represent a static method that belongs to type `F` and has two arguments, of type `F` and type `C`. When is called, `firstArgument` is an instance of `F`. The resulting delegate represents a static method that is closed over that instance of `F`. Note that in the case where `F` and `C` are the same type, the static method has two arguments of that type. (In this case, `D` is closed over a null reference if `firstArgument` is `null`.) + + + +## Examples + This section contains three code examples. The first example demonstrates the four kinds of delegates that can be created: closed over an instance method, open over an instance method, open over a static method, and closed over a static method. + + The second code example demonstrates compatible parameter types and return types. + + The third code example defines a single delegate type, and shows all the methods that delegate type can represent. + + **Example 1** + + The following code example demonstrates the four ways a delegate can be created using this overload of the method. + > [!NOTE] -> There are two overloads of the method that specify `firstArgument` and a ; their functionality is the same except that one allows you to specify whether to throw on failure to bind, and the other always throws. This code example uses both overloads. - - The example declares a class `C` with a static method `M2` and an instance method `M1`, and three delegate types: `D1` takes an instance of `C` and a string, `D2` takes a string, and `D3` has no arguments. - - A second class named `Example` contains the code that creates the delegates. - -- A delegate of type `D2`, closed over an instance of `C`, is created for the instance method `M1`. It is invoked with different strings, to show that the bound instance of `C` is always used. - -- A delegate of type `D1`, representing an open instance method, is created for the instance method `M1`. An instance must be passed when the delegate is invoked. - -- A delegate of type `D2`, representing an open static method, is created for the static method `M2`. - -- Finally, a delegate of type `D3`, closed over a string, is created for the static method `M2`. The method is invoked to show that it uses the bound string. - +> There are two overloads of the method that specify `firstArgument` and a ; their functionality is the same except that one allows you to specify whether to throw on failure to bind, and the other always throws. This code example uses both overloads. + + The example declares a class `C` with a static method `M2` and an instance method `M1`, and three delegate types: `D1` takes an instance of `C` and a string, `D2` takes a string, and `D3` has no arguments. + + A second class named `Example` contains the code that creates the delegates. + +- A delegate of type `D2`, closed over an instance of `C`, is created for the instance method `M1`. It is invoked with different strings, to show that the bound instance of `C` is always used. + +- A delegate of type `D1`, representing an open instance method, is created for the instance method `M1`. An instance must be passed when the delegate is invoked. + +- A delegate of type `D2`, representing an open static method, is created for the static method `M2`. + +- Finally, a delegate of type `D3`, closed over a string, is created for the static method `M2`. The method is invoked to show that it uses the bound string. + :::code language="csharp" source="~/snippets/csharp/System/Delegate/CreateDelegate/openClosedOver.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Delegate/CreateDelegate/openClosedOver.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Delegate.CreateDelegateTOM/VB/openClosedOver.vb" id="Snippet1"::: - **Example 2** - - The following code example demonstrates compatibility of parameter types and return types. - + **Example 2** + + The following code example demonstrates compatibility of parameter types and return types. + > [!NOTE] -> This code example uses the method overload. The use of other overloads that take is similar. - - The code example defines a base class named `Base` and a class named `Derived` that derives from `Base`. The derived class has a `static` (`Shared` in Visual Basic) method named `MyMethod` with one parameter of type `Base` and a return type of `Derived`. The code example also defines a delegate named `Example` that has one parameter of type `Derived` and a return type of `Base`. - - The code example demonstrates that the delegate named `Example` can be used to represent the method `MyMethod`. The method can be bound to the delegate because: - -- The parameter type of the delegate (`Derived`) is more restrictive than the parameter type of `MyMethod` (`Base`), so that it is always safe to pass the argument of the delegate to `MyMethod`. - -- The return type of `MyMethod` (`Derived`) is more restrictive than the parameter type of the delegate (`Base`), so that it is always safe to cast the return type of the method to the return type of the delegate. - - The code example produces no output. - +> This code example uses the method overload. The use of other overloads that take is similar. + + The code example defines a base class named `Base` and a class named `Derived` that derives from `Base`. The derived class has a `static` (`Shared` in Visual Basic) method named `MyMethod` with one parameter of type `Base` and a return type of `Derived`. The code example also defines a delegate named `Example` that has one parameter of type `Derived` and a return type of `Base`. + + The code example demonstrates that the delegate named `Example` can be used to represent the method `MyMethod`. The method can be bound to the delegate because: + +- The parameter type of the delegate (`Derived`) is more restrictive than the parameter type of `MyMethod` (`Base`), so that it is always safe to pass the argument of the delegate to `MyMethod`. + +- The return type of `MyMethod` (`Derived`) is more restrictive than the parameter type of the delegate (`Base`), so that it is always safe to cast the return type of the method to the return type of the delegate. + + The code example produces no output. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Delegate.CreateDelegate_RelaxedFit/cpp/source.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Delegate/CreateDelegate/source1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Delegate/CreateDelegate/source1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Delegate.CreateDelegate_RelaxedFit/vb/source.vb" id="Snippet1"::: - - **Example 3** - - The following code example shows all the methods a single delegate type can represent. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Delegate.CreateDelegate_RelaxedFit/vb/source.vb" id="Snippet1"::: + + **Example 3** + + The following code example shows all the methods a single delegate type can represent. + > [!NOTE] -> There are two overloads of the method that specify `firstArgument` and a ; their functionality is the same except that one allows you to specify whether to throw on failure to bind, and the other always throws. This code example uses both overloads. - - The code example defines two classes, `C` and `F`, and a delegate type `D` with one argument of type `C`. The classes have matching static and instance methods `M1`, `M3`, and `M4`, and class `C` also has an instance method `M2` that has no arguments. - - A third class named `Example` contains the code that creates the delegates. - -- Delegates are created for instance method `M1` of type `C` and type `F`; each is closed over an instance of the respective type. Method `M1` of type `C` displays the `ID` properties of the bound instance and of the argument. - -- A delegate is created for method `M2` of type `C`. This is an open instance delegate, in which the argument of the delegate represents the hidden first argument on the instance method. The method has no other arguments. - -- Delegates are created for static method `M3` of type `C` and type `F`; these are open static delegates. - -- Finally, delegates are created for static method `M4` of type `C` and type `F`; each method has the declaring type as its first argument, and an instance of the type is supplied, so the delegates are closed over their first arguments. Method `M4` of type `C` displays the `ID` properties of the bound instance and of the argument. - +> There are two overloads of the method that specify `firstArgument` and a ; their functionality is the same except that one allows you to specify whether to throw on failure to bind, and the other always throws. This code example uses both overloads. + + The code example defines two classes, `C` and `F`, and a delegate type `D` with one argument of type `C`. The classes have matching static and instance methods `M1`, `M3`, and `M4`, and class `C` also has an instance method `M2` that has no arguments. + + A third class named `Example` contains the code that creates the delegates. + +- Delegates are created for instance method `M1` of type `C` and type `F`; each is closed over an instance of the respective type. Method `M1` of type `C` displays the `ID` properties of the bound instance and of the argument. + +- A delegate is created for method `M2` of type `C`. This is an open instance delegate, in which the argument of the delegate represents the hidden first argument on the instance method. The method has no other arguments. + +- Delegates are created for static method `M3` of type `C` and type `F`; these are open static delegates. + +- Finally, delegates are created for static method `M4` of type `C` and type `F`; each method has the declaring type as its first argument, and an instance of the type is supplied, so the delegates are closed over their first arguments. Method `M4` of type `C` displays the `ID` properties of the bound instance and of the argument. + :::code language="csharp" source="~/snippets/csharp/System/Delegate/CreateDelegate/source.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Delegate/CreateDelegate/source.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Delegate.CreateDelegateTOM_2/vb/source.vb" id="Snippet1"::: @@ -1525,25 +1525,25 @@ ]]> - is . - - -or- - - is . + is . + +-or- + + is . - does not inherit . - - -or- - - is not a . See [Runtime Types in Reflection](/previous-versions/dotnet/netframework-4.0/ms172329(v=vs.100)). - - -or- - - cannot be bound, and is . - - -or- - - is not a . See [Runtime Types in Reflection](/previous-versions/dotnet/netframework-4.0/ms172329(v=vs.100)). + does not inherit . + +-or- + + is not a . See [Runtime Types in Reflection](/previous-versions/dotnet/netframework-4.0/ms172329(v=vs.100)). + +-or- + + cannot be bound, and is . + +-or- + + is not a . See [Runtime Types in Reflection](/previous-versions/dotnet/netframework-4.0/ms172329(v=vs.100)). The method of is not found. The caller does not have the permissions necessary to access . @@ -1605,44 +1605,44 @@ Creates a delegate of the specified type that represents the specified instance method to invoke on the specified class instance with the specified case-sensitivity. A delegate of the specified type that represents the specified instance method to invoke on the specified class instance. - method overload, specifying `true` for `throwOnBindFailure`. - + method overload, specifying `true` for `throwOnBindFailure`. + > [!NOTE] -> Starting with the .NET Framework 2.0 Service Pack 1, this method can be used to access non-public methods if the caller has been granted with the flag and if the grant set of the non-public methods is restricted to the caller's grant set, or a subset thereof. (See [Security Considerations for Reflection](/dotnet/framework/reflection-and-codedom/security-considerations-for-reflection).) -> -> To use this functionality, your application should target the .NET Framework 3.5 or later. - +> Starting with the .NET Framework 2.0 Service Pack 1, this method can be used to access non-public methods if the caller has been granted with the flag and if the grant set of the non-public methods is restricted to the caller's grant set, or a subset thereof. (See [Security Considerations for Reflection](/dotnet/framework/reflection-and-codedom/security-considerations-for-reflection).) +> +> To use this functionality, your application should target the .NET Framework 3.5 or later. + ]]> - is . - - -or- - - is . - - -or- - - is . + is . + +-or- + + is . + +-or- + + is . - does not inherit . - - -or- - - is not a . See [Runtime Types in Reflection](/previous-versions/dotnet/netframework-4.0/ms172329(v=vs.100)). - - -or- - - is not an instance method. - - -or- - - cannot be bound, for example because it cannot be found. + does not inherit . + +-or- + + is not a . See [Runtime Types in Reflection](/previous-versions/dotnet/netframework-4.0/ms172329(v=vs.100)). + +-or- + + is not an instance method. + +-or- + + cannot be bound, for example because it cannot be found. The method of is not found. The caller does not have the permissions necessary to access . @@ -1710,52 +1710,52 @@ Creates a delegate of the specified type that represents the specified static method of the specified class, with the specified case-sensitivity. A delegate of the specified type that represents the specified static method of the specified class. - method overload, specifying `true` for `throwOnBindFailure`. - + method overload, specifying `true` for `throwOnBindFailure`. + > [!NOTE] -> Starting with the .NET Framework 2.0 Service Pack 1, this method can be used to access non-public methods if the caller has been granted with the flag and if the grant set of the non-public methods is restricted to the caller's grant set, or a subset thereof. (See [Security Considerations for Reflection](/dotnet/framework/reflection-and-codedom/security-considerations-for-reflection).) -> -> To use this functionality, your application should target the .NET Framework 3.5 or later. - +> Starting with the .NET Framework 2.0 Service Pack 1, this method can be used to access non-public methods if the caller has been granted with the flag and if the grant set of the non-public methods is restricted to the caller's grant set, or a subset thereof. (See [Security Considerations for Reflection](/dotnet/framework/reflection-and-codedom/security-considerations-for-reflection).) +> +> To use this functionality, your application should target the .NET Framework 3.5 or later. + ]]> - is . - - -or- - - is . - - -or- - - is . + is . + +-or- + + is . + +-or- + + is . - does not inherit . - - -or- - - is not a . See [Runtime Types in Reflection](/previous-versions/dotnet/netframework-4.0/ms172329(v=vs.100)). - - -or- - - is not a . - - -or- - - is an open generic type. That is, its property is . - - -or- - - is not a method ( method in Visual Basic). - - -or- - - cannot be bound, for example because it cannot be found. + does not inherit . + +-or- + + is not a . See [Runtime Types in Reflection](/previous-versions/dotnet/netframework-4.0/ms172329(v=vs.100)). + +-or- + + is not a . + +-or- + + is an open generic type. That is, its property is . + +-or- + + is not a method ( method in Visual Basic). + +-or- + + cannot be bound, for example because it cannot be found. The method of is not found. The caller does not have the permissions necessary to access . @@ -1824,42 +1824,42 @@ Creates a delegate of the specified type that represents the specified instance method to invoke on the specified class instance, with the specified case-sensitivity and the specified behavior on failure to bind. A delegate of the specified type that represents the specified instance method to invoke on the specified class instance. - [!NOTE] -> Starting with the .NET Framework 2.0 Service Pack 1, this method can be used to access non-public methods if the caller has been granted with the flag and if the grant set of the non-public methods is restricted to the caller's grant set, or a subset thereof. (See [Security Considerations for Reflection](/dotnet/framework/reflection-and-codedom/security-considerations-for-reflection).) -> -> To use this functionality, your application should target the .NET Framework 3.5 or later. - +> Starting with the .NET Framework 2.0 Service Pack 1, this method can be used to access non-public methods if the caller has been granted with the flag and if the grant set of the non-public methods is restricted to the caller's grant set, or a subset thereof. (See [Security Considerations for Reflection](/dotnet/framework/reflection-and-codedom/security-considerations-for-reflection).) +> +> To use this functionality, your application should target the .NET Framework 3.5 or later. + ]]> - is . - - -or- - - is . - - -or- - - is . + is . + +-or- + + is . + +-or- + + is . - does not inherit . - - -or- - - is not a . See [Runtime Types in Reflection](/previous-versions/dotnet/netframework-4.0/ms172329(v=vs.100)). - - -or- - - is not an instance method. - - -or- - - cannot be bound, for example because it cannot be found, and is . + does not inherit . + +-or- + + is not a . See [Runtime Types in Reflection](/previous-versions/dotnet/netframework-4.0/ms172329(v=vs.100)). + +-or- + + is not an instance method. + +-or- + + cannot be bound, for example because it cannot be found, and is . The method of is not found. The caller does not have the permissions necessary to access . @@ -1935,50 +1935,50 @@ Creates a delegate of the specified type that represents the specified static method of the specified class, with the specified case-sensitivity and the specified behavior on failure to bind. A delegate of the specified type that represents the specified static method of the specified class. - [!NOTE] -> Starting with the .NET Framework 2.0 Service Pack 1, this method can be used to access non-public methods if the caller has been granted with the flag and if the grant set of the non-public methods is restricted to the caller's grant set, or a subset thereof. (See [Security Considerations for Reflection](/dotnet/framework/reflection-and-codedom/security-considerations-for-reflection).) -> -> To use this functionality, your application should target the .NET Framework 3.5 or later. - +> Starting with the .NET Framework 2.0 Service Pack 1, this method can be used to access non-public methods if the caller has been granted with the flag and if the grant set of the non-public methods is restricted to the caller's grant set, or a subset thereof. (See [Security Considerations for Reflection](/dotnet/framework/reflection-and-codedom/security-considerations-for-reflection).) +> +> To use this functionality, your application should target the .NET Framework 3.5 or later. + ]]> - is . - - -or- - - is . - - -or- - - is . + is . + +-or- + + is . + +-or- + + is . - does not inherit . - - -or- - - is not a . See [Runtime Types in Reflection](/previous-versions/dotnet/netframework-4.0/ms172329(v=vs.100)). - - -or- - - is not a . - - -or- - - is an open generic type. That is, its property is . - - -or- - - is not a method ( method in Visual Basic). - - -or- - - cannot be bound, for example because it cannot be found, and is . + does not inherit . + +-or- + + is not a . See [Runtime Types in Reflection](/previous-versions/dotnet/netframework-4.0/ms172329(v=vs.100)). + +-or- + + is not a . + +-or- + + is an open generic type. That is, its property is . + +-or- + + is not a method ( method in Visual Basic). + +-or- + + cannot be bound, for example because it cannot be found, and is . The method of is not found. The caller does not have the permissions necessary to access . @@ -2049,28 +2049,28 @@ - An array of objects that are the arguments to pass to the method represented by the current delegate. - - -or- - - , if the method represented by the current delegate does not require arguments. + An array of objects that are the arguments to pass to the method represented by the current delegate. + +-or- + +, if the method represented by the current delegate does not require arguments. Dynamically invokes (late-bound) the method represented by the current delegate. The object returned by the method represented by the delegate. - method. - + method. + ]]> The array does not have the correct number of arguments. The elements of the array do not match the signature of the delegate. - The method represented by the delegate is an instance method and the target object is . - - -or- - - One of the encapsulated methods throws an exception. + The method represented by the delegate is an instance method and the target object is . + +-or- + +One of the encapsulated methods throws an exception. The caller does not have access to the method represented by the delegate (for example, if the method is private). @@ -2128,28 +2128,28 @@ The number, order, or type of parameters listed in is i - An array of objects that are the arguments to pass to the method represented by the current delegate. - - -or- - - , if the method represented by the current delegate does not require arguments. + An array of objects that are the arguments to pass to the method represented by the current delegate. + +-or- + +, if the method represented by the current delegate does not require arguments. Dynamically invokes (late-bound) the method represented by the current delegate. The object returned by the method represented by the delegate. - method. - + method. + ]]> The array does not have the correct number of arguments. The elements of the array do not match the signature of the delegate. - The method represented by the delegate is an instance method and the target object is . - - -or- - - One of the encapsulated methods throws an exception. + The method represented by the delegate is an instance method and the target object is . + +-or- + +One of the encapsulated methods throws an exception. The caller does not have access to the method represented by the delegate (for example, if the method is private). @@ -2223,21 +2223,21 @@ The number, order, or type of parameters listed in is i if and the current delegate have the same targets, methods, and invocation list; otherwise, . - @@ -2286,11 +2286,11 @@ The number, order, or type of parameters listed in is i Returns a hash code for the delegate. A hash code for the delegate. - @@ -2338,22 +2338,22 @@ The number, order, or type of parameters listed in is i Returns the invocation list of the delegate. An array of delegates representing the invocation list of the current delegate. - method to get a total count of the methods assigned to the delegate, to execute the delegates in reverse order, and to execute the methods whose name do not include the substring "File". - + method to get a total count of the methods assigned to the delegate, to execute the delegates in reverse order, and to execute the methods whose name do not include the substring "File". + :::code language="csharp" source="~/snippets/csharp/System/Delegate/GetInvocationList/GetInvocationList1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/System.Delegate.GetInvocationList/fs/GetInvocationList1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.Delegate.GetInvocationList/vb/GetInvocationList1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.Delegate.GetInvocationList/vb/GetInvocationList1.vb" id="Snippet1"::: + ]]> @@ -2402,11 +2402,11 @@ The number, order, or type of parameters listed in is i Gets the method represented by the current delegate. A describing the method represented by the current delegate. - property. - + ]]> @@ -2586,23 +2586,23 @@ The number, order, or type of parameters listed in is i if is equal to ; otherwise, . - ]]> @@ -2663,23 +2663,23 @@ The number, order, or type of parameters listed in is i if is not equal to ; otherwise, . - ]]> @@ -2743,11 +2743,11 @@ The number, order, or type of parameters listed in is i Removes the last occurrence of the invocation list of a delegate from the invocation list of another delegate. A new delegate with an invocation list formed by taking the invocation list of and removing the last occurrence of the invocation list of , if the invocation list of is found within the invocation list of . Returns if is or if the invocation list of is not found within the invocation list of . Returns a null reference if the invocation list of is equal to the invocation list of or if is a null reference. - The delegate types do not match. @@ -2811,11 +2811,11 @@ The number, order, or type of parameters listed in is i Removes all occurrences of the invocation list of a delegate from the invocation list of another delegate. A new delegate with an invocation list formed by taking the invocation list of and removing all occurrences of the invocation list of , if the invocation list of is found within the invocation list of . Returns if is or if the invocation list of is not found within the invocation list of . Returns a null reference if the invocation list of is equal to the invocation list of , if contains only a series of invocation lists that are equal to the invocation list of , or if is a null reference. - The delegate types do not match. @@ -2867,11 +2867,11 @@ The number, order, or type of parameters listed in is i Removes the invocation list of a delegate from the invocation list of another delegate. A new delegate with an invocation list formed by taking the invocation list of the current delegate and removing the invocation list of , if the invocation list of is found within the current delegate's invocation list. Returns the current delegate if is or if the invocation list of is not found within the current delegate's invocation list. Returns if the invocation list of is equal to the current delegate's invocation list. - @@ -2931,13 +2931,13 @@ The number, order, or type of parameters listed in is i Gets the class instance on which the current delegate invokes the instance method. The object on which the current delegate invokes the instance method, if the delegate represents an instance method; if the delegate represents a static method. - diff --git a/xml/System/DivideByZeroException.xml b/xml/System/DivideByZeroException.xml index 292221dfa72..d9188227e51 100644 --- a/xml/System/DivideByZeroException.xml +++ b/xml/System/DivideByZeroException.xml @@ -64,38 +64,38 @@ The exception that is thrown when there is an attempt to divide an integral or value by zero. - number by zero throws a exception. To prevent the exception, ensure that the denominator in a division operation with integer or values is non-zero. - - Dividing a floating-point value by zero doesn't throw an exception; it results in positive infinity, negative infinity, or not a number (NaN), according to the rules of IEEE 754 arithmetic. Because the following example uses floating-point division rather than integer division, the operation does not throw a exception. - + number by zero throws a exception. To prevent the exception, ensure that the denominator in a division operation with integer or values is non-zero. + + Dividing a floating-point value by zero doesn't throw an exception; it results in positive infinity, negative infinity, or not a number (NaN), according to the rules of IEEE 754 arithmetic. Because the following example uses floating-point division rather than integer division, the operation does not throw a exception. + :::code language="csharp" source="~/snippets/csharp/System/DivideByZeroException/Overview/exception2.cs" interactive="try-dotnet" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.dividebyzeroexception.class/fs/exception2.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.dividebyzeroexception.class/vb/exception2.vb" id="Snippet2"::: - For more information, see and . - - The following Microsoft intermediate language (MSIL) instructions throw : - -- div - -- div.un - -- rem - -- rem.un - - uses the HRESULT COR_E_DIVIDEBYZERO, which has the value 0x80020012. - - For a list of initial property values for an instance of , see the constructors. - - - -## Examples - The following example handles a exception in integer division. - + For more information, see and . + + The following Microsoft intermediate language (MSIL) instructions throw : + +- div + +- div.un + +- rem + +- rem.un + + uses the HRESULT COR_E_DIVIDEBYZERO, which has the value 0x80020012. + + For a list of initial property values for an instance of , see the constructors. + + + +## Examples + The following example handles a exception in integer division. + :::code language="csharp" source="~/snippets/csharp/System/DivideByZeroException/Overview/exception1.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.dividebyzeroexception.class/fs/exception1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.dividebyzeroexception.class/vb/exception1.vb" id="Snippet1"::: @@ -156,18 +156,18 @@ Initializes a new instance of the class. - property of the new instance to a system-supplied message that describes the error, such as "Attempted to divide by zero." This message takes into account the current system culture. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The localized error message string.| - + property of the new instance to a system-supplied message that describes the error, such as "Attempted to divide by zero." This message takes into account the current system culture. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The localized error message string.| + ]]> @@ -214,18 +214,18 @@ A that describes the error. Initializes a new instance of the class with a specified error message. - . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The error message string.| - + . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The error message string.| + ]]> @@ -287,11 +287,11 @@ The contextual information about the source or destination. Initializes a new instance of the class with serialized data. - @@ -340,18 +340,18 @@ The exception that is the cause of the current exception. If the parameter is not , the current exception is raised in a block that handles the inner exception. Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception. - property. The property returns the same value that is passed into the constructor, or `null` if the property does not supply the inner exception value to the constructor. - - The following table shows the initial property values for an instance of . - -|Property Type|Condition| -|-------------------|---------------| -||The inner exception reference.| -||The error message string.| - + property. The property returns the same value that is passed into the constructor, or `null` if the property does not supply the inner exception value to the constructor. + + The following table shows the initial property values for an instance of . + +|Property Type|Condition| +|-------------------|---------------| +||The inner exception reference.| +||The error message string.| + ]]> diff --git a/xml/System/DllNotFoundException.xml b/xml/System/DllNotFoundException.xml index 3d1ee851fdb..9524cf4fa5c 100644 --- a/xml/System/DllNotFoundException.xml +++ b/xml/System/DllNotFoundException.xml @@ -65,17 +65,17 @@ The exception that is thrown when a DLL specified in a DLL import cannot be found. - uses the HRESULT COR_E_DLLNOTFOUND, which has the value 0x80131524. - - For a list of initial property values for an instance of , see the constructors. - - The is thrown when a dynamic link library defined by the attribute or a comparable language construct, such as the Visual Basic `Declare` statement, cannot be found. It is not thrown when the common language runtime is unable to load a .NET Framework assembly. - - Note that the can specify the path to the directory in which the DLL resides. If a path is not specified, Windows uses the search order described in [Dynamic-Link Library Search Order](https://go.microsoft.com/fwlink/?LinkId=122531). - + uses the HRESULT COR_E_DLLNOTFOUND, which has the value 0x80131524. + + For a list of initial property values for an instance of , see the constructors. + + The is thrown when a dynamic link library defined by the attribute or a comparable language construct, such as the Visual Basic `Declare` statement, cannot be found. It is not thrown when the common language runtime is unable to load a .NET Framework assembly. + + Note that the can specify the path to the directory in which the DLL resides. If a path is not specified, Windows uses the search order described in [Dynamic-Link Library Search Order](https://go.microsoft.com/fwlink/?LinkId=122531). + ]]> @@ -134,16 +134,16 @@ Initializes a new instance of the class with default properties. - . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The localized error message string.| - + . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The localized error message string.| + ]]> @@ -191,16 +191,16 @@ The error message that explains the reason for the exception. Initializes a new instance of the class with a specified error message. - . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The error message string.| - + . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The error message string.| + ]]> @@ -309,18 +309,18 @@ The exception that is the cause of the current exception. If the parameter is not , the current exception is raised in a block that handles the inner exception. Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception. - property. The property returns the same value that is passed into the constructor, or `null` if the property does not supply the inner exception value to the constructor. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||The inner exception reference.| -||The error message string.| - + property. The property returns the same value that is passed into the constructor, or `null` if the property does not supply the inner exception value to the constructor. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||The inner exception reference.| +||The error message string.| + ]]> diff --git a/xml/System/Double.xml b/xml/System/Double.xml index 8f57704dec5..2e1f6370ec0 100644 --- a/xml/System/Double.xml +++ b/xml/System/Double.xml @@ -1284,25 +1284,34 @@ This computes `arctan(x) / π` in the interval `[-0.5, +0.5]`. A double-precision floating-point number to compare. Compares this instance to a specified double-precision floating-point number and returns an integer that indicates whether the value of this instance is less than, equal to, or greater than the value of the specified double-precision floating-point number. - A signed number indicating the relative values of this instance and . - - Return Value - - Description - - Less than zero - - This instance is less than , or this instance is not a number () and is a number. - - Zero - - This instance is equal to , or both this instance and are not a number (), , or . - - Greater than zero - - This instance is greater than , or this instance is a number and is not a number (). - - + A signed number indicating the relative values of this instance and . + + Return Value + + + Description + + + + + Less than zero + + + This instance is less than , or this instance is not a number () and is a number. + + + Zero + + + This instance is equal to , or both this instance and are not a number (), , or . + + + Greater than zero + + + This instance is greater than , or this instance is a number and is not a number (). + + An object to compare, or . Compares this instance to a specified object and returns an integer that indicates whether the value of this instance is less than, equal to, or greater than the value of the specified object. - A signed number indicating the relative values of this instance and . - - Value - - Description - - A negative integer - - This instance is less than , or this instance is not a number () and is a number. - - Zero - - This instance is equal to , or this instance and are both , , or A positive integer - - This instance is greater than , OR this instance is a number and is not a number (), OR is . + A signed number indicating the relative values of this instance and . + + Value + + + Description + + + + + A negative integer + + + This instance is less than , or this instance is not a number () and is a number. + + + Zero + + + This instance is equal to , or this instance and are both , , or + + + A positive integer + + + This instance is greater than , OR this instance is a number and is not a number (), OR is . + + - 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 a is defined and the argument is not typed as an , compilers may perform an implicit conversion and call the method. Otherwise, they call the method, which always returns if its argument is not a value. The following example illustrates the difference in behavior between the two method overloads. In the case of all primitive numeric types except for and in C#, 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 language="csharp" source="~/snippets/csharp/System/Double/Equals/equalsoverl.cs" interactive="try-dotnet" id="Snippet2"::: - :::code language="fsharp" source="~/snippets/fsharp/System/Double/Equals/equalsoverl.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.double.equals/vb/equalsoverl.vb" id="Snippet2"::: + 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 a is defined and the argument is not typed as an , compilers may perform an implicit conversion and call the method. Otherwise, they call the method, which always returns if its argument is not a value. The following example illustrates the difference in behavior between the two method overloads. In the case of all primitive numeric types except for and in C#, 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 language="csharp" source="~/snippets/csharp/System/Double/Equals/equalsoverl.cs" interactive="try-dotnet" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/Double/Equals/equalsoverl.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.double.equals/vb/equalsoverl.vb" id="Snippet2"::: @@ -2107,11 +2125,7 @@ Euler's number is approximately 2.7182818284590452354. ]]> - 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 a is defined and the argument is not typed as an , compilers may perform an implicit conversion and call the method. Otherwise, they call the method, which always returns if its argument is not a value. The following example illustrates the difference in behavior between the two method overloads. In the case of all primitive numeric types except for and in C#, 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 language="csharp" source="~/snippets/csharp/System/Double/Equals/equalsoverl.cs" interactive="try-dotnet" id="Snippet2"::: - :::code language="fsharp" source="~/snippets/fsharp/System/Double/Equals/equalsoverl.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.double.equals/vb/equalsoverl.vb" id="Snippet2"::: + 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 a is defined and the argument is not typed as an , compilers may perform an implicit conversion and call the method. Otherwise, they call the method, which always returns if its argument is not a value. The following example illustrates the difference in behavior between the two method overloads. In the case of all primitive numeric types except for and in C#, 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 language="csharp" source="~/snippets/csharp/System/Double/Equals/equalsoverl.cs" interactive="try-dotnet" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/Double/Equals/equalsoverl.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.double.equals/vb/equalsoverl.vb" id="Snippet2"::: @@ -2185,7 +2199,9 @@ Euler's number is approximately 2.7182818284590452354. The power to which 10 is raised. Computes 10 raised to a given power. - 10 + 10 + + To be added. @@ -2223,7 +2239,9 @@ Euler's number is approximately 2.7182818284590452354. The power to which 10 is raised. Computes 10 raised to a given power and subtracts one. - 10 - 1 + 10 + + - 1 To be added. @@ -2261,7 +2279,9 @@ Euler's number is approximately 2.7182818284590452354. The power to which 2 is raised. Computes 2 raised to a given power. - 2 + 2 + + To be added. @@ -2299,7 +2319,9 @@ Euler's number is approximately 2.7182818284590452354. The power to which 2 is raised. Computes 2 raised to a given power and subtracts one. - 2 - 1 + 2 + + - 1 To be added. @@ -2337,7 +2359,9 @@ Euler's number is approximately 2.7182818284590452354. The power to which E is raised. Computes E raised to a given power and subtracts one. - E - 1 + E + + - 1 To be added. @@ -4833,8 +4857,7 @@ If a separator is encountered in the `s` parameter during a parse operation, and is . does not represent a number in a valid format. - - .NET Framework and .NET Core 2.2 and earlier versions only: represents a number that is less than Double.MinValue or greater than Double.MaxValue. + .NET Framework and .NET Core 2.2 and earlier versions only: represents a number that is less than Double.MinValue or greater than Double.MaxValue. Parsing Numeric Strings in .NET @@ -5060,14 +5083,13 @@ If a separator is encountered in the `s` parameter during a parse operation, and is . does not represent a number in a valid format. - - .NET Framework and .NET Core 2.2 and earlier versions only: represents a number that is less than Double.MinValue or greater than Double.MaxValue. + .NET Framework and .NET Core 2.2 and earlier versions only: represents a number that is less than Double.MinValue or greater than Double.MaxValue. is not a value. - -or- +-or- - includes the value. + includes the value. Parsing Numeric Strings in .NET @@ -5189,8 +5211,7 @@ If a separator is encountered in the `s` parameter during a parse operation, and is . does not represent a number in a valid format. - - .NET Framework and .NET Core 2.2 and earlier versions only: represents a number that is less than Double.MinValue or greater than Double.MaxValue. + .NET Framework and .NET Core 2.2 and earlier versions only: represents a number that is less than Double.MinValue or greater than Double.MaxValue. Parsing Numeric Strings in .NET @@ -5285,7 +5306,7 @@ If a separator is encountered in the `s` parameter during a parse operation, and A character span that contains the number to convert. - A bitwise combination of enumeration values that indicate the style elements that can be present in . A typical value to specify is combined with . + A bitwise combination of enumeration values that indicate the style elements that can be present in . A typical value to specify is combined with . An object that supplies culture-specific formatting information about . Converts a character span that contains the string representation of a number in a specified style and culture-specific format to its double-precision floating-point number equivalent. A double-precision floating-point number that is equivalent to the numeric value or symbol specified in . @@ -5303,9 +5324,9 @@ If `s` is out of range of the data type, the method returns is not a value. - -or- +-or- - is the value. + is the value. @@ -5456,11 +5477,10 @@ If a separator is encountered in the `s` parameter during a parse operation, and is not a value. - -or- +-or- - is the value. - - .NET Framework and .NET Core 2.2 and earlier versions only: represents a number that is less than Double.MinValue or greater than Double.MaxValue. + is the value. + .NET Framework and .NET Core 2.2 and earlier versions only: represents a number that is less than Double.MinValue or greater than Double.MaxValue. Parsing Numeric Strings in .NET @@ -9416,11 +9436,7 @@ Tau is approximately 6.2831853071795864769. is invalid. - In some cases, values formatted with the "R" standard numeric format string do not successfully round-trip if compiled using the or switches and run on 64-bit systems. To work around this problem, you can format values by using the "G17" standard numeric format string. The following example uses the "R" format string with a value that does not round-trip successfully, and also uses the "G17" format string to successfully round-trip the original value. - - :::code language="csharp" source="~/snippets/csharp/System/Double/ToString/roundtripex2.cs" interactive="try-dotnet" id="Snippet6"::: - :::code language="fsharp" source="~/snippets/fsharp/System/Double/ToString/roundtripex2.fs" id="Snippet6"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Double.ToString/vb/roundtripex2.vb" id="Snippet6"::: + In some cases, values formatted with the "R" standard numeric format string do not successfully round-trip if compiled using the or switches and run on 64-bit systems. To work around this problem, you can format values by using the "G17" standard numeric format string. The following example uses the "R" format string with a value that does not round-trip successfully, and also uses the "G17" format string to successfully round-trip the original value. :::code language="csharp" source="~/snippets/csharp/System/Double/ToString/roundtripex2.cs" interactive="try-dotnet" id="Snippet6"::: :::code language="fsharp" source="~/snippets/fsharp/System/Double/ToString/roundtripex2.fs" id="Snippet6"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Double.ToString/vb/roundtripex2.vb" id="Snippet6"::: Formatting Types in .NET @@ -9542,11 +9558,7 @@ Tau is approximately 6.2831853071795864769. ]]> - In some cases, values formatted with the "R" standard numeric format string do not successfully round-trip if compiled using the or switches and run on 64-bit systems. To work around this problem, you can format values by using the "G17" standard numeric format string. The following example uses the "R" format string with a value that does not round-trip successfully, and also uses the "G17" format string to successfully round-trip the original value. - - :::code language="csharp" source="~/snippets/csharp/System/Double/ToString/roundtripex1.cs" interactive="try-dotnet" id="Snippet5"::: - :::code language="fsharp" source="~/snippets/fsharp/System/Double/ToString/roundtripex1.fs" id="Snippet5"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Double.ToString/vb/roundtripex1.vb" id="Snippet5"::: + In some cases, values formatted with the "R" standard numeric format string do not successfully round-trip if compiled using the or switches and run on 64-bit systems. To work around this problem, you can format values by using the "G17" standard numeric format string. The following example uses the "R" format string with a value that does not round-trip successfully, and also uses the "G17" format string to successfully round-trip the original value. :::code language="csharp" source="~/snippets/csharp/System/Double/ToString/roundtripex1.cs" interactive="try-dotnet" id="Snippet5"::: :::code language="fsharp" source="~/snippets/fsharp/System/Double/ToString/roundtripex1.fs" id="Snippet5"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Double.ToString/vb/roundtripex1.vb" id="Snippet5"::: Formatting Types in .NET @@ -10313,9 +10325,9 @@ On .NET Core 3.0 and later versions, no exception is thrown when `s` is out of r is not a value. - -or- +-or- - includes the value. + includes the value. Parsing Numeric Strings in .NET diff --git a/xml/System/DuplicateWaitObjectException.xml b/xml/System/DuplicateWaitObjectException.xml index 3d1b912b40c..b6554cb0b8b 100644 --- a/xml/System/DuplicateWaitObjectException.xml +++ b/xml/System/DuplicateWaitObjectException.xml @@ -65,18 +65,18 @@ The exception that is thrown when an object appears more than once in an array of synchronization objects. - objects. If the array of objects passed to or contains any duplicate operating system handles, is thrown. For more information, see . - - uses the HRESULT COR_E_DUPLICATEWAITOBJECT, which has the value 0x80131529. - - For a list of initial property values for an instance of , see the constructors. - + objects. If the array of objects passed to or contains any duplicate operating system handles, is thrown. For more information, see . + + uses the HRESULT COR_E_DUPLICATEWAITOBJECT, which has the value 0x80131529. + + For a list of initial property values for an instance of , see the constructors. + > [!NOTE] -> This exception is not included in [.NET for Windows Store apps](https://go.microsoft.com/fwlink/?LinkID=247912) or the [Portable Class Library](/dotnet/standard/cross-platform/cross-platform-development-with-the-portable-class-library), but it is thrown by some members that are. To catch the exception in that case, write a `catch` statement for instead. - +> This exception is not included in [.NET for Windows Store apps](https://go.microsoft.com/fwlink/?LinkID=247912) or the [Portable Class Library](/dotnet/standard/cross-platform/cross-platform-development-with-the-portable-class-library), but it is thrown by some members that are. To catch the exception in that case, write a `catch` statement for instead. + ]]> @@ -128,18 +128,18 @@ Initializes a new instance of the class. - property of the new instance to a system-supplied message that describes the error, such as "Duplicate objects in argument." This message takes into account the current system culture. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The localized error message string.| - + property of the new instance to a system-supplied message that describes the error, such as "Duplicate objects in argument." This message takes into account the current system culture. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The localized error message string.| + ]]> @@ -182,19 +182,19 @@ The name of the parameter that caused the exception. Initializes a new instance of the class with the name of the parameter that causes this exception. - . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The localized error message string.| -||The parameter name string.| - + . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The localized error message string.| +||The parameter name string.| + ]]> @@ -256,11 +256,11 @@ The contextual information about the source or destination. Initializes a new instance of the class with serialized data. - XML and SOAP Serialization @@ -305,18 +305,18 @@ The exception that is the cause of the current exception. If the parameter is not , the current exception is raised in a block that handles the inner exception. Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception. - property. The property returns the same value that is passed to this constructor. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||The exception specified by `innerException`.| -||The error message string specified by `message`.| - + property. The property returns the same value that is passed to this constructor. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||The exception specified by `innerException`.| +||The error message string specified by `message`.| + ]]> @@ -361,21 +361,21 @@ The message that describes the error. Initializes a new instance of the class with a specified error message and the name of the parameter that causes this exception. - property. The property returns the same value that is passed into the constructor, or a null reference (`Nothing` in Visual Basic) if the property does not supply the inner exception value to the constructor. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic)| -||The error message string.| -||The parameter name string.| - + property. The property returns the same value that is passed into the constructor, or a null reference (`Nothing` in Visual Basic) if the property does not supply the inner exception value to the constructor. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic)| +||The error message string.| +||The parameter name string.| + ]]> diff --git a/xml/System/EntryPointNotFoundException.xml b/xml/System/EntryPointNotFoundException.xml index d8fb9ef3f68..2902e22bc78 100644 --- a/xml/System/EntryPointNotFoundException.xml +++ b/xml/System/EntryPointNotFoundException.xml @@ -59,65 +59,65 @@ The exception that is thrown when an attempt to load a class fails due to the absence of an entry method. - exception is thrown when the common language runtime is unable to load an assembly because it cannot identify the assembly's entry point. This exception can be thrown under the following conditions: - -- The common language runtime is unable to locate an application entry point (typically a `Main` method) in an executable assembly. The application entry point must be a global or `static` method that has either no parameters or a string array as its only parameter. The entry point can return `void`, or it can return an or exit code. An application assembly cannot define more than one entry point. - -- The call to a function in a Windows DLL cannot be resolved because the function cannot be found. In the following example, an exception is thrown because User32.dll does not include a function named `GetMyNumber`. - + exception is thrown when the common language runtime is unable to load an assembly because it cannot identify the assembly's entry point. This exception can be thrown under the following conditions: + +- The common language runtime is unable to locate an application entry point (typically a `Main` method) in an executable assembly. The application entry point must be a global or `static` method that has either no parameters or a string array as its only parameter. The entry point can return `void`, or it can return an or exit code. An application assembly cannot define more than one entry point. + +- The call to a function in a Windows DLL cannot be resolved because the function cannot be found. In the following example, an exception is thrown because User32.dll does not include a function named `GetMyNumber`. + :::code language="csharp" source="~/snippets/csharp/System/EntryPointNotFoundException/Overview/nofunction1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/EntryPointNotFoundException/Overview/nofunction1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.entrypointnotfoundexception.class/vb/nofunction1.vb" id="Snippet1"::: - -- The call to a function in a Windows DLL cannot be resolved because the name used in the method call does not match a name found in the assembly. Frequently, this occurs because the field is either implicitly or explicitly set to `true`, the called method includes one or more string parameters and has both an ANSI and a Unicode version, and the name used in the method call does not correspond to the name of this ANSI or Unicode version. The following example provides an illustration by attempting to call the Windows `MessageBox` function in User32.dll. Because the first method definition specifies for string marshaling, the common language looks for the wide-character version of the function, `MessageBoxW`, instead of the name used in the method call, `MessageBox`. The second method definition corrects this problem by calling the `MessageBoxW` instead of the `MessageBox` function. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.entrypointnotfoundexception.class/vb/nofunction1.vb" id="Snippet1"::: + +- The call to a function in a Windows DLL cannot be resolved because the name used in the method call does not match a name found in the assembly. Frequently, this occurs because the field is either implicitly or explicitly set to `true`, the called method includes one or more string parameters and has both an ANSI and a Unicode version, and the name used in the method call does not correspond to the name of this ANSI or Unicode version. The following example provides an illustration by attempting to call the Windows `MessageBox` function in User32.dll. Because the first method definition specifies for string marshaling, the common language looks for the wide-character version of the function, `MessageBoxW`, instead of the name used in the method call, `MessageBox`. The second method definition corrects this problem by calling the `MessageBoxW` instead of the `MessageBox` function. + :::code language="csharp" source="~/snippets/csharp/System/EntryPointNotFoundException/Overview/badcall1.cs" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/EntryPointNotFoundException/Overview/badcall1.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.entrypointnotfoundexception.class/vb/badcall1.vb" id="Snippet2"::: - -- You are trying to call a function in a dynamic link library by its simple name rather than its decorated name. Typically, the C++ compiler generates a decorated name for DLL functions. For example, the following C++ code defines a function named `Double` in a library named TestDll.dll. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.entrypointnotfoundexception.class/cpp/testdll.cpp" id="Snippet6"::: - - When the code in the following example tries to call the function, an exception is thrown because the `Double` function cannot be found. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.entrypointnotfoundexception.class/vb/badcall1.vb" id="Snippet2"::: + +- You are trying to call a function in a dynamic link library by its simple name rather than its decorated name. Typically, the C++ compiler generates a decorated name for DLL functions. For example, the following C++ code defines a function named `Double` in a library named TestDll.dll. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.entrypointnotfoundexception.class/cpp/testdll.cpp" id="Snippet6"::: + + When the code in the following example tries to call the function, an exception is thrown because the `Double` function cannot be found. + :::code language="csharp" source="~/snippets/csharp/System/EntryPointNotFoundException/Overview/mangle1.cs" id="Snippet7"::: :::code language="fsharp" source="~/snippets/fsharp/System/EntryPointNotFoundException/Overview/mangle1.fs" id="Snippet7"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.entrypointnotfoundexception.class/vb/mangle1.vb" id="Snippet7"::: - - However, if the function is called by using its decorated name (in this case, `?Double@@YAHH@Z`), the function call succeeds, as the following example shows. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.entrypointnotfoundexception.class/vb/mangle1.vb" id="Snippet7"::: + + However, if the function is called by using its decorated name (in this case, `?Double@@YAHH@Z`), the function call succeeds, as the following example shows. + :::code language="csharp" source="~/snippets/csharp/System/EntryPointNotFoundException/Overview/mangle2.cs" id="Snippet8"::: :::code language="fsharp" source="~/snippets/fsharp/System/EntryPointNotFoundException/Overview/mangle2.fs" id="Snippet8"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.entrypointnotfoundexception.class/vb/mangle2.vb" id="Snippet8"::: - - You can find the decorated names of functions exported by a DLL by using a utility such as Dumpbin.exe. - -- You are attempting to call a method in a managed assembly as if it were an unmanaged dynamic link library. To see this in action, compile the following example to an assembly named StringUtilities.dll. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.entrypointnotfoundexception.class/vb/mangle2.vb" id="Snippet8"::: + + You can find the decorated names of functions exported by a DLL by using a utility such as Dumpbin.exe. + +- You are attempting to call a method in a managed assembly as if it were an unmanaged dynamic link library. To see this in action, compile the following example to an assembly named StringUtilities.dll. + :::code language="csharp" source="~/snippets/csharp/System/EntryPointNotFoundException/Overview/stringutilities.cs" id="Snippet3"::: :::code language="fsharp" source="~/snippets/fsharp/System/EntryPointNotFoundException/Overview/stringutilities.fs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.entrypointnotfoundexception.class/vb/stringutilities.vb" id="Snippet3"::: - - Then compile and execute the following example, which attempts to call the `StringUtilities.SayGoodMorning` method in the StringUtilities.dll dynamic link library as if it were unmanaged code. The result is an exception. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.entrypointnotfoundexception.class/vb/stringutilities.vb" id="Snippet3"::: + + Then compile and execute the following example, which attempts to call the `StringUtilities.SayGoodMorning` method in the StringUtilities.dll dynamic link library as if it were unmanaged code. The result is an exception. + :::code language="csharp" source="~/snippets/csharp/System/EntryPointNotFoundException/Overview/importassembly1.cs" id="Snippet4"::: :::code language="fsharp" source="~/snippets/fsharp/System/EntryPointNotFoundException/Overview/importassembly1.fs" id="Snippet4"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.entrypointnotfoundexception.class/vb/importassembly1.vb" id="Snippet4"::: - - To eliminate the exception, add a reference to the managed assembly and access the `StringUtilities.SayGoodMorning` method just as you would access any other method in managed code, as the following example does. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.entrypointnotfoundexception.class/vb/importassembly1.vb" id="Snippet4"::: + + To eliminate the exception, add a reference to the managed assembly and access the `StringUtilities.SayGoodMorning` method just as you would access any other method in managed code, as the following example does. + :::code language="csharp" source="~/snippets/csharp/System/EntryPointNotFoundException/Overview/fiximportassembly1.cs" id="Snippet5"::: :::code language="fsharp" source="~/snippets/fsharp/System/EntryPointNotFoundException/Overview/fiximportassembly1.fs" id="Snippet5"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.entrypointnotfoundexception.class/vb/fiximportassembly1.vb" id="Snippet5"::: - -- You are trying to call a method in a COM DLL as if it were a Windows DLL. To access a COM DLL, select the **Add Reference** option in Visual Studio to add a reference to the project, and then select the type library from the **COM** tab. - - For a list of initial property values for an instance of , see the constructors. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.entrypointnotfoundexception.class/vb/fiximportassembly1.vb" id="Snippet5"::: + +- You are trying to call a method in a COM DLL as if it were a Windows DLL. To access a COM DLL, select the **Add Reference** option in Visual Studio to add a reference to the project, and then select the type library from the **COM** tab. + + For a list of initial property values for an instance of , see the constructors. + ]]> @@ -167,18 +167,18 @@ Initializes a new instance of the class. - property of the new instance to a system-supplied message that describes the error, such as "Entry point was not found." This message takes into account the current system culture. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The localized error message string.| - + property of the new instance to a system-supplied message that describes the error, such as "Entry point was not found." This message takes into account the current system culture. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The localized error message string.| + ]]> @@ -221,18 +221,18 @@ The error message that explains the reason for the exception. Initializes a new instance of the class with a specified error message. - . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The error message string.| - + . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The error message string.| + ]]> @@ -294,11 +294,11 @@ The contextual information about the source or destination. Initializes a new instance of the class with serialized data. - @@ -343,18 +343,18 @@ The exception that is the cause of the current exception. If the parameter is not a null reference ( in Visual Basic), the current exception is raised in a block that handles the inner exception. Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception. - property. The property returns the same value that is passed into the constructor, or a null reference (`Nothing` in Visual Basic) if the property does not supply the inner exception value to the constructor. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||The inner exception reference.| -||The error message string.| - + property. The property returns the same value that is passed into the constructor, or a null reference (`Nothing` in Visual Basic) if the property does not supply the inner exception value to the constructor. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||The inner exception reference.| +||The error message string.| + ]]> diff --git a/xml/System/Enum.xml b/xml/System/Enum.xml index 161160454b1..df1a37ffbb5 100644 --- a/xml/System/Enum.xml +++ b/xml/System/Enum.xml @@ -392,23 +392,34 @@ An object to compare, or . Compares this instance to a specified object and returns an indication of their relative values. - A signed number that indicates the relative values of this instance and . - - Value - - Meaning - - Less than zero - - The value of this instance is less than the value of . - - Zero - - The value of this instance is equal to the value of . - - Greater than zero - - The value of this instance is greater than the value of , or is . + A signed number that indicates the relative values of this instance and . + + Value + + + Meaning + + + + + Less than zero + + + The value of this instance is less than the value of . + + + Zero + + + The value of this instance is equal to the value of . + + + Greater than zero + + + The value of this instance is greater than the value of , or is . + + The , , or parameter is . The parameter is not an type. - -or- +-or- - The is from an enumeration that differs in type from . +The is from an enumeration that differs in type from . - -or- +-or- - The type of is not an underlying type of . +The type of is not an underlying type of . The parameter contains an invalid value. equals "X", but the enumeration type is unknown. @@ -752,9 +763,9 @@ is not an . - -or- +-or- - is neither of type nor does it have the same underlying type as . + is neither of type nor does it have the same underlying type as . .NET 8 and later versions: is a Boolean-backed enumeration type. @@ -1158,9 +1169,9 @@ is not an . The method is invoked by reflection in a reflection-only context, - -or- +-or- - is a type from an assembly loaded in a reflection-only context. + is a type from an assembly loaded in a reflection-only context. .NET 8 and later versions: is a Boolean-backed enumeration type. @@ -1241,11 +1252,8 @@ An enumeration type. Retrieves an array of the values of the underlying type constants in a specified enumeration. - An array that contains the values of the underlying type constants in . - - You can use this method to get enumeration values when it's hard to create an array of the enumeration type. - For example, you might use this method for the enumeration or on a platform where run-time code generation is not available. - + An array that contains the values of the underlying type constants in . + You can use this method to get enumeration values when it's hard to create an array of the enumeration type. For example, you might use this method for the enumeration or on a platform where run-time code generation is not available. is null. @@ -1295,10 +1303,7 @@ An enumeration type. Retrieves an array of the values of the underlying type constants in a specified enumeration type. An array that contains the values of the underlying type constants in . - - You can use this method to get enumeration values when it's hard to create an array of the enumeration type. - For example, you might use this method for the enumeration or on a platform where run-time code generation is not available. - + You can use this method to get enumeration values when it's hard to create an array of the enumeration type. For example, you might use this method for the enumeration or on a platform where run-time code generation is not available. @@ -1470,23 +1475,17 @@ is not an . - -or- +-or- - The type of is an enumeration, but it is not an enumeration of type . +The type of is an enumeration, but it is not an enumeration of type . - -or- +-or- - The type of is not an underlying type of . +The type of is not an underlying type of . is not type , , , , , , , or , or . - If is an enumeration that is defined by using the attribute, the method returns if multiple bit fields in are set but does not correspond to a composite enumeration value, or if is a string concatenation of the names of multiple bit flags. In the following example, a Pets enumeration is defined with the attribute. The method returns when you pass it an enumeration value that has two bit fields (Pets.Dog and Pets.Cat) set, and when you pass it the string representation of that enumeration value ("Dog, Cat"). - - :::code language="csharp" source="~/snippets/csharp/System/Enum/IsDefined/isdefined2.cs" interactive="try-dotnet" id="Snippet2"::: - :::code language="fsharp" source="~/snippets/fsharp/System/Enum/IsDefined/isdefined2.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Enum.IsDefined/vb/isdefined2.vb" id="Snippet2"::: - - You can determine whether multiple bit fields are set by calling the method. + If is an enumeration that is defined by using the attribute, the method returns if multiple bit fields in are set but does not correspond to a composite enumeration value, or if is a string concatenation of the names of multiple bit flags. In the following example, a Pets enumeration is defined with the attribute. The method returns when you pass it an enumeration value that has two bit fields (Pets.Dog and Pets.Cat) set, and when you pass it the string representation of that enumeration value ("Dog, Cat"). :::code language="csharp" source="~/snippets/csharp/System/Enum/IsDefined/isdefined2.cs" interactive="try-dotnet" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/Enum/IsDefined/isdefined2.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Enum.IsDefined/vb/isdefined2.vb" id="Snippet2"::: You can determine whether multiple bit fields are set by calling the method. @@ -1694,13 +1693,13 @@ is not an . - -or- +-or- - is either an empty string or only contains white space. + is either an empty string or only contains white space. - -or- +-or- - is a name, but not one of the named constants defined for the enumeration. + is a name, but not one of the named constants defined for the enumeration. is outside the range of the underlying type of . .NET 8 and later versions: is a Boolean-backed enumeration type. @@ -1842,13 +1841,13 @@ is not an . - -or- +-or- - is either an empty string ("") or only contains white space. + is either an empty string ("") or only contains white space. - -or- +-or- - is a name, but not one of the named constants defined for the enumeration. + is a name, but not one of the named constants defined for the enumeration. is outside the range of the underlying type of . .NET 8 and later versions: is a Boolean-backed enumeration type. @@ -3486,9 +3485,9 @@ is not an . - -or- +-or- - is not type , , , , , , , or . + is not type , , , , , , , or . .NET 8 and later versions: is a Boolean-backed enumeration type. @@ -3863,17 +3862,7 @@ ]]> - If multiple enumeration members have the same underlying value and you attempt to retrieve the string representation of an enumeration member's name based on its underlying value, your code should not make any assumptions about which name the method will return. For example, the following enumeration defines two members, Shade.Gray and Shade.Grey, that have the same underlying value. - - :::code language="csharp" source="~/snippets/csharp/System/Enum/ToString/tostringbyvalue1.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/Enum/ToString/tostringbyvalue1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.enum.tostring/vb/tostringbyvalue1.vb" id="Snippet1"::: - - The following method call attempts to retrieve the name of a member of the Shade enumeration whose underlying value is 1. The method can return either "Gray" or "Grey", and your code should not make any assumptions about which string will be returned. - - :::code language="csharp" source="~/snippets/csharp/System/Enum/ToString/tostringbyvalue1.cs" id="Snippet2"::: - :::code language="fsharp" source="~/snippets/fsharp/System/Enum/ToString/tostringbyvalue1.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.enum.tostring/vb/tostringbyvalue1.vb" id="Snippet2"::: + If multiple enumeration members have the same underlying value and you attempt to retrieve the string representation of an enumeration member's name based on its underlying value, your code should not make any assumptions about which name the method will return. For example, the following enumeration defines two members, Shade.Gray and Shade.Grey, that have the same underlying value. :::code language="csharp" source="~/snippets/csharp/System/Enum/ToString/tostringbyvalue1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Enum/ToString/tostringbyvalue1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.enum.tostring/vb/tostringbyvalue1.vb" id="Snippet1"::: The following method call attempts to retrieve the name of a member of the Shade enumeration whose underlying value is 1. The method can return either "Gray" or "Grey", and your code should not make any assumptions about which string will be returned. :::code language="csharp" source="~/snippets/csharp/System/Enum/ToString/tostringbyvalue1.cs" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/Enum/ToString/tostringbyvalue1.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.enum.tostring/vb/tostringbyvalue1.vb" id="Snippet2"::: @@ -4028,17 +4017,7 @@ equals "X", but the enumeration type is unknown. - If multiple enumeration members have the same underlying value and you attempt to retrieve the string representation of an enumeration member's name based on its underlying value, your code should not make any assumptions about which name the method will return. For example, the following enumeration defines two members, Shade.Gray and Shade.Grey, that have the same underlying value. - - :::code language="csharp" source="~/snippets/csharp/System/Enum/ToString/tostringbyvalue1.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/Enum/ToString/tostringbyvalue1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.enum.tostring/vb/tostringbyvalue1.vb" id="Snippet1"::: - - The following method call attempts to retrieve the name of a member of the Shade enumeration whose underlying value is 1. The method can return either "Gray" or "Grey", and your code should not make any assumptions about which string will be returned. - - :::code language="csharp" source="~/snippets/csharp/System/Enum/ToString/tostringbyvalue1.cs" id="Snippet3"::: - :::code language="fsharp" source="~/snippets/fsharp/System/Enum/ToString/tostringbyvalue1.fs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.enum.tostring/vb/tostringbyvalue1.vb" id="Snippet3"::: + If multiple enumeration members have the same underlying value and you attempt to retrieve the string representation of an enumeration member's name based on its underlying value, your code should not make any assumptions about which name the method will return. For example, the following enumeration defines two members, Shade.Gray and Shade.Grey, that have the same underlying value. :::code language="csharp" source="~/snippets/csharp/System/Enum/ToString/tostringbyvalue1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Enum/ToString/tostringbyvalue1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.enum.tostring/vb/tostringbyvalue1.vb" id="Snippet1"::: The following method call attempts to retrieve the name of a member of the Shade enumeration whose underlying value is 1. The method can return either "Gray" or "Grey", and your code should not make any assumptions about which string will be returned. :::code language="csharp" source="~/snippets/csharp/System/Enum/ToString/tostringbyvalue1.cs" id="Snippet3"::: :::code language="fsharp" source="~/snippets/fsharp/System/Enum/ToString/tostringbyvalue1.fs" id="Snippet3"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.enum.tostring/vb/tostringbyvalue1.vb" id="Snippet3"::: diff --git a/xml/System/Environment+SpecialFolder.xml b/xml/System/Environment+SpecialFolder.xml index 2b1cdd2033d..bdf0f62f085 100644 --- a/xml/System/Environment+SpecialFolder.xml +++ b/xml/System/Environment+SpecialFolder.xml @@ -56,25 +56,25 @@ Specifies enumerated constants used to retrieve directory paths to system special folders. - method returns the locations associated with this enumeration. The locations of these folders can have different values on different operating systems, the user can change some of the locations, and the locations are localized. - - For more information about special folders, see the [KNOWNFOLDERID](/windows/desktop/shell/knownfolderid) constants in the Windows documentation. - - - -## Examples - The following example shows how to use with the method to get the System directory. - + method returns the locations associated with this enumeration. The locations of these folders can have different values on different operating systems, the user can change some of the locations, and the locations are localized. + + For more information about special folders, see the [KNOWNFOLDERID](/windows/desktop/shell/knownfolderid) constants in the Windows documentation. + + + +## Examples + The following example shows how to use with the method to get the System directory. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Environment.GetFolderPath/CPP/getfolderpath.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Environment+SpecialFolder/Overview/getfolderpath.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Environment+SpecialFolder/Overview/getfolderpath.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Environment.GetFolderPath/VB/getfolderpath.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Environment.GetFolderPath/VB/getfolderpath.vb" id="Snippet1"::: + ]]> @@ -511,9 +511,7 @@ 43 - The directory for components that are shared across applications. - - To get the x86 common program files directory in a non-x86 process, use the member. + The directory for components that are shared across applications. To get the x86 common program files directory in a non-x86 process, use the member. @@ -1193,7 +1191,7 @@ 5 - The **My Documents** folder. This member is equivalent to . + The **My Documents** folder. This member is equivalent to . @@ -1394,7 +1392,7 @@ 5 - The directory that serves as a common repository for documents. This member is equivalent to . + The directory that serves as a common repository for documents. This member is equivalent to . @@ -1474,9 +1472,7 @@ 38 - The program files directory. - - In a non-x86 process, passing to the method returns the path for non-x86 programs. To get the x86 program files directory in a non-x86 process, use the member. + The program files directory. In a non-x86 process, passing to the method returns the path for non-x86 programs. To get the x86 program files directory in a non-x86 process, use the member. diff --git a/xml/System/Environment+SpecialFolderOption.xml b/xml/System/Environment+SpecialFolderOption.xml index cba5f37ced5..011376ae2fd 100644 --- a/xml/System/Environment+SpecialFolderOption.xml +++ b/xml/System/Environment+SpecialFolderOption.xml @@ -50,11 +50,11 @@ Specifies options to use for getting the path to a special folder. - enumeration is used to define the precise behavior of the method. - + enumeration is used to define the precise behavior of the method. + ]]> diff --git a/xml/System/Environment.xml b/xml/System/Environment.xml index 4e856ab60c2..ec85664ec4c 100644 --- a/xml/System/Environment.xml +++ b/xml/System/Environment.xml @@ -1254,7 +1254,7 @@ The following example creates environment variables for the Gets the path to the specified system special folder. The path to the specified system special folder, if that folder physically exists on your computer; otherwise, an empty string (""). - A folder will not physically exist if the operating system did not create it, the existing folder was deleted, or the folder is a virtual directory, such as My Computer, which does not correspond to a physical path. + A folder will not physically exist if the operating system did not create it, the existing folder was deleted, or the folder is a virtual directory, such as My Computer, which does not correspond to a physical path. Gets the path to the specified system special folder using a specified option for accessing special folders. The path to the specified system special folder, if that folder physically exists on your computer; otherwise, an empty string (""). - A folder will not physically exist if the operating system did not create it, the existing folder was deleted, or the folder is a virtual directory, such as My Computer, which does not correspond to a physical path. + A folder will not physically exist if the operating system did not create it, the existing folder was deleted, or the folder is a virtual directory, such as My Computer, which does not correspond to a physical path. This property was unable to obtain the system version. - -or- +-or- - The obtained platform identifier is not a member of +The obtained platform identifier is not a member of @@ -2058,13 +2058,13 @@ The following example attempts to retrieve the value of an environment variable contains a zero-length string, an initial hexadecimal zero character (0x00), or an equal sign ("="). - -or- +-or- - The length of or is greater than or equal to 32,767 characters. +The length of or is greater than or equal to 32,767 characters. - -or- +-or- - An error occurred during the execution of this operation. +An error occurred during the execution of this operation. The caller does not have the required permission to perform this operation. @@ -2183,25 +2183,25 @@ The following example creates environment variables for the contains a zero-length string, an initial hexadecimal zero character (0x00), or an equal sign ("="). - -or- +-or- - The length of is greater than or equal to 32,767 characters. +The length of is greater than or equal to 32,767 characters. - -or- +-or- - is not a member of the enumeration. + is not a member of the enumeration. - -or- +-or- - is or , and the length of is greater than or equal to 255. + is or , and the length of is greater than or equal to 255. - -or- +-or- - is and the length of is greater than or equal to 32,767 characters. + is and the length of is greater than or equal to 32,767 characters. - -or- +-or- - An error occurred during the execution of this operation. +An error occurred during the execution of this operation. The caller does not have the required permission to perform this operation. diff --git a/xml/System/EnvironmentVariableTarget.xml b/xml/System/EnvironmentVariableTarget.xml index 339bda1785c..7f761f1ee7d 100644 --- a/xml/System/EnvironmentVariableTarget.xml +++ b/xml/System/EnvironmentVariableTarget.xml @@ -51,38 +51,38 @@ Specifies the location where an environment variable is stored or retrieved in a set or get operation. - enumeration is used by certain overloads of the , , and methods to specify the location, or target, where the name and value of an environment variable is stored or retrieved. - -The target can be one of three locations: - +The enumeration is used by certain overloads of the , , and methods to specify the location, or target, where the name and value of an environment variable is stored or retrieved. + +The target can be one of three locations: + - The environment block associated with the current process (`EnvironmentVariableTarget.Process`). The user creates the environment variable in a set operation. When the process terminates, the operating system destroys the environment variable in that process. - The Windows operating system registry key reserved for environment variables associated with the current user (`EnvironmentVariableTarget.User`). - - On Windows systems, when the user creates the environment variable in a set operation, the operating system stores the environment variable in the system registry, but not in the current process. If the user starts a new process, the operating system copies the environment variable from the registry to that process. When the process terminates, the operating system destroys the environment variable in that process. However, the environment variable in the registry persists until the user removes it programmatically or by means of an operating system tool. + + On Windows systems, when the user creates the environment variable in a set operation, the operating system stores the environment variable in the system registry, but not in the current process. If the user starts a new process, the operating system copies the environment variable from the registry to that process. When the process terminates, the operating system destroys the environment variable in that process. However, the environment variable in the registry persists until the user removes it programmatically or by means of an operating system tool. On Unix-based systems, an attempt to create an enviroment variable with `EnvironmentVariable.User` has no effect, and an attempt to retrieve an enviroment variable using `EnvironmentVariable.User` returns `null` (in C#) or `Nothing` (in Visual Basic). -- The registry key reserved for environment variables associated with all users on the local machine (`EnvironmentVariableTarget.Machine`). +- The registry key reserved for environment variables associated with all users on the local machine (`EnvironmentVariableTarget.Machine`). When a user creates the environment variable in a set operation, the operating system stores the environment variable in the system registry, but not in the current process. If any user on the local machine starts a new process, the operating system copies the environment variable from the registry to that process. When the process terminates, the operating system destroys the environment variable in that process. However, the environment variable in the registry persists until a user removes it programmatically or by means of an operating system tool. On Unix-based systems, an attempt to create an enviroment variable with `EnvironmentVariable.Machine` has no effect, and an attempt to retrieve an enviroment variable using `EnvironmentVariable.Machine` returns `null` (in C#) or `Nothing` (in Visual Basic). -## Examples +## Examples + +The following example uses the enumeration in methods that create, retrieve, and delete environment variables. The output from the example shows that environmnent variables stored and retrieved without specifying a `EnvironmentVariableTarget` value are stored in the environment block associated with the current process (`EnvironmentVariableTarget.Process`). The example output from Unix-based systems also shows that attempts to define an environment variable with a value other than `EnvironmentVariableTarget.Process` is ignored. -The following example uses the enumeration in methods that create, retrieve, and delete environment variables. The output from the example shows that environmnent variables stored and retrieved without specifying a `EnvironmentVariableTarget` value are stored in the environment block associated with the current process (`EnvironmentVariableTarget.Process`). The example output from Unix-based systems also shows that attempts to define an environment variable with a value other than `EnvironmentVariableTarget.Process` is ignored. - :::code language="csharp" source="~/snippets/csharp/System/Environment/GetEnvironmentVariable/gsev.cs"::: :::code language="fsharp" source="~/snippets/fsharp/System/Environment/GetEnvironmentVariable/gsev.fs"::: -:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/environment.getsetenvar/VB/gsev.vb"::: - +:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/environment.getsetenvar/VB/gsev.vb"::: + ]]> diff --git a/xml/System/Exception.xml b/xml/System/Exception.xml index fd67e57d176..d22279ce340 100644 --- a/xml/System/Exception.xml +++ b/xml/System/Exception.xml @@ -95,244 +95,244 @@ Represents errors that occur during application execution. - -## Errors and exceptions - Run-time errors can occur for a variety of reasons. However, not all errors should be handled as exceptions in your code. Here are some categories of errors that can occur at run time and the appropriate ways to respond to them. - -- **Usage errors.** A usage error represents an error in program logic that can result in an exception. However, the error should be addressed not through exception handling but by modifying the faulty code. For example, the override of the method in the following example assumes that the `obj` argument must always be non-null. - + +## Errors and exceptions + Run-time errors can occur for a variety of reasons. However, not all errors should be handled as exceptions in your code. Here are some categories of errors that can occur at run time and the appropriate ways to respond to them. + +- **Usage errors.** A usage error represents an error in program logic that can result in an exception. However, the error should be addressed not through exception handling but by modifying the faulty code. For example, the override of the method in the following example assumes that the `obj` argument must always be non-null. + :::code language="csharp" source="~/snippets/csharp/System/Exception/Overview/usageerrors1.cs" id="Snippet4"::: :::code language="fsharp" source="~/snippets/fsharp/System/Exception/Overview/usageerrors1.fs" id="Snippet4"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.exception.class/vb/usageerrors1.vb" id="Snippet4"::: - - The exception that results when `obj` is `null` can be eliminated by modifying the source code to explicitly test for null before calling the override and then re-compiling. The following example contains the corrected source code that handles a `null` argument. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.exception.class/vb/usageerrors1.vb" id="Snippet4"::: + + The exception that results when `obj` is `null` can be eliminated by modifying the source code to explicitly test for null before calling the override and then re-compiling. The following example contains the corrected source code that handles a `null` argument. + :::code language="csharp" source="~/snippets/csharp/System/Exception/Overview/usageerrors2.cs" interactive="try-dotnet" id="Snippet5"::: :::code language="fsharp" source="~/snippets/fsharp/System/Exception/Overview/usageerrors2.fs" id="Snippet5"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.exception.class/vb/usageerrors2.vb" id="Snippet5"::: - - Instead of using exception handling for usage errors, you can use the method to identify usage errors in debug builds, and the method to identify usage errors in both debug and release builds. For more information, see [Assertions in Managed Code](/visualstudio/debugger/assertions-in-managed-code). - -- **Program errors.** A program error is a run-time error that cannot necessarily be avoided by writing bug-free code. - - In some cases, a program error may reflect an expected or routine error condition. In this case, you may want to avoid using exception handling to deal with the program error and instead retry the operation. For example, if the user is expected to input a date in a particular format, you can parse the date string by calling the method, which returns a value that indicates whether the parse operation succeeded, instead of using the method, which throws a exception if the date string cannot be converted to a value. Similarly, if a user tries to open a file that does not exist, you can first call the method to check whether the file exists and, if it does not, prompt the user whether they want to create it. - - In other cases, a program error reflects an unexpected error condition that can be handled in your code. For example, even if you've checked to ensure that a file exists, it may be deleted before you can open it, or it may be corrupted. In that case, trying to open the file by instantiating a object or calling the method may throw a exception. In these cases, you should use exception handling to recover from the error. - -- **System failures.** A system failure is a run-time error that cannot be handled programmatically in a meaningful way. For example, any method can throw an exception if the common language runtime is unable to allocate additional memory. Ordinarily, system failures are not handled by using exception handling. Instead, you may be able to use an event such as and call the method to log exception information and notify the user of the failure before the application terminates. - - -## Try/catch blocks - The common language runtime provides an exception handling model that is based on the representation of exceptions as objects, and the separation of program code and exception handling code into `try` blocks and `catch` blocks. There can be one or more `catch` blocks, each designed to handle a particular type of exception, or one block designed to catch a more specific exception than another block. - - If an application handles exceptions that occur during the execution of a block of application code, the code must be placed within a `try` statement and is called a `try` block. Application code that handles exceptions thrown by a `try` block is placed within a `catch` statement and is called a `catch` block. Zero or more `catch` blocks are associated with a `try` block, and each `catch` block includes a type filter that determines the types of exceptions it handles. - - When an exception occurs in a `try` block, the system searches the associated `catch` blocks in the order they appear in application code, until it locates a `catch` block that handles the exception. A `catch` block handles an exception of type `T` if the type filter of the catch block specifies `T` or any type that `T` derives from. The system stops searching after it finds the first `catch` block that handles the exception. For this reason, in application code, a `catch` block that handles a type must be specified before a `catch` block that handles its base types, as demonstrated in the example that follows this section. A catch block that handles `System.Exception` is specified last. - - If none of the `catch` blocks associated with the current `try` block handle the exception, and the current `try` block is nested within other `try` blocks in the current call, the `catch` blocks associated with the next enclosing `try` block are searched. If no `catch` block for the exception is found, the system searches previous nesting levels in the current call. If no `catch` block for the exception is found in the current call, the exception is passed up the call stack, and the previous stack frame is searched for a `catch` block that handles the exception. The search of the call stack continues until the exception is handled or until no more frames exist on the call stack. If the top of the call stack is reached without finding a `catch` block that handles the exception, the default exception handler handles it and the application terminates. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.exception.class/vb/usageerrors2.vb" id="Snippet5"::: + + Instead of using exception handling for usage errors, you can use the method to identify usage errors in debug builds, and the method to identify usage errors in both debug and release builds. For more information, see [Assertions in Managed Code](/visualstudio/debugger/assertions-in-managed-code). + +- **Program errors.** A program error is a run-time error that cannot necessarily be avoided by writing bug-free code. + + In some cases, a program error may reflect an expected or routine error condition. In this case, you may want to avoid using exception handling to deal with the program error and instead retry the operation. For example, if the user is expected to input a date in a particular format, you can parse the date string by calling the method, which returns a value that indicates whether the parse operation succeeded, instead of using the method, which throws a exception if the date string cannot be converted to a value. Similarly, if a user tries to open a file that does not exist, you can first call the method to check whether the file exists and, if it does not, prompt the user whether they want to create it. + + In other cases, a program error reflects an unexpected error condition that can be handled in your code. For example, even if you've checked to ensure that a file exists, it may be deleted before you can open it, or it may be corrupted. In that case, trying to open the file by instantiating a object or calling the method may throw a exception. In these cases, you should use exception handling to recover from the error. + +- **System failures.** A system failure is a run-time error that cannot be handled programmatically in a meaningful way. For example, any method can throw an exception if the common language runtime is unable to allocate additional memory. Ordinarily, system failures are not handled by using exception handling. Instead, you may be able to use an event such as and call the method to log exception information and notify the user of the failure before the application terminates. + + +## Try/catch blocks + The common language runtime provides an exception handling model that is based on the representation of exceptions as objects, and the separation of program code and exception handling code into `try` blocks and `catch` blocks. There can be one or more `catch` blocks, each designed to handle a particular type of exception, or one block designed to catch a more specific exception than another block. + + If an application handles exceptions that occur during the execution of a block of application code, the code must be placed within a `try` statement and is called a `try` block. Application code that handles exceptions thrown by a `try` block is placed within a `catch` statement and is called a `catch` block. Zero or more `catch` blocks are associated with a `try` block, and each `catch` block includes a type filter that determines the types of exceptions it handles. + + When an exception occurs in a `try` block, the system searches the associated `catch` blocks in the order they appear in application code, until it locates a `catch` block that handles the exception. A `catch` block handles an exception of type `T` if the type filter of the catch block specifies `T` or any type that `T` derives from. The system stops searching after it finds the first `catch` block that handles the exception. For this reason, in application code, a `catch` block that handles a type must be specified before a `catch` block that handles its base types, as demonstrated in the example that follows this section. A catch block that handles `System.Exception` is specified last. + + If none of the `catch` blocks associated with the current `try` block handle the exception, and the current `try` block is nested within other `try` blocks in the current call, the `catch` blocks associated with the next enclosing `try` block are searched. If no `catch` block for the exception is found, the system searches previous nesting levels in the current call. If no `catch` block for the exception is found in the current call, the exception is passed up the call stack, and the previous stack frame is searched for a `catch` block that handles the exception. The search of the call stack continues until the exception is handled or until no more frames exist on the call stack. If the top of the call stack is reached without finding a `catch` block that handles the exception, the default exception handler handles it and the application terminates. + ### F# try..with Expression F# does not use `catch` blocks. Instead, a raised exception is pattern matched using a single `with` block. As this is an expression, rather than a statement, all paths must return the same type. To learn more, see [The try...with Expression](/dotnet/fsharp/language-reference/exception-handling/the-try-with-expression). - -## Exception type features - Exception types support the following features: - -- Human-readable text that describes the error. When an exception occurs, the runtime makes a text message available to inform the user of the nature of the error and to suggest action to resolve the problem. This text message is held in the property of the exception object. During the creation of the exception object, you can pass a text string to the constructor to describe the details of that particular exception. If no error message argument is supplied to the constructor, the default error message is used. For more information, see the property. - -- The state of the call stack when the exception was thrown. The property carries a stack trace that can be used to determine where the error occurs in the code. The stack trace lists all the called methods and the line numbers in the source file where the calls are made. - - -## Exception class properties - The class includes a number of properties that help identify the code location, the type, the help file, and the reason for the exception: , , , , , , , and . - - When a causal relationship exists between two or more exceptions, the property maintains this information. The outer exception is thrown in response to this inner exception. The code that handles the outer exception can use the information from the earlier inner exception to handle the error more appropriately. Supplementary information about the exception can be stored as a collection of key/value pairs in the property. - - The error message string that is passed to the constructor during the creation of the exception object should be localized and can be supplied from a resource file by using the class. For more information about localized resources, see the [Creating Satellite Assemblies](/dotnet/framework/resources/creating-satellite-assemblies-for-desktop-apps) and [Packaging and Deploying Resources](/dotnet/framework/resources/packaging-and-deploying-resources-in-desktop-apps) topics. - - To provide the user with extensive information about why the exception occurred, the property can hold a URL (or URN) to a help file. - - The class uses the HRESULT COR_E_EXCEPTION, which has the value 0x80131500. - - For a list of initial property values for an instance of the class, see the constructors. - - -## Performance considerations - Throwing or handling an exception consumes a significant amount of system resources and execution time. Throw exceptions only to handle truly extraordinary conditions, not to handle predictable events or flow control. For example, in some cases, such as when you're developing a class library, it's reasonable to throw an exception if a method argument is invalid, because you expect your method to be called with valid parameters. An invalid method argument, if it is not the result of a usage error, means that something extraordinary has occurred. Conversely, do not throw an exception if user input is invalid, because you can expect users to occasionally enter invalid data. Instead, provide a retry mechanism so users can enter valid input. Nor should you use exceptions to handle usage errors. Instead, use [assertions](/visualstudio/debugger/assertions-in-managed-code) to identify and correct usage errors. - - In addition, do not throw an exception when a return code is sufficient; do not convert a return code to an exception; and do not routinely catch an exception, ignore it, and then continue processing. - - -## Re-throwing an exception - In many cases, an exception handler simply wants to pass the exception on to the caller. This most often occurs in: - -- A class library that in turn wraps calls to methods in the .NET Framework class library or other class libraries. - -- An application or library that encounters a fatal exception. The exception handler can log the exception and then re-throw the exception. - - The recommended way to re-throw an exception is to simply use the [throw](/dotnet/csharp/language-reference/keywords/throw) statement in C#, the [reraise](/dotnet/fsharp/language-reference/exception-handling/the-raise-function#reraising-an-exception) function in F#, and the [Throw](/dotnet/visual-basic/language-reference/statements/throw-statement) statement in Visual Basic without including an expression. This ensures that all call stack information is preserved when the exception is propagated to the caller. The following example illustrates this. A string extension method, `FindOccurrences`, wraps one or more calls to without validating its arguments beforehand. - + +## Exception type features + Exception types support the following features: + +- Human-readable text that describes the error. When an exception occurs, the runtime makes a text message available to inform the user of the nature of the error and to suggest action to resolve the problem. This text message is held in the property of the exception object. During the creation of the exception object, you can pass a text string to the constructor to describe the details of that particular exception. If no error message argument is supplied to the constructor, the default error message is used. For more information, see the property. + +- The state of the call stack when the exception was thrown. The property carries a stack trace that can be used to determine where the error occurs in the code. The stack trace lists all the called methods and the line numbers in the source file where the calls are made. + + +## Exception class properties + The class includes a number of properties that help identify the code location, the type, the help file, and the reason for the exception: , , , , , , , and . + + When a causal relationship exists between two or more exceptions, the property maintains this information. The outer exception is thrown in response to this inner exception. The code that handles the outer exception can use the information from the earlier inner exception to handle the error more appropriately. Supplementary information about the exception can be stored as a collection of key/value pairs in the property. + + The error message string that is passed to the constructor during the creation of the exception object should be localized and can be supplied from a resource file by using the class. For more information about localized resources, see the [Creating Satellite Assemblies](/dotnet/framework/resources/creating-satellite-assemblies-for-desktop-apps) and [Packaging and Deploying Resources](/dotnet/framework/resources/packaging-and-deploying-resources-in-desktop-apps) topics. + + To provide the user with extensive information about why the exception occurred, the property can hold a URL (or URN) to a help file. + + The class uses the HRESULT COR_E_EXCEPTION, which has the value 0x80131500. + + For a list of initial property values for an instance of the class, see the constructors. + + +## Performance considerations + Throwing or handling an exception consumes a significant amount of system resources and execution time. Throw exceptions only to handle truly extraordinary conditions, not to handle predictable events or flow control. For example, in some cases, such as when you're developing a class library, it's reasonable to throw an exception if a method argument is invalid, because you expect your method to be called with valid parameters. An invalid method argument, if it is not the result of a usage error, means that something extraordinary has occurred. Conversely, do not throw an exception if user input is invalid, because you can expect users to occasionally enter invalid data. Instead, provide a retry mechanism so users can enter valid input. Nor should you use exceptions to handle usage errors. Instead, use [assertions](/visualstudio/debugger/assertions-in-managed-code) to identify and correct usage errors. + + In addition, do not throw an exception when a return code is sufficient; do not convert a return code to an exception; and do not routinely catch an exception, ignore it, and then continue processing. + + +## Re-throwing an exception + In many cases, an exception handler simply wants to pass the exception on to the caller. This most often occurs in: + +- A class library that in turn wraps calls to methods in the .NET Framework class library or other class libraries. + +- An application or library that encounters a fatal exception. The exception handler can log the exception and then re-throw the exception. + + The recommended way to re-throw an exception is to simply use the [throw](/dotnet/csharp/language-reference/keywords/throw) statement in C#, the [reraise](/dotnet/fsharp/language-reference/exception-handling/the-raise-function#reraising-an-exception) function in F#, and the [Throw](/dotnet/visual-basic/language-reference/statements/throw-statement) statement in Visual Basic without including an expression. This ensures that all call stack information is preserved when the exception is propagated to the caller. The following example illustrates this. A string extension method, `FindOccurrences`, wraps one or more calls to without validating its arguments beforehand. + :::code language="csharp" source="~/snippets/csharp/System/Exception/Overview/rethrow1.cs" id="Snippet6"::: :::code language="fsharp" source="~/snippets/fsharp/System/Exception/Overview/rethrow1.fs" id="Snippet6"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.exception.class/vb/rethrow1.vb" id="Snippet6"::: - - A caller then calls `FindOccurrences` twice. In the second call to `FindOccurrences`, the caller passes a `null` as the search string, which causes the method to throw an exception. This exception is handled by the `FindOccurrences` method and passed back to the caller. Because the throw statement is used with no expression, the output from the example shows that the call stack is preserved. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.exception.class/vb/rethrow1.vb" id="Snippet6"::: + + A caller then calls `FindOccurrences` twice. In the second call to `FindOccurrences`, the caller passes a `null` as the search string, which causes the method to throw an exception. This exception is handled by the `FindOccurrences` method and passed back to the caller. Because the throw statement is used with no expression, the output from the example shows that the call stack is preserved. + :::code language="csharp" source="~/snippets/csharp/System/Exception/Overview/rethrow1.cs" id="Snippet7"::: :::code language="fsharp" source="~/snippets/fsharp/System/Exception/Overview/rethrow1.fs" id="Snippet7"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.exception.class/vb/rethrow1.vb" id="Snippet7"::: - - In contrast, if the exception is re-thrown by using the - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.exception.class/vb/rethrow1.vb" id="Snippet7"::: + + In contrast, if the exception is re-thrown by using the + ```csharp throw e; -``` - -```vb -Throw e +``` + +```vb +Throw e ``` ```fsharp raise e ``` - - statement, the full call stack is not preserved, and the example would generate the following output: - -```Output - -'a' occurs at the following character positions: 4, 7, 15 - -An exception (ArgumentNullException) occurred. -Message: - Value cannot be null. -Parameter name: value - -Stack Trace: - at Library.FindOccurrences(String s, String f) - at Example.Main() - -``` - - A slightly more cumbersome alternative is to throw a new exception, and to preserve the original exception's call stack information in an inner exception. The caller can then use the new exception's property to retrieve stack frame and other information about the original exception. In this case, the throw statement is: - + + statement, the full call stack is not preserved, and the example would generate the following output: + +```Output + +'a' occurs at the following character positions: 4, 7, 15 + +An exception (ArgumentNullException) occurred. +Message: + Value cannot be null. +Parameter name: value + +Stack Trace: + at Library.FindOccurrences(String s, String f) + at Example.Main() + +``` + + A slightly more cumbersome alternative is to throw a new exception, and to preserve the original exception's call stack information in an inner exception. The caller can then use the new exception's property to retrieve stack frame and other information about the original exception. In this case, the throw statement is: + :::code language="csharp" source="~/snippets/csharp/System/Exception/Overview/rethrow3.cs" id="Snippet8"::: :::code language="fsharp" source="~/snippets/fsharp/System/Exception/Overview/rethrow3.fs" id="Snippet8"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.exception.class/vb/rethrow3.vb" id="Snippet8"::: - - The user code that handles the exception has to know that the property contains information about the original exception, as the following exception handler illustrates. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.exception.class/vb/rethrow3.vb" id="Snippet8"::: + + The user code that handles the exception has to know that the property contains information about the original exception, as the following exception handler illustrates. + :::code language="csharp" source="~/snippets/csharp/System/Exception/Overview/rethrow3.cs" id="Snippet9"::: :::code language="fsharp" source="~/snippets/fsharp/System/Exception/Overview/rethrow3.fs" id="Snippet9"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.exception.class/vb/rethrow3.vb" id="Snippet9"::: - - -## Choosing standard exceptions - When you have to throw an exception, you can often use an existing exception type in the .NET Framework instead of implementing a custom exception. You should use a standard exception type under these two conditions: - -- You are throwing an exception that is caused by a usage error (that is, by an error in program logic made by the developer who is calling your method). Typically, you would throw an exception such as , , , or . The string you supply to the exception object's constructor when instantiating the exception object should describe the error so that the developer can fix it. For more information, see the property. - -- You are handling an error that can be communicated to the caller with an existing .NET Framework exception. You should throw the most derived exception possible. For example, if a method requires an argument to be a valid member of an enumeration type, you should throw an (the most derived class) rather than an . - - The following table lists common exception types and the conditions under which you would throw them. - -|Exception|Condition| -|---------------|---------------| -||A non-null argument that is passed to a method is invalid.| -||An argument that is passed to a method is `null`.| -||An argument is outside the range of valid values.| -||Part of a directory path is not valid.| -||The denominator in an integer or division operation is zero.| -||A drive is unavailable or does not exist.| -||A file does not exist.| -||A value is not in an appropriate format to be converted from a string by a conversion method such as `Parse`.| -||An index is outside the bounds of an array or collection.| -||A method call is invalid in an object's current state.| -||The specified key for accessing a member in a collection cannot be found.| -||A method or operation is not implemented.| -||A method or operation is not supported.| -||An operation is performed on an object that has been disposed.| -||An arithmetic, casting, or conversion operation results in an overflow.| -||A path or file name exceeds the maximum system-defined length.| -||The operation is not supported on the current platform.| -||An array with the wrong number of dimensions is passed to a method.| -||The time interval allotted to an operation has expired.| -||An invalid Uniform Resource Identifier (URI) is used.| - - -## Implementing custom exceptions - In the following cases, using an existing .NET Framework exception to handle an error condition is not adequate: - -- When the exception reflects a unique program error that cannot be mapped to an existing .NET Framework exception. - -- When the exception requires handling that is different from the handling that is appropriate for an existing .NET Framework exception, or the exception must be disambiguated from a similar exception. For example, if you throw an exception when parsing the numeric representation of a string that is out of range of the target integral type, you would not want to use the same exception for an error that results from the caller not supplying the appropriate constrained values when calling the method. - - The class is the base class of all exceptions in the .NET Framework. Many derived classes rely on the inherited behavior of the members of the class; they do not override the members of , nor do they define any unique members. - - To define your own exception class: - -1. Define a class that inherits from . If necessary, define any unique members needed by your class to provide additional information about the exception. For example, the class includes a property that specifies the name of the parameter whose argument caused the exception, and the property includes a property that indicates the time-out interval. - -2. If necessary, override any inherited members whose functionality you want to change or modify. Note that most existing derived classes of do not override the behavior of inherited members. - -3. Determine whether your custom exception object is serializable. Serialization enables you to save information about the exception and permits exception information to be shared by a server and a client proxy in a remoting context. To make the exception object serializable, mark it with the attribute. - -4. Define the constructors of your exception class. Typically, exception classes have one or more of the following constructors: - - - , which uses default values to initialize the properties of a new exception object. - - - , which initializes a new exception object with a specified error message. - - - , which initializes a new exception object with a specified error message and inner exception. - - - , which is a `protected` constructor that initializes a new exception object from serialized data. You should implement this constructor if you've chosen to make your exception object serializable. - - The following example illustrates the use of a custom exception class. It defines a `NotPrimeException` exception that is thrown when a client tries to retrieve a sequence of prime numbers by specifying a starting number that is not prime. The exception defines a new property, `NonPrime`, that returns the non-prime number that caused the exception. Besides implementing a protected parameterless constructor and a constructor with and parameters for serialization, the `NotPrimeException` class defines three additional constructors to support the `NonPrime` property. Each constructor calls a base class constructor in addition to preserving the value of the non-prime number. The `NotPrimeException` class is also marked with the attribute. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.exception.class/vb/rethrow3.vb" id="Snippet9"::: + + +## Choosing standard exceptions + When you have to throw an exception, you can often use an existing exception type in the .NET Framework instead of implementing a custom exception. You should use a standard exception type under these two conditions: + +- You are throwing an exception that is caused by a usage error (that is, by an error in program logic made by the developer who is calling your method). Typically, you would throw an exception such as , , , or . The string you supply to the exception object's constructor when instantiating the exception object should describe the error so that the developer can fix it. For more information, see the property. + +- You are handling an error that can be communicated to the caller with an existing .NET Framework exception. You should throw the most derived exception possible. For example, if a method requires an argument to be a valid member of an enumeration type, you should throw an (the most derived class) rather than an . + + The following table lists common exception types and the conditions under which you would throw them. + +|Exception|Condition| +|---------------|---------------| +||A non-null argument that is passed to a method is invalid.| +||An argument that is passed to a method is `null`.| +||An argument is outside the range of valid values.| +||Part of a directory path is not valid.| +||The denominator in an integer or division operation is zero.| +||A drive is unavailable or does not exist.| +||A file does not exist.| +||A value is not in an appropriate format to be converted from a string by a conversion method such as `Parse`.| +||An index is outside the bounds of an array or collection.| +||A method call is invalid in an object's current state.| +||The specified key for accessing a member in a collection cannot be found.| +||A method or operation is not implemented.| +||A method or operation is not supported.| +||An operation is performed on an object that has been disposed.| +||An arithmetic, casting, or conversion operation results in an overflow.| +||A path or file name exceeds the maximum system-defined length.| +||The operation is not supported on the current platform.| +||An array with the wrong number of dimensions is passed to a method.| +||The time interval allotted to an operation has expired.| +||An invalid Uniform Resource Identifier (URI) is used.| + + +## Implementing custom exceptions + In the following cases, using an existing .NET Framework exception to handle an error condition is not adequate: + +- When the exception reflects a unique program error that cannot be mapped to an existing .NET Framework exception. + +- When the exception requires handling that is different from the handling that is appropriate for an existing .NET Framework exception, or the exception must be disambiguated from a similar exception. For example, if you throw an exception when parsing the numeric representation of a string that is out of range of the target integral type, you would not want to use the same exception for an error that results from the caller not supplying the appropriate constrained values when calling the method. + + The class is the base class of all exceptions in the .NET Framework. Many derived classes rely on the inherited behavior of the members of the class; they do not override the members of , nor do they define any unique members. + + To define your own exception class: + +1. Define a class that inherits from . If necessary, define any unique members needed by your class to provide additional information about the exception. For example, the class includes a property that specifies the name of the parameter whose argument caused the exception, and the property includes a property that indicates the time-out interval. + +2. If necessary, override any inherited members whose functionality you want to change or modify. Note that most existing derived classes of do not override the behavior of inherited members. + +3. Determine whether your custom exception object is serializable. Serialization enables you to save information about the exception and permits exception information to be shared by a server and a client proxy in a remoting context. To make the exception object serializable, mark it with the attribute. + +4. Define the constructors of your exception class. Typically, exception classes have one or more of the following constructors: + + - , which uses default values to initialize the properties of a new exception object. + + - , which initializes a new exception object with a specified error message. + + - , which initializes a new exception object with a specified error message and inner exception. + + - , which is a `protected` constructor that initializes a new exception object from serialized data. You should implement this constructor if you've chosen to make your exception object serializable. + + The following example illustrates the use of a custom exception class. It defines a `NotPrimeException` exception that is thrown when a client tries to retrieve a sequence of prime numbers by specifying a starting number that is not prime. The exception defines a new property, `NonPrime`, that returns the non-prime number that caused the exception. Besides implementing a protected parameterless constructor and a constructor with and parameters for serialization, the `NotPrimeException` class defines three additional constructors to support the `NonPrime` property. Each constructor calls a base class constructor in addition to preserving the value of the non-prime number. The `NotPrimeException` class is also marked with the attribute. + :::code language="csharp" source="~/snippets/csharp/System/Exception/Overview/notprimeexception.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Exception/Overview/notprimeexception.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.exception.class/vb/notprimeexception.vb" id="Snippet1"::: - - The `PrimeNumberGenerator` class shown in the following example uses the Sieve of Eratosthenes to calculate the sequence of prime numbers from 2 to a limit specified by the client in the call to its class constructor. The `GetPrimesFrom` method returns all prime numbers that are greater than or equal to a specified lower limit, but throws a `NotPrimeException` if that lower limit is not a prime number. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.exception.class/vb/notprimeexception.vb" id="Snippet1"::: + + The `PrimeNumberGenerator` class shown in the following example uses the Sieve of Eratosthenes to calculate the sequence of prime numbers from 2 to a limit specified by the client in the call to its class constructor. The `GetPrimesFrom` method returns all prime numbers that are greater than or equal to a specified lower limit, but throws a `NotPrimeException` if that lower limit is not a prime number. + :::code language="csharp" source="~/snippets/csharp/System/Exception/Overview/primenumbergenerator.cs" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/Exception/Overview/primenumbergenerator.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.exception.class/vb/primenumbergenerator.vb" id="Snippet2"::: - - The following example makes two calls to the `GetPrimesFrom` method with non-prime numbers, one of which crosses application domain boundaries. In both cases, the exception is thrown and successfully handled in client code. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.exception.class/vb/primenumbergenerator.vb" id="Snippet2"::: + + The following example makes two calls to the `GetPrimesFrom` method with non-prime numbers, one of which crosses application domain boundaries. In both cases, the exception is thrown and successfully handled in client code. + :::code language="csharp" source="~/snippets/csharp/System/Exception/Overview/example.cs" id="Snippet3"::: :::code language="fsharp" source="~/snippets/fsharp/System/Exception/Overview/example.fs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.exception.class/vb/example.vb" id="Snippet3"::: - -## Windows Runtime and .NET Framework 4.5.1 - In .NET for Windows 8.x Store apps for Windows 8, some exception information is typically lost when an exception is propagated through non-.NET Framework stack frames. Starting with the .NET Framework 4.5.1 and Windows 8.1, the common language runtime continues to use the original object that was thrown unless that exception was modified in a non-.NET Framework stack frame. - - - -## Examples - The following example demonstrates a `catch` (`with` in F#) block that is defined to handle errors. This `catch` block also catches errors, because derives from and there is no `catch` block explicitly defined for errors. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.exception.class/vb/example.vb" id="Snippet3"::: + +## Windows Runtime and .NET Framework 4.5.1 + In .NET for Windows 8.x Store apps for Windows 8, some exception information is typically lost when an exception is propagated through non-.NET Framework stack frames. Starting with the .NET Framework 4.5.1 and Windows 8.1, the common language runtime continues to use the original object that was thrown unless that exception was modified in a non-.NET Framework stack frame. + + + +## Examples + The following example demonstrates a `catch` (`with` in F#) block that is defined to handle errors. This `catch` block also catches errors, because derives from and there is no `catch` block explicitly defined for errors. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/CatchException/CPP/catchexception.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Exception/Overview/catchexception.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Exception/Overview/catchexception.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/CatchException/VB/catchexception.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/CatchException/VB/catchexception.vb" id="Snippet1"::: + ]]> Handling and Throwing Exceptions @@ -390,23 +390,23 @@ Stack Trace: Initializes a new instance of the class. - property of the new instance to a system-supplied message that describes the error and takes into account the current system culture. - - All the derived classes should provide this parameterless constructor. The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||A system-supplied localized description.| - - - -## Examples - The following code example derives an `Exception` that uses a predefined message. The code demonstrates the use of the parameterless constructor for the derived class and the base `Exception` class. - + property of the new instance to a system-supplied message that describes the error and takes into account the current system culture. + + All the derived classes should provide this parameterless constructor. The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||A system-supplied localized description.| + + + +## Examples + The following code example derives an `Exception` that uses a predefined message. The code demonstrates the use of the parameterless constructor for the derived class and the base `Exception` class. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Exception.Ctor/CPP/new.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Exception/.ctor/new.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Exception/.ctor/new.fs" id="Snippet1"::: @@ -458,23 +458,23 @@ Stack Trace: The message that describes the error. Initializes a new instance of the class with a specified error message. - property of the new instance by using the `message` parameter. If the `message` parameter is `null`, this is the same as calling the constructor. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The error message string.| - - - -## Examples - The following code example derives an `Exception` for a specific condition. The code demonstrates the use of the constructor that takes a caller-specified message as a parameter, for both the derived class and the base `Exception` class. - + property of the new instance by using the `message` parameter. If the `message` parameter is `null`, this is the same as calling the constructor. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The error message string.| + + + +## Examples + The following code example derives an `Exception` for a specific condition. The code demonstrates the use of the constructor that takes a caller-specified message as a parameter, for both the derived class and the base `Exception` class. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Exception.Ctor/CPP/news.cpp" id="Snippet2"::: :::code language="csharp" source="~/snippets/csharp/System/Exception/.ctor/news.cs" interactive="try-dotnet" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/Exception/.ctor/news.fs" id="Snippet2"::: @@ -541,21 +541,21 @@ Stack Trace: The that contains contextual information about the source or destination. Initializes a new instance of the class with serialized data. - , ) constructor. The code serializes the instance to a file, deserializes the file into a new exception, which it throws, and then catches and displays the exception's data. - + , ) constructor. The code serializes the instance to a file, deserializes the file into a new exception, which it throws, and then catches and displays the exception's data. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Exception.GetObjectData/CPP/getobjdata.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Exception/.ctor/getobjdata.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Exception/.ctor/getobjdata.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Exception.GetObjectData/VB/getobjdata.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Exception.GetObjectData/VB/getobjdata.vb" id="Snippet1"::: + ]]> @@ -610,23 +610,23 @@ Stack Trace: The exception that is the cause of the current exception, or a null reference ( in Visual Basic) if no inner exception is specified. Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception. - property. The property returns the same value that is passed into the constructor, or a null reference (`Nothing` in Visual Basic) if the property does not supply the inner exception value to the constructor. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||The inner exception reference.| -||The error message string.| - - - -## Examples - The following code example derives an `Exception` for a specific condition. The code demonstrates the use of the constructor that takes a message and an inner exception as parameters, for both the derived class and the base `Exception` class. - + property. The property returns the same value that is passed into the constructor, or a null reference (`Nothing` in Visual Basic) if the property does not supply the inner exception value to the constructor. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||The inner exception reference.| +||The error message string.| + + + +## Examples + The following code example derives an `Exception` for a specific condition. The code demonstrates the use of the constructor that takes a message and an inner exception as parameters, for both the derived class and the base `Exception` class. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Exception.Ctor/CPP/newsi.cpp" id="Snippet3"::: :::code language="csharp" source="~/snippets/csharp/System/Exception/.ctor/newsi.cs" interactive="try-dotnet" id="Snippet3"::: :::code language="fsharp" source="~/snippets/fsharp/System/Exception/.ctor/newsi.fs" id="Snippet3"::: @@ -690,39 +690,39 @@ Stack Trace: Gets a collection of key/value pairs that provide additional user-defined information about the exception. An object that implements the interface and contains a collection of user-defined key/value pairs. The default is an empty collection. - object returned by the property to store and retrieve supplementary information relevant to the exception. The information is in the form of an arbitrary number of user-defined key/value pairs. The key component of each key/value pair is typically an identifying string, whereas the value component of the pair can be any type of object. - -## Key/Value Pair Security - The key/value pairs stored in the collection returned by the property are not secure. If your application calls a nested series of routines, and each routine contains exception handlers, the resulting call stack contains a hierarchy of those exception handlers. If a lower-level routine throws an exception, any upper-level exception handler in the call stack hierarchy can read and/or modify the key/value pairs stored in the collection by any other exception handler. This means you must guarantee that the information in the key/value pairs is not confidential and that your application will operate correctly if the information in the key/value pairs is corrupted. - -## Key Conflicts - A key conflict occurs when different exception handlers specify the same key to access a key/value pair. Use caution when developing your application because the consequence of a key conflict is that lower-level exception handlers can inadvertently communicate with higher-level exception handlers, and this communication might cause subtle program errors. However, if you are cautious you can use key conflicts to enhance your application. - -## Avoiding Key Conflicts - Avoid key conflicts by adopting a naming convention to generate unique keys for key/value pairs. For example, a naming convention might yield a key that consists of the period-delimited name of your application, the method that provides supplementary information for the pair, and a unique identifier. - - Suppose two applications, named Products and Suppliers, each has a method named Sales. The Sales method in the Products application provides the identification number (the stock keeping unit or SKU) of a product. The Sales method in the Suppliers application provides the identification number, or SID, of a supplier. Consequently, the naming convention for this example yields the keys, "Products.Sales.SKU" and "Suppliers.Sales.SID". - -## Exploiting Key Conflicts - Exploit key conflicts by using the presence of one or more special, prearranged keys to control processing. Suppose, in one scenario, the highest level exception handler in the call stack hierarchy catches all exceptions thrown by lower-level exception handlers. If a key/value pair with a special key exists, the high-level exception handler formats the remaining key/value pairs in the object in some nonstandard way; otherwise, the remaining key/value pairs are formatted in some normal manner. - - Now suppose, in another scenario, the exception handler at each level of the call stack hierarchy catches the exception thrown by the next lower-level exception handler. In addition, each exception handler knows the collection returned by the property contains a set of key/value pairs that can be accessed with a prearranged set of keys. - - Each exception handler uses the prearranged set of keys to update the value component of the corresponding key/value pair with information unique to that exception handler. After the update process is complete, the exception handler throws the exception to the next higher-level exception handler. Finally, the highest level exception handler accesses the key/value pairs and displays the consolidated update information from all the lower-level exception handlers. - - - -## Examples - The following example demonstrates how to add and retrieve information using the property. - + object returned by the property to store and retrieve supplementary information relevant to the exception. The information is in the form of an arbitrary number of user-defined key/value pairs. The key component of each key/value pair is typically an identifying string, whereas the value component of the pair can be any type of object. + +## Key/Value Pair Security + The key/value pairs stored in the collection returned by the property are not secure. If your application calls a nested series of routines, and each routine contains exception handlers, the resulting call stack contains a hierarchy of those exception handlers. If a lower-level routine throws an exception, any upper-level exception handler in the call stack hierarchy can read and/or modify the key/value pairs stored in the collection by any other exception handler. This means you must guarantee that the information in the key/value pairs is not confidential and that your application will operate correctly if the information in the key/value pairs is corrupted. + +## Key Conflicts + A key conflict occurs when different exception handlers specify the same key to access a key/value pair. Use caution when developing your application because the consequence of a key conflict is that lower-level exception handlers can inadvertently communicate with higher-level exception handlers, and this communication might cause subtle program errors. However, if you are cautious you can use key conflicts to enhance your application. + +## Avoiding Key Conflicts + Avoid key conflicts by adopting a naming convention to generate unique keys for key/value pairs. For example, a naming convention might yield a key that consists of the period-delimited name of your application, the method that provides supplementary information for the pair, and a unique identifier. + + Suppose two applications, named Products and Suppliers, each has a method named Sales. The Sales method in the Products application provides the identification number (the stock keeping unit or SKU) of a product. The Sales method in the Suppliers application provides the identification number, or SID, of a supplier. Consequently, the naming convention for this example yields the keys, "Products.Sales.SKU" and "Suppliers.Sales.SID". + +## Exploiting Key Conflicts + Exploit key conflicts by using the presence of one or more special, prearranged keys to control processing. Suppose, in one scenario, the highest level exception handler in the call stack hierarchy catches all exceptions thrown by lower-level exception handlers. If a key/value pair with a special key exists, the high-level exception handler formats the remaining key/value pairs in the object in some nonstandard way; otherwise, the remaining key/value pairs are formatted in some normal manner. + + Now suppose, in another scenario, the exception handler at each level of the call stack hierarchy catches the exception thrown by the next lower-level exception handler. In addition, each exception handler knows the collection returned by the property contains a set of key/value pairs that can be accessed with a prearranged set of keys. + + Each exception handler uses the prearranged set of keys to update the value component of the corresponding key/value pair with information unique to that exception handler. After the update process is complete, the exception handler throws the exception to the next higher-level exception handler. Finally, the highest level exception handler accesses the key/value pairs and displays the consolidated update information from all the lower-level exception handlers. + + + +## Examples + The following example demonstrates how to add and retrieve information using the property. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/exception.data/CPP/data.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Exception/Data/data.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Exception/Data/data.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/exception.data/VB/data.vb" id="Snippet1"::: - + ]]> @@ -779,24 +779,24 @@ Stack Trace: When overridden in a derived class, returns the that is the root cause of one or more subsequent exceptions. The first exception thrown in a chain of exceptions. If the property of the current exception is a null reference ( in Visual Basic), this property returns the current exception. - @@ -869,21 +869,21 @@ Stack Trace: The that contains contextual information about the source or destination. When overridden in a derived class, sets the with information about the exception. - with all the exception object data targeted for serialization. During deserialization, the exception is reconstituted from the `SerializationInfo` transmitted over the stream. - - - -## Examples - The following code example defines a derived serializable `Exception` class that implements `GetObjectData`, which makes minor changes to two properties and then calls the base class to perform the serialization. The example forces a divide-by-0 error and then creates an instance of the derived exception. The code serializes the instance to a file, deserializes the file into a new exception, which it throws, and then catches and displays the exception's data. - + with all the exception object data targeted for serialization. During deserialization, the exception is reconstituted from the `SerializationInfo` transmitted over the stream. + + + +## Examples + The following code example defines a derived serializable `Exception` class that implements `GetObjectData`, which makes minor changes to two properties and then calls the base class to perform the serialization. The example forces a divide-by-0 error and then creates an instance of the derived exception. The code serializes the instance to a file, deserializes the file into a new exception, which it throws, and then catches and displays the exception's data. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Exception.GetObjectData/CPP/getobjdata.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Exception/.ctor/getobjdata.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Exception/.ctor/getobjdata.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Exception.GetObjectData/VB/getobjdata.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Exception.GetObjectData/VB/getobjdata.vb" id="Snippet1"::: + ]]> The parameter is a null reference ( in Visual Basic). @@ -939,11 +939,11 @@ Stack Trace: Gets the runtime type of the current instance. A object that represents the exact runtime type of the current instance. - method exists to support the .NET Framework infrastructure, and internally invokes the fundamental method, . - + method exists to support the .NET Framework infrastructure, and internally invokes the fundamental method, . + ]]> @@ -995,18 +995,18 @@ Stack Trace: Gets or sets a link to the help file associated with this exception. The Uniform Resource Name (URN) or Uniform Resource Locator (URL). - Gets or sets HRESULT, a coded numerical value that is assigned to a specific exception. The HRESULT value. - property's setter is protected, whereas its getter is public. In previous versions of the .NET Framework, both getter and setter are protected. - - - -## Examples - The following code example defines a derived `Exception` class that sets the `HResult` property to a custom value in its constructor. - + property's setter is protected, whereas its getter is public. In previous versions of the .NET Framework, both getter and setter are protected. + + + +## Examples + The following code example defines a derived `Exception` class that sets the `HResult` property to a custom value in its constructor. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Exception.HResult/CPP/hresult.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Exception/HResult/hresult.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Exception/HResult/hresult.fs" id="Snippet1"::: @@ -1130,24 +1130,24 @@ Stack Trace: Gets the instance that caused the current exception. An object that describes the error that caused the current exception. The property returns the same value as was passed into the constructor, or if the inner exception value was not supplied to the constructor. This property is read-only. - property of `X` should contain a reference to `Y`. - - Use the property to obtain the set of exceptions that led to the current exception. - - You can create a new exception that catches an earlier exception. The code that handles the second exception can make use of the additional information from the earlier exception to handle the error more appropriately. - - Suppose that there is a function that reads a file and formats the data from that file. In this example, as the code tries to read the file, an is thrown. The function catches the and throws a . The could be saved in the property of the , enabling the code that catches the to examine the cause of the initial error. - - The property, which holds a reference to the inner exception, is set upon initialization of the exception object. - - - -## Examples - The following example demonstrates throwing and catching an exception that references an inner exception. - + property of `X` should contain a reference to `Y`. + + Use the property to obtain the set of exceptions that led to the current exception. + + You can create a new exception that catches an earlier exception. The code that handles the second exception can make use of the additional information from the earlier exception to handle the error more appropriately. + + Suppose that there is a function that reads a file and formats the data from that file. In this example, as the code tries to read the file, an is thrown. The function catches the and throws a . The could be saved in the property of the , enabling the code that catches the to examine the cause of the initial error. + + The property, which holds a reference to the inner exception, is set upon initialization of the exception object. + + + +## Examples + The following example demonstrates throwing and catching an exception that references an inner exception. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/InnerEx/CPP/innerex.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Exception/InnerException/innerex.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Exception/InnerException/innerex.fs" id="Snippet1"::: @@ -1215,38 +1215,36 @@ Stack Trace: Gets a message that describes the current exception. The error message that explains the reason for the exception, or an empty string (""). - property should completely describe the error and, when possible, should also explain how to correct the error. Top-level exception handlers may display the message to end-users, so you should ensure that it is grammatically correct and that each sentence of the message ends with a period. Do not use question marks or exclamation points. If your application uses localized exception messages, you should ensure that they are accurately translated. - + property should completely describe the error and, when possible, should also explain how to correct the error. Top-level exception handlers may display the message to end-users, so you should ensure that it is grammatically correct and that each sentence of the message ends with a period. Do not use question marks or exclamation points. If your application uses localized exception messages, you should ensure that they are accurately translated. + > [!IMPORTANT] -> Do not disclose sensitive information in exception messages without checking for the appropriate permissions. - - The value of the property is included in the information returned by . The property is set only when creating an . If no message was supplied to the constructor for the current instance, the system supplies a default message that is formatted using the current system culture. - -## Windows Runtime and .NET Framework 4.5.1 - Starting with the .NET Framework 4.5.1 and Windows 8.1, the fidelity of error messages from exceptions that are propagated from Windows Runtime types and members that are not part of the .NET Framework is improved. In particular, exception messages from Visual C++ component extensions (C++/CX) are now propagated back into .NET Framework objects. - - - -## Examples +> Do not disclose sensitive information in exception messages without checking for the appropriate permissions. + + The value of the property is included in the information returned by . The property is set only when creating an . If no message was supplied to the constructor for the current instance, the system supplies a default message that is formatted using the current system culture. + +## Windows Runtime and .NET Framework 4.5.1 + Starting with the .NET Framework 4.5.1 and Windows 8.1, the fidelity of error messages from exceptions that are propagated from Windows Runtime types and members that are not part of the .NET Framework is improved. In particular, exception messages from Visual C++ component extensions (C++/CX) are now propagated back into .NET Framework objects. + + + +## Examples The following code example throws and then catches an exception and displays the exception's text message using the property. - + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Exception.Properties/CPP/properties.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Exception/HelpLink/properties.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Exception/HelpLink/properties.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Exception.Properties/VB/properties.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Exception.Properties/VB/properties.vb" id="Snippet1"::: + ]]> If you throw an exception from a property, and you need to refer in the text of to the property argument that you set or get, use "value" as the name of the property argument. - The property is overridden in classes that require control over message content or format. Application code typically accesses this property when it needs to display information about an exception that has been caught. - - The error message should be localized. + The property is overridden in classes that require control over message content or format. Application code typically accesses this property when it needs to display information about an exception that has been caught. The error message should be localized. @@ -1295,19 +1293,19 @@ Stack Trace: Occurs when an exception is serialized to create an exception state object that contains serialized data about the exception. - interface. - - When the event is subscribed to, the exception is deserialized and created as an empty exception. The exception's constructor is not run, and the exception state is also deserialized. The callback method of the exception state object is then notified so that it can push deserialized data into the empty exception. - - The event enables transparent exception types to serialize and deserialize exception data. Transparent code can execute commands within the bounds of the permission set it is operating within, but cannot execute, call, derive from, or contain critical code. - - If the event is not subscribed to, deserialization occurs as usual using the constructor. - + interface. + + When the event is subscribed to, the exception is deserialized and created as an empty exception. The exception's constructor is not run, and the exception state is also deserialized. The callback method of the exception state object is then notified so that it can push deserialized data into the empty exception. + + The event enables transparent exception types to serialize and deserialize exception data. Transparent code can execute commands within the bounds of the permission set it is operating within, but cannot execute, call, derive from, or contain critical code. + + If the event is not subscribed to, deserialization occurs as usual using the constructor. + Typically, a handler for the event is added in the exception's constructor to provide for its serialization. But because the constructor is not executed when the event handler executes, serializing a deserialized exception can throw a exception when you try to deserialize the exception. To avoid this, you should also add the handler for the event in the method. See the Examples section for an illustration. - + ]]> @@ -1366,20 +1364,20 @@ Stack Trace: Gets or sets the name of the application or the object that causes the error. The name of the application or the object that causes the error. - property is not set explicitly, the runtime automatically sets it to the name of the assembly in which the exception originated. - - - -## Examples - The following example throws an `Exception` that sets the `Source` property in its constructor and then catches the exception and displays `Source`. - + property is not set explicitly, the runtime automatically sets it to the name of the assembly in which the exception originated. + + + +## Examples + The following example throws an `Exception` that sets the `Source` property in its constructor and then catches the exception and displays `Source`. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Exception.Properties/CPP/properties.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Exception/HelpLink/properties.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Exception/HelpLink/properties.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Exception.Properties/VB/properties.vb" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Exception.Properties/VB/properties.vb" id="Snippet1"::: ]]> @@ -1437,33 +1435,31 @@ Stack Trace: Gets a string representation of the immediate frames on the call stack. A string that describes the immediate frames of the call stack. If no stack trace is available (such as prior to stack unwinding from a statement), the value is . - property returns the frames of the call stack that originate at the location where the exception was thrown. You can obtain information about additional frames in the call stack by creating a new instance of the class and using its method. - - The common language runtime (CLR) updates the stack trace whenever an exception is thrown in application code (by using the `throw` keyword). If the exception was rethrown in a method that is different than the method where it was originally thrown, the stack trace contains both the location in the method where the exception was originally thrown, and the location in the method where the exception was rethrown. If the exception is thrown, and later rethrown, in the same method, the stack trace only contains the location where the exception was rethrown and does not include the location where the exception was originally thrown. - - The property may not report as many method calls as expected because of code transformations, such as inlining, that occur during optimization. - - - -## Examples - The following code example throws an `Exception` and then catches it and displays a stack trace using the `StackTrace` property. - + property returns the frames of the call stack that originate at the location where the exception was thrown. You can obtain information about additional frames in the call stack by creating a new instance of the class and using its method. + + The common language runtime (CLR) updates the stack trace whenever an exception is thrown in application code (by using the `throw` keyword). If the exception was rethrown in a method that is different than the method where it was originally thrown, the stack trace contains both the location in the method where the exception was originally thrown, and the location in the method where the exception was rethrown. If the exception is thrown, and later rethrown, in the same method, the stack trace only contains the location where the exception was rethrown and does not include the location where the exception was originally thrown. + + The property may not report as many method calls as expected because of code transformations, such as inlining, that occur during optimization. + + + +## Examples + The following code example throws an `Exception` and then catches it and displays a stack trace using the `StackTrace` property. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Exception.Properties/CPP/properties.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Exception/HelpLink/properties.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Exception/HelpLink/properties.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Exception.Properties/VB/properties.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Exception.Properties/VB/properties.vb" id="Snippet1"::: + ]]> - The property is overridden in classes that require control over the stack trace content or format. - - By default, the stack trace is captured immediately before an exception object is thrown. Use to get stack trace information when no exception is being thrown. + The property is overridden in classes that require control over the stack trace content or format. By default, the stack trace is captured immediately before an exception object is thrown. Use to get stack trace information when no exception is being thrown. @@ -1519,19 +1515,19 @@ Stack Trace: Gets the method that throws the current exception. The that threw the current exception. - obtains the method from the stack trace. If the stack trace is a null reference, also returns a null reference. - + obtains the method from the stack trace. If the stack trace is a null reference, also returns a null reference. + > [!NOTE] -> The property may not accurately report the name of the method in which an exception was thrown if the exception handler handles an exception across application domain boundaries. - - - -## Examples - The following code example throws an `Exception` and then catches it and displays the originating method using the `TargetSite` property. - +> The property may not accurately report the name of the method in which an exception was thrown if the exception handler handles an exception across application domain boundaries. + + + +## Examples + The following code example throws an `Exception` and then catches it and displays the originating method using the `TargetSite` property. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Exception.Properties/CPP/properties.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Exception/HelpLink/properties.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Exception/HelpLink/properties.fs" id="Snippet1"::: @@ -1596,27 +1592,27 @@ Stack Trace: Creates and returns a string representation of the current exception. A string representation of the current exception. - returns a representation of the current exception that is intended to be understood by humans. Where the exception contains culture-sensitive data, the string representation returned by `ToString` is required to take into account the current system culture. Although there are no exact requirements for the format of the returned string, it should attempt to reflect the value of the object as perceived by the user. - - The default implementation of obtains the name of the class that threw the current exception, the message, the result of calling on the inner exception, and the result of calling . If any of these members is `null`, its value is not included in the returned string. - - If there is no error message or if it is an empty string (""), then no error message is returned. The name of the inner exception and the stack trace are returned only if they are not `null`. - - This method overrides . - - - -## Examples - The following example causes an exception and displays the result of calling on that exception. Note that the method is called implicitly when the Exception class instance appears in the argument list of the method. - + returns a representation of the current exception that is intended to be understood by humans. Where the exception contains culture-sensitive data, the string representation returned by `ToString` is required to take into account the current system culture. Although there are no exact requirements for the format of the returned string, it should attempt to reflect the value of the object as perceived by the user. + + The default implementation of obtains the name of the class that threw the current exception, the message, the result of calling on the inner exception, and the result of calling . If any of these members is `null`, its value is not included in the returned string. + + If there is no error message or if it is an empty string (""), then no error message is returned. The name of the inner exception and the stack trace are returned only if they are not `null`. + + This method overrides . + + + +## Examples + The following example causes an exception and displays the result of calling on that exception. Note that the method is called implicitly when the Exception class instance appears in the argument list of the method. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.exception.tostring/cpp/ToStringEx1.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Exception/ToString/ToStringEx1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Exception/ToString/ToStringEx1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.exception.tostring/vb/ToStringEx1.vb" id="Snippet1"::: - + ]]> diff --git a/xml/System/ExecutionEngineException.xml b/xml/System/ExecutionEngineException.xml index 493de1f2948..3bb156e990f 100644 --- a/xml/System/ExecutionEngineException.xml +++ b/xml/System/ExecutionEngineException.xml @@ -67,11 +67,11 @@ The exception that is thrown when there is an internal error in the execution engine of the common language runtime. This class cannot be inherited. - . If further execution of your application cannot be sustained, use the method. - + . If further execution of your application cannot be sustained, use the method. + ]]> @@ -120,18 +120,18 @@ Initializes a new instance of the class. - property of the new instance to a system-supplied message that describes the error, such as "Internal error occurred." This message takes into account the current system culture. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The localized error message string.| - + property of the new instance to a system-supplied message that describes the error, such as "Internal error occurred." This message takes into account the current system culture. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The localized error message string.| + ]]> @@ -174,18 +174,18 @@ The message that describes the error. Initializes a new instance of the class with a specified error message. - property of the new exception using the `message` parameter. The content of `message` is intended to be understood by humans. The caller of this constructor is required to ensure that this string has been localized for the current system culture. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The error message string.| - + property of the new exception using the `message` parameter. The content of `message` is intended to be understood by humans. The caller of this constructor is required to ensure that this string has been localized for the current system culture. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The error message string.| + ]]> @@ -230,18 +230,18 @@ The exception that is the cause of the current exception. If the parameter is not a null reference ( in Visual Basic), the current exception is raised in a block that handles the inner exception. Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception. - property. The property returns the same value that is passed into the constructor, or a null reference (`Nothing` in Visual Basic) if the property does not supply the inner exception value to the constructor. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||The inner exception reference.| -||The error message string.| - + property. The property returns the same value that is passed into the constructor, or a null reference (`Nothing` in Visual Basic) if the property does not supply the inner exception value to the constructor. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||The inner exception reference.| +||The error message string.| + ]]> diff --git a/xml/System/FakeLoggerServiceProviderExtensions.xml b/xml/System/FakeLoggerServiceProviderExtensions.xml index 68400677618..8ed71dab7e8 100644 --- a/xml/System/FakeLoggerServiceProviderExtensions.xml +++ b/xml/System/FakeLoggerServiceProviderExtensions.xml @@ -15,8 +15,8 @@ - Extensions for configuring fake logging, used in unit tests. - + Extensions for configuring fake logging, used in unit tests. + To be added. @@ -47,8 +47,8 @@ The service provider containing the logger. - Gets the object that collects log records sent to the fake logger. - + Gets the object that collects log records sent to the fake logger. + The collector which tracks records logged to fake loggers. To be added. No collector exists in the provider. diff --git a/xml/System/FakeRedactionServiceProviderExtensions.xml b/xml/System/FakeRedactionServiceProviderExtensions.xml index b7ae6cd4045..1f1cc374ac0 100644 --- a/xml/System/FakeRedactionServiceProviderExtensions.xml +++ b/xml/System/FakeRedactionServiceProviderExtensions.xml @@ -15,8 +15,8 @@ - Extensions that allow registering a fake redactor in the application. - + Extensions that allow registering a fake redactor in the application. + To be added. @@ -47,12 +47,11 @@ The container used to obtain the collector instance. - Gets the fake redactor collector instance from the dependency injection container. - + Gets the fake redactor collector instance from the dependency injection container. + The obtained collector. - should be registered and used only with fake redaction implementation. - + should be registered and used only with fake redaction implementation. The collector is not in the container. is . diff --git a/xml/System/FieldAccessException.xml b/xml/System/FieldAccessException.xml index 2b1aabfac43..646b4cc1c6f 100644 --- a/xml/System/FieldAccessException.xml +++ b/xml/System/FieldAccessException.xml @@ -62,18 +62,18 @@ The exception that is thrown when there is an invalid attempt to access a private or protected field inside a class. - uses the HRESULT COR_E_FIELDACCESS, which has the value 0x80131507. - - For a list of initial property values for an instance of , see the constructors. - + uses the HRESULT COR_E_FIELDACCESS, which has the value 0x80131507. + + For a list of initial property values for an instance of , see the constructors. + > [!NOTE] -> This exception is not included in the [.NET for Windows Store apps](https://go.microsoft.com/fwlink/?LinkID=247912) or the [Portable Class Library](/dotnet/standard/cross-platform/cross-platform-development-with-the-portable-class-library), but it is thrown by some members that are. To catch the exception in that case, write a `catch` statement for instead. - +> This exception is not included in the [.NET for Windows Store apps](https://go.microsoft.com/fwlink/?LinkID=247912) or the [Portable Class Library](/dotnet/standard/cross-platform/cross-platform-development-with-the-portable-class-library), but it is thrown by some members that are. To catch the exception in that case, write a `catch` statement for instead. + ]]> @@ -126,18 +126,18 @@ Initializes a new instance of the class. - property of the new instance to a system-supplied message that describes the error, such as "Attempted to access a field that is not accessible by the caller." This message takes the current system culture into account. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The localized error message string.| - + property of the new instance to a system-supplied message that describes the error, such as "Attempted to access a field that is not accessible by the caller." This message takes the current system culture into account. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The localized error message string.| + ]]> @@ -182,18 +182,18 @@ The error message that explains the reason for the exception. Initializes a new instance of the class with a specified error message. - property of the new instance by using the `message` parameter. The content of `message` is intended to be understood by humans. The caller of this constructor must ensure that this string has been localized for the current system culture. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The localized error message string.| - + property of the new instance by using the `message` parameter. The content of `message` is intended to be understood by humans. The caller of this constructor must ensure that this string has been localized for the current system culture. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The localized error message string.| + ]]> @@ -255,11 +255,11 @@ The contextual information about the source or destination. Initializes a new instance of the class with serialized data. - @@ -306,18 +306,18 @@ The exception that is the cause of the current exception. If the parameter is not , the current exception is raised in a block that handles the inner exception. Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception. - property. The property returns the same value that is passed into the constructor, or returns `null` if it does not supply the inner exception value to the constructor. The caller of this constructor must ensure that this string has been localized for the current system culture. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||The inner exception reference.| -||The localized error message string.| - + property. The property returns the same value that is passed into the constructor, or returns `null` if it does not supply the inner exception value to the constructor. The caller of this constructor must ensure that this string has been localized for the current system culture. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||The inner exception reference.| +||The localized error message string.| + ]]> diff --git a/xml/System/FileStyleUriParser.xml b/xml/System/FileStyleUriParser.xml index e86eeccf1e1..89dc3867ba6 100644 --- a/xml/System/FileStyleUriParser.xml +++ b/xml/System/FileStyleUriParser.xml @@ -73,11 +73,11 @@ Creates a customizable parser based on the File scheme. - - + + ]]> diff --git a/xml/System/FlagsAttribute.xml b/xml/System/FlagsAttribute.xml index 170bdec2ea6..47b252c4ed9 100644 --- a/xml/System/FlagsAttribute.xml +++ b/xml/System/FlagsAttribute.xml @@ -60,57 +60,57 @@ Indicates that an enumeration can be treated as a bit field; that is, a set of flags. - is applied to this class, and its property specifies `false`. This attribute can only be applied to enumerations. - -## Guidelines for FlagsAttribute and Enum - -- Use the custom attribute for an enumeration only if a bitwise operation (AND, OR, EXCLUSIVE OR) is to be performed on a numeric value. - -- Define enumeration constants in powers of two, that is, 1, 2, 4, 8, and so on. This means the individual flags in combined enumeration constants do not overlap. - -- Consider creating an enumerated constant for commonly used flag combinations. For example, if you have an enumeration used for file I/O operations that contains the enumerated constants `Read = 1` and `Write = 2`, consider creating the enumerated constant `ReadWrite = Read OR Write`, which combines the `Read` and `Write` flags. In addition, the bitwise OR operation used to combine the flags might be considered an advanced concept in some circumstances that should not be required for simple tasks. - -- Use caution if you define a negative number as a flag enumerated constant because many flag positions might be set to 1, which might make your code confusing and encourage coding errors. - -- A convenient way to test whether a flag is set in a numeric value is to perform a bitwise AND operation between the numeric value and the flag enumerated constant, which sets all bits in the numeric value to zero that do not correspond to the flag, then test whether the result of that operation is equal to the flag enumerated constant. - -- Use `None` as the name of the flag enumerated constant whose value is zero. You cannot use the `None` enumerated constant in a bitwise AND operation to test for a flag because the result is always zero. However, you can perform a logical, not a bitwise, comparison between the numeric value and the `None` enumerated constant to determine whether any bits in the numeric value are set. - - If you create a value enumeration instead of a flags enumeration, it is still worthwhile to create a `None` enumerated constant. The reason is that by default the memory used for the enumeration is initialized to zero by the common language runtime. Consequently, if you do not define a constant whose value is zero, the enumeration will contain an illegal value when it is created. - - If there is an obvious default case your application needs to represent, consider using an enumerated constant whose value is zero to represent the default. If there is no default case, consider using an enumerated constant whose value is zero that means the case that is not represented by any of the other enumerated constants. - -- Do not define an enumeration value solely to mirror the state of the enumeration itself. For example, do not define an enumerated constant that merely marks the end of the enumeration. If you need to determine the last value of the enumeration, check for that value explicitly. In addition, you can perform a range check for the first and last enumerated constant if all values within the range are valid. - -- Do not specify enumerated constants that are reserved for future use. - -- When you define a method or property that takes an enumerated constant as a value, consider validating the value. The reason is that you can cast a numeric value to the enumeration type even if that numeric value is not defined in the enumeration. - - - -## Examples - The following example illustrates the use of the `FlagsAttribute` attribute and shows the effect on the method of using `FlagsAttribute` on an declaration. - + is applied to this class, and its property specifies `false`. This attribute can only be applied to enumerations. + +## Guidelines for FlagsAttribute and Enum + +- Use the custom attribute for an enumeration only if a bitwise operation (AND, OR, EXCLUSIVE OR) is to be performed on a numeric value. + +- Define enumeration constants in powers of two, that is, 1, 2, 4, 8, and so on. This means the individual flags in combined enumeration constants do not overlap. + +- Consider creating an enumerated constant for commonly used flag combinations. For example, if you have an enumeration used for file I/O operations that contains the enumerated constants `Read = 1` and `Write = 2`, consider creating the enumerated constant `ReadWrite = Read OR Write`, which combines the `Read` and `Write` flags. In addition, the bitwise OR operation used to combine the flags might be considered an advanced concept in some circumstances that should not be required for simple tasks. + +- Use caution if you define a negative number as a flag enumerated constant because many flag positions might be set to 1, which might make your code confusing and encourage coding errors. + +- A convenient way to test whether a flag is set in a numeric value is to perform a bitwise AND operation between the numeric value and the flag enumerated constant, which sets all bits in the numeric value to zero that do not correspond to the flag, then test whether the result of that operation is equal to the flag enumerated constant. + +- Use `None` as the name of the flag enumerated constant whose value is zero. You cannot use the `None` enumerated constant in a bitwise AND operation to test for a flag because the result is always zero. However, you can perform a logical, not a bitwise, comparison between the numeric value and the `None` enumerated constant to determine whether any bits in the numeric value are set. + + If you create a value enumeration instead of a flags enumeration, it is still worthwhile to create a `None` enumerated constant. The reason is that by default the memory used for the enumeration is initialized to zero by the common language runtime. Consequently, if you do not define a constant whose value is zero, the enumeration will contain an illegal value when it is created. + + If there is an obvious default case your application needs to represent, consider using an enumerated constant whose value is zero to represent the default. If there is no default case, consider using an enumerated constant whose value is zero that means the case that is not represented by any of the other enumerated constants. + +- Do not define an enumeration value solely to mirror the state of the enumeration itself. For example, do not define an enumerated constant that merely marks the end of the enumeration. If you need to determine the last value of the enumeration, check for that value explicitly. In addition, you can perform a range check for the first and last enumerated constant if all values within the range are valid. + +- Do not specify enumerated constants that are reserved for future use. + +- When you define a method or property that takes an enumerated constant as a value, consider validating the value. The reason is that you can cast a numeric value to the enumeration type even if that numeric value is not defined in the enumeration. + + + +## Examples + The following example illustrates the use of the `FlagsAttribute` attribute and shows the effect on the method of using `FlagsAttribute` on an declaration. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.FlagsAttribute/CPP/flags.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/FlagsAttribute/Overview/flags.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/FlagsAttribute/Overview/flags.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.FlagsAttribute/VB/flags.vb" id="Snippet1"::: - - The preceding example defines two color-related enumerations, `SingleHue` and `MultiHue`. The latter has the `FlagsAttribute` attribute; the former does not. The example shows the difference in behavior when a range of integers, including integers that do not represent underlying values of the enumeration type, are cast to the enumeration type and their string representations displayed. For example, note that 3 cannot be represented as a `SingleHue` value because 3 is not the underlying value of any `SingleHue` member, whereas the `FlagsAttribute` attribute makes it possible to represent 3 as a `MultiHue` value of `Black, Red`. + + The preceding example defines two color-related enumerations, `SingleHue` and `MultiHue`. The latter has the `FlagsAttribute` attribute; the former does not. The example shows the difference in behavior when a range of integers, including integers that do not represent underlying values of the enumeration type, are cast to the enumeration type and their string representations displayed. For example, note that 3 cannot be represented as a `SingleHue` value because 3 is not the underlying value of any `SingleHue` member, whereas the `FlagsAttribute` attribute makes it possible to represent 3 as a `MultiHue` value of `Black, Red`. The following example defines another enumeration with the `FlagsAttribute` attribute and shows how to use bitwise logical and equality operators to determine whether one or more bit fields are set in an enumeration value. You can also use the method to do that, but that is not shown in this example. - + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.FlagsAttribute/CPP/flags1.cpp" id="Snippet2"::: :::code language="csharp" source="~/snippets/csharp/System/FlagsAttribute/Overview/flags1.cs" interactive="try-dotnet" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/FlagsAttribute/Overview/flags1.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.FlagsAttribute/VB/flags1.vb" id="Snippet2"::: - + ]]> @@ -152,23 +152,23 @@ Initializes a new instance of the class. - method to display the types of service provided to each household. - + method to display the types of service provided to each household. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.FlagsAttribute/CPP/flags1.cpp" id="Snippet2"::: :::code language="csharp" source="~/snippets/csharp/System/FlagsAttribute/Overview/flags1.cs" interactive="try-dotnet" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/FlagsAttribute/Overview/flags1.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.FlagsAttribute/VB/flags1.vb" id="Snippet2"::: - - The following example illustrates the use of the `FlagsAttribute` attribute and shows the effect on the method of using `FlagsAttribute` on an declaration. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.FlagsAttribute/VB/flags1.vb" id="Snippet2"::: + + The following example illustrates the use of the `FlagsAttribute` attribute and shows the effect on the method of using `FlagsAttribute` on an declaration. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.FlagsAttribute/CPP/flags.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/FlagsAttribute/Overview/flags.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/FlagsAttribute/Overview/flags.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.FlagsAttribute/VB/flags.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.FlagsAttribute/VB/flags.vb" id="Snippet1"::: + ]]> diff --git a/xml/System/FormatException.xml b/xml/System/FormatException.xml index 0822bd4a297..4e2e27bf713 100644 --- a/xml/System/FormatException.xml +++ b/xml/System/FormatException.xml @@ -70,111 +70,111 @@ The exception that is thrown when the format of an argument is invalid, or when a composite format string is not well formed. - exception can be thrown for one of the following reasons: - -- In a call to a method that converts a string to some other data type, the string doesn't conform to the required pattern. This typically occurs when calling some methods of the class and the `Parse` and `ParseExact` methods of some types. - - In most cases, particularly if the string that you're converting is input by a user or read from a file, you should use a `try/catch` (`try/with` in F#) block and handle the exception if the conversion is unsuccessful. You can also replace the call to the conversion method with a call to a `TryParse` or `TryParseExact` method, if one exists. However, a exception that is thrown when you're trying to parse a predefined or hard-coded string indicates a program error. In this case, you should correct the error rather than handle the exception. - - The conversion of a string to the following types in the namespace can throw a exception: - - - . The and methods require the string to be converted to be "True", "true", "False", or "false". Any other value throws a exception. - - - and . All date and time data is interpreted based on the formatting conventions of a particular culture: either the current culture (or, in some cases, the current application domain culture), the invariant culture, or a specified culture. When you call the and methods, date and time data must also conform *exactly* to a pattern specified by one or more [standard format strings](/dotnet/standard/base-types/standard-date-and-time-format-strings) or [custom format strings](/dotnet/standard/base-types/custom-date-and-time-format-strings) that are provided as arguments in the method call. If it doesn't conform to an expected culture-specific pattern, a exception is thrown. This means that date and time data saved in a culture-specific format on one system might not parse successfully on another system. - - For more information about parsing dates and times, see [Parsing Date and Time Strings](/dotnet/standard/base-types/parsing-datetime) and the documentation for the method that threw the exception. - - - **GUIDs.** The string representation of a GUID must consist of 32 hexadecimal digits (0-F), and must be in one of the five formats output by the method. For more information, see the method. - - - **Numeric types, including all signed integers, unsigned integers, and floating-point types.** The string to be parsed must consist of the Latin digits 0-9. A positive or negative sign, decimal separator, group separators, and currency symbol may also be permitted. Trying to parse a string that contains any other character always throws a exception. - - All numeric strings are interpreted based on the formatting conventions of a particular culture: either the current culture, the invariant culture, or a specified culture. As a result, a numeric string that is parsed by using the conventions of one culture might fail when using the conventions of another. - - For more information about parsing numeric strings, see [Parsing Numeric Strings](/dotnet/standard/base-types/parsing-numeric) and the documentation for the specific method that threw the exception. - - - **Time intervals.** The string to be parsed must be either in fixed culture-insensitive format or in a culture-sensitive format defined by the current culture, the invariant culture, or a specified culture. If the string isn't in an appropriate format, or if, at the minimum, the days, hours, and minutes components of the time interval aren't present, the parsing method throws a exception. For more information, see the documentation for the parsing method that threw the exception. - -- A type implements the interface, which supports format strings that define how an object is converted to its string representation, and an invalid format string is used. This is most common in a formatting operation. In the following example, the "Q" standard format string is used in a composite format string to format a number. However, "Q" is not a valid [standard format string](/dotnet/standard/base-types/standard-numeric-format-strings). - + exception can be thrown for one of the following reasons: + +- In a call to a method that converts a string to some other data type, the string doesn't conform to the required pattern. This typically occurs when calling some methods of the class and the `Parse` and `ParseExact` methods of some types. + + In most cases, particularly if the string that you're converting is input by a user or read from a file, you should use a `try/catch` (`try/with` in F#) block and handle the exception if the conversion is unsuccessful. You can also replace the call to the conversion method with a call to a `TryParse` or `TryParseExact` method, if one exists. However, a exception that is thrown when you're trying to parse a predefined or hard-coded string indicates a program error. In this case, you should correct the error rather than handle the exception. + + The conversion of a string to the following types in the namespace can throw a exception: + + - . The and methods require the string to be converted to be "True", "true", "False", or "false". Any other value throws a exception. + + - and . All date and time data is interpreted based on the formatting conventions of a particular culture: either the current culture (or, in some cases, the current application domain culture), the invariant culture, or a specified culture. When you call the and methods, date and time data must also conform *exactly* to a pattern specified by one or more [standard format strings](/dotnet/standard/base-types/standard-date-and-time-format-strings) or [custom format strings](/dotnet/standard/base-types/custom-date-and-time-format-strings) that are provided as arguments in the method call. If it doesn't conform to an expected culture-specific pattern, a exception is thrown. This means that date and time data saved in a culture-specific format on one system might not parse successfully on another system. + + For more information about parsing dates and times, see [Parsing Date and Time Strings](/dotnet/standard/base-types/parsing-datetime) and the documentation for the method that threw the exception. + + - **GUIDs.** The string representation of a GUID must consist of 32 hexadecimal digits (0-F), and must be in one of the five formats output by the method. For more information, see the method. + + - **Numeric types, including all signed integers, unsigned integers, and floating-point types.** The string to be parsed must consist of the Latin digits 0-9. A positive or negative sign, decimal separator, group separators, and currency symbol may also be permitted. Trying to parse a string that contains any other character always throws a exception. + + All numeric strings are interpreted based on the formatting conventions of a particular culture: either the current culture, the invariant culture, or a specified culture. As a result, a numeric string that is parsed by using the conventions of one culture might fail when using the conventions of another. + + For more information about parsing numeric strings, see [Parsing Numeric Strings](/dotnet/standard/base-types/parsing-numeric) and the documentation for the specific method that threw the exception. + + - **Time intervals.** The string to be parsed must be either in fixed culture-insensitive format or in a culture-sensitive format defined by the current culture, the invariant culture, or a specified culture. If the string isn't in an appropriate format, or if, at the minimum, the days, hours, and minutes components of the time interval aren't present, the parsing method throws a exception. For more information, see the documentation for the parsing method that threw the exception. + +- A type implements the interface, which supports format strings that define how an object is converted to its string representation, and an invalid format string is used. This is most common in a formatting operation. In the following example, the "Q" standard format string is used in a composite format string to format a number. However, "Q" is not a valid [standard format string](/dotnet/standard/base-types/standard-numeric-format-strings). + :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/iformattable1.cs" id="Snippet7"::: :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/iformattable1.fs" id="Snippet7"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.formatexception/vb/iformattable1.vb" id="Snippet7"::: - - This exception results from a coding error. To correct the error, either remove the format string or substitute a valid one. The following example corrects the error by replacing the invalid format string with the "C" (currency) format string. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.formatexception/vb/iformattable1.vb" id="Snippet7"::: + + This exception results from a coding error. To correct the error, either remove the format string or substitute a valid one. The following example corrects the error by replacing the invalid format string with the "C" (currency) format string. + :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/iformattable2.cs" id="Snippet8"::: :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/iformattable2.fs" id="Snippet8"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.formatexception/vb/iformattable2.vb" id="Snippet8"::: - - A exception can also be thrown by parsing methods, such as and , that require the string to be parsed to conform exactly to the pattern specified by a format string. In the following example, the string representation of a GUID is expected to conform to the pattern specified by the "G" standard format string. However, the structure's implementation of does not support the "G" format string. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.formatexception/vb/iformattable2.vb" id="Snippet8"::: + + A exception can also be thrown by parsing methods, such as and , that require the string to be parsed to conform exactly to the pattern specified by a format string. In the following example, the string representation of a GUID is expected to conform to the pattern specified by the "G" standard format string. However, the structure's implementation of does not support the "G" format string. + :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/iformattable3.cs" id="Snippet9"::: :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/iformattable3.fs" id="Snippet9"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.formatexception/vb/iformattable3.vb" id="Snippet9"::: - - This exception also results from a coding error. To correct it, call a parsing method that doesn't require a precise format, such as or , or substitute a valid format string. The following example corrects the error by calling the method. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.formatexception/vb/iformattable3.vb" id="Snippet9"::: + + This exception also results from a coding error. To correct it, call a parsing method that doesn't require a precise format, such as or , or substitute a valid format string. The following example corrects the error by calling the method. + :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/iformattable4.cs" interactive="try-dotnet" id="Snippet10"::: :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/iformattable4.fs" id="Snippet10"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.formatexception/vb/iformattable4.vb" id="Snippet10"::: - -- One or more of the indexes of the format items in a [composite format string](/dotnet/standard/base-types/composite-formatting) is greater than the indexes of the items in the object list or parameter array. In the following example, the largest index of a format item in the format string is 3. Because the indexes of items in the object list are zero-based, this format string would require the object list to have four items. Instead, it has only three, `dat`, `temp`, and `scale`, so the code results in a exception at run time:. - + +- One or more of the indexes of the format items in a [composite format string](/dotnet/standard/base-types/composite-formatting) is greater than the indexes of the items in the object list or parameter array. In the following example, the largest index of a format item in the format string is 3. Because the indexes of items in the object list are zero-based, this format string would require the object list to have four items. Instead, it has only three, `dat`, `temp`, and `scale`, so the code results in a exception at run time:. + :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/example1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/example1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.formatexception/vb/example1.vb" id="Snippet1"::: - - In this case, the exception is a result of developer error. It should be corrected rather than handled in a `try/catch` block by making sure that each item in the object list corresponds to the index of a format item. To correct this example, change the index of the second format item to refer to the `dat` variable, and decrement the index of each subsequent format item by one. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.formatexception/vb/example1.vb" id="Snippet1"::: + + In this case, the exception is a result of developer error. It should be corrected rather than handled in a `try/catch` block by making sure that each item in the object list corresponds to the index of a format item. To correct this example, change the index of the second format item to refer to the `dat` variable, and decrement the index of each subsequent format item by one. + :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/example2.cs" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/example2.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.formatexception/vb/example2.vb" id="Snippet2"::: - -- The composite format string isn't well-formed. When this happens, the exception is always a result of developer error. It should be corrected rather than handled in a `try/catch` block. - - Trying to include literal braces in a string, as the following example does, will throw the exception. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.formatexception/vb/example2.vb" id="Snippet2"::: + +- The composite format string isn't well-formed. When this happens, the exception is always a result of developer error. It should be corrected rather than handled in a `try/catch` block. + + Trying to include literal braces in a string, as the following example does, will throw the exception. + :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/qa3.cs" id="Snippet23"::: :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/qa3.fs" id="Snippet23"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format/vb/qa3.vb" id="Snippet23"::: - - The recommended technique for including literal braces in a composite format string is to include them in the object list and use format items to insert them into the result string. For example, you can modify the previous composite format string as shown here. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format/vb/qa3.vb" id="Snippet23"::: + + The recommended technique for including literal braces in a composite format string is to include them in the object list and use format items to insert them into the result string. For example, you can modify the previous composite format string as shown here. + :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/qa3.cs" interactive="try-dotnet-method" id="Snippet24"::: :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/qa3.fs" id="Snippet24"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format/vb/qa3.vb" id="Snippet24"::: - - The exception is also thrown if your format string contains a typo. The following call to the method omits a closing brace and pairs an opening brace with a closing bracket. - + + The exception is also thrown if your format string contains a typo. The following call to the method omits a closing brace and pairs an opening brace with a closing bracket. + :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/example3.cs" id="Snippet3"::: :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/example3.fs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.formatexception/vb/example3.vb" id="Snippet3"::: - - To correct the error, ensure that all opening and closing braces correspond. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.formatexception/vb/example3.vb" id="Snippet3"::: + + To correct the error, ensure that all opening and closing braces correspond. + :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/example3.cs" id="Snippet4"::: :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/example3.fs" id="Snippet4"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.formatexception/vb/example3.vb" id="Snippet4"::: - -- You've supplied the object list in a composite formatting method as a strongly typed parameter array, and the exception indicates that the index of one or more format items exceeds the number of arguments in the object list. This occurs because no explicit conversion between array types exists, so instead the compiler treats the array as a single argument rather than as a parameter array. For example, the following call to the method throws a exception, although the highest index of the format items is 3, and the parameter array of type has four elements. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.formatexception/vb/example3.vb" id="Snippet4"::: + +- You've supplied the object list in a composite formatting method as a strongly typed parameter array, and the exception indicates that the index of one or more format items exceeds the number of arguments in the object list. This occurs because no explicit conversion between array types exists, so instead the compiler treats the array as a single argument rather than as a parameter array. For example, the following call to the method throws a exception, although the highest index of the format items is 3, and the parameter array of type has four elements. + :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/qa1.cs" id="Snippet5"::: :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/qa1.fs" id="Snippet5"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.formatexception/vb/qa1.vb" id="Snippet5"::: - - Instead of handling this exception, you should eliminate its cause. Because neither Visual Basic nor C# can convert an integer array to an object array, you have to perform the conversion yourself before calling the composite formatting method. The following example provides one implementation. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.formatexception/vb/qa1.vb" id="Snippet5"::: + + Instead of handling this exception, you should eliminate its cause. Because neither Visual Basic nor C# can convert an integer array to an object array, you have to perform the conversion yourself before calling the composite formatting method. The following example provides one implementation. + :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/qa2.cs" interactive="try-dotnet" id="Snippet6"::: :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/qa2.fs" id="Snippet6"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.formatexception/vb/qa2.vb" id="Snippet6"::: - - uses the HRESULT COR_E_FORMAT, which has the value 0x80131537. - - The class derives from and adds no unique members. For a list of initial property values for an instance of , see the constructors. - + + uses the HRESULT COR_E_FORMAT, which has the value 0x80131537. + + The class derives from and adds no unique members. For a list of initial property values for an instance of , see the constructors. + ]]> @@ -231,18 +231,18 @@ Initializes a new instance of the class. - property of the new instance to a system-supplied message that describes the error, such as "Invalid format." This message takes into account the current system culture. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The localized error message string.| - + property of the new instance to a system-supplied message that describes the error, such as "Invalid format." This message takes into account the current system culture. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The localized error message string.| + ]]> @@ -289,18 +289,18 @@ The message that describes the error. Initializes a new instance of the class with a specified error message. - property of the new exception using the `message` parameter. The content of `message` is intended to be understood by humans. The caller of this constructor is required to ensure that this string has been localized for the current system culture. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The error message string.| - + property of the new exception using the `message` parameter. The content of `message` is intended to be understood by humans. The caller of this constructor is required to ensure that this string has been localized for the current system culture. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The error message string.| + ]]> @@ -362,11 +362,11 @@ The contextual information about the source or destination. Initializes a new instance of the class with serialized data. - @@ -415,18 +415,18 @@ The exception that is the cause of the current exception. If the parameter is not a null reference ( in Visual Basic), the current exception is raised in a block that handles the inner exception. Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception. - property. The property returns the same value that is passed into the constructor, or a null reference (`Nothing` in Visual Basic) if the property does not supply the inner exception value to the constructor. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||The inner exception reference.| -||The error message string.| - + property. The property returns the same value that is passed into the constructor, or a null reference (`Nothing` in Visual Basic) if the property does not supply the inner exception value to the constructor. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||The inner exception reference.| +||The error message string.| + ]]> diff --git a/xml/System/FormattableString.xml b/xml/System/FormattableString.xml index c060b3967ba..8cf842a3267 100644 --- a/xml/System/FormattableString.xml +++ b/xml/System/FormattableString.xml @@ -54,13 +54,13 @@ Represents a composite format string, along with the arguments to be formatted. - , , and . For more information on composite formatting, see [Composite Formatting](/dotnet/standard/base-types/composite-formatting). - - A instance may result from an interpolated string in C# or Visual Basic. - + , , and . For more information on composite formatting, see [Composite Formatting](/dotnet/standard/base-types/composite-formatting). + + A instance may result from an interpolated string in C# or Visual Basic. + ]]> Composite Formatting @@ -139,11 +139,11 @@ Gets the number of arguments to be formatted. The number of arguments to be formatted. - method, or they can be retrieved individually by index number from the method. The indexes of individual arguments range from zero to - 1. - + method, or they can be retrieved individually by index number from the method. The indexes of individual arguments range from zero to - 1. + ]]> @@ -253,17 +253,17 @@ Within the scope of that import directive, an interpolated string may be formatt Returns the composite format string. The composite format string. - Composite Formatting @@ -358,11 +358,11 @@ Within the scope of that import directive, an interpolated string may be formatt Returns an object array that contains one or more objects to format. An object array that contains one or more objects to format. - @@ -408,21 +408,21 @@ Within the scope of that import directive, an interpolated string may be formatt Returns a result string in which arguments are formatted by using the conventions of the invariant culture. The string that results from formatting the current instance by using the conventions of the invariant culture. - @@ -475,13 +475,13 @@ Invariant($"{{ lat = {latitude}; lon = {longitude} }}") Returns the string that results from formatting the format string along with its arguments by using the formatting conventions of a specified culture. A string formatted using the conventions of the parameter. - implementation. - - This member is an explicit interface implementation. It can be used only when the instance is cast to an interface. - + implementation. + + This member is an explicit interface implementation. It can be used only when the instance is cast to an interface. + ]]> diff --git a/xml/System/FtpStyleUriParser.xml b/xml/System/FtpStyleUriParser.xml index d2952c8993c..03289747d42 100644 --- a/xml/System/FtpStyleUriParser.xml +++ b/xml/System/FtpStyleUriParser.xml @@ -73,11 +73,11 @@ Creates a customizable parser based on the File Transfer Protocol (FTP) scheme. - - + + ]]> diff --git a/xml/System/Func`1.xml b/xml/System/Func`1.xml index 0a98e500ecc..b12058157e4 100644 --- a/xml/System/Func`1.xml +++ b/xml/System/Func`1.xml @@ -81,51 +81,51 @@ Encapsulates a method that has no parameters and returns a value of the type specified by the parameter. The return value of the method that this delegate encapsulates. - [!NOTE] -> To reference a method that has no parameters and returns `void` (`unit`, in F#) (or in Visual Basic, that is declared as a `Sub` rather than as a `Function`), use the delegate instead. - - When you use the delegate, you do not have to explicitly define a delegate that encapsulates a parameterless method. For example, the following code explicitly declares a delegate named `WriteMethod` and assigns a reference to the `OutputTarget.SendToFile` instance method to its delegate instance. - +> To reference a method that has no parameters and returns `void` (`unit`, in F#) (or in Visual Basic, that is declared as a `Sub` rather than as a `Function`), use the delegate instead. + + When you use the delegate, you do not have to explicitly define a delegate that encapsulates a parameterless method. For example, the following code explicitly declares a delegate named `WriteMethod` and assigns a reference to the `OutputTarget.SendToFile` instance method to its delegate instance. + :::code language="csharp" source="~/snippets/csharp/System/FuncTResult/Overview/Delegate.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Func~1/fs/Delegate.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Func~1/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. - + + 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 language="csharp" source="~/snippets/csharp/System/FuncTResult/Overview/Func1.cs" interactive="try-dotnet" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Func~1/fs/Func1.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Func~1/vb/Func1.vb" id="Snippet2"::: - - You can use the delegate with anonymous methods in C#, as the following example illustrates. (For an introduction to anonymous methods, see [Anonymous Methods](/dotnet/csharp/programming-guide/statements-expressions-operators/anonymous-methods).) - + + You can use the delegate with anonymous methods in C#, as the following example illustrates. (For an introduction to anonymous methods, see [Anonymous Methods](/dotnet/csharp/programming-guide/statements-expressions-operators/anonymous-methods).) + :::code language="csharp" source="~/snippets/csharp/System/FuncTResult/Overview/Anon.cs" interactive="try-dotnet" 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 (VB)](/dotnet/visual-basic/programming-guide/language-features/procedures/lambda-expressions), [Lambda Expressions (C#)](/dotnet/csharp/programming-guide/statements-expressions-operators/lambda-expressions), and [Lambda Expressions (F#)](/dotnet/fsharp/language-reference/functions/lambda-expressions-the-fun-keyword/).) - + + You can also assign a lambda expression to a delegate, as the following example illustrates. (For an introduction to lambda expressions, see [Lambda Expressions (VB)](/dotnet/visual-basic/programming-guide/language-features/procedures/lambda-expressions), [Lambda Expressions (C#)](/dotnet/csharp/programming-guide/statements-expressions-operators/lambda-expressions), and [Lambda Expressions (F#)](/dotnet/fsharp/language-reference/functions/lambda-expressions-the-fun-keyword/).) + :::code language="csharp" source="~/snippets/csharp/System/FuncTResult/Overview/Lambda.cs" interactive="try-dotnet" id="Snippet4"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Func~1/fs/Lambda.fs" id="Snippet4"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Func~1/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 `Func` parameters, you can pass these methods a lambda expression without explicitly instantiating a `Func` delegate. - - If you have an expensive computation that you want to execute only if the result is actually needed, you can assign the expensive function to a delegate. The execution of the function can then be delayed until a property that accesses the value is used in an expression. The example in the next section demonstrates how to do this. - - - -## Examples - The following example demonstrates how to use a delegate that takes no parameters. This code creates a generic class named `LazyValue` that has a field of type . This delegate field can store a reference to any function that returns a value of the type that corresponds to the type parameter of the `LazyValue` object. The `LazyValue` type also has a `Value` property that executes the function (if it has not already been executed) and returns the resulting value. - - The example creates two methods and instantiates two `LazyValue` objects with lambda expressions that call these methods. The lambda expressions do not take parameters because they just need to call a method. As the output shows, the two methods are executed only when the value of each `LazyValue` object is retrieved. - + + 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 `Func` parameters, you can pass these methods a lambda expression without explicitly instantiating a `Func` delegate. + + If you have an expensive computation that you want to execute only if the result is actually needed, you can assign the expensive function to a delegate. The execution of the function can then be delayed until a property that accesses the value is used in an expression. The example in the next section demonstrates how to do this. + + + +## Examples + The following example demonstrates how to use a delegate that takes no parameters. This code creates a generic class named `LazyValue` that has a field of type . This delegate field can store a reference to any function that returns a value of the type that corresponds to the type parameter of the `LazyValue` object. The `LazyValue` type also has a `Value` property that executes the function (if it has not already been executed) and returns the resulting value. + + The example creates two methods and instantiates two `LazyValue` objects with lambda expressions that call these methods. The lambda expressions do not take parameters because they just need to call a method. As the output shows, the two methods are executed only when the value of each `LazyValue` object is retrieved. + :::code language="csharp" source="~/snippets/csharp/System/FuncTResult/Overview/Example.cs" interactive="try-dotnet" id="Snippet5"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Func~1/fs/Example.fs" id="Snippet5"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Func~1/vb/Example.vb" id="Snippet5"::: - + ]]> Lambda Expressions (C# Programming Guide) diff --git a/xml/System/Func`10.xml b/xml/System/Func`10.xml index 9cdf7e1997c..debdf00218d 100644 --- a/xml/System/Func`10.xml +++ b/xml/System/Func`10.xml @@ -138,18 +138,18 @@ Encapsulates a method that has nine parameters and returns a value of the type specified by the parameter. The return value of the method that this delegate encapsulates. - [!NOTE] -> To reference a method that has nine parameters and returns `void` (or in Visual Basic, that is declared as a `Sub` rather than as a `Function`), use the generic delegate instead. - - You can also use the delegate with anonymous methods and lambda expressions. - - 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. - +> To reference a method that has nine parameters and returns `void` (or in Visual Basic, that is declared as a `Sub` rather than as a `Function`), use the generic delegate instead. + + You can also use the delegate with anonymous methods and lambda expressions. + + 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. + ]]> diff --git a/xml/System/Func`11.xml b/xml/System/Func`11.xml index a0d51eee72b..13fbfc22200 100644 --- a/xml/System/Func`11.xml +++ b/xml/System/Func`11.xml @@ -146,18 +146,18 @@ Encapsulates a method that has 10 parameters and returns a value of the type specified by the parameter. The return value of the method that this delegate encapsulates. - [!NOTE] -> To reference a method that has 10 parameters and returns `void` (or in Visual Basic, that is declared as a `Sub` rather than as a `Function`), use the generic delegate instead. - - You can also use the delegate with anonymous methods and lambda expressions. - - 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. - +> To reference a method that has 10 parameters and returns `void` (or in Visual Basic, that is declared as a `Sub` rather than as a `Function`), use the generic delegate instead. + + You can also use the delegate with anonymous methods and lambda expressions. + + 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. + ]]> diff --git a/xml/System/Func`12.xml b/xml/System/Func`12.xml index c7d235f8687..d7b2f0721b4 100644 --- a/xml/System/Func`12.xml +++ b/xml/System/Func`12.xml @@ -154,18 +154,18 @@ Encapsulates a method that has 11 parameters and returns a value of the type specified by the parameter. The return value of the method that this delegate encapsulates. - [!NOTE] -> To reference a method that has 11 parameters and returns `void` (or in Visual Basic, that is declared as a `Sub` rather than as a `Function`), use the generic delegate instead. - - You can also use the delegate with anonymous methods and lambda expressions. - - 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. - +> To reference a method that has 11 parameters and returns `void` (or in Visual Basic, that is declared as a `Sub` rather than as a `Function`), use the generic delegate instead. + + You can also use the delegate with anonymous methods and lambda expressions. + + 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. + ]]> diff --git a/xml/System/Func`13.xml b/xml/System/Func`13.xml index 24596a0d3c5..0eb69eb356c 100644 --- a/xml/System/Func`13.xml +++ b/xml/System/Func`13.xml @@ -162,18 +162,18 @@ Encapsulates a method that has 12 parameters and returns a value of the type specified by the parameter. The return value of the method that this delegate encapsulates. - [!NOTE] -> To reference a method that has 12 parameters and returns `void` (or in Visual Basic, that is declared as a `Sub` rather than as a `Function`), use the generic delegate instead. - - You can also use the delegate with anonymous methods and lambda expressions. - - 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. - +> To reference a method that has 12 parameters and returns `void` (or in Visual Basic, that is declared as a `Sub` rather than as a `Function`), use the generic delegate instead. + + You can also use the delegate with anonymous methods and lambda expressions. + + 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. + ]]> diff --git a/xml/System/Func`14.xml b/xml/System/Func`14.xml index 7a9e50df975..f4a3868e0ee 100644 --- a/xml/System/Func`14.xml +++ b/xml/System/Func`14.xml @@ -170,18 +170,18 @@ Encapsulates a method that has 13 parameters and returns a value of the type specified by the parameter. The return value of the method that this delegate encapsulates. - [!NOTE] -> To reference a method that has 13 parameters and returns `void` (or in Visual Basic, that is declared as a `Sub` rather than as a `Function`), use the generic delegate instead. - - You can also use the delegate with anonymous methods and lambda expressions. - - 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. - +> To reference a method that has 13 parameters and returns `void` (or in Visual Basic, that is declared as a `Sub` rather than as a `Function`), use the generic delegate instead. + + You can also use the delegate with anonymous methods and lambda expressions. + + 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. + ]]> diff --git a/xml/System/Func`15.xml b/xml/System/Func`15.xml index cf7e8dfb69e..06fe7d48c96 100644 --- a/xml/System/Func`15.xml +++ b/xml/System/Func`15.xml @@ -178,18 +178,18 @@ Encapsulates a method that has 14 parameters and returns a value of the type specified by the parameter. The return value of the method that this delegate encapsulates. - [!NOTE] -> To reference a method that has 14 parameters and returns `void` (or in Visual Basic, that is declared as a `Sub` rather than as a `Function`), use the generic delegate instead. - - You can also use the delegate with anonymous methods and lambda expressions. - - 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. - +> To reference a method that has 14 parameters and returns `void` (or in Visual Basic, that is declared as a `Sub` rather than as a `Function`), use the generic delegate instead. + + You can also use the delegate with anonymous methods and lambda expressions. + + 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. + ]]> diff --git a/xml/System/Func`16.xml b/xml/System/Func`16.xml index a73d3dbc40f..6c1c11fef47 100644 --- a/xml/System/Func`16.xml +++ b/xml/System/Func`16.xml @@ -186,18 +186,18 @@ Encapsulates a method that has 15 parameters and returns a value of the type specified by the parameter. The return value of the method that this delegate encapsulates. - [!NOTE] -> To reference a method that has 15 parameters and returns `void` (or in Visual Basic, that is declared as a `Sub` rather than as a `Function`), use the generic delegate instead. - - You can also use the delegate with anonymous methods and lambda expressions. - - 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. - +> To reference a method that has 15 parameters and returns `void` (or in Visual Basic, that is declared as a `Sub` rather than as a `Function`), use the generic delegate instead. + + You can also use the delegate with anonymous methods and lambda expressions. + + 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. + ]]> diff --git a/xml/System/Func`17.xml b/xml/System/Func`17.xml index 9b994aafdd9..4718a209ebb 100644 --- a/xml/System/Func`17.xml +++ b/xml/System/Func`17.xml @@ -194,18 +194,18 @@ Encapsulates a method that has 16 parameters and returns a value of the type specified by the parameter. The return value of the method that this delegate encapsulates. - [!NOTE] -> To reference a method that has 16 parameters and returns `void` (or in Visual Basic, that is declared as a `Sub` rather than as a `Function`), use the generic delegate instead. - - You can also use the delegate with anonymous methods and lambda expressions. - - 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. - +> To reference a method that has 16 parameters and returns `void` (or in Visual Basic, that is declared as a `Sub` rather than as a `Function`), use the generic delegate instead. + + You can also use the delegate with anonymous methods and lambda expressions. + + 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. + ]]> diff --git a/xml/System/Func`2.xml b/xml/System/Func`2.xml index 819b5c095d1..80b5e8e5bc1 100644 --- a/xml/System/Func`2.xml +++ b/xml/System/Func`2.xml @@ -96,48 +96,48 @@ Encapsulates a method that has one parameter and returns a value of the type specified by the parameter. The return value of the method that this delegate encapsulates. - [!NOTE] -> 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. - +> 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 language="csharp" source="~/snippets/csharp/System/FuncT,TResult/Overview/Delegate.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Func~2/fs/Delegate.fs" id="Snippet1"::: :::code language="vb" source="~/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. - + + 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 language="csharp" source="~/snippets/csharp/System/FuncT,TResult/Overview/Func2_1.cs" interactive="try-dotnet-method" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Func~2/fs/Func2_1.fs" id="Snippet2"::: :::code language="vb" source="~/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](/dotnet/csharp/programming-guide/statements-expressions-operators/anonymous-methods).) - + + 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](/dotnet/csharp/programming-guide/statements-expressions-operators/anonymous-methods).) + :::code language="csharp" source="~/snippets/csharp/System/FuncT,TResult/Overview/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 (VB)](/dotnet/visual-basic/programming-guide/language-features/procedures/lambda-expressions), [Lambda Expressions (C#)](/dotnet/csharp/programming-guide/statements-expressions-operators/lambda-expressions) and [Lambda Expressions (F#)](/dotnet/fsharp/language-reference/functions/lambda-expressions-the-fun-keyword).) - + + You can also assign a lambda expression to a delegate, as the following example illustrates. (For an introduction to lambda expressions, see [Lambda Expressions (VB)](/dotnet/visual-basic/programming-guide/language-features/procedures/lambda-expressions), [Lambda Expressions (C#)](/dotnet/csharp/programming-guide/statements-expressions-operators/lambda-expressions) and [Lambda Expressions (F#)](/dotnet/fsharp/language-reference/functions/lambda-expressions-the-fun-keyword).) + :::code language="csharp" source="~/snippets/csharp/System/FuncT,TResult/Overview/Lambda.cs" interactive="try-dotnet-method" id="Snippet4"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Func~2/fs/Lambda.fs" id="Snippet4"::: :::code language="vb" source="~/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. - - - -## 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. + + 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. + + + +## 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 language="csharp" source="~/snippets/csharp/System/FuncT,TResult/Overview/Example.cs" interactive="try-dotnet-method" id="Snippet5"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Func~2/fs/Example.fs" id="Snippet5"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Func~2/vb/Example.vb" id="Snippet5"::: :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Func~2/cpp/Example.cpp" id="Snippet6"::: - + ]]> Lambda Expressions (C# Programming Guide) diff --git a/xml/System/Func`3.xml b/xml/System/Func`3.xml index c0bfe7c09f9..14d0700985b 100644 --- a/xml/System/Func`3.xml +++ b/xml/System/Func`3.xml @@ -110,43 +110,43 @@ Encapsulates a method that has two parameters and returns a value of the type specified by the parameter. The return value of the method that this delegate encapsulates. - [!NOTE] -> To reference a method that has two parameters and returns `void` (`unit` in F#) (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 two parameters. For example, the following code explicitly declares a delegate named `ExtractMethod` and assigns a reference to the `ExtractWords` method to its delegate instance. - +> To reference a method that has two parameters and returns `void` (`unit` in F#) (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 two parameters. For example, the following code explicitly declares a delegate named `ExtractMethod` and assigns a reference to the `ExtractWords` method to its delegate instance. + :::code language="csharp" source="~/snippets/csharp/System/FuncT1,T2,TResult/Overview/Delegate.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Func~3/fs/Delegate.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Func~3/vb/Delegate.vb" id="Snippet1"::: - - The following example simplifies this code by instantiating a delegate instead of explicitly defining a new delegate and assigning a named method to it. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Func~3/vb/Delegate.vb" id="Snippet1"::: + + The following example simplifies this code by instantiating a delegate instead of explicitly defining a new delegate and assigning a named method to it. + :::code language="csharp" source="~/snippets/csharp/System/FuncT1,T2,TResult/Overview/Func3.cs" interactive="try-dotnet" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Func~3/fs/Func3.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Func~3/vb/Func3.vb" id="Snippet2"::: - - You can use the delegate with anonymous methods in C#, as the following example illustrates. (For an introduction to anonymous methods, see [Anonymous Methods](/dotnet/csharp/programming-guide/statements-expressions-operators/anonymous-methods).) - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Func~3/vb/Func3.vb" id="Snippet2"::: + + You can use the delegate with anonymous methods in C#, as the following example illustrates. (For an introduction to anonymous methods, see [Anonymous Methods](/dotnet/csharp/programming-guide/statements-expressions-operators/anonymous-methods).) + :::code language="csharp" source="~/snippets/csharp/System/FuncT1,T2,TResult/Overview/Anon.cs" interactive="try-dotnet" 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 (VB)](/dotnet/visual-basic/programming-guide/language-features/procedures/lambda-expressions), [Lambda Expressions (C#)](/dotnet/csharp/programming-guide/statements-expressions-operators/lambda-expressions) and [Lambda Expressions (F#)](/dotnet/fsharp/language-reference/functions/lambda-expressions-the-fun-keyword).) - + + You can also assign a lambda expression to a delegate, as the following example illustrates. (For an introduction to lambda expressions, see [Lambda Expressions (VB)](/dotnet/visual-basic/programming-guide/language-features/procedures/lambda-expressions), [Lambda Expressions (C#)](/dotnet/csharp/programming-guide/statements-expressions-operators/lambda-expressions) and [Lambda Expressions (F#)](/dotnet/fsharp/language-reference/functions/lambda-expressions-the-fun-keyword).) + :::code language="csharp" source="~/snippets/csharp/System/FuncT1,T2,TResult/Overview/Lambda.cs" interactive="try-dotnet" id="Snippet4"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Func~3/fs/Lambda.fs" id="Snippet4"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Func~3/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. - - - -## Examples - The following example demonstrates how to declare and use a delegate. This example declares a variable and assigns it a lambda expression that takes a value and an value as parameters. The lambda expression returns `true` if the length of the parameter is equal to the value of the parameter. The delegate that encapsulates this method is subsequently used in a query to filter strings in an array of strings. - + 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. + + + +## Examples + The following example demonstrates how to declare and use a delegate. This example declares a variable and assigns it a lambda expression that takes a value and an value as parameters. The lambda expression returns `true` if the length of the parameter is equal to the value of the parameter. The delegate that encapsulates this method is subsequently used in a query to filter strings in an array of strings. + :::code language="csharp" source="~/snippets/csharp/System/FuncT1,T2,TResult/Overview/Example.cs" interactive="try-dotnet" id="Snippet5"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Func~3/fs/Example.fs" id="Snippet5"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Func~3/vb/Example.vb" id="Snippet5"::: diff --git a/xml/System/Func`4.xml b/xml/System/Func`4.xml index e683978c4b7..d4a4812df4f 100644 --- a/xml/System/Func`4.xml +++ b/xml/System/Func`4.xml @@ -124,47 +124,47 @@ Encapsulates a method that has three parameters and returns a value of the type specified by the parameter. The return value of the method that this delegate encapsulates. - [!NOTE] -> To reference a method that has three parameters and returns `void` (`unit` in F#) (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 three parameters. For example, the following code explicitly declares a generic delegate named `ParseNumber` and assigns a reference to the method to its delegate instance. - +> To reference a method that has three parameters and returns `void` (`unit` in F#) (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 three parameters. For example, the following code explicitly declares a generic delegate named `ParseNumber` and assigns a reference to the method to its delegate instance. + :::code language="csharp" source="~/snippets/csharp/System/FuncT1,T2,T3,TResult/Overview/Delegate.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/FuncT1,T2,T3,TResult/Overview/Delegate.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Func~4/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 language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Func~4/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 language="csharp" source="~/snippets/csharp/System/FuncT1,T2,T3,TResult/Overview/Func4.cs" interactive="try-dotnet" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/FuncT1,T2,T3,TResult/Overview/Func4.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Func~4/vb/Func4.vb" id="Snippet2"::: - - You can use the delegate with anonymous methods in C#, as the following example illustrates. (For an introduction to anonymous methods, see [Anonymous Methods](/dotnet/csharp/programming-guide/statements-expressions-operators/anonymous-methods).) - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Func~4/vb/Func4.vb" id="Snippet2"::: + + You can use the delegate with anonymous methods in C#, as the following example illustrates. (For an introduction to anonymous methods, see [Anonymous Methods](/dotnet/csharp/programming-guide/statements-expressions-operators/anonymous-methods).) + :::code language="csharp" source="~/snippets/csharp/System/FuncT1,T2,T3,TResult/Overview/Anon.cs" interactive="try-dotnet" 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 (VB)](/dotnet/visual-basic/programming-guide/language-features/procedures/lambda-expressions), [Lambda Expressions (C#)](/dotnet/csharp/programming-guide/statements-expressions-operators/lambda-expressions) and [Lambda Expressions (F#)](/dotnet/fsharp/language-reference/functions/lambda-expressions-the-fun-keyword).) - + + You can also assign a lambda expression to a delegate, as the following example illustrates. (For an introduction to lambda expressions, see [Lambda Expressions (VB)](/dotnet/visual-basic/programming-guide/language-features/procedures/lambda-expressions), [Lambda Expressions (C#)](/dotnet/csharp/programming-guide/statements-expressions-operators/lambda-expressions) and [Lambda Expressions (F#)](/dotnet/fsharp/language-reference/functions/lambda-expressions-the-fun-keyword).) + :::code language="csharp" source="~/snippets/csharp/System/FuncT1,T2,T3,TResult/Overview/Lambda.cs" interactive="try-dotnet" id="Snippet4"::: :::code language="fsharp" source="~/snippets/fsharp/System/FuncT1,T2,T3,TResult/Overview/Lambda.fs" id="Snippet4"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Func~4/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 `Func` parameters, you can pass these methods a lambda expression without explicitly instantiating a `Func` delegate. - - - -## Examples - The following example demonstrates how to declare and use a delegate. This example declares a variable and assigns it a lambda expression that takes a value and an value as parameters. The lambda expression returns `true` if the length of the parameter is equal to the value of the parameter. The delegate that encapsulates this method is subsequently used in a query to filter strings in an array of strings. - + + 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 `Func` parameters, you can pass these methods a lambda expression without explicitly instantiating a `Func` delegate. + + + +## Examples + The following example demonstrates how to declare and use a delegate. This example declares a variable and assigns it a lambda expression that takes a value and an value as parameters. The lambda expression returns `true` if the length of the parameter is equal to the value of the parameter. The delegate that encapsulates this method is subsequently used in a query to filter strings in an array of strings. + :::code language="csharp" source="~/snippets/csharp/System/FuncT1,T2,TResult/Overview/Example.cs" interactive="try-dotnet" id="Snippet5"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Func~3/fs/Example.fs" id="Snippet5"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Func~3/vb/Example.vb" id="Snippet5"::: - + ]]> Lambda Expressions (C# Programming Guide) diff --git a/xml/System/Func`5.xml b/xml/System/Func`5.xml index 16edd27efd0..9bc4a8719b4 100644 --- a/xml/System/Func`5.xml +++ b/xml/System/Func`5.xml @@ -116,47 +116,47 @@ Encapsulates a method that has four parameters and returns a value of the type specified by the parameter. The return value of the method that this delegate encapsulates. - [!NOTE] -> To reference a method that has four parameters and returns `void` (`unit` in F#) (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 four parameters. For example, the following code explicitly declares a generic delegate named `Searcher` and assigns a reference to the method to its delegate instance. - +> To reference a method that has four parameters and returns `void` (`unit` in F#) (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 four parameters. For example, the following code explicitly declares a generic delegate named `Searcher` and assigns a reference to the method to its delegate instance. + :::code language="csharp" source="~/snippets/csharp/System/FuncT1,T2,T3,T4,TResult/Overview/Delegate.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/FuncT1,T2,T3,T4,TResult/Overview/Delegate.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Func~5/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 language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Func~5/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 language="csharp" source="~/snippets/csharp/System/FuncT1,T2,T3,T4,TResult/Overview/Func5.cs" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/FuncT1,T2,T3,T4,TResult/Overview/Func5.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Func~5/vb/Func5.vb" id="Snippet2"::: - - You can use the delegate with anonymous methods in C#, as the following example illustrates. (For an introduction to anonymous methods, see [Anonymous Methods](/dotnet/csharp/programming-guide/statements-expressions-operators/anonymous-methods).) - - :::code language="csharp" source="~/snippets/csharp/System/FuncT1,T2,T3,T4,TResult/Overview/Anon.cs" 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 (VB)](/dotnet/visual-basic/programming-guide/language-features/procedures/lambda-expressions), [Lambda Expressions (C#)](/dotnet/csharp/programming-guide/statements-expressions-operators/lambda-expressions) and [Lambda Expressions (F#)](/dotnet/fsharp/language-reference/functions/lambda-expressions-the-fun-keyword).) - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Func~5/vb/Func5.vb" id="Snippet2"::: + + You can use the delegate with anonymous methods in C#, as the following example illustrates. (For an introduction to anonymous methods, see [Anonymous Methods](/dotnet/csharp/programming-guide/statements-expressions-operators/anonymous-methods).) + + :::code language="csharp" source="~/snippets/csharp/System/FuncT1,T2,T3,T4,TResult/Overview/Anon.cs" 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 (VB)](/dotnet/visual-basic/programming-guide/language-features/procedures/lambda-expressions), [Lambda Expressions (C#)](/dotnet/csharp/programming-guide/statements-expressions-operators/lambda-expressions) and [Lambda Expressions (F#)](/dotnet/fsharp/language-reference/functions/lambda-expressions-the-fun-keyword).) + :::code language="csharp" source="~/snippets/csharp/System/FuncT1,T2,T3,T4,TResult/Overview/Lambda.cs" id="Snippet4"::: :::code language="fsharp" source="~/snippets/fsharp/System/FuncT1,T2,T3,T4,TResult/Overview/Lambda.fs" id="Snippet4"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Func~5/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 `Func` parameters, you can pass these methods a lambda expression without explicitly instantiating a `Func` delegate. - - - -## Examples - The following example demonstrates how to declare and use a delegate. This example declares a variable and assigns it a lambda expression that takes a value and an value as parameters. The lambda expression returns `true` if the length of the parameter is equal to the value of the parameter. The delegate that encapsulates this method is subsequently used in a query to filter strings in an array of strings. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Func~5/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 `Func` parameters, you can pass these methods a lambda expression without explicitly instantiating a `Func` delegate. + + + +## Examples + The following example demonstrates how to declare and use a delegate. This example declares a variable and assigns it a lambda expression that takes a value and an value as parameters. The lambda expression returns `true` if the length of the parameter is equal to the value of the parameter. The delegate that encapsulates this method is subsequently used in a query to filter strings in an array of strings. + :::code language="csharp" source="~/snippets/csharp/System/FuncT1,T2,TResult/Overview/Example.cs" interactive="try-dotnet" id="Snippet5"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Func~3/fs/Example.fs" id="Snippet5"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Func~3/vb/Example.vb" id="Snippet5"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Func~3/vb/Example.vb" id="Snippet5"::: + ]]> Lambda Expressions (C# Programming Guide) diff --git a/xml/System/Func`6.xml b/xml/System/Func`6.xml index 3b1bfe5ae7c..e136c0876dc 100644 --- a/xml/System/Func`6.xml +++ b/xml/System/Func`6.xml @@ -106,18 +106,18 @@ Encapsulates a method that has five parameters and returns a value of the type specified by the parameter. The return value of the method that this delegate encapsulates. - [!NOTE] -> To reference a method that has five parameters and returns `void` (or in Visual Basic, that is declared as a `Sub` rather than as a `Function`), use the generic delegate instead. - - You can also use the delegate with anonymous methods and lambda expressions. - - 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. - +> To reference a method that has five parameters and returns `void` (or in Visual Basic, that is declared as a `Sub` rather than as a `Function`), use the generic delegate instead. + + You can also use the delegate with anonymous methods and lambda expressions. + + 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. + ]]> diff --git a/xml/System/Func`7.xml b/xml/System/Func`7.xml index e5a1c443156..d21fbc82340 100644 --- a/xml/System/Func`7.xml +++ b/xml/System/Func`7.xml @@ -114,18 +114,18 @@ Encapsulates a method that has six parameters and returns a value of the type specified by the parameter. The return value of the method that this delegate encapsulates. - [!NOTE] -> To reference a method that has six parameters and returns `void` (or in Visual Basic, that is declared as a `Sub` rather than as a `Function`), use the generic delegate instead. - - You can also use the delegate with anonymous methods and lambda expressions. - - 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. - +> To reference a method that has six parameters and returns `void` (or in Visual Basic, that is declared as a `Sub` rather than as a `Function`), use the generic delegate instead. + + You can also use the delegate with anonymous methods and lambda expressions. + + 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. + ]]> diff --git a/xml/System/Func`8.xml b/xml/System/Func`8.xml index 197e5ca9fdb..b6456b05151 100644 --- a/xml/System/Func`8.xml +++ b/xml/System/Func`8.xml @@ -122,18 +122,18 @@ Encapsulates a method that has seven parameters and returns a value of the type specified by the parameter. The return value of the method that this delegate encapsulates. - [!NOTE] -> To reference a method that has seven parameters and returns `void` (or in Visual Basic, that is declared as a `Sub` rather than as a `Function`), use the generic delegate instead. - - You can also use the delegate with anonymous methods and lambda expressions. - - 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. - +> To reference a method that has seven parameters and returns `void` (or in Visual Basic, that is declared as a `Sub` rather than as a `Function`), use the generic delegate instead. + + You can also use the delegate with anonymous methods and lambda expressions. + + 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. + ]]> diff --git a/xml/System/Func`9.xml b/xml/System/Func`9.xml index baac43d9d4b..b5a997b5d90 100644 --- a/xml/System/Func`9.xml +++ b/xml/System/Func`9.xml @@ -130,18 +130,18 @@ Encapsulates a method that has eight parameters and returns a value of the type specified by the parameter. The return value of the method that this delegate encapsulates. - [!NOTE] -> To reference a method that has eight parameters and returns `void` (or in Visual Basic, that is declared as a `Sub` rather than as a `Function`), use the generic delegate instead. - - You can also use the delegate with anonymous methods and lambda expressions. - - 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. - +> To reference a method that has eight parameters and returns `void` (or in Visual Basic, that is declared as a `Sub` rather than as a `Function`), use the generic delegate instead. + + You can also use the delegate with anonymous methods and lambda expressions. + + 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. + ]]> diff --git a/xml/System/GC.xml b/xml/System/GC.xml index d694653b13d..f265bdc0fb0 100644 --- a/xml/System/GC.xml +++ b/xml/System/GC.xml @@ -191,9 +191,9 @@ is less than or equal to 0. - -or- +-or- - On a 32-bit computer, is larger than Int32.MaxValue. +On a 32-bit computer, is larger than Int32.MaxValue. @@ -610,9 +610,9 @@ Skipping zero-initialization using this API only has a material performance bene is not valid. - -or- +-or- - is not one of the values. + is not one of the values. Induced Collections @@ -686,9 +686,9 @@ Skipping zero-initialization using this API only has a material performance bene is not valid. - -or- +-or- - is not one of the values. + is not one of the values. @@ -889,13 +889,13 @@ Skipping zero-initialization using this API only has a material performance bene The garbage collector is not in no GC region latency mode. - -or- +-or- - The no GC region latency mode was ended previously because a garbage collection was induced. +The no GC region latency mode was ended previously because a garbage collection was induced. - -or- +-or- - A memory allocation exceeded the amount specified in the call to the method. +A memory allocation exceeded the amount specified in the call to the method. Latency Modes @@ -1198,7 +1198,7 @@ The following example demonstrates the use of the Garbage collection has already been performed on . The target of the weak reference - has already been garbage collected. + has already been garbage collected. @@ -1519,7 +1519,7 @@ The following example demonstrates the use of the @@ -1745,9 +1745,9 @@ The following example demonstrates the use of the is less than or equal to 0. - -or- +-or- - On a 32-bit computer, is larger than Int32.MaxValue. +On a 32-bit computer, is larger than Int32.MaxValue. diff --git a/xml/System/GCCollectionMode.xml b/xml/System/GCCollectionMode.xml index d0c75ece3b9..f26ee69e95f 100644 --- a/xml/System/GCCollectionMode.xml +++ b/xml/System/GCCollectionMode.xml @@ -50,20 +50,20 @@ Specifies the behavior for a forced garbage collection. - method overload to specify the value. - - - -## Examples - The following example forces a garbage collection for generation 2 objects with the Optimized setting. - + method overload to specify the value. + + + +## Examples + The following example forces a garbage collection for generation 2 objects with the Optimized setting. + :::code language="csharp" source="~/snippets/csharp/System/GC/Collect/Program.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/GC/Collect/Program.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.GC.GCCollectionMode/vb/program.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.GC.GCCollectionMode/vb/program.vb" id="Snippet1"::: + ]]> Induced Collections diff --git a/xml/System/GCMemoryInfo.xml b/xml/System/GCMemoryInfo.xml index d513fd01256..6939f904122 100644 --- a/xml/System/GCMemoryInfo.xml +++ b/xml/System/GCMemoryInfo.xml @@ -143,11 +143,11 @@ A garbage collection (GC) is identified by its , For example, the application has the following five objects: `| OBJ_A | OBJ_B | OBJ_C | OBJ_D | OBJ_E |` - + If `OBJ_B`, `OBJ_C`, and `OBJ_E` are garbage collected but the heap is not compacted, the resulting heap will look like the following: `| OBJ_A | F | OBJ_D |` - + The memory between `OBJ_A` and `OBJ_D`, which is marked `F`, is considered part of the `FragmentedBytes` and is used to allocate new objects. The memory after `OBJ_D` is not considered part of the `FragmentedBytes` but is also used to allocate new objects. @@ -278,7 +278,7 @@ The memory after `OBJ_D` is not considered part of the `FragmentedBytes` but is Gets the index of this GC. The index of this GC. GC indices start with 1 and are increased at the beginning of a GC. - Since the information is updated at the end of a GC, this means you can get the information for a background GC with a smaller index than a foreground GC that finished earlier. + Since the information is updated at the end of a GC, this means you can get the information for a background GC with a smaller index than a foreground GC that finished earlier. diff --git a/xml/System/GCNotificationStatus.xml b/xml/System/GCNotificationStatus.xml index 751397bbf82..ea8e61db687 100644 --- a/xml/System/GCNotificationStatus.xml +++ b/xml/System/GCNotificationStatus.xml @@ -45,21 +45,21 @@ Provides information about the current registration for notification of the next full garbage collection. - method to register for a full garbage collection notification. Then use the method or the method to return a enumeration that contains the status of the notification. - - - -## Examples - The following example obtains a enumeration from the method. If the enumeration returns Succeeded, it calls the custom method `OnFullGCApproachNotify` to perform actions in response to the approaching full garbage collection. This code example is part of a larger example provided for [Garbage Collection Notifications](/dotnet/standard/garbage-collection/notifications) topic. - + method to register for a full garbage collection notification. Then use the method or the method to return a enumeration that contains the status of the notification. + + + +## Examples + The following example obtains a enumeration from the method. If the enumeration returns Succeeded, it calls the custom method `OnFullGCApproachNotify` to perform actions in response to the approaching full garbage collection. This code example is part of a larger example provided for [Garbage Collection Notifications](/dotnet/standard/garbage-collection/notifications) topic. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/GCNotification/cpp/program.cpp" id="Snippet8"::: :::code language="csharp" source="~/snippets/csharp/System/GC/CancelFullGCNotification/Program.cs" id="Snippet8"::: :::code language="fsharp" source="~/snippets/fsharp/System/GC/CancelFullGCNotification/Program.fs" id="Snippet8"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/GCNotification/vb/program.vb" id="Snippet8"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/GCNotification/vb/program.vb" id="Snippet8"::: + ]]> Garbage Collection Notifications diff --git a/xml/System/GenericUriParser.xml b/xml/System/GenericUriParser.xml index bc80d573383..0ebb79bb8db 100644 --- a/xml/System/GenericUriParser.xml +++ b/xml/System/GenericUriParser.xml @@ -39,19 +39,19 @@ A customizable parser for a hierarchical URI. - , , , , or . - - When creating a customizable parser, the behavior of the parser is specified by passing a bitwise combination of the values available in the enumeration to the constructor. - - The existing class has been extended to provide support for International Resource Identifiers (IRI) and Internationalized Domain Names (IDN). Current users will not see any change from the .NET Framework 2.0 behavior unless they specifically enable IRI. This ensures application compatibility with prior versions of the .NET Framework. - - All parsers derived from will not gain IRI and IDN support by default. The option does not include IRI and IDN support. Two new values are added to the enumeration to indicate if a custom parser supports IRI and IDN. - - For more information on IRI and IDN support, see the Remarks section for the class. - + , , , , or . + + When creating a customizable parser, the behavior of the parser is specified by passing a bitwise combination of the values available in the enumeration to the constructor. + + The existing class has been extended to provide support for International Resource Identifiers (IRI) and Internationalized Domain Names (IDN). Current users will not see any change from the .NET Framework 2.0 behavior unless they specifically enable IRI. This ensures application compatibility with prior versions of the .NET Framework. + + All parsers derived from will not gain IRI and IDN support by default. The option does not include IRI and IDN support. Two new values are added to the enumeration to indicate if a custom parser supports IRI and IDN. + + For more information on IRI and IDN support, see the Remarks section for the class. + ]]> @@ -92,29 +92,29 @@ Specify the options for this . Create a customizable parser for a hierarchical URI. - - - If you want to create a parser based on a well-known scheme, use , , , , or . - - When creating a customizable parser, the behavior of the parser is specified by passing a bitwise combination of the values available in the enumeration to the constructor. - - The existing class has been extended to provide support for International Resource Identifiers (IRI) and Internationalized Domain Names (IDN). Current users will not see any change from the .NET Framework 2.0 behavior unless they specifically enable IRI. This ensures application compatibility with prior versions of the .NET Framework. - - All parsers derived from will not gain IRI and IDN support by default. The option does not include IRI and IDN support. Two new values are added to the enumeration to indicate if a custom parser supports IRI and IDN. - - The type indicates the parser supports the parsing rules specified in RFC 3987 for International Resource Identifiers (IRI). Whether IRI is used is dictated by configuration values. - - The type indicates the parser supports Internationalized Domain Name (IDN) parsing (IDN) of host names. Whether IDN is used is dictated by configuration values. - - The configuration setting for the is indirectly controlled by the configuration setting that controls IRI processing in the class. IRI processing must be enabled for IDN processing to be possible. If IRI processing is disabled, then IDN processing will be set to the default setting where the .NET Framework 2.0 behavior is used for compatibility and IDN names are not used. - - The Internationalized Domain Name (IDN) attribute only controls IDN processing. All other IRI processing (character normalization, for example) is performed by default. - - For more information on IRI and IDN support, see the Remarks section for the class. - + + + If you want to create a parser based on a well-known scheme, use , , , , or . + + When creating a customizable parser, the behavior of the parser is specified by passing a bitwise combination of the values available in the enumeration to the constructor. + + The existing class has been extended to provide support for International Resource Identifiers (IRI) and Internationalized Domain Names (IDN). Current users will not see any change from the .NET Framework 2.0 behavior unless they specifically enable IRI. This ensures application compatibility with prior versions of the .NET Framework. + + All parsers derived from will not gain IRI and IDN support by default. The option does not include IRI and IDN support. Two new values are added to the enumeration to indicate if a custom parser supports IRI and IDN. + + The type indicates the parser supports the parsing rules specified in RFC 3987 for International Resource Identifiers (IRI). Whether IRI is used is dictated by configuration values. + + The type indicates the parser supports Internationalized Domain Name (IDN) parsing (IDN) of host names. Whether IDN is used is dictated by configuration values. + + The configuration setting for the is indirectly controlled by the configuration setting that controls IRI processing in the class. IRI processing must be enabled for IDN processing to be possible. If IRI processing is disabled, then IDN processing will be set to the default setting where the .NET Framework 2.0 behavior is used for compatibility and IDN names are not used. + + The Internationalized Domain Name (IDN) attribute only controls IDN processing. All other IRI processing (character normalization, for example) is performed by default. + + For more information on IRI and IDN support, see the Remarks section for the class. + ]]> diff --git a/xml/System/GenericUriParserOptions.xml b/xml/System/GenericUriParserOptions.xml index 3708cbb1601..c19f091d4e8 100644 --- a/xml/System/GenericUriParserOptions.xml +++ b/xml/System/GenericUriParserOptions.xml @@ -44,19 +44,19 @@ Specifies options for a . - constructor. - - The existing class has been extended to provide support for International Resource Identifiers (IRI) based on RFC 3987. Current users will not see any change from the .NET Framework 2.0 behavior unless they specifically enable IRI. This ensures application compatibility with prior versions of the .NET Framework. - - The configuration setting for the is indirectly controlled by the configuration setting that controls IRI processing in the class. IRI processing must be enabled for IDN processing to be possible. If IRI processing is disabled, then IDN processing will be set to the default setting where the .NET Framework 2.0 behavior is used for compatibility and IDN names are not used. - - The Internationalized Domain Name (IDN) attribute only controls IDN processing. All other IRI processing (character normalization, for example) is performed by default. - - For more information on IRI support, see the Remarks section for the class. - + constructor. + + The existing class has been extended to provide support for International Resource Identifiers (IRI) based on RFC 3987. Current users will not see any change from the .NET Framework 2.0 behavior unless they specifically enable IRI. This ensures application compatibility with prior versions of the .NET Framework. + + The configuration setting for the is indirectly controlled by the configuration setting that controls IRI processing in the class. IRI processing must be enabled for IDN processing to be possible. If IRI processing is disabled, then IDN processing will be set to the default setting where the .NET Framework 2.0 behavior is used for compatibility and IDN names are not used. + + The Internationalized Domain Name (IDN) attribute only controls IDN processing. All other IRI processing (character normalization, for example) is performed by default. + + For more information on IRI support, see the Remarks section for the class. + ]]> diff --git a/xml/System/GopherStyleUriParser.xml b/xml/System/GopherStyleUriParser.xml index 487362a118a..c6400f028f5 100644 --- a/xml/System/GopherStyleUriParser.xml +++ b/xml/System/GopherStyleUriParser.xml @@ -73,11 +73,11 @@ Creates a customizable parser based on the Gopher scheme. - - + + ]]> diff --git a/xml/System/Guid.xml b/xml/System/Guid.xml index 0f8c7f8d509..10ac6f64d43 100644 --- a/xml/System/Guid.xml +++ b/xml/System/Guid.xml @@ -107,23 +107,23 @@ Represents a globally unique identifier (GUID). - class to assign a GUID to an interface and to a user-defined class. It retrieves the value of the GUID by calling the method, and compares it with two other GUIDs to determine whether they are equal. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Guid/CPP/Guids.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/Guid/Overview/Guids.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/Guid/Overview/Guids.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Guid/VB/Guids.vb" id="Snippet1"::: - - Note that the attribute is typically used in an application to expose a type to COM. If you compile this example, you can run the [Assembly Registration tool (Regasm.exe)](/dotnet/framework/tools/regasm-exe-assembly-registration-tool) on the generated assembly to create registry (.reg) and type library (.tlb) files. The .reg file can be used to register the coclass in the registry, and the .tlb file can provide metadata for COM interop. - + class to assign a GUID to an interface and to a user-defined class. It retrieves the value of the GUID by calling the method, and compares it with two other GUIDs to determine whether they are equal. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Guid/CPP/Guids.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/Guid/Overview/Guids.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Guid/Overview/Guids.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Guid/VB/Guids.vb" id="Snippet1"::: + + Note that the attribute is typically used in an application to expose a type to COM. If you compile this example, you can run the [Assembly Registration tool (Regasm.exe)](/dotnet/framework/tools/regasm-exe-assembly-registration-tool) on the generated assembly to create registry (.reg) and type library (.tlb) files. The .reg file can be used to register the coclass in the registry, and the .tlb file can provide metadata for COM interop. + ]]> @@ -272,61 +272,61 @@ - A string that contains a GUID in one of the following formats ("d" represents a hexadecimal digit whose case is ignored): - - 32 contiguous hexadecimal digits: - - dddddddddddddddddddddddddddddddd - - -or- - - Groups of 8, 4, 4, 4, and 12 hexadecimal digits with hyphens between the groups. The entire GUID can optionally be enclosed in matching braces or parentheses: - - dddddddd-dddd-dddd-dddd-dddddddddddd - - -or- - - {dddddddd-dddd-dddd-dddd-dddddddddddd} - - -or- - - (dddddddd-dddd-dddd-dddd-dddddddddddd) - - -or- - - Groups of 8, 4, and 4 hexadecimal digits, and a subset of eight groups of 2 hexadecimal digits, with each group prefixed by "0x" or "0X", and separated by commas. The entire GUID, as well as the subset, is enclosed in matching braces: - - {0xdddddddd, 0xdddd, 0xdddd,{0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd}} - - All braces, commas, and "0x" prefixes are required. All embedded spaces are ignored. All leading zeros in a group are ignored. - - The hexadecimal digits shown in a group are the maximum number of meaningful hexadecimal digits that can appear in that group. You can specify from 1 to the number of hexadecimal digits shown for a group. The specified digits are assumed to be the low-order digits of the group. + A string that contains a GUID in one of the following formats ("d" represents a hexadecimal digit whose case is ignored): + + 32 contiguous hexadecimal digits: + + dddddddddddddddddddddddddddddddd + + -or- + + Groups of 8, 4, 4, 4, and 12 hexadecimal digits with hyphens between the groups. The entire GUID can optionally be enclosed in matching braces or parentheses: + + dddddddd-dddd-dddd-dddd-dddddddddddd + + -or- + + {dddddddd-dddd-dddd-dddd-dddddddddddd} + + -or- + + (dddddddd-dddd-dddd-dddd-dddddddddddd) + + -or- + + Groups of 8, 4, and 4 hexadecimal digits, and a subset of eight groups of 2 hexadecimal digits, with each group prefixed by "0x" or "0X", and separated by commas. The entire GUID, as well as the subset, is enclosed in matching braces: + + {0xdddddddd, 0xdddd, 0xdddd,{0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd,0xdd}} + + All braces, commas, and "0x" prefixes are required. All embedded spaces are ignored. All leading zeros in a group are ignored. + + The hexadecimal digits shown in a group are the maximum number of meaningful hexadecimal digits that can appear in that group. You can specify from 1 to the number of hexadecimal digits shown for a group. The specified digits are assumed to be the low-order digits of the group. Initializes a new instance of the structure by using the value represented by the specified string. - constructor. - - :::code language="csharp" source="~/snippets/csharp/System/Guid/.ctor/ctor1.cs" interactive="try-dotnet-method" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/Guid/.ctor/ctor1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.guid.ctor/vb/ctor1.vb" id="Snippet1"::: - + constructor. + + :::code language="csharp" source="~/snippets/csharp/System/Guid/.ctor/ctor1.cs" interactive="try-dotnet-method" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Guid/.ctor/ctor1.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.guid.ctor/vb/ctor1.vb" id="Snippet1"::: + ]]> @@ -417,11 +417,11 @@ The remaining 8 bytes of the GUID. Initializes a new instance of the structure by using the specified integers and byte array. - that corresponds to "00000001-0002-0003-0001-020304050607". - + that corresponds to "00000001-0002-0003-0001-020304050607". + ]]> @@ -491,20 +491,20 @@ The next byte of the GUID. Initializes a new instance of the structure by using the specified integers and bytes. - @@ -574,11 +574,11 @@ The next byte of the GUID. Initializes a new instance of the structure by using the specified unsigned integers and bytes. - @@ -641,54 +641,63 @@ An object to compare to this instance. Compares this instance to a specified object and returns an indication of their relative values. - A signed number indicating the relative values of this instance and . - - Return value - - Description - - A negative integer - - This instance is less than . - - Zero - - This instance is equal to . - - A positive integer - - This instance is greater than . - - + A signed number indicating the relative values of this instance and . + + Return value + + + Description + + + + + A negative integer + + + This instance is less than . + + + Zero + + + This instance is equal to . + + + A positive integer + + + This instance is greater than . + + - method compares the GUIDs as if they were values provided to the constructor, as follows: - -- It compares the values, and returns a result if they are unequal. If they are equal, it performs the next comparison. - -- It compares the first values, and returns a result if they are unequal. If they are equal, it performs the next comparison. - -- It compares the second values, and returns a result if they are unequal. If they are equal, it performs the next comparison. - -- If performs a byte-by-byte comparison of the next eight values. When it encounters the first unequal pair, it returns the result. Otherwise, it returns 0 to indicate that the two values are equal. - - Note that the final eight bytes appear in the string representation of a in reverse order, from low byte to high byte. For example, in the string representation of the value "01e75c83-c6f5-4192-b57e-7427cec5560d", the final eight bytes are "b57e-7427cec5560d." In other words, the final eight bytes are compared on a byte-by-byte basis from left to right starting with 0xb5. - - If two GUIDs have equal values for a component, the method compares the next component. When it finds a component whose values are unequal, it returns the result. - - This method implements the interface and performs slightly better than the method because it does not have to convert the `value` parameter to a value. - - - -## Examples - The following example calls the method to compare a GUID value with two similar GUID values. - - :::code language="csharp" source="~/snippets/csharp/System/Guid/CompareTo/compareto2.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/Guid/CompareTo/compareto2.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.guid.compareto/vb/compareto2.vb" id="Snippet1"::: - + method compares the GUIDs as if they were values provided to the constructor, as follows: + +- It compares the values, and returns a result if they are unequal. If they are equal, it performs the next comparison. + +- It compares the first values, and returns a result if they are unequal. If they are equal, it performs the next comparison. + +- It compares the second values, and returns a result if they are unequal. If they are equal, it performs the next comparison. + +- If performs a byte-by-byte comparison of the next eight values. When it encounters the first unequal pair, it returns the result. Otherwise, it returns 0 to indicate that the two values are equal. + + Note that the final eight bytes appear in the string representation of a in reverse order, from low byte to high byte. For example, in the string representation of the value "01e75c83-c6f5-4192-b57e-7427cec5560d", the final eight bytes are "b57e-7427cec5560d." In other words, the final eight bytes are compared on a byte-by-byte basis from left to right starting with 0xb5. + + If two GUIDs have equal values for a component, the method compares the next component. When it finds a component whose values are unequal, it returns the result. + + This method implements the interface and performs slightly better than the method because it does not have to convert the `value` parameter to a value. + + + +## Examples + The following example calls the method to compare a GUID value with two similar GUID values. + + :::code language="csharp" source="~/snippets/csharp/System/Guid/CompareTo/compareto2.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Guid/CompareTo/compareto2.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.guid.compareto/vb/compareto2.vb" id="Snippet1"::: + ]]> @@ -742,54 +751,63 @@ An object to compare, or . Compares this instance to a specified object and returns an indication of their relative values. - A signed number indicating the relative values of this instance and . - - Return value - - Description - - A negative integer - - This instance is less than . - - Zero - - This instance is equal to . - - A positive integer - - This instance is greater than , or is . - - + A signed number indicating the relative values of this instance and . + + Return value + + + Description + + + + + A negative integer + + + This instance is less than . + + + Zero + + + This instance is equal to . + + + A positive integer + + + This instance is greater than , or is . + + - ; otherwise, an exception is thrown. Any instance of , regardless of its value, is considered greater than `null`. - - The method compares the GUIDs as if they were values provided to the constructor, as follows: - -- It compares the values, and returns a result if they are unequal. If they are equal, it performs the next comparison. - -- It compares the first values, and returns a result if they are unequal. If they are equal, it performs the next comparison. - -- It compares the second values, and returns a result if they are unequal. If they are equal, it performs the next comparison. - -- If performs a byte-by-byte comparison of the next eight values. When it encounters the first unequal pair, it returns the result. Otherwise, it returns 0 to indicate that the two values are equal. - - If two GUIDs have equal values for a component, the method compares the next component. When it finds a component whose values are unequal, it returns the result. - - Note that the final eight bytes appear in the string representation of a in reverse order, from low byte to high byte. For example, in the string representation of the value "01e75c83-c6f5-4192-b57e-7427cec5560d", the final eight bytes are "b57e-7427cec5560d." - - - -## Examples - The following example uses the attribute to assign a GUID to a class. It retrieves the value of this GUID by calling the method and passing the property of the returned object to the method. Then it compares that GUID with an array of values. - - :::code language="csharp" source="~/snippets/csharp/System/Guid/CompareTo/compareto1.cs" interactive="try-dotnet" id="Snippet2"::: - :::code language="fsharp" source="~/snippets/fsharp/System/Guid/CompareTo/compareto1.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.guid.compareto/vb/compareto1.vb" id="Snippet2"::: - + ; otherwise, an exception is thrown. Any instance of , regardless of its value, is considered greater than `null`. + + The method compares the GUIDs as if they were values provided to the constructor, as follows: + +- It compares the values, and returns a result if they are unequal. If they are equal, it performs the next comparison. + +- It compares the first values, and returns a result if they are unequal. If they are equal, it performs the next comparison. + +- It compares the second values, and returns a result if they are unequal. If they are equal, it performs the next comparison. + +- If performs a byte-by-byte comparison of the next eight values. When it encounters the first unequal pair, it returns the result. Otherwise, it returns 0 to indicate that the two values are equal. + + If two GUIDs have equal values for a component, the method compares the next component. When it finds a component whose values are unequal, it returns the result. + + Note that the final eight bytes appear in the string representation of a in reverse order, from low byte to high byte. For example, in the string representation of the value "01e75c83-c6f5-4192-b57e-7427cec5560d", the final eight bytes are "b57e-7427cec5560d." + + + +## Examples + The following example uses the attribute to assign a GUID to a class. It retrieves the value of this GUID by calling the method and passing the property of the returned object to the method. Then it compares that GUID with an array of values. + + :::code language="csharp" source="~/snippets/csharp/System/Guid/CompareTo/compareto1.cs" interactive="try-dotnet" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Guid/CompareTo/compareto1.fs" id="Snippet2"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.guid.compareto/vb/compareto1.vb" id="Snippet2"::: + ]]> @@ -836,15 +854,15 @@ A read-only instance of the structure whose value is all zeros. - field to determine whether a GUID is non-zero. The following example uses the operator to compare two GUID values with to determine whether they consist exclusively of zeros. - - :::code language="csharp" source="~/snippets/csharp/System/Guid/Empty/empty.cs" interactive="try-dotnet-method" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/Guid/Empty/empty.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.guid.empty/vb/empty.vb" id="Snippet1"::: - + field to determine whether a GUID is non-zero. The following example uses the operator to compare two GUID values with to determine whether they consist exclusively of zeros. + + :::code language="csharp" source="~/snippets/csharp/System/Guid/Empty/empty.cs" interactive="try-dotnet-method" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Guid/Empty/empty.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.guid.empty/vb/empty.vb" id="Snippet1"::: + ]]> @@ -910,13 +928,13 @@ if is equal to this instance; otherwise, . - objects are equal if they have identical byte values. - - This method performs slightly better than the method because it does not have to box the `g` parameter. - + objects are equal if they have identical byte values. + + This method performs slightly better than the method because it does not have to box the `g` parameter. + ]]> @@ -983,11 +1001,11 @@ if is a that has the same value as this instance; otherwise, . - objects are equal if they have identical byte values. - + objects are equal if they have identical byte values. + ]]> @@ -1084,26 +1102,26 @@ Initializes a new instance of the structure. A new GUID object. - . The method creates a Version 4 Universally Unique Identifier (UUID) as described in [RFC 4122, Sec. 4.4](https://datatracker.ietf.org/doc/html/rfc4122#section-4.4). The returned is guaranteed to not equal . - - On Windows, this function wraps a call to the [CoCreateGuid](/windows/win32/api/combaseapi/nf-combaseapi-cocreateguid) function. The generated GUID contains 122 bits of strong entropy. - - On non-Windows platforms, starting with .NET 6, this function calls the OS's underlying cryptographically secure pseudo-random number generator (CSPRNG) to generate 122 bits of strong entropy. In previous versions of .NET, the entropy is not guaranteed to be generated by a CSPRNG. - - It is recommended that applications __not__ use the _NewGuid_ method for cryptographic purposes. First, since a Version 4 UUID has a partially predictable bit pattern, the _NewGuid_ function cannot serve as a proper cryptographic pseudo-random function (PRF). If the output of _NewGuid_ is given to a cryptographic component which requires its input to be generated by a proper PRF, the cryptographic component may not be able to maintain its security properties. Second, _NewGuid_ utilizes at most 122 bits of entropy, regardless of platform. Some cryptographic components set a minimum entropy level on their inputs as a matter of policy. Such policies often set the minimum entropy level at 128 bits or higher. Passing the output of _NewGuid_ to such a routine may violate its policy. - - If an application requires random data for cryptographic purposes, consider using a static method on the class. That class provides a random number generator suitable for cryptographic use. - -## Examples - The following code example creates and displays the values of two objects. - - :::code language="csharp" source="~/snippets/csharp/System/Guid/NewGuid/ng.cs" interactive="try-dotnet-method" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/Guid/NewGuid/ng.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.guid.newguid/vb/ng.vb" id="Snippet1"::: - + . The method creates a Version 4 Universally Unique Identifier (UUID) as described in [RFC 4122, Sec. 4.4](https://datatracker.ietf.org/doc/html/rfc4122#section-4.4). The returned is guaranteed to not equal . + + On Windows, this function wraps a call to the [CoCreateGuid](/windows/win32/api/combaseapi/nf-combaseapi-cocreateguid) function. The generated GUID contains 122 bits of strong entropy. + + On non-Windows platforms, starting with .NET 6, this function calls the OS's underlying cryptographically secure pseudo-random number generator (CSPRNG) to generate 122 bits of strong entropy. In previous versions of .NET, the entropy is not guaranteed to be generated by a CSPRNG. + + It is recommended that applications __not__ use the _NewGuid_ method for cryptographic purposes. First, since a Version 4 UUID has a partially predictable bit pattern, the _NewGuid_ function cannot serve as a proper cryptographic pseudo-random function (PRF). If the output of _NewGuid_ is given to a cryptographic component which requires its input to be generated by a proper PRF, the cryptographic component may not be able to maintain its security properties. Second, _NewGuid_ utilizes at most 122 bits of entropy, regardless of platform. Some cryptographic components set a minimum entropy level on their inputs as a matter of policy. Such policies often set the minimum entropy level at 128 bits or higher. Passing the output of _NewGuid_ to such a routine may violate its policy. + + If an application requires random data for cryptographic purposes, consider using a static method on the class. That class provides a random number generator suitable for cryptographic use. + +## Examples + The following code example creates and displays the values of two objects. + + :::code language="csharp" source="~/snippets/csharp/System/Guid/NewGuid/ng.cs" interactive="try-dotnet-method" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Guid/NewGuid/ng.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.guid.newguid/vb/ng.vb" id="Snippet1"::: + ]]> @@ -1156,15 +1174,15 @@ if and are equal; otherwise, . - - -## Examples - The following example uses the operator to compare two GUID values with to determine whether they consist exclusively of zeros. - - :::code language="csharp" source="~/snippets/csharp/System/Guid/Empty/empty.cs" interactive="try-dotnet-method" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/Guid/Empty/empty.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.guid.empty/vb/empty.vb" id="Snippet1"::: - + + +## Examples + The following example uses the operator to compare two GUID values with to determine whether they consist exclusively of zeros. + + :::code language="csharp" source="~/snippets/csharp/System/Guid/Empty/empty.cs" interactive="try-dotnet-method" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Guid/Empty/empty.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.guid.empty/vb/empty.vb" id="Snippet1"::: + ]]> @@ -1400,37 +1418,37 @@ Converts a read-only character span that represents a GUID to the equivalent structure. A structure that contains the value that was parsed. - method trims any leading or trailing white space characters from `input` and converts the remaining characters in `input` to a value. This method can convert a character span that represents any of the five formats produced by the methods, as shown in the following table. - -|Specifier|Description|Format| -|---------------|-----------------|------------| -|`N`|32 hexadecimal digits|00000000000000000000000000000000| -|`D`|32 hexadecimal digits separated by hyphens|00000000-0000-0000-0000-000000000000| -|`B`|32 hexadecimal digits separated by hyphens, enclosed in braces|{00000000-0000-0000-0000-000000000000}| -|`P`|32 hexadecimal digits separated by hyphens, enclosed in parentheses|(00000000-0000-0000-0000-000000000000)| -|`X`|Four hexadecimal values enclosed in braces, where the fourth value is a subset of eight hexadecimal values that is also enclosed in braces|{0x00000000,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}| - -The method throws a if it is unable to successfully parse the string. Some of the reasons why this might occur include: - -- `input` contains characters that are not part of the hexadecimal character set. - -- `input` has too many or too few characters. - -- `input` is not in one of the formats recognized by the method and listed in the previous table. - -Use the method to catch any unsuccessful parse operations without having to handle an exception. - + method trims any leading or trailing white space characters from `input` and converts the remaining characters in `input` to a value. This method can convert a character span that represents any of the five formats produced by the methods, as shown in the following table. + +|Specifier|Description|Format| +|---------------|-----------------|------------| +|`N`|32 hexadecimal digits|00000000000000000000000000000000| +|`D`|32 hexadecimal digits separated by hyphens|00000000-0000-0000-0000-000000000000| +|`B`|32 hexadecimal digits separated by hyphens, enclosed in braces|{00000000-0000-0000-0000-000000000000}| +|`P`|32 hexadecimal digits separated by hyphens, enclosed in parentheses|(00000000-0000-0000-0000-000000000000)| +|`X`|Four hexadecimal values enclosed in braces, where the fourth value is a subset of eight hexadecimal values that is also enclosed in braces|{0x00000000,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}| + +The method throws a if it is unable to successfully parse the string. Some of the reasons why this might occur include: + +- `input` contains characters that are not part of the hexadecimal character set. + +- `input` has too many or too few characters. + +- `input` is not in one of the formats recognized by the method and listed in the previous table. + +Use the method to catch any unsuccessful parse operations without having to handle an exception. + ]]> - is not in a recognized format. - --or- - + is not in a recognized format. + +-or- + After trimming, the length of the read-only character span is 0. @@ -1483,36 +1501,36 @@ After trimming, the length of the read-only character span is 0. Converts the string representation of a GUID to the equivalent structure. A structure that contains the value that was parsed. - method trims any leading or trailing white space from `input` and converts the string representation of a GUID to a value. This method can convert strings in any of the five formats produced by the and methods, as shown in the following table. - -|Specifier|Description|Format| -|---------------|-----------------|------------| -|`N`|32 hexadecimal digits|00000000000000000000000000000000| -|`D`|32 hexadecimal digits separated by hyphens|00000000-0000-0000-0000-000000000000| -|`B`|32 hexadecimal digits separated by hyphens, enclosed in braces|{00000000-0000-0000-0000-000000000000}| -|`P`|32 hexadecimal digits separated by hyphens, enclosed in parentheses|(00000000-0000-0000-0000-000000000000)| -|`X`|Four hexadecimal values enclosed in braces, where the fourth value is a subset of eight hexadecimal values that is also enclosed in braces|{0x00000000,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}| - - The method throws a if it is unable to successfully parse the string. Some of the reasons why this might occur include: - -- `input` contains characters that are not part of the hexadecimal character set. - -- `input` has too many or too few characters. - -- `input` is not in one of the formats recognized by the method and listed in the previous table. - - Use the method to catch any unsuccessful parse operations without having to handle an exception. - -## Examples - The following example creates a new GUID, converts it to three separate string representations by calling the method with the "B", "D", and "X" format specifiers, and then calls the method to convert the strings back to values. - - :::code language="csharp" source="~/snippets/csharp/System/Guid/Parse/parseex1.cs" interactive="try-dotnet-method" id="Snippet3"::: - :::code language="fsharp" source="~/snippets/fsharp/System/Guid/Parse/parseex1.fs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.guid.parse/vb/parseex1.vb" id="Snippet3"::: - + method trims any leading or trailing white space from `input` and converts the string representation of a GUID to a value. This method can convert strings in any of the five formats produced by the and methods, as shown in the following table. + +|Specifier|Description|Format| +|---------------|-----------------|------------| +|`N`|32 hexadecimal digits|00000000000000000000000000000000| +|`D`|32 hexadecimal digits separated by hyphens|00000000-0000-0000-0000-000000000000| +|`B`|32 hexadecimal digits separated by hyphens, enclosed in braces|{00000000-0000-0000-0000-000000000000}| +|`P`|32 hexadecimal digits separated by hyphens, enclosed in parentheses|(00000000-0000-0000-0000-000000000000)| +|`X`|Four hexadecimal values enclosed in braces, where the fourth value is a subset of eight hexadecimal values that is also enclosed in braces|{0x00000000,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}| + + The method throws a if it is unable to successfully parse the string. Some of the reasons why this might occur include: + +- `input` contains characters that are not part of the hexadecimal character set. + +- `input` has too many or too few characters. + +- `input` is not in one of the formats recognized by the method and listed in the previous table. + + Use the method to catch any unsuccessful parse operations without having to handle an exception. + +## Examples + The following example creates a new GUID, converts it to three separate string representations by calling the method with the "B", "D", and "X" format specifiers, and then calls the method to convert the strings back to values. + + :::code language="csharp" source="~/snippets/csharp/System/Guid/Parse/parseex1.cs" interactive="try-dotnet-method" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Guid/Parse/parseex1.fs" id="Snippet3"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.guid.parse/vb/parseex1.vb" id="Snippet3"::: + ]]> @@ -1663,20 +1681,20 @@ After trimming, the length of the read-only character span is 0. Converts the character span representation of a GUID to the equivalent structure, provided that the string is in the specified format. A structure that contains the value that was parsed. - method requires the read-only character span to convert to be exactly in the format specified by the `format` parameter, after leading and trailing white-space characters are removed. The following table shows the accepted format specifiers for the `format` parameter. "0" represents a digit; hyphens ("-"), braces ("{", "}"), and parentheses ("(", ")") appear as shown. - -|Specifier|Format of the `input` parameter| -|---------------|-------------------------------------| -|N|32 hexadecimal digits:

00000000000000000000000000000000| -|D|32 hexadecimal digits separated by hyphens:

00000000-0000-0000-0000-000000000000| -|B|32 hexadecimal digits separated by hyphens, enclosed in braces:

{00000000-0000-0000-0000-000000000000}| -|P|32 hexadecimal digits separated by hyphens, enclosed in parentheses:

(00000000-0000-0000-0000-000000000000)| -|X|Four hexadecimal values enclosed in braces, where the fourth value is a subset of eight hexadecimal values that is also enclosed in braces:

{0x00000000,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}| - + method requires the read-only character span to convert to be exactly in the format specified by the `format` parameter, after leading and trailing white-space characters are removed. The following table shows the accepted format specifiers for the `format` parameter. "0" represents a digit; hyphens ("-"), braces ("{", "}"), and parentheses ("(", ")") appear as shown. + +|Specifier|Format of the `input` parameter| +|---------------|-------------------------------------| +|N|32 hexadecimal digits:

00000000000000000000000000000000| +|D|32 hexadecimal digits separated by hyphens:

00000000-0000-0000-0000-000000000000| +|B|32 hexadecimal digits separated by hyphens, enclosed in braces:

{00000000-0000-0000-0000-000000000000}| +|P|32 hexadecimal digits separated by hyphens, enclosed in parentheses:

(00000000-0000-0000-0000-000000000000)| +|X|Four hexadecimal values enclosed in braces, where the fourth value is a subset of eight hexadecimal values that is also enclosed in braces:

{0x00000000,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}| + ]]>
@@ -1739,26 +1757,26 @@ The method requires the read-only character spa Converts the string representation of a GUID to the equivalent structure, provided that the string is in the specified format. A structure that contains the value that was parsed. - method requires the string to convert to be exactly in the format specified by the `format` parameter, after leading and trailing white-space characters are removed. The following table shows the accepted format specifiers for the `format` parameter. "0" represents a digit; hyphens ("-"), braces ("{", "}"), and parentheses ("(", ")") appear as shown. - -|Specifier|Format of the `input` parameter| -|---------------|-------------------------------------| -|N|32 hexadecimal digits:

00000000000000000000000000000000| -|D|32 hexadecimal digits separated by hyphens:

00000000-0000-0000-0000-000000000000| -|B|32 hexadecimal digits separated by hyphens, enclosed in braces:

{00000000-0000-0000-0000-000000000000}| -|P|32 hexadecimal digits separated by hyphens, enclosed in parentheses:

(00000000-0000-0000-0000-000000000000)| -|X|Four hexadecimal values enclosed in braces, where the fourth value is a subset of eight hexadecimal values that is also enclosed in braces:

{0x00000000,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}| - -## Examples - The following example calls the method with each of the supported format specifiers to generate an array of strings that represent a single GUID. These are then passed to the method, which successfully parses only the string that conforms to the "B" format specifier. - - :::code language="csharp" source="~/snippets/csharp/System/Guid/Parse/parseexactex1.cs" interactive="try-dotnet-method" id="Snippet4"::: - :::code language="fsharp" source="~/snippets/fsharp/System/Guid/Parse/parseexactex1.fs" id="Snippet4"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.guid.parse/vb/parseexactex1.vb" id="Snippet4"::: - + method requires the string to convert to be exactly in the format specified by the `format` parameter, after leading and trailing white-space characters are removed. The following table shows the accepted format specifiers for the `format` parameter. "0" represents a digit; hyphens ("-"), braces ("{", "}"), and parentheses ("(", ")") appear as shown. + +|Specifier|Format of the `input` parameter| +|---------------|-------------------------------------| +|N|32 hexadecimal digits:

00000000000000000000000000000000| +|D|32 hexadecimal digits separated by hyphens:

00000000-0000-0000-0000-000000000000| +|B|32 hexadecimal digits separated by hyphens, enclosed in braces:

{00000000-0000-0000-0000-000000000000}| +|P|32 hexadecimal digits separated by hyphens, enclosed in parentheses:

(00000000-0000-0000-0000-000000000000)| +|X|Four hexadecimal values enclosed in braces, where the fourth value is a subset of eight hexadecimal values that is also enclosed in braces:

{0x00000000,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}| + +## Examples + The following example calls the method with each of the supported format specifiers to generate an array of strings that represent a single GUID. These are then passed to the method, which successfully parses only the string that conforms to the "B" format specifier. + + :::code language="csharp" source="~/snippets/csharp/System/Guid/Parse/parseexactex1.cs" interactive="try-dotnet-method" id="Snippet4"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Guid/Parse/parseexactex1.fs" id="Snippet4"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.guid.parse/vb/parseexactex1.vb" id="Snippet4"::: + ]]>
@@ -1801,28 +1819,44 @@ The method requires the read-only character spa An object to compare to this instance. Compares this instance to a specified object and returns an indication of their relative values. - A signed number indicating the relative values of this instance and . - Return valueDescriptionA negative integerThis instance is less than .ZeroThis instance is equal to .A positive integerThis instance is greater than . + A signed number indicating the relative values of this instance and . + + Return value + Description + + + A negative integer + This instance is less than . + + + Zero + This instance is equal to . + + + A positive integer + This instance is greater than . + + - instance is cast to an interface. - -The `CompareTo` method compares the GUIDs as if they were values provided to the constructor, as follows: - -- It compares the values, and returns a result if they are unequal. If they are equal, it performs the next comparison. -- It compares the first values, and returns a result if they are unequal. If they are equal, it performs the next comparison. -- It compares the second values, and returns a result if they are unequal. If they are equal, it performs the next comparison. -- If performs a byte-by-byte comparison of the next eight values. When it encounters the first unequal pair, it returns the result. Otherwise, it returns 0 to indicate that the two values are equal. - -Note that the final eight bytes appear in the string representation of a in reverse order, from low byte to high byte. For example, in the string representation of the value "01e75c83-c6f5-4192-b57e-7427cec5560d", the final eight bytes are "b57e-7427cec5560d." In other words, the final eight bytes are compared on a byte-by-byte basis from left to right starting with 0xb5. - -If two GUIDs have equal values for a component, the method compares the next component. When it finds a component whose values are unequal, it returns the result. - -This method implements the interface and performs slightly better than the method because it does not have to convert the `value` parameter to a value. - + instance is cast to an interface. + +The `CompareTo` method compares the GUIDs as if they were values provided to the constructor, as follows: + +- It compares the values, and returns a result if they are unequal. If they are equal, it performs the next comparison. +- It compares the first values, and returns a result if they are unequal. If they are equal, it performs the next comparison. +- It compares the second values, and returns a result if they are unequal. If they are equal, it performs the next comparison. +- If performs a byte-by-byte comparison of the next eight values. When it encounters the first unequal pair, it returns the result. Otherwise, it returns 0 to indicate that the two values are equal. + +Note that the final eight bytes appear in the string representation of a in reverse order, from low byte to high byte. For example, in the string representation of the value "01e75c83-c6f5-4192-b57e-7427cec5560d", the final eight bytes are "b57e-7427cec5560d." In other words, the final eight bytes are compared on a byte-by-byte basis from left to right starting with 0xb5. + +If two GUIDs have equal values for a component, the method compares the next component. When it finds a component whose values are unequal, it returns the result. + +This method implements the interface and performs slightly better than the method because it does not have to convert the `value` parameter to a value. + ]]> @@ -1864,26 +1898,26 @@ This method implements the Returns a string representation of the value of this instance, according to the provided format specifier and culture-specific format information. The value of this represented as a series of lowercase hexadecimal digits in the specified format. -
00000000000000000000000000000000| -|`D`|32 digits separated by hyphens:

00000000-0000-0000-0000-000000000000| -|`B`|32 digits separated by hyphens, enclosed in braces:

{00000000-0000-0000-0000-000000000000}| -|`P`|32 digits separated by hyphens, enclosed in parentheses:

(00000000-0000-0000-0000-000000000000)| -|`X`|Four hexadecimal values enclosed in braces, where the fourth value is a subset of eight hexadecimal values that is also enclosed in braces:

{0x00000000,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}| - -The hexadecimal digits a through f are lowercase in the returned string. To convert them to uppercase, call the method on the returned string. - -Because the `provider` parameter is ignored, you cannot use it to provide a custom formatting solution. To represent a value as a string in a format that isn't supported by the standard GUID format strings, call the method with a `provider` object that implements both the and interfaces. For more information, see the ["Custom Formatting with ICustomFormatter"](/dotnet/standard/base-types/formatting-types#custom-formatting-with-icustomformatter) section in the [Formatting Types](/dotnet/standard/base-types/formatting-types) article. - +
00000000000000000000000000000000| +|`D`|32 digits separated by hyphens:

00000000-0000-0000-0000-000000000000| +|`B`|32 digits separated by hyphens, enclosed in braces:

{00000000-0000-0000-0000-000000000000}| +|`P`|32 digits separated by hyphens, enclosed in parentheses:

(00000000-0000-0000-0000-000000000000)| +|`X`|Four hexadecimal values enclosed in braces, where the fourth value is a subset of eight hexadecimal values that is also enclosed in braces:

{0x00000000,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}| + +The hexadecimal digits a through f are lowercase in the returned string. To convert them to uppercase, call the method on the returned string. + +Because the `provider` parameter is ignored, you cannot use it to provide a custom formatting solution. To represent a value as a string in a format that isn't supported by the standard GUID format strings, call the method with a `provider` object that implements both the and interfaces. For more information, see the ["Custom Formatting with ICustomFormatter"](/dotnet/standard/base-types/formatting-types#custom-formatting-with-icustomformatter) section in the [Formatting Types](/dotnet/standard/base-types/formatting-types) article. + ]]>
The value of is not null, an empty string (""), or one of the following single format specifiers:"N", "D", "B", "P", or "X". @@ -2035,22 +2069,22 @@ Because the `provider` parameter is ignored, you cannot use it to provide a cust Returns a 16-element byte array that contains the value of this instance. A 16-element byte array. - value by calling the constructor. - - Note that the order of bytes in the returned byte array is different from the string representation of a value. The order of the beginning four-byte group and the next two two-byte groups is reversed, whereas the order of the last two-byte group and the closing six-byte group is the same. The example provides an illustration. - - - -## Examples - The following example calls the method to create a value, and then calls the method to represent the value as a byte array. It then displays both values to the console. Finally, it instantiates a new value from the byte array and calls its method to show that the two values are identical. - - :::code language="csharp" source="~/snippets/csharp/System/Guid/ToByteArray/tobytearray3.cs" interactive="try-dotnet-method" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/Guid/ToByteArray/tobytearray3.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.guid.tobytearray/vb/tobytearray3.vb" id="Snippet1"::: - + value by calling the constructor. + + Note that the order of bytes in the returned byte array is different from the string representation of a value. The order of the beginning four-byte group and the next two two-byte groups is reversed, whereas the order of the last two-byte group and the closing six-byte group is the same. The example provides an illustration. + + + +## Examples + The following example calls the method to create a value, and then calls the method to represent the value as a byte array. It then displays both values to the console. Finally, it instantiates a new value from the byte array and calls its method to show that the two values are identical. + + :::code language="csharp" source="~/snippets/csharp/System/Guid/ToByteArray/tobytearray3.cs" interactive="try-dotnet-method" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Guid/ToByteArray/tobytearray3.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.guid.tobytearray/vb/tobytearray3.vb" id="Snippet1"::: + ]]> @@ -2151,17 +2185,13 @@ Because the `provider` parameter is ignored, you cannot use it to provide a cust Returns a string representation of the value of this instance in registry format. - The value of this , formatted by using the "D" format specifier as follows: - - xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx - - where the value of the GUID is represented as a series of lowercase hexadecimal digits in groups of 8, 4, 4, 4, and 12 digits and separated by hyphens. An example of a return value is "382c74c3-721d-4f34-80e5-57657b6cbc27". To convert the hexadecimal digits from a through f to uppercase, call the method on the returned string. + The value of this , formatted by using the "D" format specifier as follows: xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx where the value of the GUID is represented as a series of lowercase hexadecimal digits in groups of 8, 4, 4, 4, and 12 digits and separated by hyphens. An example of a return value is "382c74c3-721d-4f34-80e5-57657b6cbc27". To convert the hexadecimal digits from a through f to uppercase, call the method on the returned string. - @@ -2229,21 +2259,21 @@ Because the `provider` parameter is ignored, you cannot use it to provide a cust Returns a string representation of the value of this instance, according to the provided format specifier. The value of this , represented as a series of lowercase hexadecimal digits in the specified format. -
00000000000000000000000000000000| -|`D`|32 digits separated by hyphens:

00000000-0000-0000-0000-000000000000| -|`B`|32 digits separated by hyphens, enclosed in braces:

{00000000-0000-0000-0000-000000000000}| -|`P`|32 digits separated by hyphens, enclosed in parentheses:

(00000000-0000-0000-0000-000000000000)| -|`X`|Four hexadecimal values enclosed in braces, where the fourth value is a subset of eight hexadecimal values that is also enclosed in braces:

{0x00000000,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}| - - The hexadecimal digits a through f are lowercase in the returned string. To convert them to uppercase, call the method on the returned string. - +
00000000000000000000000000000000| +|`D`|32 digits separated by hyphens:

00000000-0000-0000-0000-000000000000| +|`B`|32 digits separated by hyphens, enclosed in braces:

{00000000-0000-0000-0000-000000000000}| +|`P`|32 digits separated by hyphens, enclosed in parentheses:

(00000000-0000-0000-0000-000000000000)| +|`X`|Four hexadecimal values enclosed in braces, where the fourth value is a subset of eight hexadecimal values that is also enclosed in braces:

{0x00000000,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}| + + The hexadecimal digits a through f are lowercase in the returned string. To convert them to uppercase, call the method on the returned string. + ]]>
The value of is not , an empty string (""), "N", "D", "B", "P", or "X". @@ -2313,25 +2343,25 @@ Because the `provider` parameter is ignored, you cannot use it to provide a cust Returns a string representation of the value of this instance of the class, according to the provided format specifier and culture-specific format information. The value of this , represented as a series of lowercase hexadecimal digits in the specified format. -
00000000000000000000000000000000| -|`D`|32 digits separated by hyphens:

00000000-0000-0000-0000-000000000000| -|`B`|32 digits separated by hyphens, enclosed in braces:

{00000000-0000-0000-0000-000000000000}| -|`P`|32 digits separated by hyphens, enclosed in parentheses:

(00000000-0000-0000-0000-000000000000)| -|`X`|Four hexadecimal values enclosed in braces, where the fourth value is a subset of eight hexadecimal values that is also enclosed in braces:

{0x00000000,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}| - - The hexadecimal digits a through f are lowercase in the returned string. To convert them to uppercase, call the method on the returned string. - - Because the `provider` parameter is ignored, you cannot use it to provide a custom formatting solution. To represent a value as a string in a format that isn't supported by the standard GUID format strings, call the method with a `provider` object that implements both the and interfaces. For more information, see the "Custom Formatting with ICustomFormatter" section in the [Formatting Types](/dotnet/standard/base-types/formatting-types) article. - +
00000000000000000000000000000000| +|`D`|32 digits separated by hyphens:

00000000-0000-0000-0000-000000000000| +|`B`|32 digits separated by hyphens, enclosed in braces:

{00000000-0000-0000-0000-000000000000}| +|`P`|32 digits separated by hyphens, enclosed in parentheses:

(00000000-0000-0000-0000-000000000000)| +|`X`|Four hexadecimal values enclosed in braces, where the fourth value is a subset of eight hexadecimal values that is also enclosed in braces:

{0x00000000,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}| + + The hexadecimal digits a through f are lowercase in the returned string. To convert them to uppercase, call the method on the returned string. + + Because the `provider` parameter is ignored, you cannot use it to provide a custom formatting solution. To represent a value as a string in a format that isn't supported by the standard GUID format strings, call the method with a `provider` object that implements both the and interfaces. For more information, see the "Custom Formatting with ICustomFormatter" section in the [Formatting Types](/dotnet/standard/base-types/formatting-types) article. + ]]>
The value of is not , an empty string (""), "N", "D", "B", "P", or "X". @@ -2526,26 +2556,26 @@ Because the `provider` parameter is ignored, you cannot use it to provide a cust if the parse operation was successful; otherwise, . - method, except that instead of returning the parsed GUID, it returns `false` if `input` is `null` or not in a recognized format, and doesn't throw an exception. It trims any leading or trailing white space from `input` and converts strings in any of the five formats recognized by the and methods, as shown in the following table. - -|Specifier|Description|Format| -|---------------|-----------------|------------| -|`N`|32 digits|00000000000000000000000000000000| -|`D`|32 digits separated by hyphens|00000000-0000-0000-0000-000000000000| -|`B`|32 digits separated by hyphens, enclosed in braces|{00000000-0000-0000-0000-000000000000}| -|`P`|32 digits separated by hyphens, enclosed in parentheses|(00000000-0000-0000-0000-000000000000)| -|`X`|Four hexadecimal values enclosed in braces, where the fourth value is a subset of eight hexadecimal values that is also enclosed in braces|{0x00000000,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}| - -## Examples - The following example creates a new GUID, converts it to three separate string representations by calling the method with the "B", "D", and "X" format specifiers, and then calls the method to convert the strings back to values. - - :::code language="csharp" source="~/snippets/csharp/System/Guid/Parse/tryparseex1.cs" interactive="try-dotnet-method" id="Snippet2"::: - :::code language="fsharp" source="~/snippets/fsharp/System/Guid/Parse/tryparseex1.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.guid.parse/vb/tryparseex1.vb" id="Snippet2"::: - + method, except that instead of returning the parsed GUID, it returns `false` if `input` is `null` or not in a recognized format, and doesn't throw an exception. It trims any leading or trailing white space from `input` and converts strings in any of the five formats recognized by the and methods, as shown in the following table. + +|Specifier|Description|Format| +|---------------|-----------------|------------| +|`N`|32 digits|00000000000000000000000000000000| +|`D`|32 digits separated by hyphens|00000000-0000-0000-0000-000000000000| +|`B`|32 digits separated by hyphens, enclosed in braces|{00000000-0000-0000-0000-000000000000}| +|`P`|32 digits separated by hyphens, enclosed in parentheses|(00000000-0000-0000-0000-000000000000)| +|`X`|Four hexadecimal values enclosed in braces, where the fourth value is a subset of eight hexadecimal values that is also enclosed in braces|{0x00000000,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}| + +## Examples + The following example creates a new GUID, converts it to three separate string representations by calling the method with the "B", "D", and "X" format specifiers, and then calls the method to convert the strings back to values. + + :::code language="csharp" source="~/snippets/csharp/System/Guid/Parse/tryparseex1.cs" interactive="try-dotnet-method" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Guid/Parse/tryparseex1.fs" id="Snippet2"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.guid.parse/vb/tryparseex1.vb" id="Snippet2"::: + ]]> @@ -2769,28 +2799,28 @@ Because the `provider` parameter is ignored, you cannot use it to provide a cust if the parse operation was successful; otherwise, . -
00000000000000000000000000000000| -|D|32 digits separated by hyphens:

00000000-0000-0000-0000-000000000000| -|B|32 digits separated by hyphens, enclosed in braces:

{00000000-0000-0000-0000-000000000000}| -|P|32 digits separated by hyphens, enclosed in parentheses:

(00000000-0000-0000-0000-000000000000)| -|X|Four hexadecimal values enclosed in braces, where the fourth value is a subset of eight hexadecimal values that is also enclosed in braces:

{0x00000000,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}| - -## Examples - The following example calls the method with each of the supported format specifiers to generate an array of strings that represent a single GUID. These are then passed to the method, which successfully parses the string that conforms to the "B" format specifier. - - :::code language="csharp" source="~/snippets/csharp/System/Guid/Parse/tryparseexactex1.cs" interactive="try-dotnet-method" id="Snippet5"::: - :::code language="fsharp" source="~/snippets/fsharp/System/Guid/Parse/tryparseexactex1.fs" id="Snippet5"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.guid.parse/vb/tryparseexactex1.vb" id="Snippet5"::: - +
00000000000000000000000000000000| +|D|32 digits separated by hyphens:

00000000-0000-0000-0000-000000000000| +|B|32 digits separated by hyphens, enclosed in braces:

{00000000-0000-0000-0000-000000000000}| +|P|32 digits separated by hyphens, enclosed in parentheses:

(00000000-0000-0000-0000-000000000000)| +|X|Four hexadecimal values enclosed in braces, where the fourth value is a subset of eight hexadecimal values that is also enclosed in braces:

{0x00000000,0x0000,0x0000,{0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}}| + +## Examples + The following example calls the method with each of the supported format specifiers to generate an array of strings that represent a single GUID. These are then passed to the method, which successfully parses the string that conforms to the "B" format specifier. + + :::code language="csharp" source="~/snippets/csharp/System/Guid/Parse/tryparseexactex1.cs" interactive="try-dotnet-method" id="Snippet5"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Guid/Parse/tryparseexactex1.fs" id="Snippet5"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.guid.parse/vb/tryparseexactex1.vb" id="Snippet5"::: + ]]>
diff --git a/xml/System/Half.xml b/xml/System/Half.xml index 1839343cc92..7dc0e8941ed 100644 --- a/xml/System/Half.xml +++ b/xml/System/Half.xml @@ -913,17 +913,15 @@ This computes `arctan(x) / π` in the interval `[-0.5, +0.5]`. An object to compare, or . Compares this instance to a specified object and returns an integer that indicates whether the value of this instance is less than, equal to, or greater than the value of the specified object. - - A value less than zero if this instance is less than , or this instance is not a number (NaN) and is a number. + A value less than zero if this instance is less than , or this instance is not a number (NaN) and is a number. - -or- +-or- - Zero if this instance is equal to , or this instance and are both not a number (NaN), , or . +Zero if this instance is equal to , or this instance and are both not a number (NaN), , or . - -or- +-or- - A value greater than zero if this instance is greater than , or this instance is a number and is not a number (NaN), or is . - +A value greater than zero if this instance is greater than , or this instance is a number and is not a number (NaN), or is . To be added. is not of type . @@ -1431,7 +1429,9 @@ This computes `cos(x * π)`. The power to which 10 is raised. Computes 10 raised to a given power. - 10 + 10 + + To be added. @@ -1463,7 +1463,9 @@ This computes `cos(x * π)`. The power to which 10 is raised. Computes 10 raised to a given power and subtracts one. - 10 - 1 + 10 + + - 1 To be added. @@ -1495,7 +1497,9 @@ This computes `cos(x * π)`. The power to which 2 is raised. Computes 2 raised to a given power. - 2 + 2 + + To be added. @@ -1527,7 +1531,9 @@ This computes `cos(x * π)`. The power to which 2 is raised. Computes 2 raised to a given power and subtracts one. - 2 - 1 + 2 + + - 1 To be added. @@ -1559,7 +1565,9 @@ This computes `cos(x * π)`. The power to which E is raised. Computes E raised to a given power and subtracts one. - E - 1 + E + + - 1 To be added. @@ -4601,10 +4609,9 @@ For this method matches the IEEE 754:2 is not a value. - -or- +-or- - includes the value. - + includes the value.
@@ -4743,10 +4750,9 @@ For this method matches the IEEE 754:2 is not a value. - -or- +-or- - includes the value. - + includes the value. @@ -4803,10 +4809,9 @@ For this method matches the IEEE 754:2 is not a value. - -or- +-or- - includes the value. - + includes the value. @@ -6733,7 +6738,7 @@ This computes `tan(x * π)`. A read-only span that contains a number to convert. When this method returns, contains the half-precision floating-point number equivalent to the numeric value or symbol contained in , if the conversion succeeded, or a default value if the conversion failed. The conversion fails if the parameter is or or is not a number in a valid format. If is a valid number less than , contains . If is a valid number greater than , contains . This parameter is treated as uninitialized. Converts the span representation of a number to its half-precision floating-point number equivalent. A return value indicates whether the conversion succeeded or failed. - + if was converted successfully, otherwise. To be added. @@ -6987,10 +6992,9 @@ This computes `tan(x * π)`. is not a value. - -or- +-or- - is the value. - + is the value. @@ -7043,10 +7047,9 @@ This computes `tan(x * π)`. is not a value. - -or- +-or- - is the value. - + is the value. diff --git a/xml/System/HashCode.xml b/xml/System/HashCode.xml index 67b7fda69a0..920c38f2fe9 100644 --- a/xml/System/HashCode.xml +++ b/xml/System/HashCode.xml @@ -66,10 +66,10 @@ single hash code. This structure operates in one of two ways: ### Static Methods The static methods combine the default hash codes of up to eight values. - + :::code language="csharp" source="~/snippets/csharp/System/HashCode/Overview/example1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/HashCode/Overview/example1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.hashcode.structure/vb/example1.vb" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.hashcode.structure/vb/example1.vb" id="Snippet1"::: ### Instance Methods @@ -77,7 +77,7 @@ The static methods combine the default hash codes of up to eight values. > must be called at most once per instance of . The instance methods combine the hash codes of more than eight values. - + :::code language="csharp" source="~/snippets/csharp/System/HashCode/Overview/example2.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/HashCode/Overview/example2.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.hashcode.structure/vb/example2.vb" id="Snippet1"::: @@ -90,7 +90,7 @@ The instance methods also combine the hash codes produced by a specific :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.hashcode.structure/vb/example3.vb" id="Snippet1"::: The structure must be passed by-reference to other methods, as it is a value type. - + :::code language="csharp" source="~/snippets/csharp/System/HashCode/Overview/example4.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/HashCode/Overview/example4.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.hashcode.structure/vb/example4.vb" id="Snippet1"::: @@ -198,8 +198,7 @@ The structure must be passed by-reference to other method The type of the value to add to the hash code. The value to add to the hash code. - The to use to calculate the hash code. -This value can be a null reference (Nothing in Visual Basic), which will use the default equality comparer for . + The to use to calculate the hash code. This value can be a null reference (Nothing in Visual Basic), which will use the default equality comparer for . Adds a single value to the hash code, specifying the type that provides the hash code function. To be added. @@ -1074,9 +1073,7 @@ This method does not guarantee that the result of adding a span of bytes will ma Calculates the final hash code after consecutive invocations. The calculated hash code. - - This method must be called at most once per instance of . - + This method must be called at most once per instance of . diff --git a/xml/System/HttpStyleUriParser.xml b/xml/System/HttpStyleUriParser.xml index 1a3153dcd10..5029487086b 100644 --- a/xml/System/HttpStyleUriParser.xml +++ b/xml/System/HttpStyleUriParser.xml @@ -73,11 +73,11 @@ Create a customizable parser based on the HTTP scheme. - - + + ]]> diff --git a/xml/System/IAppDomainSetup.xml b/xml/System/IAppDomainSetup.xml index 54a59cd658a..99593bda859 100644 --- a/xml/System/IAppDomainSetup.xml +++ b/xml/System/IAppDomainSetup.xml @@ -30,11 +30,11 @@ Represents assembly binding information that can be added to an instance of . - and methods to identify the data to use. - + and methods to identify the data to use. + ]]> @@ -61,11 +61,11 @@ Gets or sets the name of the directory containing the application. A containing the name of the application base directory. - has finished its first bind. - + has finished its first bind. + ]]> @@ -142,15 +142,15 @@ Gets or sets the name of the configuration file for an application domain. A that specifies the name of the configuration file. - has finished its first bind. - + has finished its first bind. + ]]> @@ -177,13 +177,13 @@ Gets or sets the directory where dynamically generated files are stored and accessed. A that specifies the directory containing dynamic assemblies. - is created, a directory called the Dynamic Directory can be specified to store dynamic assemblies. This directory is logically located under the , although it can reside in another part of the directory. - - This property cannot be changed after the has finished its first bind. - + is created, a directory called the Dynamic Directory can be specified to store dynamic assemblies. This directory is logically located under the , although it can reside in another part of the directory. + + This property cannot be changed after the has finished its first bind. + ]]> @@ -234,11 +234,11 @@ Gets or sets the list of directories that is combined with the directory to probe for private assemblies. A containing a list of directory names, where each name is separated by a semicolon. - @@ -265,13 +265,13 @@ Gets or sets the private binary directory path used to locate an application. A containing a list of directory names, where each name is separated by a semicolon. - has finished its first bind. - + has finished its first bind. + ]]> @@ -298,15 +298,15 @@ Gets or sets the names of the directories containing assemblies to be shadow copied. A containing a list of directory names, where each name is separated by a semicolon. - , including the directory specified by , are shadow copied by default if this property is not set. - - If an executable file is in use, updates to the executable file are stored in a shadow copy directory. Existing users continue using the original executable file until it terminates, while new users use the shadow copied executable file. - - This property cannot be changed after the has finished its first bind. - + , including the directory specified by , are shadow copied by default if this property is not set. + + If an executable file is in use, updates to the executable file are stored in a shadow copy directory. Existing users continue using the original executable file until it terminates, while new users use the shadow copied executable file. + + This property cannot be changed after the has finished its first bind. + ]]> @@ -333,11 +333,11 @@ Gets or sets a string that indicates whether shadow copying is turned on or off. A containing the value "true" to indicate that shadow copying is turned on; or "false" to indicate that shadow copying is turned off. - has finished its first bind. - + has finished its first bind. + ]]> diff --git a/xml/System/IAsyncDisposable.xml b/xml/System/IAsyncDisposable.xml index acd2df743a9..c7fc72ece5e 100644 --- a/xml/System/IAsyncDisposable.xml +++ b/xml/System/IAsyncDisposable.xml @@ -36,7 +36,7 @@ Provides a mechanism for releasing unmanaged resources asynchronously. - implementation when you are finished using it. To make sure resources are released even in case of an exception, put the code that uses the `IAsyncDisposable` object into the [using](/dotnet/csharp/language-reference/keywords/using) statement (in C# beginning from version 8.0) or call the method inside a `finally` clause of the `try`/`finally` statement. For more information about the `try`/`finally` pattern, see [try-finally](/dotnet/csharp/language-reference/keywords/try-finally) (C#) or [Try...Catch...Finally Statement](/dotnet/visual-basic/language-reference/statements/try-catch-finally-statement) (Visual Basic). -### Implementing IAsyncDisposable - +### Implementing IAsyncDisposable + You might implement `IAsyncDisposable` in the following situations: - When developing an asynchronous enumerator that owns unmanaged resources. Asynchronous enumerators are used with the C# 8.0 async streams feature. For more information about async streams, see [Tutorial: Generate and consume async streams using C# 8.0 and .NET Core 3.0](/dotnet/csharp/tutorials/generate-consume-asynchronous-stream). @@ -59,7 +59,7 @@ You might implement `IAsyncDisposable` in the following situations: - When your class owns unmanaged resources and releasing them requires a resource-intensive I/O operation, such as flushing the contents of an intermediate buffer into a file or sending a packet over a network to close a connection. Use the method to perform whatever cleanup is necessary after using the unmanaged resources, such as freeing, releasing, or resetting the unmanaged resources. For more information, see [Implement a DisposeAsync method](/dotnet/standard/garbage-collection/implementing-disposeasync). - + ]]> @@ -96,7 +96,7 @@ Use the method to perform whateve Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously. A task that represents the asynchronous dispose operation. - . If an object's `DisposeAsync` method is called more than once, the object must ignore all calls after the first one and synchronously return a successfully completed . The object must not throw an exception if its `DisposeAsync` method is called multiple times. Instance methods other than `DisposeAsync` can throw an when resources are already disposed. - + ]]> diff --git a/xml/System/IAsyncResult.xml b/xml/System/IAsyncResult.xml index c6adc4479bd..13779ebb910 100644 --- a/xml/System/IAsyncResult.xml +++ b/xml/System/IAsyncResult.xml @@ -53,34 +53,34 @@ Represents the status of an asynchronous operation. - interface is implemented by classes containing methods that can operate asynchronously. It is the return type of methods that initiate an asynchronous operation, such as , and it is passed to methods that conclude an asynchronous operation, such as . objects are also passed to methods invoked by delegates when an asynchronous operation completes. - - An object that supports the interface stores state information for an asynchronous operation and provides a synchronization object to allow threads to be signaled when the operation completes. - + interface is implemented by classes containing methods that can operate asynchronously. It is the return type of methods that initiate an asynchronous operation, such as , and it is passed to methods that conclude an asynchronous operation, such as . objects are also passed to methods invoked by delegates when an asynchronous operation completes. + + An object that supports the interface stores state information for an asynchronous operation and provides a synchronization object to allow threads to be signaled when the operation completes. + > [!NOTE] -> The class is the implementation of that is returned by the `BeginInvoke` method when you use a delegate to call a method asynchronously. - - For a detailed description of how the interface is used, see the [Calling Synchronous Methods Asynchronously](/dotnet/standard/asynchronous-programming-patterns/calling-synchronous-methods-asynchronously) topic. - - - -## Examples - The following example demonstrates how to use the property to get a , and how to wait for an asynchronous call on a delegate. The is signaled when the asynchronous call completes, and you can wait for it by calling the method. - - The example consists of two classes: the class that contains the method that is called asynchronously, and the class that contains the `Main` method that makes the call. - - For more information and more examples of calling methods asynchronously by using delegates, see [Calling Synchronous Methods Asynchronously](/dotnet/standard/asynchronous-programming-patterns/calling-synchronous-methods-asynchronously). - +> The class is the implementation of that is returned by the `BeginInvoke` method when you use a delegate to call a method asynchronously. + + For a detailed description of how the interface is used, see the [Calling Synchronous Methods Asynchronously](/dotnet/standard/asynchronous-programming-patterns/calling-synchronous-methods-asynchronously) topic. + + + +## Examples + The following example demonstrates how to use the property to get a , and how to wait for an asynchronous call on a delegate. The is signaled when the asynchronous call completes, and you can wait for it by calling the method. + + The example consists of two classes: the class that contains the method that is called asynchronously, and the class that contains the `Main` method that makes the call. + + For more information and more examples of calling methods asynchronously by using delegates, see [Calling Synchronous Methods Asynchronously](/dotnet/standard/asynchronous-programming-patterns/calling-synchronous-methods-asynchronously). + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/AsyncDelegateExamples/cpp/TestMethod.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/IAsyncResult/Overview/TestMethod.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AsyncDelegateExamples/VB/TestMethod.vb" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AsyncDelegateExamples/VB/TestMethod.vb" id="Snippet1"::: :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/AsyncDelegateExamples/cpp/waithandle.cpp" id="Snippet3"::: :::code language="csharp" source="~/snippets/csharp/System/IAsyncResult/Overview/waithandle.cs" id="Snippet3"::: -:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AsyncDelegateExamples/VB/WaitHandle.vb" id="Snippet3"::: - +:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AsyncDelegateExamples/VB/WaitHandle.vb" id="Snippet3"::: + ]]> @@ -137,27 +137,27 @@ Gets a user-defined object that qualifies or contains information about an asynchronous operation. A user-defined object that qualifies or contains information about an asynchronous operation. - property is used to pass information to a callback method. The last parameter of the `BeginInvoke` method call is a format string, which the callback method uses to format an output message. - - The example consists of two classes: the class that contains the method that is called asynchronously, and the class that contains the `Main` method that makes the call. - - For more information about how this callback example works, and more examples of calling methods asynchronously by using delegates, see [Calling Synchronous Methods Asynchronously](/dotnet/standard/asynchronous-programming-patterns/calling-synchronous-methods-asynchronously). - + property is used to pass information to a callback method. The last parameter of the `BeginInvoke` method call is a format string, which the callback method uses to format an output message. + + The example consists of two classes: the class that contains the method that is called asynchronously, and the class that contains the `Main` method that makes the call. + + For more information about how this callback example works, and more examples of calling methods asynchronously by using delegates, see [Calling Synchronous Methods Asynchronously](/dotnet/standard/asynchronous-programming-patterns/calling-synchronous-methods-asynchronously). + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/AsyncDelegateExamples/cpp/TestMethod.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/IAsyncResult/Overview/TestMethod.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AsyncDelegateExamples/VB/TestMethod.vb" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AsyncDelegateExamples/VB/TestMethod.vb" id="Snippet1"::: :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/AsyncDelegateExamples/cpp/callback.cpp" id="Snippet5"::: :::code language="csharp" source="~/snippets/csharp/System/IAsyncResult/Overview/callback.cs" id="Snippet5"::: -:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AsyncDelegateExamples/VB/callback.vb" id="Snippet5"::: - +:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AsyncDelegateExamples/VB/callback.vb" id="Snippet5"::: + ]]> @@ -210,29 +210,29 @@ Gets a that is used to wait for an asynchronous operation to complete. A that is used to wait for an asynchronous operation to complete. - until the operation concludes. The return value can be used to perform a , , or operation. - - The common language runtime supplies a number of waitable objects, such as , , and , all of which mirror Win32 synchronization primitives. - - - -## Examples - The following example demonstrates how to use the property to get a , and how to wait for an asynchronous call on a delegate. The is signaled when the asynchronous call completes, and you can wait for it by calling the method. - - The example consists of two classes: the class that contains the method that is called asynchronously, and the class that contains the `Main` method that makes the call. - - For more information and more examples of calling methods asynchronously by using delegates, see [Calling Synchronous Methods Asynchronously](/dotnet/standard/asynchronous-programming-patterns/calling-synchronous-methods-asynchronously). - + until the operation concludes. The return value can be used to perform a , , or operation. + + The common language runtime supplies a number of waitable objects, such as , , and , all of which mirror Win32 synchronization primitives. + + + +## Examples + The following example demonstrates how to use the property to get a , and how to wait for an asynchronous call on a delegate. The is signaled when the asynchronous call completes, and you can wait for it by calling the method. + + The example consists of two classes: the class that contains the method that is called asynchronously, and the class that contains the `Main` method that makes the call. + + For more information and more examples of calling methods asynchronously by using delegates, see [Calling Synchronous Methods Asynchronously](/dotnet/standard/asynchronous-programming-patterns/calling-synchronous-methods-asynchronously). + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/AsyncDelegateExamples/cpp/TestMethod.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/IAsyncResult/Overview/TestMethod.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AsyncDelegateExamples/VB/TestMethod.vb" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AsyncDelegateExamples/VB/TestMethod.vb" id="Snippet1"::: :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/AsyncDelegateExamples/cpp/waithandle.cpp" id="Snippet3"::: :::code language="csharp" source="~/snippets/csharp/System/IAsyncResult/Overview/waithandle.cs" id="Snippet3"::: -:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AsyncDelegateExamples/VB/WaitHandle.vb" id="Snippet3"::: - +:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AsyncDelegateExamples/VB/WaitHandle.vb" id="Snippet3"::: + ]]> @@ -286,11 +286,11 @@ if the asynchronous operation completed synchronously; otherwise, . - delegate, it is probable that the thread that initiated the asynchronous operation is the current thread. - + delegate, it is probable that the thread that initiated the asynchronous operation is the current thread. + ]]> @@ -343,27 +343,27 @@ if the operation is complete; otherwise, . - property of the to discover when an asynchronous call completes. In this case, the asynchronous call is made by using the `BeginInvoke` method of a delegate. You might use the property to poll for completion when making the asynchronous call from a thread that services the user interface. Polling for completion allows the calling thread to continue executing while the asynchronous call executes on a thread. - - The example consists of two classes: the class that contains the method that is called asynchronously, and the class that contains the `Main` method that makes the call. - - For more information and more examples of calling methods asynchronously by using delegates, see [Calling Synchronous Methods Asynchronously](/dotnet/standard/asynchronous-programming-patterns/calling-synchronous-methods-asynchronously). - + property of the to discover when an asynchronous call completes. In this case, the asynchronous call is made by using the `BeginInvoke` method of a delegate. You might use the property to poll for completion when making the asynchronous call from a thread that services the user interface. Polling for completion allows the calling thread to continue executing while the asynchronous call executes on a thread. + + The example consists of two classes: the class that contains the method that is called asynchronously, and the class that contains the `Main` method that makes the call. + + For more information and more examples of calling methods asynchronously by using delegates, see [Calling Synchronous Methods Asynchronously](/dotnet/standard/asynchronous-programming-patterns/calling-synchronous-methods-asynchronously). + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/AsyncDelegateExamples/cpp/TestMethod.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/IAsyncResult/Overview/TestMethod.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AsyncDelegateExamples/VB/TestMethod.vb" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AsyncDelegateExamples/VB/TestMethod.vb" id="Snippet1"::: :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/AsyncDelegateExamples/cpp/polling.cpp" id="Snippet4"::: :::code language="csharp" source="~/snippets/csharp/System/IAsyncResult/Overview/polling.cs" id="Snippet4"::: -:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AsyncDelegateExamples/VB/polling.vb" id="Snippet4"::: - +:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AsyncDelegateExamples/VB/polling.vb" id="Snippet4"::: + ]]> diff --git a/xml/System/ICloneable.xml b/xml/System/ICloneable.xml index 60853ae13a1..eb3229c5638 100644 --- a/xml/System/ICloneable.xml +++ b/xml/System/ICloneable.xml @@ -48,11 +48,11 @@ Supports cloning, which creates a new instance of a class with the same value as an existing instance. - interface enables you to provide a customized implementation that creates a copy of an existing object. The interface contains one member, the method, which is intended to provide cloning support beyond that supplied by . For more information about cloning, deep versus shallow copies, and examples, see the method. - + interface enables you to provide a customized implementation that creates a copy of an existing object. The interface contains one member, the method, which is intended to provide cloning support beyond that supplied by . For more information about cloning, deep versus shallow copies, and examples, see the method. + ]]> @@ -99,15 +99,15 @@ Creates a new object that is a copy of the current instance. A new object that is a copy of this instance. - can perform either a deep copy or a shallow copy. In a deep copy, all objects are duplicated; in a shallow copy, only the top-level objects are duplicated and the lower levels contain references. Because callers of cannot depend on the method performing a predictable cloning operation, we recommend that not be implemented in public APIs. - - See for more information on cloning, deep versus shallow copies, and examples. - + can perform either a deep copy or a shallow copy. In a deep copy, all objects are duplicated; in a shallow copy, only the top-level objects are duplicated and the lower levels contain references. Because callers of cannot depend on the method performing a predictable cloning operation, we recommend that not be implemented in public APIs. + + See for more information on cloning, deep versus shallow copies, and examples. + ]]> diff --git a/xml/System/IComparable.xml b/xml/System/IComparable.xml index 5a901b1115b..69bf87f25f1 100644 --- a/xml/System/IComparable.xml +++ b/xml/System/IComparable.xml @@ -53,30 +53,30 @@ Defines a generalized type-specific comparison method that a value type or class implements to order or sort its instances. - , that indicates whether the position of the current instance in the sort order is before, after, or the same as a second object of the same type. The instance's implementation is called automatically by methods such as and . - - The implementation of the method must return an that has one of three values, as shown in the following table. - -|Value|Meaning| -|-----------|-------------| -|Less than zero|The current instance precedes the object specified by the method in the sort order.| -|Zero|This current instance occurs in the same position in the sort order as the object specified by the method.| -|Greater than zero|This current instance follows the object specified by the method in the sort order.| - - All numeric types (such as and ) implement , as do , , and . Custom types should also provide their own implementation of to enable object instances to be ordered or sorted. - - - -## Examples - The following example illustrates the implementation of and the requisite method. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/IComparable Example/CPP/source.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/IComparable/Overview/source.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/IComparable/Overview/source.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/IComparable Example/VB/source.vb" id="Snippet1"::: + , that indicates whether the position of the current instance in the sort order is before, after, or the same as a second object of the same type. The instance's implementation is called automatically by methods such as and . + + The implementation of the method must return an that has one of three values, as shown in the following table. + +|Value|Meaning| +|-----------|-------------| +|Less than zero|The current instance precedes the object specified by the method in the sort order.| +|Zero|This current instance occurs in the same position in the sort order as the object specified by the method.| +|Greater than zero|This current instance follows the object specified by the method in the sort order.| + + All numeric types (such as and ) implement , as do , , and . Custom types should also provide their own implementation of to enable object instances to be ordered or sorted. + + + +## Examples + The following example illustrates the implementation of and the requisite method. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/IComparable Example/CPP/source.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/IComparable/Overview/source.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/IComparable/Overview/source.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/IComparable Example/VB/source.vb" id="Snippet1"::: ]]> @@ -126,63 +126,62 @@ An object to compare with this instance. Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object. - A value that indicates the relative order of the objects being compared. The return value has these meanings: - - Value - - Meaning - - Less than zero - - This instance precedes in the sort order. - - Zero - - This instance occurs in the same position in the sort order as . - - Greater than zero - - This instance follows in the sort order. - - + A value that indicates the relative order of the objects being compared. The return value has these meanings: + + Value + + + Meaning + + + + + Less than zero + + + This instance precedes in the sort order. + + + Zero + + + This instance occurs in the same position in the sort order as . + + + Greater than zero + + + This instance follows in the sort order. + + - method is implemented by types whose values can be ordered or sorted. It is called automatically by methods of non-generic collection objects, such as , to order each member of the array. If a custom class or structure does not implement , its members cannot be ordered and the sort operation can throw an . - - This method is only a definition and must be implemented by a specific class or value type to have effect. The meaning of the comparisons specified in the Return Value section ("precedes", "occurs in the same position as", and "follows") depends on the particular implementation. - - By definition, any object compares greater than (or follows) `null`, and two null references compare equal to each other. - - The parameter, `obj`, must be the same type as the class or value type that implements this interface; otherwise, an is thrown. - - - -## Examples - The following example illustrates the use of to compare a `Temperature` object implementing with another object. The `Temperature` object implements by simply wrapping a call to the method. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/IComparable Example/CPP/source.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/IComparable/Overview/source.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/IComparable/Overview/source.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/IComparable Example/VB/source.vb" id="Snippet1"::: + method is implemented by types whose values can be ordered or sorted. It is called automatically by methods of non-generic collection objects, such as , to order each member of the array. If a custom class or structure does not implement , its members cannot be ordered and the sort operation can throw an . + + This method is only a definition and must be implemented by a specific class or value type to have effect. The meaning of the comparisons specified in the Return Value section ("precedes", "occurs in the same position as", and "follows") depends on the particular implementation. + + By definition, any object compares greater than (or follows) `null`, and two null references compare equal to each other. + + The parameter, `obj`, must be the same type as the class or value type that implements this interface; otherwise, an is thrown. + + + +## Examples + The following example illustrates the use of to compare a `Temperature` object implementing with another object. The `Temperature` object implements by simply wrapping a call to the method. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/IComparable Example/CPP/source.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/IComparable/Overview/source.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/IComparable/Overview/source.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/IComparable Example/VB/source.vb" id="Snippet1"::: ]]> is not the same type as this instance. - For objects A, B and C, the following must be true: - - A.CompareTo(A) must return zero. - - If A.CompareTo(B) returns zero, then B.CompareTo(A) must return zero. - - If A.CompareTo(B) returns zero and B.CompareTo(C) returns zero, then A.CompareTo(C) must return zero. - - If A.CompareTo(B) returns a value other than zero, then B.CompareTo(A) must return a value of the opposite sign. - - If A.CompareTo(B) returns a value not equal to zero, and B.CompareTo(C) returns a value of the same sign as , then A.CompareTo(C) must return a value of the same sign as and . + For objects A, B and C, the following must be true: A.CompareTo(A) must return zero. If A.CompareTo(B) returns zero, then B.CompareTo(A) must return zero. If A.CompareTo(B) returns zero and B.CompareTo(C) returns zero, then A.CompareTo(C) must return zero. If A.CompareTo(B) returns a value other than zero, then B.CompareTo(A) must return a value of the opposite sign. If A.CompareTo(B) returns a value not equal to zero, and B.CompareTo(C) returns a value of the same sign as , then A.CompareTo(C) must return a value of the same sign as and . Use the method to determine the ordering of instances of a class. diff --git a/xml/System/IComparable`1.xml b/xml/System/IComparable`1.xml index fa5ba9bd8f0..69a8a9fda64 100644 --- a/xml/System/IComparable`1.xml +++ b/xml/System/IComparable`1.xml @@ -59,28 +59,28 @@ The type of object to compare. Defines a generalized comparison method that a value type or class implements to create a type-specific comparison method for ordering or sorting its instances. - , that indicates whether the position of the current instance in the sort order is before, after, or the same as a second object of the same type. Typically, the method is not called directly from developer code. Instead, it is called automatically by methods such as and . - - Typically, types that provide an implementation also implement the interface. The interface defines the method, which determines the equality of instances of the implementing type. - - The implementation of the method must return an that has one of three values, as shown in the following table. - -|Value|Meaning| -|-----------|-------------| -|Less than zero|This object precedes the object specified by the method in the sort order.| -|Zero|This current instance occurs in the same position in the sort order as the object specified by the method argument.| -|Greater than zero|This current instance follows the object specified by the method argument in the sort order.| - - All numeric types (such as and ) implement , as do , , and . Custom types should also provide their own implementation of to enable object instances to be ordered or sorted. - - - -## Examples - The following example illustrates the implementation of for a simple `Temperature` object. The example creates a collection of strings with `Temperature` object keys, and adds several pairs of temperatures and strings to the list out of sequence. In the call to the method, the collection uses the implementation to sort the list entries, which are then displayed in order of increasing temperature. - + , that indicates whether the position of the current instance in the sort order is before, after, or the same as a second object of the same type. Typically, the method is not called directly from developer code. Instead, it is called automatically by methods such as and . + + Typically, types that provide an implementation also implement the interface. The interface defines the method, which determines the equality of instances of the implementing type. + + The implementation of the method must return an that has one of three values, as shown in the following table. + +|Value|Meaning| +|-----------|-------------| +|Less than zero|This object precedes the object specified by the method in the sort order.| +|Zero|This current instance occurs in the same position in the sort order as the object specified by the method argument.| +|Greater than zero|This current instance follows the object specified by the method argument in the sort order.| + + All numeric types (such as and ) implement , as do , , and . Custom types should also provide their own implementation of to enable object instances to be ordered or sorted. + + + +## Examples + The following example illustrates the implementation of for a simple `Temperature` object. The example creates a collection of strings with `Temperature` object keys, and adds several pairs of temperatures and strings to the list out of sequence. In the call to the method, the collection uses the implementation to sort the list entries, which are then displayed in order of increasing temperature. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/IComparable`1 Example/CPP/source.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/IComparableT/Overview/source.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/IComparableT/Overview/source.fs" id="Snippet1"::: @@ -89,9 +89,7 @@ ]]> - Replace the type parameter of the interface with the type that is implementing this interface. - - If you implement , you should overload the , , , and operators to return values that are consistent with . In addition, you should also implement . See the article for complete information. + Replace the type parameter of the interface with the type that is implementing this interface. If you implement , you should overload the , , , and operators to return values that are consistent with . In addition, you should also implement . See the article for complete information. @@ -147,40 +145,49 @@ An object to compare with this instance. Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object. - A value that indicates the relative order of the objects being compared. The return value has these meanings: - - Value - - Meaning - - Less than zero - - This instance precedes in the sort order. - - Zero - - This instance occurs in the same position in the sort order as . - - Greater than zero - - This instance follows in the sort order. - - + A value that indicates the relative order of the objects being compared. The return value has these meanings: + + Value + + + Meaning + + + + + Less than zero + + + This instance precedes in the sort order. + + + Zero + + + This instance occurs in the same position in the sort order as . + + + Greater than zero + + + This instance follows in the sort order. + + - provides a strongly typed comparison method for ordering members of a generic collection object. Because of this, it is usually not called directly from developer code. Instead, it is called automatically by methods such as and . - - This method is only a definition and must be implemented by a specific class or value type to have effect. The meaning of the comparisons specified in the Return Values section ("precedes", "occurs in the same position as", and "follows) depends on the particular implementation. - - By definition, any object compares greater than `null`, and two null references compare equal to each other. - - - -## Examples - The following code example illustrates the implementation of for a simple `Temperature` object. The example creates a collection of strings with `Temperature` object keys, and adds several pairs of temperatures and strings to the list out of sequence. In the call to the method, the collection uses the implementation to sort the list entries, which are then displayed in order of increasing temperature. - + provides a strongly typed comparison method for ordering members of a generic collection object. Because of this, it is usually not called directly from developer code. Instead, it is called automatically by methods such as and . + + This method is only a definition and must be implemented by a specific class or value type to have effect. The meaning of the comparisons specified in the Return Values section ("precedes", "occurs in the same position as", and "follows) depends on the particular implementation. + + By definition, any object compares greater than `null`, and two null references compare equal to each other. + + + +## Examples + The following code example illustrates the implementation of for a simple `Temperature` object. The example creates a collection of strings with `Temperature` object keys, and adds several pairs of temperatures and strings to the list out of sequence. In the call to the method, the collection uses the implementation to sort the list entries, which are then displayed in order of increasing temperature. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/IComparable`1 Example/CPP/source.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/IComparableT/Overview/source.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/IComparableT/Overview/source.fs" id="Snippet1"::: @@ -189,17 +196,7 @@ ]]> - For objects A, B, and C, the following must be true: - - A.CompareTo(A) is required to return zero. - - If A.CompareTo(B) returns zero, then B.CompareTo(A) is required to return zero. - - If A.CompareTo(B) returns zero and B.CompareTo(C) returns zero, then A.CompareTo(C) is required to return zero. - - If A.CompareTo(B) returns a value other than zero, then B.CompareTo(A) is required to return a value of the opposite sign. - - If A.CompareTo(B) returns a value that is not equal to zero, and B.CompareTo(C) returns a value of the same sign as , then A.CompareTo(C) is required to return a value of the same sign as and . + For objects A, B, and C, the following must be true: A.CompareTo(A) is required to return zero. If A.CompareTo(B) returns zero, then B.CompareTo(A) is required to return zero. If A.CompareTo(B) returns zero and B.CompareTo(C) returns zero, then A.CompareTo(C) is required to return zero. If A.CompareTo(B) returns a value other than zero, then B.CompareTo(A) is required to return a value of the opposite sign. If A.CompareTo(B) returns a value that is not equal to zero, and B.CompareTo(C) returns a value of the same sign as , then A.CompareTo(C) is required to return a value of the same sign as and . Use the method to determine the ordering of instances of a class. diff --git a/xml/System/IConvertible.xml b/xml/System/IConvertible.xml index 7eea9157b57..b2b50e3a01c 100644 --- a/xml/System/IConvertible.xml +++ b/xml/System/IConvertible.xml @@ -55,22 +55,22 @@ Defines methods that convert the value of the implementing reference or value type to a common language runtime type that has an equivalent value. - , , , , , , , , , , , , , , and . - - If there is no meaningful conversion to a common language runtime type, then a particular interface method implementation throws . For example, if this interface is implemented on a Boolean type, the implementation of the method throws an exception because there is no meaningful equivalent to a Boolean type. - - The common language runtime typically exposes the interface through the class. The common language runtime also uses the interface internally, in explicit interface implementations, to simplify the code used to support conversions in the class and basic common language runtime types. - - In addition to the interface, the .NET Framework provides classes called type converters for converting user-defined data types to other data types. For more information, see the [Generalized Type Conversion](/previous-versions/visualstudio/visual-studio-2013/yy580hbd(v=vs.120)) topic. - - - -## Examples - The following code sample demonstrates an implementation of for a Complex number class, allowing it to be cast first as a and then calling the static members on that . - + , , , , , , , , , , , , , , and . + + If there is no meaningful conversion to a common language runtime type, then a particular interface method implementation throws . For example, if this interface is implemented on a Boolean type, the implementation of the method throws an exception because there is no meaningful equivalent to a Boolean type. + + The common language runtime typically exposes the interface through the class. The common language runtime also uses the interface internally, in explicit interface implementations, to simplify the code used to support conversions in the class and basic common language runtime types. + + In addition to the interface, the .NET Framework provides classes called type converters for converting user-defined data types to other data types. For more information, see the [Generalized Type Conversion](/previous-versions/visualstudio/visual-studio-2013/yy580hbd(v=vs.120)) topic. + + + +## Examples + The following code sample demonstrates an implementation of for a Complex number class, allowing it to be cast first as a and then calling the static members on that . + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.IConvertible/CPP/iconvertible.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/IConvertible/Overview/iconvertible.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/IConvertible/Overview/iconvertible.fs" id="Snippet1"::: @@ -79,9 +79,7 @@ ]]> - If you implement the interface, your implementation will be called automatically by the method if the parameter is an instance of your implementing type and the parameter is a common language runtime type. - - Most conversion methods have a parameter of type that represents either the current culture () or a specific culture. For the most part, the implementations of the base types ignore this parameter. However, you can choose whether to use it in your code. + If you implement the interface, your implementation will be called automatically by the method if the parameter is an instance of your implementing type and the parameter is a common language runtime type. Most conversion methods have a parameter of type that represents either the current culture () or a specific culture. For the most part, the implementations of the base types ignore this parameter. However, you can choose whether to use it in your code. Type Conversion in the .NET Framework diff --git a/xml/System/ICustomFormatter.xml b/xml/System/ICustomFormatter.xml index c092b98a3af..4bc3537c382 100644 --- a/xml/System/ICustomFormatter.xml +++ b/xml/System/ICustomFormatter.xml @@ -53,65 +53,41 @@ Defines a method that supports custom formatting of the value of an object. - interface includes a single method, . When this interface is implemented by a reference or value type, the method returns a custom-formatted string representation of an object's value. - - Typically, the interface is implemented with the interface to customize the behavior of two .NET Framework composite string formatting methods that include an parameter. Specifically, the interface can provide custom formatting of the value of an object passed to the and methods. - - Providing a custom representation of an object's value requires that you do the following: - -1. Define a class that implements the interface and its single member, the method. - -2. Define a class that implements the interface and its single member, the method. The method returns an instance of your implementation. Often, a single class implements both and . In that case, the class's `GetFormat` implementation just returns an instance of itself. - -3. Pass the implementation as the `provider` argument of the method or a comparable method. - - The .NET library method will then use your custom formatting instead of its own. - -## Examples - - The following example implements to allow binary, octal, and hexadecimal formatting of integral values. In this example, a single class, `MyFormatter`, implements both and . Its method determines whether the `formatType` parameter represents an type. If it does, `MyFormatter` returns an instance of itself; otherwise, it returns `null`. Its implementation determines whether the format parameter is one of the three supported format strings ("B" for binary, "O" for octal, and "H" for hexadecimal) and formats the `arg` parameter appropriately. Otherwise, if `arg` is not `null`, it calls the `arg` parameter's implementation, if one exists, or its parameterless `ToString` method, if one does not. If `arg` is `null`, the method returns . - + interface includes a single method, . When this interface is implemented by a reference or value type, the method returns a custom-formatted string representation of an object's value. + + Typically, the interface is implemented with the interface to customize the behavior of two .NET Framework composite string formatting methods that include an parameter. Specifically, the interface can provide custom formatting of the value of an object passed to the and methods. + + Providing a custom representation of an object's value requires that you do the following: + +1. Define a class that implements the interface and its single member, the method. + +2. Define a class that implements the interface and its single member, the method. The method returns an instance of your implementation. Often, a single class implements both and . In that case, the class's `GetFormat` implementation just returns an instance of itself. + +3. Pass the implementation as the `provider` argument of the method or a comparable method. + + The .NET library method will then use your custom formatting instead of its own. + +## Examples + + The following example implements to allow binary, octal, and hexadecimal formatting of integral values. In this example, a single class, `MyFormatter`, implements both and . Its method determines whether the `formatType` parameter represents an type. If it does, `MyFormatter` returns an instance of itself; otherwise, it returns `null`. Its implementation determines whether the format parameter is one of the three supported format strings ("B" for binary, "O" for octal, and "H" for hexadecimal) and formats the `arg` parameter appropriately. Otherwise, if `arg` is not `null`, it calls the `arg` parameter's implementation, if one exists, or its parameterless `ToString` method, if one does not. If `arg` is `null`, the method returns . + :::code language="csharp" source="~/snippets/csharp/System/ICustomFormatter/Overview/myformatter.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/ICustomFormatter/Overview/myformatter.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.icustomformatter.class/vb/myformatter.vb" id="Snippet1"::: - - `MyFormatter` can then be used to provide custom formatting by passing a `MyFormatter` object as the `provider` parameter of the method, as the following example shows. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.icustomformatter.class/vb/myformatter.vb" id="Snippet1"::: + + `MyFormatter` can then be used to provide custom formatting by passing a `MyFormatter` object as the `provider` parameter of the method, as the following example shows. + :::code language="csharp" source="~/snippets/csharp/System/ICustomFormatter/Overview/myformatter.cs" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/ICustomFormatter/Overview/myformatter.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.icustomformatter.class/vb/myformatter.vb" id="Snippet2"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.icustomformatter.class/vb/myformatter.vb" id="Snippet2"::: + ]]> - The common language runtime attempts to use your implementation for every format item in a composite format string. As a result, you should expect that your implementation will be called to provide formatting services to objects or values that it is not designed to handle. In these cases, your method must call the appropriate formatting method for that object or value. - - There are two kinds of implementations: intrinsic and extension. - - Intrinsic implementations are implementations that provide custom formatting for an application-defined object. In this case, your implementation should include the following: - -- A definition of format strings that define the formatting of the object. Format strings are optional. Typically, a "G" or "g" format string defines the general (or most commonly used) format. However, you are free to define any format strings that you choose. You are also free to decide whether they are case-sensitive or case-insensitive. - -- A test to ensure that the type of the object passed to your method is your application-defined type. If it is not, you should call the object's implementation, if one exists, or its method, if it does not. You should be prepared to handle any exceptions these method calls might throw. - -- Code to handle a null format string, if your implementation supports format strings. The most common approach is to replace a null format string with the general format specifier. - -- Code to handle any format strings that your implementation supports. - -- Code to handle format strings that you do not support. The most common approach is to throw a , although you can provide default formatting. - - Extension implementations are implementations that provide custom formatting for a type that already has formatting support. For example, you could define a CustomerNumberFormatter that formats an integral type with hyphens between specific digits. In this case, your implementation should include the following: - -- A definition of format strings that extend the formatting of the object. These format strings are required, but they must not conflict with the type's existing format strings. For example, if you are extending formatting for the type, you should not implement the "C", "D", "E", "F", and "G" format specifiers, among others. - -- A test that the type of the object passed to your method is a type whose formatting your extension supports. If it is not, call the object's implementation, if one exists, or the object's parameterless method, if it does not. You should be prepared to handle any exceptions these method calls might throw. - -- Code to handle any format strings that your extension supports. - -- Code to handle any format strings that your extension does not support. These should be passed on to the type's implementation. You should be prepared to handle any exceptions these method calls might throw. + The common language runtime attempts to use your implementation for every format item in a composite format string. As a result, you should expect that your implementation will be called to provide formatting services to objects or values that it is not designed to handle. In these cases, your method must call the appropriate formatting method for that object or value. There are two kinds of implementations: intrinsic and extension. Intrinsic implementations are implementations that provide custom formatting for an application-defined object. In this case, your implementation should include the following: - A definition of format strings that define the formatting of the object. Format strings are optional. Typically, a "G" or "g" format string defines the general (or most commonly used) format. However, you are free to define any format strings that you choose. You are also free to decide whether they are case-sensitive or case-insensitive. - A test to ensure that the type of the object passed to your method is your application-defined type. If it is not, you should call the object's implementation, if one exists, or its method, if it does not. You should be prepared to handle any exceptions these method calls might throw. - Code to handle a null format string, if your implementation supports format strings. The most common approach is to replace a null format string with the general format specifier. - Code to handle any format strings that your implementation supports. - Code to handle format strings that you do not support. The most common approach is to throw a , although you can provide default formatting. Extension implementations are implementations that provide custom formatting for a type that already has formatting support. For example, you could define a CustomerNumberFormatter that formats an integral type with hyphens between specific digits. In this case, your implementation should include the following: - A definition of format strings that extend the formatting of the object. These format strings are required, but they must not conflict with the type's existing format strings. For example, if you are extending formatting for the type, you should not implement the "C", "D", "E", "F", and "G" format specifiers, among others. - A test that the type of the object passed to your method is a type whose formatting your extension supports. If it is not, call the object's implementation, if one exists, or the object's parameterless method, if it does not. You should be prepared to handle any exceptions these method calls might throw. - Code to handle any format strings that your extension supports. - Code to handle any format strings that your extension does not support. These should be passed on to the type's implementation. You should be prepared to handle any exceptions these method calls might throw. @@ -166,42 +142,42 @@ Converts the value of a specified object to an equivalent string representation using specified format and culture-specific formatting information. The string representation of the value of , formatted as specified by and . - is a callback method. It is called by a method that supports custom formatting, such as or . The implementation is called once for each format item in a [composite format string](/dotnet/standard/base-types/composite-formatting). For example, in the following statement, the method is called three times. - + is a callback method. It is called by a method that supports custom formatting, such as or . The implementation is called once for each format item in a [composite format string](/dotnet/standard/base-types/composite-formatting). For example, in the following statement, the method is called three times. + :::code language="csharp" source="~/snippets/csharp/System/ICustomFormatter/Overview/myformatter.cs" id="Snippet4"::: :::code language="fsharp" source="~/snippets/fsharp/System/ICustomFormatter/Overview/myformatter.fs" id="Snippet4"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.icustomformatter.class/vb/myformatter.vb" id="Snippet4"::: - - The `arg` parameter is the object in the object list whose zero-based position corresponds to the index of a particular format item. - - The `format` parameter contains a format string, which is the `formatString` component of a format item. If the format item has no `formatString` component, the value of `format` is `null`. If `format` is `null`, depending on the type of `arg`, you may be able to use the default format specification of your choice. - - The `formatProvider` parameter is the implementation that provides formatting for `arg`. Typically, it is an instance of your implementation. If `formatProvider` is `null`, ignore that parameter. - - Your implementation of the method must include the following functionality so the .NET Framework can provide formatting you do not support. If your format method does not support a format, determine whether the object being formatted implements the interface. If it does, invoke the method of that interface. Otherwise, invoke the default method of the underlying object. The following code illustrates this pattern. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.icustomformatter.class/vb/myformatter.vb" id="Snippet4"::: + + The `arg` parameter is the object in the object list whose zero-based position corresponds to the index of a particular format item. + + The `format` parameter contains a format string, which is the `formatString` component of a format item. If the format item has no `formatString` component, the value of `format` is `null`. If `format` is `null`, depending on the type of `arg`, you may be able to use the default format specification of your choice. + + The `formatProvider` parameter is the implementation that provides formatting for `arg`. Typically, it is an instance of your implementation. If `formatProvider` is `null`, ignore that parameter. + + Your implementation of the method must include the following functionality so the .NET Framework can provide formatting you do not support. If your format method does not support a format, determine whether the object being formatted implements the interface. If it does, invoke the method of that interface. Otherwise, invoke the default method of the underlying object. The following code illustrates this pattern. + :::code language="csharp" source="~/snippets/csharp/System/ICustomFormatter/Overview/myformatter.cs" id="Snippet3"::: :::code language="fsharp" source="~/snippets/fsharp/System/ICustomFormatter/Overview/myformatter.fs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.icustomformatter.class/vb/myformatter.vb" id="Snippet3"::: - - - -## Examples - The following example implements to allow binary, octal, and hexadecimal formatting of integral values. Its implementation determines whether the format parameter is one of the three supported format strings ("B" for binary, "O" for octal, and "H" for hexadecimal) and formats the `arg` parameter appropriately. Otherwise, if `arg` is not `null`, it calls the `arg` parameter's implementation, if one exists, or its parameterless `ToString` method, if one does not. If `arg` is `null`, the method returns . - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.icustomformatter.class/vb/myformatter.vb" id="Snippet3"::: + + + +## Examples + The following example implements to allow binary, octal, and hexadecimal formatting of integral values. Its implementation determines whether the format parameter is one of the three supported format strings ("B" for binary, "O" for octal, and "H" for hexadecimal) and formats the `arg` parameter appropriately. Otherwise, if `arg` is not `null`, it calls the `arg` parameter's implementation, if one exists, or its parameterless `ToString` method, if one does not. If `arg` is `null`, the method returns . + :::code language="csharp" source="~/snippets/csharp/System/ICustomFormatter/Overview/myformatter.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/ICustomFormatter/Overview/myformatter.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.icustomformatter.class/vb/myformatter.vb" id="Snippet1"::: - - `MyFormatter` can then be used to provide custom formatting by passing a `MyFormatter` object as the `provider` parameter of the method, as the following example shows. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.icustomformatter.class/vb/myformatter.vb" id="Snippet1"::: + + `MyFormatter` can then be used to provide custom formatting by passing a `MyFormatter` object as the `provider` parameter of the method, as the following example shows. + :::code language="csharp" source="~/snippets/csharp/System/ICustomFormatter/Overview/myformatter.cs" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/ICustomFormatter/Overview/myformatter.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.icustomformatter.class/vb/myformatter.vb" id="Snippet2"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.icustomformatter.class/vb/myformatter.vb" id="Snippet2"::: + ]]> diff --git a/xml/System/IDisposable.xml b/xml/System/IDisposable.xml index 1a68acb78ef..8f57d7970f2 100644 --- a/xml/System/IDisposable.xml +++ b/xml/System/IDisposable.xml @@ -49,106 +49,106 @@ Provides a mechanism for releasing unmanaged resources. - method of this interface to explicitly release unmanaged resources in conjunction with the garbage collector. The consumer of an object can call this method when the object is no longer needed. - + method of this interface to explicitly release unmanaged resources in conjunction with the garbage collector. The consumer of an object can call this method when the object is no longer needed. + > [!WARNING] -> It is a breaking change to add the interface to an existing class. Because pre-existing consumers of your type cannot call , you cannot be certain that unmanaged resources held by your type will be released. - - Because the implementation is called by the consumer of a type when the resources owned by an instance are no longer needed, you should either wrap the managed object in a (the recommended alternative), or you should override to free unmanaged resources in the event that the consumer forgets to call . - +> It is a breaking change to add the interface to an existing class. Because pre-existing consumers of your type cannot call , you cannot be certain that unmanaged resources held by your type will be released. + + Because the implementation is called by the consumer of a type when the resources owned by an instance are no longer needed, you should either wrap the managed object in a (the recommended alternative), or you should override to free unmanaged resources in the event that the consumer forgets to call . + > [!IMPORTANT] -> In the .NET Framework, the C++ compiler supports deterministic disposal of resources and does not allow direct implementation of the method. - - For a detailed discussion about how this interface and the method are used, see the [Garbage Collection](/dotnet/standard/garbage-collection/) and [Implementing a Dispose Method](/dotnet/standard/garbage-collection/implementing-dispose) topics. - -## Using an object that implements IDisposable - If your app simply uses an object that implements the interface, you should call the object's implementation when you are finished using it. Depending on your programming language, you can do this in one of two ways: - -- By using a language construct such as the `using` statement in C# and Visual Basic, and the `use` statement or `using` function in F#. - -- By wrapping the call to the implementation in a `try`/`finally` block. - +> In the .NET Framework, the C++ compiler supports deterministic disposal of resources and does not allow direct implementation of the method. + + For a detailed discussion about how this interface and the method are used, see the [Garbage Collection](/dotnet/standard/garbage-collection/) and [Implementing a Dispose Method](/dotnet/standard/garbage-collection/implementing-dispose) topics. + +## Using an object that implements IDisposable + If your app simply uses an object that implements the interface, you should call the object's implementation when you are finished using it. Depending on your programming language, you can do this in one of two ways: + +- By using a language construct such as the `using` statement in C# and Visual Basic, and the `use` statement or `using` function in F#. + +- By wrapping the call to the implementation in a `try`/`finally` block. + > [!NOTE] -> Documentation for types that implement note that fact and include a reminder to call its implementation. - - -### The C#, F#, and Visual Basic Using statement - If your language supports a construct such as the [using](/dotnet/csharp/language-reference/keywords/using) statement in C#, the [Using](/dotnet/visual-basic/language-reference/statements/using-statement) statement in Visual Basic, or the [use](/dotnet/fsharp/language-reference/resource-management-the-use-keyword) statement in F#, you can use it instead of explicitly calling yourself. The following example uses this approach in defining a `WordCount` class that preserves information about a file and the number of words in it. - +> Documentation for types that implement note that fact and include a reminder to call its implementation. + + +### The C#, F#, and Visual Basic Using statement + If your language supports a construct such as the [using](/dotnet/csharp/language-reference/keywords/using) statement in C#, the [Using](/dotnet/visual-basic/language-reference/statements/using-statement) statement in Visual Basic, or the [use](/dotnet/fsharp/language-reference/resource-management-the-use-keyword) statement in F#, you can use it instead of explicitly calling yourself. The following example uses this approach in defining a `WordCount` class that preserves information about a file and the number of words in it. + :::code language="csharp" source="~/snippets/csharp/System/IDisposable/Overview/calling1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/IDisposable/Overview/calling1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.idisposable/vb/calling1.vb" id="Snippet1"::: - - The `using` statement (`use` expression in F#) is actually a syntactic convenience. At compile time, the language compiler implements the intermediate language (IL) for a `try`/`finally` block. - - For more information about the `using` statement, see the [Using Statement](/dotnet/visual-basic/language-reference/statements/using-statement) or [using Statement](/dotnet/csharp/language-reference/keywords/using-statement) topics. - -### The Try/Finally block - If your programming language does not support a construct like the `using` statement in C# or Visual Basic, or the `use` statement in F#, or if you prefer not to use it, you can call the implementation from the `finally` block of a `try`/`finally` statement. The following example replaces the `using` block in the previous example with a `try`/`finally` block. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.idisposable/vb/calling1.vb" id="Snippet1"::: + + The `using` statement (`use` expression in F#) is actually a syntactic convenience. At compile time, the language compiler implements the intermediate language (IL) for a `try`/`finally` block. + + For more information about the `using` statement, see the [Using Statement](/dotnet/visual-basic/language-reference/statements/using-statement) or [using Statement](/dotnet/csharp/language-reference/keywords/using-statement) topics. + +### The Try/Finally block + If your programming language does not support a construct like the `using` statement in C# or Visual Basic, or the `use` statement in F#, or if you prefer not to use it, you can call the implementation from the `finally` block of a `try`/`finally` statement. The following example replaces the `using` block in the previous example with a `try`/`finally` block. + :::code language="csharp" source="~/snippets/csharp/System/IDisposable/Overview/calling2.cs" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/IDisposable/Overview/calling2.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.idisposable/vb/calling2.vb" id="Snippet2"::: - - For more information about the `try`/`finally` pattern, see [Try...Catch...Finally Statement](/dotnet/visual-basic/language-reference/statements/try-catch-finally-statement), [try-finally](/dotnet/csharp/language-reference/keywords/try-finally), [try...finally Expression](/dotnet/fsharp/language-reference/exception-handling/the-try-finally-expression), or [try-finally Statement](/cpp/c-language/try-finally-statement-c). - -## Implementing IDisposable - You should implement if your type uses unmanaged resources directly or if you wish to use disposable resources yourself. The consumers of your type can call your implementation to free resources when the instance is no longer needed. To handle cases in which they fail to call , you should either use a class derived from to wrap the unmanaged resources, or you should override the method for a reference type. In either case, you use the method to perform whatever cleanup is necessary after using the unmanaged resources, such as freeing, releasing, or resetting the unmanaged resources. For more information about implementing , see [the Dispose(bool) method overload](/dotnet/standard/garbage-collection/implementing-dispose#the-disposebool-method-overload). - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.idisposable/vb/calling2.vb" id="Snippet2"::: + + For more information about the `try`/`finally` pattern, see [Try...Catch...Finally Statement](/dotnet/visual-basic/language-reference/statements/try-catch-finally-statement), [try-finally](/dotnet/csharp/language-reference/keywords/try-finally), [try...finally Expression](/dotnet/fsharp/language-reference/exception-handling/the-try-finally-expression), or [try-finally Statement](/cpp/c-language/try-finally-statement-c). + +## Implementing IDisposable + You should implement if your type uses unmanaged resources directly or if you wish to use disposable resources yourself. The consumers of your type can call your implementation to free resources when the instance is no longer needed. To handle cases in which they fail to call , you should either use a class derived from to wrap the unmanaged resources, or you should override the method for a reference type. In either case, you use the method to perform whatever cleanup is necessary after using the unmanaged resources, such as freeing, releasing, or resetting the unmanaged resources. For more information about implementing , see [the Dispose(bool) method overload](/dotnet/standard/garbage-collection/implementing-dispose#the-disposebool-method-overload). + > [!IMPORTANT] -> If you are defining a base class that uses unmanaged resources and that either has, or is likely to have, subclasses that should be disposed, you should implement the method and provide a second overload of `Dispose`, as discussed in the next section. - - -## IDisposable and the inheritance hierarchy - A base class with subclasses that should be disposable must implement as follows. You should use this pattern whenever you implement on any type that isn't `sealed` (`NotInheritable` in Visual Basic). - -- It should provide one public, non-virtual method and a protected virtual `Dispose(Boolean disposing)` method. - -- The method must call `Dispose(true)` and should suppress finalization for performance. - -- The base type should not include any finalizers. - - The following code fragment reflects the dispose pattern for base classes. It assumes that your type does not override the method. - +> If you are defining a base class that uses unmanaged resources and that either has, or is likely to have, subclasses that should be disposed, you should implement the method and provide a second overload of `Dispose`, as discussed in the next section. + + +## IDisposable and the inheritance hierarchy + A base class with subclasses that should be disposable must implement as follows. You should use this pattern whenever you implement on any type that isn't `sealed` (`NotInheritable` in Visual Basic). + +- It should provide one public, non-virtual method and a protected virtual `Dispose(Boolean disposing)` method. + +- The method must call `Dispose(true)` and should suppress finalization for performance. + +- The base type should not include any finalizers. + + The following code fragment reflects the dispose pattern for base classes. It assumes that your type does not override the method. + :::code language="csharp" source="~/snippets/csharp/System/IDisposable/Overview/base1.cs" id="Snippet3"::: :::code language="fsharp" source="~/snippets/fsharp/System/IDisposable/Overview/base1.fs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.idisposable/vb/base1.vb" id="Snippet3"::: - - If you do override the method, your class should implement the following pattern. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.idisposable/vb/base1.vb" id="Snippet3"::: + + If you do override the method, your class should implement the following pattern. + :::code language="csharp" source="~/snippets/csharp/System/IDisposable/Overview/base2.cs" id="Snippet5"::: :::code language="fsharp" source="~/snippets/fsharp/System/IDisposable/Overview/base2.fs" id="Snippet5"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.idisposable/vb/base2.vb" id="Snippet5"::: - - Subclasses should implement the disposable pattern as follows: - -- They must override `Dispose(Boolean)` and call the base class `Dispose(Boolean)` implementation. - -- They can provide a finalizer if needed. The finalizer must call `Dispose(false)`. - - Note that derived classes do not themselves implement the interface and do not include a parameterless method. They only override the base class `Dispose(Boolean)` method. - - The following code fragment reflects the dispose pattern for derived classes. It assumes that your type does not override the method. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.idisposable/vb/base2.vb" id="Snippet5"::: + + Subclasses should implement the disposable pattern as follows: + +- They must override `Dispose(Boolean)` and call the base class `Dispose(Boolean)` implementation. + +- They can provide a finalizer if needed. The finalizer must call `Dispose(false)`. + + Note that derived classes do not themselves implement the interface and do not include a parameterless method. They only override the base class `Dispose(Boolean)` method. + + The following code fragment reflects the dispose pattern for derived classes. It assumes that your type does not override the method. + :::code language="csharp" source="~/snippets/csharp/System/IDisposable/Overview/derived1.cs" id="Snippet4"::: :::code language="fsharp" source="~/snippets/fsharp/System/IDisposable/Overview/derived1.fs" id="Snippet4"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.idisposable/vb/derived1.vb" id="Snippet4"::: - - - -## Examples - The following example demonstrates how to create a resource class that implements the interface. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.idisposable/vb/derived1.vb" id="Snippet4"::: + + + +## Examples + The following example demonstrates how to create a resource class that implements the interface. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.IDisposable.Dispose Example/CPP/idisposabledispose.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/IDisposable/Overview/idisposabledispose.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/IDisposable/Overview/idisposabledispose.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.IDisposable.Dispose Example/VB/idisposabledispose.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.IDisposable.Dispose Example/VB/idisposabledispose.vb" id="Snippet1"::: + ]]> @@ -196,43 +196,43 @@ Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. - [!WARNING] -> If you are using a class that implements the interface, you should call its implementation when you are finished using the class. For more information, see the "Using an object that implements IDisposable" section in the topic. - - When implementing this method, ensure that all held resources are freed by propagating the call through the containment hierarchy. For example, if an object A allocates an object B, and object B allocates an object C, then A's implementation must call on B, which must in turn call on C. - +> If you are using a class that implements the interface, you should call its implementation when you are finished using the class. For more information, see the "Using an object that implements IDisposable" section in the topic. + + When implementing this method, ensure that all held resources are freed by propagating the call through the containment hierarchy. For example, if an object A allocates an object B, and object B allocates an object C, then A's implementation must call on B, which must in turn call on C. + > [!IMPORTANT] -> The C++ compiler supports deterministic disposal of resources and does not allow direct implementation of the method. - - An object must also call the method of its base class if the base class implements . For more information about implementing on a base class and its subclasses, see the "IDisposable and the inheritance hierarchy" section in the topic. - - If an object's method is called more than once, the object must ignore all calls after the first one. The object must not throw an exception if its method is called multiple times. Instance methods other than can throw an when resources are already disposed. - - Users might expect a resource type to use a particular convention to denote an allocated state versus a freed state. An example of this is stream classes, which are traditionally thought of as open or closed. The implementer of a class that has such a convention might choose to implement a public method with a customized name, such as `Close`, that calls the method. - - Because the method must be called explicitly, there is always a danger that the unmanaged resources will not be released, because the consumer of an object fails to call its method. There are two ways to avoid this: - -- Wrap the managed resource in an object derived from . Your implementation then calls the method of the instances. For more information, see "The SafeHandle alternative" section in the topic. - -- Implement a finalizer to free resources when is not called. By default, the garbage collector automatically calls an object's finalizer before reclaiming its memory. However, if the method has been called, it is typically unnecessary for the garbage collector to call the disposed object's finalizer. To prevent automatic finalization, implementations can call the method. - - When you use an object that accesses unmanaged resources, such as a , a good practice is to create the instance with a `using` statement. The `using` statement automatically closes the stream and calls on the object when the code that is using it has completed. For an example, see the class. - - - -## Examples - The following example shows how you can implement the method. - +> The C++ compiler supports deterministic disposal of resources and does not allow direct implementation of the method. + + An object must also call the method of its base class if the base class implements . For more information about implementing on a base class and its subclasses, see the "IDisposable and the inheritance hierarchy" section in the topic. + + If an object's method is called more than once, the object must ignore all calls after the first one. The object must not throw an exception if its method is called multiple times. Instance methods other than can throw an when resources are already disposed. + + Users might expect a resource type to use a particular convention to denote an allocated state versus a freed state. An example of this is stream classes, which are traditionally thought of as open or closed. The implementer of a class that has such a convention might choose to implement a public method with a customized name, such as `Close`, that calls the method. + + Because the method must be called explicitly, there is always a danger that the unmanaged resources will not be released, because the consumer of an object fails to call its method. There are two ways to avoid this: + +- Wrap the managed resource in an object derived from . Your implementation then calls the method of the instances. For more information, see "The SafeHandle alternative" section in the topic. + +- Implement a finalizer to free resources when is not called. By default, the garbage collector automatically calls an object's finalizer before reclaiming its memory. However, if the method has been called, it is typically unnecessary for the garbage collector to call the disposed object's finalizer. To prevent automatic finalization, implementations can call the method. + + When you use an object that accesses unmanaged resources, such as a , a good practice is to create the instance with a `using` statement. The `using` statement automatically closes the stream and calls on the object when the code that is using it has completed. For an example, see the class. + + + +## Examples + The following example shows how you can implement the method. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.IDisposable.Dispose Example/CPP/idisposabledispose.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/IDisposable/Overview/idisposabledispose.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/IDisposable/Overview/idisposabledispose.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.IDisposable.Dispose Example/VB/idisposabledispose.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.IDisposable.Dispose Example/VB/idisposabledispose.vb" id="Snippet1"::: + ]]> Implementing a Dispose Method diff --git a/xml/System/IEquatable`1.xml b/xml/System/IEquatable`1.xml index 773bf92683a..bc6fe372675 100644 --- a/xml/System/IEquatable`1.xml +++ b/xml/System/IEquatable`1.xml @@ -52,33 +52,25 @@ The type of objects to compare. Defines a generalized method that a value type or class implements to create a type-specific method for determining equality of instances. - method to create a type-specific method suitable for determining equality of instances. - + method to create a type-specific method suitable for determining equality of instances. + > [!NOTE] -> The interface defines the method, which determines the sort order of instances of the implementing type. The interface defines the method, which determines the equality of instances of the implementing type. - - The interface is used by generic collection objects such as , , and when testing for equality in such methods as `Contains`, `IndexOf`, `LastIndexOf`, and `Remove`. It should be implemented for any object that might be stored in a generic collection. - - - -## Examples - See the example for the method. - +> The interface defines the method, which determines the sort order of instances of the implementing type. The interface defines the method, which determines the equality of instances of the implementing type. + + The interface is used by generic collection objects such as , , and when testing for equality in such methods as `Contains`, `IndexOf`, `LastIndexOf`, and `Remove`. It should be implemented for any object that might be stored in a generic collection. + + + +## Examples + See the example for the method. + ]]> - Replace the type parameter of the interface with the type that is implementing this interface. - - If you implement , you should also override the base class implementations of and so that their behavior is consistent with that of the method. If you do override , your overridden implementation is also called in calls to the static method on your class. In addition, you should overload the and operators. This ensures that all tests for equality return consistent results. - - For information on overriding , see . - - For a value type, you should always implement and override for better performance. boxes value types and relies on reflection to compare two values for equality. Both your implementation of and your override of should return consistent results. - - If you implement , you should also implement if instances of your type can be ordered or sorted. If your type implements , you almost always also implement . + Replace the type parameter of the interface with the type that is implementing this interface. If you implement , you should also override the base class implementations of and so that their behavior is consistent with that of the method. If you do override , your overridden implementation is also called in calls to the static method on your class. In addition, you should overload the and operators. This ensures that all tests for equality return consistent results. For information on overriding , see . For a value type, you should always implement and override for better performance. boxes value types and relies on reflection to compare two values for equality. Both your implementation of and your override of should return consistent results. If you implement , you should also implement if instances of your type can be ordered or sorted. If your type implements , you almost always also implement . Note that there are some designs where a type supports an order relation, but equality may be distinct from an ordering relation. Consider a `Person` class where you sort alphabetically. Two people with the same name sort the same, but are not the same person. @@ -138,42 +130,42 @@ if the current object is equal to the parameter; otherwise, . - method is intended to perform a test for equality with another object of type `T`, the same type as the current object. The method is called in the following circumstances: - -- When the `Equals` method is called and the `other` argument is a strongly-typed object of type `T`. (If `other` is not of type `T`, the base method is called. Of the two methods, offers slightly better performance.) - -- When the search methods of a number of generic collection objects are called. Some of these types and their methods include the following: - - - Some of the generic overloads of the method. - - - The search methods of the class, including , , , and . - - - The search methods of the class, including and . - - - The search methods of the generic class, including and . - - In other words, to handle the possibility that objects of a class will be stored in an array or a generic collection object, it is a good idea to implement so that the object can be easily identified and manipulated. - - When implementing the method, define equality appropriately for the type specified by the generic type argument. For example, if the type argument is , define equality appropriately for the comparison of two 32-bit signed integers. - - - -## Examples - The following example shows the partial implementation of a `Person` class that implements and has two properties, `LastName` and `SSN`. The method returns `True` if the `SSN` property of two `Person` objects is identical; otherwise, it returns `False`. - + method is intended to perform a test for equality with another object of type `T`, the same type as the current object. The method is called in the following circumstances: + +- When the `Equals` method is called and the `other` argument is a strongly-typed object of type `T`. (If `other` is not of type `T`, the base method is called. Of the two methods, offers slightly better performance.) + +- When the search methods of a number of generic collection objects are called. Some of these types and their methods include the following: + + - Some of the generic overloads of the method. + + - The search methods of the class, including , , , and . + + - The search methods of the class, including and . + + - The search methods of the generic class, including and . + + In other words, to handle the possibility that objects of a class will be stored in an array or a generic collection object, it is a good idea to implement so that the object can be easily identified and manipulated. + + When implementing the method, define equality appropriately for the type specified by the generic type argument. For example, if the type argument is , define equality appropriately for the comparison of two 32-bit signed integers. + + + +## Examples + The following example shows the partial implementation of a `Person` class that implements and has two properties, `LastName` and `SSN`. The method returns `True` if the `SSN` property of two `Person` objects is identical; otherwise, it returns `False`. + :::code language="csharp" source="~/snippets/csharp/System/IEquatableT/Equals/EqualsEx2.cs" id="Snippet3"::: :::code language="fsharp" source="~/snippets/fsharp/System/IEquatableT/Equals/EqualsEx2.fs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.GenericIEquatable.Equals/vb/EqualsEx2.vb" id="Snippet3"::: - - `Person` objects can then be stored in a object and can be identified by the `Contains` method, as the following example shows. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.GenericIEquatable.Equals/vb/EqualsEx2.vb" id="Snippet3"::: + + `Person` objects can then be stored in a object and can be identified by the `Contains` method, as the following example shows. + :::code language="csharp" source="~/snippets/csharp/System/IEquatableT/Equals/Snippet12.cs" id="Snippet12"::: :::code language="fsharp" source="~/snippets/fsharp/System/IEquatableT/Equals/Snippet12.fs" id="Snippet12"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.GenericIEquatable.Equals/vb/Snippet12.vb" id="Snippet12"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.GenericIEquatable.Equals/vb/Snippet12.vb" id="Snippet12"::: + ]]> diff --git a/xml/System/IFormatProvider.xml b/xml/System/IFormatProvider.xml index 76d1aabe3f3..63ef600b819 100644 --- a/xml/System/IFormatProvider.xml +++ b/xml/System/IFormatProvider.xml @@ -53,46 +53,46 @@ Provides a mechanism for retrieving an object to control formatting. - interface supplies an object that provides formatting information for formatting and parsing operations. Formatting operations convert the value of a type to the string representation of that value. Typical formatting methods are the `ToString` methods of a type, as well as . Parsing operations convert the string representation of a value to a type with that value. Typical parsing methods are `Parse` and `TryParse`. - - The interface consists of a single method, . is a callback method: The parsing or formatting method calls it and passes it a object that represents the type of object that the formatting or parsing method expects will provide formatting information. The method is responsible for returning an object of that type. - - implementations are often used implicitly by formatting and parsing methods. For example, the method implicitly uses an implementation that represents the system's current culture. implementations can also be specified explicitly by methods that have a parameter of type , such as and . - - The .NET Framework includes the following three predefined implementations to provide culture-specific information that is used in formatting or parsing numeric and date and time values: - -- The class, which provides information that is used to format numbers, such as the currency, thousands separator, and decimal separator symbols for a particular culture. For information about the predefined format strings recognized by a object and used in numeric formatting operations, see [Standard Numeric Format Strings](/dotnet/standard/base-types/standard-numeric-format-strings) and [Custom Numeric Format Strings](/dotnet/standard/base-types/custom-numeric-format-strings). - -- The class, which provides information that is used to format dates and times, such as the date and time separator symbols for a particular culture or the order and format of a date's year, month, and day components. For information about the predefined format strings recognized by a object and used in numeric formatting operations, see [Standard Date and Time Format Strings](/dotnet/standard/base-types/standard-date-and-time-format-strings) and [Custom Date and Time Format Strings](/dotnet/standard/base-types/custom-date-and-time-format-strings). - -- The class, which represents a particular culture. Its method returns a culture-specific or object, depending on whether the object is used in a formatting or parsing operation that involves numbers or dates and times. - - The .NET Framework also supports custom formatting. This typically involves the creation of a formatting class that implements both and . An instance of this class is then passed as a parameter to a method that performs a custom formatting operation, such as The example provides an illustration of such a custom implementation that formats a number as a 12-digit account number. - - - -## Examples - The following example illustrates how an implementation can change the representation of a date and time value. In this case, a single date is displayed by using objects that represent four different cultures. - + interface supplies an object that provides formatting information for formatting and parsing operations. Formatting operations convert the value of a type to the string representation of that value. Typical formatting methods are the `ToString` methods of a type, as well as . Parsing operations convert the string representation of a value to a type with that value. Typical parsing methods are `Parse` and `TryParse`. + + The interface consists of a single method, . is a callback method: The parsing or formatting method calls it and passes it a object that represents the type of object that the formatting or parsing method expects will provide formatting information. The method is responsible for returning an object of that type. + + implementations are often used implicitly by formatting and parsing methods. For example, the method implicitly uses an implementation that represents the system's current culture. implementations can also be specified explicitly by methods that have a parameter of type , such as and . + + The .NET Framework includes the following three predefined implementations to provide culture-specific information that is used in formatting or parsing numeric and date and time values: + +- The class, which provides information that is used to format numbers, such as the currency, thousands separator, and decimal separator symbols for a particular culture. For information about the predefined format strings recognized by a object and used in numeric formatting operations, see [Standard Numeric Format Strings](/dotnet/standard/base-types/standard-numeric-format-strings) and [Custom Numeric Format Strings](/dotnet/standard/base-types/custom-numeric-format-strings). + +- The class, which provides information that is used to format dates and times, such as the date and time separator symbols for a particular culture or the order and format of a date's year, month, and day components. For information about the predefined format strings recognized by a object and used in numeric formatting operations, see [Standard Date and Time Format Strings](/dotnet/standard/base-types/standard-date-and-time-format-strings) and [Custom Date and Time Format Strings](/dotnet/standard/base-types/custom-date-and-time-format-strings). + +- The class, which represents a particular culture. Its method returns a culture-specific or object, depending on whether the object is used in a formatting or parsing operation that involves numbers or dates and times. + + The .NET Framework also supports custom formatting. This typically involves the creation of a formatting class that implements both and . An instance of this class is then passed as a parameter to a method that performs a custom formatting operation, such as The example provides an illustration of such a custom implementation that formats a number as a 12-digit account number. + + + +## Examples + The following example illustrates how an implementation can change the representation of a date and time value. In this case, a single date is displayed by using objects that represent four different cultures. + :::code language="csharp" source="~/snippets/csharp/System/IFormatProvider/Overview/provider2.cs" interactive="try-dotnet" id="Snippet3"::: :::code language="fsharp" source="~/snippets/fsharp/System/IFormatProvider/Overview/provider2.fs" id="Snippet3"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.IFormatProvider.Class/vb/provider2.vb" id="Snippet3"::: - - The following example illustrates the use of a class that implements the interface and the method. The `AcctNumberFormat` class converts an value that represents an account number to a formatted 12-digit account number. Its `GetFormat` method returns a reference to the current `AcctNumberFormat` instance if the `formatType` parameter refers to a class that implements ; otherwise, `GetFormat` returns `null`. - + + The following example illustrates the use of a class that implements the interface and the method. The `AcctNumberFormat` class converts an value that represents an account number to a formatted 12-digit account number. Its `GetFormat` method returns a reference to the current `AcctNumberFormat` instance if the `formatType` parameter refers to a class that implements ; otherwise, `GetFormat` returns `null`. + :::code language="csharp" source="~/snippets/csharp/System/IFormatProvider/Overview/Provider.cs" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/IFormatProvider/Overview/Provider.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.IFormatProvider.Class/vb/Provider.vb" id="Snippet2"::: - - The class that implements can then be used in a call to a formatting and parsing operation. For example, the following code calls the method to generate a string that contains a formatted 12-digit account number. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.IFormatProvider.Class/vb/Provider.vb" id="Snippet2"::: + + The class that implements can then be used in a call to a formatting and parsing operation. For example, the following code calls the method to generate a string that contains a formatted 12-digit account number. + :::code language="csharp" source="~/snippets/csharp/System/IFormatProvider/Overview/Provider.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/IFormatProvider/Overview/Provider.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.IFormatProvider.Class/vb/Provider.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.IFormatProvider.Class/vb/Provider.vb" id="Snippet1"::: + ]]> @@ -147,30 +147,30 @@ Returns an object that provides formatting services for the specified type. An instance of the object specified by , if the implementation can supply that type of object; otherwise, . - is a callback method that formatting and parsing methods invoke to retrieve information about the format of the input string in parsing operations or the format of the output string in formatting operations. In the `formatType` parameter, the formatting or parsing method passes the type of object it requires to perform its operation. If the implementation can supply this formatting or parsing object, it returns that object. If not, it returns `null`. - - For example, in the call to the method, the method argument is an object that provides information about how the string representation of the current integer instance might be formatted. When the runtime executes the method, it calls the object's method and passes it a object that represents the type. If the object can supply a object, it returns that object. If it cannot supply an object of that type, it returns `null`. - - You can implement the interface and the method in classes that provide custom formatting or parsing services. The implementation is then passed as an argument to any overload of a parsing or formatting method that has a parameter of type , such as , , or . - - - -## Examples - The following example illustrates the use of a class that implements the interface and the method. The `AcctNumberFormat` class converts an value that represents an account number to a formatted 12-digit account number. Its `GetFormat` method returns a reference to itself if the `formatType` parameter refers to a class that implements ; otherwise, `GetFormat` returns `null`. - + is a callback method that formatting and parsing methods invoke to retrieve information about the format of the input string in parsing operations or the format of the output string in formatting operations. In the `formatType` parameter, the formatting or parsing method passes the type of object it requires to perform its operation. If the implementation can supply this formatting or parsing object, it returns that object. If not, it returns `null`. + + For example, in the call to the method, the method argument is an object that provides information about how the string representation of the current integer instance might be formatted. When the runtime executes the method, it calls the object's method and passes it a object that represents the type. If the object can supply a object, it returns that object. If it cannot supply an object of that type, it returns `null`. + + You can implement the interface and the method in classes that provide custom formatting or parsing services. The implementation is then passed as an argument to any overload of a parsing or formatting method that has a parameter of type , such as , , or . + + + +## Examples + The following example illustrates the use of a class that implements the interface and the method. The `AcctNumberFormat` class converts an value that represents an account number to a formatted 12-digit account number. Its `GetFormat` method returns a reference to itself if the `formatType` parameter refers to a class that implements ; otherwise, `GetFormat` returns `null`. + :::code language="csharp" source="~/snippets/csharp/System/IFormatProvider/Overview/Provider.cs" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/IFormatProvider/Overview/Provider.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.IFormatProvider.Class/vb/Provider.vb" id="Snippet2"::: - - An instance of the `AcctNumberFormat` class can then be passed as an argument to a method that provides formatting or parsing services. For example, the following code passes an `AcctNumberFormat` class to the method to generate a formatted 12-digit account number. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.IFormatProvider.Class/vb/Provider.vb" id="Snippet2"::: + + An instance of the `AcctNumberFormat` class can then be passed as an argument to a method that provides formatting or parsing services. For example, the following code passes an `AcctNumberFormat` class to the method to generate a formatted 12-digit account number. + :::code language="csharp" source="~/snippets/csharp/System/IFormatProvider/Overview/Provider.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/IFormatProvider/Overview/Provider.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.IFormatProvider.Class/vb/Provider.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.IFormatProvider.Class/vb/Provider.vb" id="Snippet1"::: + ]]> diff --git a/xml/System/IFormattable.xml b/xml/System/IFormattable.xml index 986d1705877..ea8ceffce98 100644 --- a/xml/System/IFormattable.xml +++ b/xml/System/IFormattable.xml @@ -53,58 +53,56 @@ Provides functionality to format the value of an object into a string representation. - interface converts an object to its string representation based on a format string and a format provider. - - A format string typically defines the general appearance of an object. For example, the .NET Framework supports the following: - -- Standard format strings for formatting enumeration values (see [Enumeration Format Strings](/dotnet/standard/base-types/enumeration-format-strings)). - -- Standard and custom format strings for formatting numeric values (see [Standard Numeric Format Strings](/dotnet/standard/base-types/standard-numeric-format-strings) and [Custom Numeric Format Strings](/dotnet/standard/base-types/custom-numeric-format-strings)). - -- Standard and custom format strings for formatting date and time values (see [Standard Date and Time Format Strings](/dotnet/standard/base-types/standard-date-and-time-format-strings) and [Custom Date and Time Format Strings](/dotnet/standard/base-types/custom-date-and-time-format-strings)). - -- Standard and custom format strings for formatting time intervals (see [Standard TimeSpan Format Strings](/dotnet/standard/base-types/standard-timespan-format-strings) and [Custom TimeSpan Format Strings](/dotnet/standard/base-types/custom-timespan-format-strings)). - - You can also define your own format strings to support formatting of your application-defined types. - - A format provider returns a formatting object that typically defines the symbols used in converting an object to its string representation. For example, when you convert a number to a currency value, a format provider defines the currency symbol that appears in the result string. The .NET Framework defines three format providers: - -- The class, which returns either a object for formatting numeric values, or a object for formatting date and time values. - -- The class, which returns an instance of itself for formatting numeric values. - -- The class, which returns an instance of itself for formatting date and time values. - - In addition, you can define your own custom format providers to supply culture-specific, profession-specific, or industry-specific information used in formatting. For more information about implementing custom formatting by using a custom format provider, see . - - The interface defines a single method, , that supplies formatting services for the implementing type. The method can be called directly. In addition, it is called automatically by the and methods, and by methods that use the [composite formatting feature](/dotnet/standard/base-types/composite-formatting) in the .NET Framework. Such methods include , , and , among others. The method is called for each format item in the method's format string. - - The interface is implemented by the base data types. - - - -## Examples - The following example defines a `Temperature` class that implements the interface. The class supports four format specifiers: "G" and "C", which indicate that the temperature is to be displayed in Celsius; "F", which indicates that the temperature is to be displayed in Fahrenheit; and "K", which indicates that the temperature is to be displayed in Kelvin. In addition, the implementation also can handle a format string that is `null` or empty. The other two `ToString` methods defined by the `Temperature` class simply wrap a call to the implementation. - + interface converts an object to its string representation based on a format string and a format provider. + + A format string typically defines the general appearance of an object. For example, the .NET Framework supports the following: + +- Standard format strings for formatting enumeration values (see [Enumeration Format Strings](/dotnet/standard/base-types/enumeration-format-strings)). + +- Standard and custom format strings for formatting numeric values (see [Standard Numeric Format Strings](/dotnet/standard/base-types/standard-numeric-format-strings) and [Custom Numeric Format Strings](/dotnet/standard/base-types/custom-numeric-format-strings)). + +- Standard and custom format strings for formatting date and time values (see [Standard Date and Time Format Strings](/dotnet/standard/base-types/standard-date-and-time-format-strings) and [Custom Date and Time Format Strings](/dotnet/standard/base-types/custom-date-and-time-format-strings)). + +- Standard and custom format strings for formatting time intervals (see [Standard TimeSpan Format Strings](/dotnet/standard/base-types/standard-timespan-format-strings) and [Custom TimeSpan Format Strings](/dotnet/standard/base-types/custom-timespan-format-strings)). + + You can also define your own format strings to support formatting of your application-defined types. + + A format provider returns a formatting object that typically defines the symbols used in converting an object to its string representation. For example, when you convert a number to a currency value, a format provider defines the currency symbol that appears in the result string. The .NET Framework defines three format providers: + +- The class, which returns either a object for formatting numeric values, or a object for formatting date and time values. + +- The class, which returns an instance of itself for formatting numeric values. + +- The class, which returns an instance of itself for formatting date and time values. + + In addition, you can define your own custom format providers to supply culture-specific, profession-specific, or industry-specific information used in formatting. For more information about implementing custom formatting by using a custom format provider, see . + + The interface defines a single method, , that supplies formatting services for the implementing type. The method can be called directly. In addition, it is called automatically by the and methods, and by methods that use the [composite formatting feature](/dotnet/standard/base-types/composite-formatting) in the .NET Framework. Such methods include , , and , among others. The method is called for each format item in the method's format string. + + The interface is implemented by the base data types. + + + +## Examples + The following example defines a `Temperature` class that implements the interface. The class supports four format specifiers: "G" and "C", which indicate that the temperature is to be displayed in Celsius; "F", which indicates that the temperature is to be displayed in Fahrenheit; and "K", which indicates that the temperature is to be displayed in Kelvin. In addition, the implementation also can handle a format string that is `null` or empty. The other two `ToString` methods defined by the `Temperature` class simply wrap a call to the implementation. + :::code language="csharp" source="~/snippets/csharp/System/IFormattable/Overview/example1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/IFormattable/Overview/example1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.iformattable/vb/example1.vb" id="Snippet1"::: - - The following example then calls the implementation either directly or by using a composite format string. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.iformattable/vb/example1.vb" id="Snippet1"::: + + The following example then calls the implementation either directly or by using a composite format string. + :::code language="csharp" source="~/snippets/csharp/System/IFormattable/Overview/example1.cs" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/IFormattable/Overview/example1.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.iformattable/vb/example1.vb" id="Snippet2"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.iformattable/vb/example1.vb" id="Snippet2"::: + ]]> - Classes that require more control over the formatting of strings than provides should implement . - - A class that implements must support the "G" (general) format specifier. Besides the "G" specifier, the class can define the list of format specifiers that it supports. In addition, the class must be prepared to handle a format specifier that is . For more information about formatting and formatting codes, see [Formatting Types](/dotnet/standard/base-types/formatting-types) + Classes that require more control over the formatting of strings than provides should implement . A class that implements must support the "G" (general) format specifier. Besides the "G" specifier, the class can define the list of format specifiers that it supports. In addition, the class must be prepared to handle a format specifier that is . For more information about formatting and formatting codes, see [Formatting Types](/dotnet/standard/base-types/formatting-types) @@ -155,56 +153,56 @@ - The format to use. - - -or- - - A null reference ( in Visual Basic) to use the default format defined for the type of the implementation. - The provider to use to format the value. - - -or- - - A null reference ( in Visual Basic) to obtain the numeric format information from the current locale setting of the operating system. + The format to use. + +-or- + +A null reference ( in Visual Basic) to use the default format defined for the type of the implementation. + The provider to use to format the value. + +-or- + +A null reference ( in Visual Basic) to obtain the numeric format information from the current locale setting of the operating system. Formats the value of the current instance using the specified format. The value of the current instance in the specified format. - method converts a value to a string representation that can be expressed in multiple ways. Its precise format depends on specific symbols or a specified order defined by specific cultures, professions, or industries. You can call the method directly. It is also called automatically by the and methods, and by methods that use the composite formatting feature in the .NET Framework, such as , , and . (For more information, see [Composite Formatting](/dotnet/standard/base-types/composite-formatting).) - - Composite formatting methods call the method once for each format item in a format string. The parameters passed to the method depend on the specific formatting method that is called and on the content of the format item, as follows: - -- If the format item does not include a format string (for example, if the format item is simply `{0}`), it is passed `null` as the value of the parameter. - -- If the format item includes a format string (for example, `{0:G}`), that format string is passed as the value of the parameter. - -- If the original method call does not include an parameter, is passed as the value of the parameter. - -- If the original method call includes an parameter, the provider that is supplied in the method call is passed as the value of the parameter. - + method converts a value to a string representation that can be expressed in multiple ways. Its precise format depends on specific symbols or a specified order defined by specific cultures, professions, or industries. You can call the method directly. It is also called automatically by the and methods, and by methods that use the composite formatting feature in the .NET Framework, such as , , and . (For more information, see [Composite Formatting](/dotnet/standard/base-types/composite-formatting).) + + Composite formatting methods call the method once for each format item in a format string. The parameters passed to the method depend on the specific formatting method that is called and on the content of the format item, as follows: + +- If the format item does not include a format string (for example, if the format item is simply `{0}`), it is passed `null` as the value of the parameter. + +- If the format item includes a format string (for example, `{0:G}`), that format string is passed as the value of the parameter. + +- If the original method call does not include an parameter, is passed as the value of the parameter. + +- If the original method call includes an parameter, the provider that is supplied in the method call is passed as the value of the parameter. + > [!NOTE] -> An object's implementation is called by composite formatting methods only if they are not passed an format provider, or if the method of the custom format provider returns `null`. - - The .NET Framework includes three format providers, all of which implement the interface: - -- supplies numeric formatting information, such as the characters to use for decimal and group separators, and the spelling and placement of currency symbols in monetary values. - -- supplies date-related and time-related formatting information, such as the position of the month, the day, and the year in a date pattern. - -- contains the default formatting information in a specific culture, including the numeric format information, and date-related and time-related formatting information. - - In addition, you can define your own custom format provider. - - - -## Examples - The following example demonstrates a `Temperature` class that implements the method. This code example is part of a larger example provided for the class. - +> An object's implementation is called by composite formatting methods only if they are not passed an format provider, or if the method of the custom format provider returns `null`. + + The .NET Framework includes three format providers, all of which implement the interface: + +- supplies numeric formatting information, such as the characters to use for decimal and group separators, and the spelling and placement of currency symbols in monetary values. + +- supplies date-related and time-related formatting information, such as the position of the month, the day, and the year in a date pattern. + +- contains the default formatting information in a specific culture, including the numeric format information, and date-related and time-related formatting information. + + In addition, you can define your own custom format provider. + + + +## Examples + The following example demonstrates a `Temperature` class that implements the method. This code example is part of a larger example provided for the class. + :::code language="csharp" source="~/snippets/csharp/System/IFormattable/Overview/example1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/IFormattable/Overview/example1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.iformattable/vb/example1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.iformattable/vb/example1.vb" id="Snippet1"::: + ]]> diff --git a/xml/System/IObservable`1.xml b/xml/System/IObservable`1.xml index 814ecd85a7d..bd110f65284 100644 --- a/xml/System/IObservable`1.xml +++ b/xml/System/IObservable`1.xml @@ -61,58 +61,58 @@ The object that provides notification information. Defines a provider for push-based notification. - and interfaces provide a generalized mechanism for push-based notification, also known as the observer design pattern. The interface represents the class that sends notifications (the provider); the interface represents the class that receives them (the observer). `T` represents the class that provides the notification information. In some push-based notifications, the implementation and `T` can represent the same type. - - The provider must implement a single method, , that indicates that an observer wants to receive push-based notifications. Callers to the method pass an instance of the observer. The method returns an implementation that enables observers to cancel notifications at any time before the provider has stopped sending them. - - At any given time, a given provider may have zero, one, or multiple observers. The provider is responsible for storing references to observers and ensuring that they are valid before it sends notifications. The interface does not make any assumptions about the number of observers or the order in which notifications are sent. - - The provider sends the following three kinds of notifications to the observer by calling methods: - -- The current data. The provider can call the method to pass the observer a `T` object that has current data, changed data, or fresh data. - -- An error condition. The provider can call the method to notify the observer that some error condition has occurred. - -- No further data. The provider can call the method to notify the observer that it has finished sending notifications. - - - -## Examples - The following example illustrates the observer design pattern. It defines a `Location` class that contains latitude and longitude information. - + and interfaces provide a generalized mechanism for push-based notification, also known as the observer design pattern. The interface represents the class that sends notifications (the provider); the interface represents the class that receives them (the observer). `T` represents the class that provides the notification information. In some push-based notifications, the implementation and `T` can represent the same type. + + The provider must implement a single method, , that indicates that an observer wants to receive push-based notifications. Callers to the method pass an instance of the observer. The method returns an implementation that enables observers to cancel notifications at any time before the provider has stopped sending them. + + At any given time, a given provider may have zero, one, or multiple observers. The provider is responsible for storing references to observers and ensuring that they are valid before it sends notifications. The interface does not make any assumptions about the number of observers or the order in which notifications are sent. + + The provider sends the following three kinds of notifications to the observer by calling methods: + +- The current data. The provider can call the method to pass the observer a `T` object that has current data, changed data, or fresh data. + +- An error condition. The provider can call the method to notify the observer that some error condition has occurred. + +- No further data. The provider can call the method to notify the observer that it has finished sending notifications. + + + +## Examples + The following example illustrates the observer design pattern. It defines a `Location` class that contains latitude and longitude information. + :::code language="csharp" source="~/snippets/csharp/System/IObservableT/Overview/provider.cs" id="Snippet5"::: :::code language="fsharp" source="~/snippets/fsharp/System/IObservableT/Overview/provider.fs" id="Snippet5"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.iobserver.class/vb/provider.vb" id="Snippet5"::: - - The `LocationTracker` class provides the implementation. Its `TrackLocation` method is passed a nullable `Location` object that contains the latitude and longitude data. If the `Location` value is not `null`, the `TrackLocation` method calls the method of each observer. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.iobserver.class/vb/provider.vb" id="Snippet5"::: + + The `LocationTracker` class provides the implementation. Its `TrackLocation` method is passed a nullable `Location` object that contains the latitude and longitude data. If the `Location` value is not `null`, the `TrackLocation` method calls the method of each observer. + :::code language="csharp" source="~/snippets/csharp/System/IObservableT/Overview/provider.cs" id="Snippet6"::: :::code language="fsharp" source="~/snippets/fsharp/System/IObservableT/Overview/provider.fs" id="Snippet6"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.iobserver.class/vb/provider.vb" id="Snippet6"::: - - If the `Location` value is `null`, the `TrackLocation` method instantiates a `LocationUnknownException` object, which is shown in the following example. It then calls each observer's method and passes it the `LocationUnknownException` object. Note that `LocationUnknownException` derives from , but does not add any new members. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.iobserver.class/vb/provider.vb" id="Snippet6"::: + + If the `Location` value is `null`, the `TrackLocation` method instantiates a `LocationUnknownException` object, which is shown in the following example. It then calls each observer's method and passes it the `LocationUnknownException` object. Note that `LocationUnknownException` derives from , but does not add any new members. + :::code language="csharp" source="~/snippets/csharp/System/IObservableT/Overview/provider.cs" id="Snippet7"::: :::code language="fsharp" source="~/snippets/fsharp/System/IObservableT/Overview/provider.fs" id="Snippet7"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.iobserver.class/vb/provider.vb" id="Snippet7"::: - - Observers register to receive notifications from a `LocationTracker` object by calling its method, which assigns a reference to the observer object to a private generic object. The method returns an `Unsubscriber` object, which is an implementation that enables observers to stop receiving notifications. The `LocationTracker` class also includes an `EndTransmission` method. When no further location data is available, the method calls each observer's method and then clears the internal list of observers. - - In this example, the `LocationReporter` class provides the implementation. It displays information about the current location to the console. Its constructor includes a `name` parameter, which enables the `LocationReporter` instance to identify itself in its string output. It also includes a `Subscribe` method, which wraps a call to the provider's method. This allows the method to assign the returned reference to a private variable. The `LocationReporter` class also includes an `Unsubscribe` method, which calls the method of the object that is returned by the method. The following code defines the `LocationReporter` class. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.iobserver.class/vb/provider.vb" id="Snippet7"::: + + Observers register to receive notifications from a `LocationTracker` object by calling its method, which assigns a reference to the observer object to a private generic object. The method returns an `Unsubscriber` object, which is an implementation that enables observers to stop receiving notifications. The `LocationTracker` class also includes an `EndTransmission` method. When no further location data is available, the method calls each observer's method and then clears the internal list of observers. + + In this example, the `LocationReporter` class provides the implementation. It displays information about the current location to the console. Its constructor includes a `name` parameter, which enables the `LocationReporter` instance to identify itself in its string output. It also includes a `Subscribe` method, which wraps a call to the provider's method. This allows the method to assign the returned reference to a private variable. The `LocationReporter` class also includes an `Unsubscribe` method, which calls the method of the object that is returned by the method. The following code defines the `LocationReporter` class. + :::code language="csharp" source="~/snippets/csharp/System/IObservableT/Overview/observer.cs" id="Snippet8"::: :::code language="fsharp" source="~/snippets/fsharp/System/IObservableT/Overview/observer.fs" id="Snippet8"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.iobserver.class/vb/observer.vb" id="Snippet8"::: - - The following code then instantiates the provider and the observer. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.iobserver.class/vb/observer.vb" id="Snippet8"::: + + The following code then instantiates the provider and the observer. + :::code language="csharp" source="~/snippets/csharp/System/IObservableT/Overview/program.cs" id="Snippet9"::: :::code language="fsharp" source="~/snippets/fsharp/System/IObservableT/Overview/program.fs" id="Snippet9"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.iobserver.class/vb/module1.vb" id="Snippet9"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.iobserver.class/vb/module1.vb" id="Snippet9"::: + ]]> @@ -162,26 +162,26 @@ Notifies the provider that an observer is to receive notifications. A reference to an interface that allows observers to stop receiving notifications before the provider has finished sending them. - method must be called to register an observer for push-based notifications. A typical implementation of the method does the following: - -- It stores a reference to the observer in a collection object, such as a object. - -- It returns a reference to an interface. This enables observers to unsubscribe (that is, to stop receiving notifications) before the provider has finished sending them and called the subscriber's method. - - At any given time, a particular instance of an implementation is responsible for handling all subscriptions and notifying all subscribers. Unless the documentation for a particular implementation indicates otherwise, observers should make no assumptions about the implementation, such as the order of notifications that multiple observers will receive. - - - -## Examples - The following example illustrates the method for an application that reports latitude and longitude information. It defines an collection object that stores references to all observers. It also returns a private class named `Unsubscriber` that implements the interface and enables subscribers to stop receiving event notifications. See the Example section of the topic for the complete example. - + method must be called to register an observer for push-based notifications. A typical implementation of the method does the following: + +- It stores a reference to the observer in a collection object, such as a object. + +- It returns a reference to an interface. This enables observers to unsubscribe (that is, to stop receiving notifications) before the provider has finished sending them and called the subscriber's method. + + At any given time, a particular instance of an implementation is responsible for handling all subscriptions and notifying all subscribers. Unless the documentation for a particular implementation indicates otherwise, observers should make no assumptions about the implementation, such as the order of notifications that multiple observers will receive. + + + +## Examples + The following example illustrates the method for an application that reports latitude and longitude information. It defines an collection object that stores references to all observers. It also returns a private class named `Unsubscriber` that implements the interface and enables subscribers to stop receiving event notifications. See the Example section of the topic for the complete example. + :::code language="csharp" source="~/snippets/csharp/System/IObservableT/Overview/provider.cs" id="Snippet13"::: :::code language="fsharp" source="~/snippets/fsharp/System/IObservableT/Overview/provider.fs" id="Snippet13"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.iobserver.class/vb/provider.vb" id="Snippet13"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.iobserver.class/vb/provider.vb" id="Snippet13"::: + ]]> diff --git a/xml/System/IObserver`1.xml b/xml/System/IObserver`1.xml index 2f02419ce03..110a94a8d0d 100644 --- a/xml/System/IObserver`1.xml +++ b/xml/System/IObserver`1.xml @@ -61,56 +61,56 @@ The object that provides notification information. Provides a mechanism for receiving push-based notifications. - and interfaces provide a generalized mechanism for push-based notification, also known as the observer design pattern. The interface represents the class that sends notifications (the provider); the interface represents the class that receives them (the observer). `T` represents the class that provides the notification information. - - An implementation arranges to receive notifications from a provider (an implementation) by passing an instance of itself to the provider's method. This method returns an object that can be used to unsubscribe the observer before the provider finishes sending notifications. - - The interface defines the following three methods that the observer must implement: - -- The method, which is typically called by the provider to supply the observer with new data or state information. - -- The method, which is typically called by the provider to indicate that data is unavailable, inaccessible, or corrupted, or that the provider has experienced some other error condition. - -- The method, which is typically called by the provider to indicate that it has finished sending notifications to observers. - - - -## Examples - The following example illustrates the observer design pattern. It defines a `Location` class that contains latitude and longitude information. - + and interfaces provide a generalized mechanism for push-based notification, also known as the observer design pattern. The interface represents the class that sends notifications (the provider); the interface represents the class that receives them (the observer). `T` represents the class that provides the notification information. + + An implementation arranges to receive notifications from a provider (an implementation) by passing an instance of itself to the provider's method. This method returns an object that can be used to unsubscribe the observer before the provider finishes sending notifications. + + The interface defines the following three methods that the observer must implement: + +- The method, which is typically called by the provider to supply the observer with new data or state information. + +- The method, which is typically called by the provider to indicate that data is unavailable, inaccessible, or corrupted, or that the provider has experienced some other error condition. + +- The method, which is typically called by the provider to indicate that it has finished sending notifications to observers. + + + +## Examples + The following example illustrates the observer design pattern. It defines a `Location` class that contains latitude and longitude information. + :::code language="csharp" source="~/snippets/csharp/System/IObservableT/Overview/provider.cs" id="Snippet5"::: :::code language="fsharp" source="~/snippets/fsharp/System/IObservableT/Overview/provider.fs" id="Snippet5"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.iobserver.class/vb/provider.vb" id="Snippet5"::: - - The `LocationReporter` class provides the implementation. It displays information about the current location to the console. Its constructor includes a `name` parameter, which allows the `LocationReporter` instance to identify itself in its string output. It also includes a `Subscribe` method, which wraps a call to the provider's method. This enables the method to assign the returned reference to a private variable. The `LocationReporter` class also includes an `Unsubscribe` method, which calls the method of the object returned by the method. The following code defines the `LocationReporter` class. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.iobserver.class/vb/provider.vb" id="Snippet5"::: + + The `LocationReporter` class provides the implementation. It displays information about the current location to the console. Its constructor includes a `name` parameter, which allows the `LocationReporter` instance to identify itself in its string output. It also includes a `Subscribe` method, which wraps a call to the provider's method. This enables the method to assign the returned reference to a private variable. The `LocationReporter` class also includes an `Unsubscribe` method, which calls the method of the object returned by the method. The following code defines the `LocationReporter` class. + :::code language="csharp" source="~/snippets/csharp/System/IObservableT/Overview/observer.cs" id="Snippet8"::: :::code language="fsharp" source="~/snippets/fsharp/System/IObservableT/Overview/observer.fs" id="Snippet8"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.iobserver.class/vb/observer.vb" id="Snippet8"::: - - The `LocationTracker` class provides the implementation. Its `TrackLocation` method is passed a nullable `Location` object that contains the latitude and longitude data. If the `Location` value is not `null`, the `TrackLocation` method calls the method of each observer. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.iobserver.class/vb/observer.vb" id="Snippet8"::: + + The `LocationTracker` class provides the implementation. Its `TrackLocation` method is passed a nullable `Location` object that contains the latitude and longitude data. If the `Location` value is not `null`, the `TrackLocation` method calls the method of each observer. + :::code language="csharp" source="~/snippets/csharp/System/IObservableT/Overview/provider.cs" id="Snippet6"::: :::code language="fsharp" source="~/snippets/fsharp/System/IObservableT/Overview/provider.fs" id="Snippet6"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.iobserver.class/vb/provider.vb" id="Snippet6"::: - - If the `Location` value is `null`, the `TrackLocation` method instantiates a `LocationNotFoundException` object, which is shown in the following example. It then calls each observer's method and passes it the `LocationNotFoundException` object. Note that `LocationNotFoundException` derives from but does not add any new members. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.iobserver.class/vb/provider.vb" id="Snippet6"::: + + If the `Location` value is `null`, the `TrackLocation` method instantiates a `LocationNotFoundException` object, which is shown in the following example. It then calls each observer's method and passes it the `LocationNotFoundException` object. Note that `LocationNotFoundException` derives from but does not add any new members. + :::code language="csharp" source="~/snippets/csharp/System/IObservableT/Overview/provider.cs" id="Snippet7"::: :::code language="fsharp" source="~/snippets/fsharp/System/IObservableT/Overview/provider.fs" id="Snippet7"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.iobserver.class/vb/provider.vb" id="Snippet7"::: - - Observers register to receive notifications from a `TrackLocation` object by calling its method, which assigns a reference to the observer object to a private generic object. The method returns an `Unsubscriber` object, which is an implementation that enables observers to stop receiving notifications. The `LocationTracker` class also includes an `EndTransmission` method. When no further location data is available, the method calls each observer's method and then clears the internal list of observers. - - The following code then instantiates the provider and the observer. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.iobserver.class/vb/provider.vb" id="Snippet7"::: + + Observers register to receive notifications from a `TrackLocation` object by calling its method, which assigns a reference to the observer object to a private generic object. The method returns an `Unsubscriber` object, which is an implementation that enables observers to stop receiving notifications. The `LocationTracker` class also includes an `EndTransmission` method. When no further location data is available, the method calls each observer's method and then clears the internal list of observers. + + The following code then instantiates the provider and the observer. + :::code language="csharp" source="~/snippets/csharp/System/IObservableT/Overview/program.cs" id="Snippet9"::: :::code language="fsharp" source="~/snippets/fsharp/System/IObservableT/Overview/program.fs" id="Snippet9"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.iobserver.class/vb/module1.vb" id="Snippet9"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.iobserver.class/vb/module1.vb" id="Snippet9"::: + ]]> @@ -155,20 +155,20 @@ Notifies the observer that the provider has finished sending push-based notifications. - implementation is called, the method can optionally call the method of the object that was returned to the observer when it called the method. - - - -## Examples - The following example provides an implementation of the method in a latitude/longitude tracking application. The method simply reports that no further data is available and calls the provider's implementation. See the Example section of the topic for the complete example. - + implementation is called, the method can optionally call the method of the object that was returned to the observer when it called the method. + + + +## Examples + The following example provides an implementation of the method in a latitude/longitude tracking application. The method simply reports that no further data is available and calls the provider's implementation. See the Example section of the topic for the complete example. + :::code language="csharp" source="~/snippets/csharp/System/IObservableT/Overview/observer.cs" id="Snippet11"::: :::code language="fsharp" source="~/snippets/fsharp/System/IObservableT/Overview/observer.fs" id="Snippet11"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.iobserver.class/vb/observer.vb" id="Snippet11"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.iobserver.class/vb/observer.vb" id="Snippet11"::: + ]]> @@ -215,20 +215,20 @@ An object that provides additional information about the error. Notifies the observer that the provider has experienced an error condition. - , it does not necessarily represent an exception that is thrown by the provider. It can also represent a routine or expected error condition, such as data that is missing or unavailable. The method should be seen as informational, and the provider should not expect the observer to provide error handling. - - - -## Examples - The following example provides an implementation of the method in a latitude/longitude tracking application. The method simply reports that data is currently unavailable; it does not make use of the object passed to it as a parameter. See the Example section of the topic for the complete example. - + , it does not necessarily represent an exception that is thrown by the provider. It can also represent a routine or expected error condition, such as data that is missing or unavailable. The method should be seen as informational, and the provider should not expect the observer to provide error handling. + + + +## Examples + The following example provides an implementation of the method in a latitude/longitude tracking application. The method simply reports that data is currently unavailable; it does not make use of the object passed to it as a parameter. See the Example section of the topic for the complete example. + :::code language="csharp" source="~/snippets/csharp/System/IObservableT/Overview/observer.cs" id="Snippet10"::: :::code language="fsharp" source="~/snippets/fsharp/System/IObservableT/Overview/observer.fs" id="Snippet10"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.iobserver.class/vb/observer.vb" id="Snippet10"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.iobserver.class/vb/observer.vb" id="Snippet10"::: + ]]> Observer Design Pattern Best Practices @@ -275,20 +275,20 @@ The current notification information. Provides the observer with new data. - method, the provider calls the observer's method to provide notifications. - - - -## Examples - The following example provides an implementation of the method in a latitude/longitude tracking application. See the Example section of the topic for the complete example. - + method, the provider calls the observer's method to provide notifications. + + + +## Examples + The following example provides an implementation of the method in a latitude/longitude tracking application. See the Example section of the topic for the complete example. + :::code language="csharp" source="~/snippets/csharp/System/IObservableT/Overview/observer.cs" id="Snippet12"::: :::code language="fsharp" source="~/snippets/fsharp/System/IObservableT/Overview/observer.fs" id="Snippet12"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.iobserver.class/vb/observer.vb" id="Snippet12"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.iobserver.class/vb/observer.vb" id="Snippet12"::: + ]]> diff --git a/xml/System/IServiceProvider.xml b/xml/System/IServiceProvider.xml index b9e04ed7fce..267859852b1 100644 --- a/xml/System/IServiceProvider.xml +++ b/xml/System/IServiceProvider.xml @@ -49,15 +49,15 @@ Defines a mechanism for retrieving a service object; that is, an object that provides custom support to other objects. - method of this interface obtains the object that provides the service. - - The interface is implemented by a number of types, including , , , and . - + method of this interface obtains the object that provides the service. + + The interface is implemented by a number of types, including , , , and . + ]]> @@ -103,11 +103,11 @@ An object that specifies the type of service object to get. Gets the service object of the specified type. - A service object of type . - - -or- - - if there is no service object of type . + A service object of type . + +-or- + + if there is no service object of type . To be added. diff --git a/xml/System/IndexOutOfRangeException.xml b/xml/System/IndexOutOfRangeException.xml index e279ce78f6b..2173c89183b 100644 --- a/xml/System/IndexOutOfRangeException.xml +++ b/xml/System/IndexOutOfRangeException.xml @@ -70,118 +70,118 @@ The exception that is thrown when an attempt is made to access an element of an array or collection with an index that is outside its bounds. - exception is thrown when an invalid index is used to access a member of an array or a collection, or to read or write from a particular location in a buffer. This exception inherits from the class but adds no unique members. - - Typically, an exception is thrown as a result of developer error. Instead of handling the exception, you should diagnose the cause of the error and correct your code. The most common causes of the error are: - -- Forgetting that the upper bound of a collection or a zero-based array is one less than its number of members or elements, as the following example illustrates. - + exception is thrown when an invalid index is used to access a member of an array or a collection, or to read or write from a particular location in a buffer. This exception inherits from the class but adds no unique members. + + Typically, an exception is thrown as a result of developer error. Instead of handling the exception, you should diagnose the cause of the error and correct your code. The most common causes of the error are: + +- Forgetting that the upper bound of a collection or a zero-based array is one less than its number of members or elements, as the following example illustrates. + :::code language="csharp" source="~/snippets/csharp/System/IndexOutOfRangeException/Overview/length1.cs" id="Snippet3"::: :::code language="fsharp" source="~/snippets/fsharp/System/IndexOutOfRangeException/Overview/length1.fs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.indexoutofrangeexception/vb/length1.vb" id="Snippet3"::: - - To correct the error, you can use code like the following. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.indexoutofrangeexception/vb/length1.vb" id="Snippet3"::: + + To correct the error, you can use code like the following. + :::code language="csharp" source="~/snippets/csharp/System/IndexOutOfRangeException/Overview/length2.cs" interactive="try-dotnet" id="Snippet4"::: :::code language="fsharp" source="~/snippets/fsharp/System/IndexOutOfRangeException/Overview/length2.fs" id="Snippet4"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.indexoutofrangeexception/vb/length2.vb" id="Snippet4"::: - - Alternately, instead of iterating all the elements in the array by their index, you can use the `foreach` statement (in C#), the `for...in` statement (in F#), or the `For Each` statement (in Visual Basic). - -- Attempting to assign an array element to another array that has not been adequately dimensioned and that has fewer elements than the original array. The following example attempts to assign the last element in the `value1` array to the same element in the `value2` array. However, the `value2` array has been incorrectly dimensioned to have six instead of seven elements. As a result, the assignment throws an exception. - + + Alternately, instead of iterating all the elements in the array by their index, you can use the `foreach` statement (in C#), the `for...in` statement (in F#), or the `For Each` statement (in Visual Basic). + +- Attempting to assign an array element to another array that has not been adequately dimensioned and that has fewer elements than the original array. The following example attempts to assign the last element in the `value1` array to the same element in the `value2` array. However, the `value2` array has been incorrectly dimensioned to have six instead of seven elements. As a result, the assignment throws an exception. + :::code language="csharp" source="~/snippets/csharp/System/IndexOutOfRangeException/Overview/Uninit1.cs" id="Snippet10"::: :::code language="fsharp" source="~/snippets/fsharp/System/IndexOutOfRangeException/Overview/Uninit1.fs" id="Snippet10"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.indexoutofrangeexception/vb/Uninit1.vb" id="Snippet10"::: - -- Using a value returned by a search method to iterate a portion of an array or collection starting at a particular index position. If you forget to check whether the search operation found a match, the runtime throws an exception, as shown in this example. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.indexoutofrangeexception/vb/Uninit1.vb" id="Snippet10"::: + +- Using a value returned by a search method to iterate a portion of an array or collection starting at a particular index position. If you forget to check whether the search operation found a match, the runtime throws an exception, as shown in this example. + :::code language="csharp" source="~/snippets/csharp/System/IndexOutOfRangeException/Overview/negative1.cs" id="Snippet5"::: :::code language="fsharp" source="~/snippets/fsharp/System/IndexOutOfRangeException/Overview/negative1.fs" id="Snippet5"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.indexoutofrangeexception/vb/negative1.vb" id="Snippet5"::: - - In this case, the method returns -1, which is an invalid index value, when it fails to find a match. To correct this error, check the search method's return value before iterating the array, as shown in this example. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.indexoutofrangeexception/vb/negative1.vb" id="Snippet5"::: + + In this case, the method returns -1, which is an invalid index value, when it fails to find a match. To correct this error, check the search method's return value before iterating the array, as shown in this example. + :::code language="csharp" source="~/snippets/csharp/System/IndexOutOfRangeException/Overview/negative2.cs" id="Snippet6"::: :::code language="fsharp" source="~/snippets/fsharp/System/IndexOutOfRangeException/Overview/negative2.fs" id="Snippet6"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.indexoutofrangeexception/vb/negative2.vb" id="Snippet6"::: - -- Trying to use or enumerate a result set, collection, or array returned by a query without testing whether the returned object has any valid data. - -- Using a computed value to define the starting index, the ending index, or the number of items to be iterated. If the result of the computation is unexpected, it might result in an exception. You should check your program's logic in calculating the index value and validate the value before iterating the array or collection. The following conditions must all be true; otherwise, an exception is thrown: - - - The starting index must be greater than or equal to for the dimension of the array that you want to iterate, or greater than or equal to 0 for a collection. - - - The ending index cannot exceed for the dimension of the array that you want to iterate, or cannot be greater than or equal to the `Count` property of a collection. - - - The following equation must be true for the dimension of the array that you want to iterate: - - ``` - start_index >= lower_bound And start_index + items_to_iterate - 1 <= upper_bound - ``` - - For a collection, the following equation must be true: - - ``` - start_index >= 0 And start_index + items_to_iterate <= Count - ``` - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.indexoutofrangeexception/vb/negative2.vb" id="Snippet6"::: + +- Trying to use or enumerate a result set, collection, or array returned by a query without testing whether the returned object has any valid data. + +- Using a computed value to define the starting index, the ending index, or the number of items to be iterated. If the result of the computation is unexpected, it might result in an exception. You should check your program's logic in calculating the index value and validate the value before iterating the array or collection. The following conditions must all be true; otherwise, an exception is thrown: + + - The starting index must be greater than or equal to for the dimension of the array that you want to iterate, or greater than or equal to 0 for a collection. + + - The ending index cannot exceed for the dimension of the array that you want to iterate, or cannot be greater than or equal to the `Count` property of a collection. + + - The following equation must be true for the dimension of the array that you want to iterate: + + ``` + start_index >= lower_bound And start_index + items_to_iterate - 1 <= upper_bound + ``` + + For a collection, the following equation must be true: + + ``` + start_index >= 0 And start_index + items_to_iterate <= Count + ``` + > [!TIP] - > The starting index of an array or collection can never be a negative number. - -- Assuming that an array must be zero-based. Arrays that are not zero-based can be created by the method and can be returned by COM interop, although they aren't CLS-compliant. The following example illustrates the that is thrown when you try to iterate a non-zero-based array created by the method. - + > The starting index of an array or collection can never be a negative number. + +- Assuming that an array must be zero-based. Arrays that are not zero-based can be created by the method and can be returned by COM interop, although they aren't CLS-compliant. The following example illustrates the that is thrown when you try to iterate a non-zero-based array created by the method. + :::code language="csharp" source="~/snippets/csharp/System/IndexOutOfRangeException/Overview/nonzero1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/IndexOutOfRangeException/Overview/nonzero1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.indexoutofrangeexception/vb/nonzero1.vb" id="Snippet1"::: - - To correct the error, as the following example does, you can call the method instead of making assumptions about the starting index of an array. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.indexoutofrangeexception/vb/nonzero1.vb" id="Snippet1"::: + + To correct the error, as the following example does, you can call the method instead of making assumptions about the starting index of an array. + :::code language="csharp" source="~/snippets/csharp/System/IndexOutOfRangeException/Overview/nonzero2.cs" interactive="try-dotnet" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/IndexOutOfRangeException/Overview/nonzero2.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.indexoutofrangeexception/vb/nonzero2.vb" id="Snippet2"::: - - Note that when you call the method to get the starting index of an array, you should also call the method to get its ending index. - -- Confusing an index and the value at that index in a numeric array or collection. This issue usually occurs when using the `foreach` statement (in C#), the `for...in` statement (in F#), or the `For Each` statement (in Visual Basic). The following example illustrates the problem. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.indexoutofrangeexception/vb/nonzero2.vb" id="Snippet2"::: + + Note that when you call the method to get the starting index of an array, you should also call the method to get its ending index. + +- Confusing an index and the value at that index in a numeric array or collection. This issue usually occurs when using the `foreach` statement (in C#), the `for...in` statement (in F#), or the `For Each` statement (in Visual Basic). The following example illustrates the problem. + :::code language="csharp" source="~/snippets/csharp/System/IndexOutOfRangeException/Overview/foreach1.cs" id="Snippet7"::: :::code language="fsharp" source="~/snippets/fsharp/System/IndexOutOfRangeException/Overview/foreach1.fs" id="Snippet7"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.indexoutofrangeexception/vb/foreach1.vb" id="Snippet7"::: - - The iteration construct returns each value in an array or collection, not its index. To eliminate the exception, use this code. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.indexoutofrangeexception/vb/foreach1.vb" id="Snippet7"::: + + The iteration construct returns each value in an array or collection, not its index. To eliminate the exception, use this code. + :::code language="csharp" source="~/snippets/csharp/System/IndexOutOfRangeException/Overview/foreach2.cs" interactive="try-dotnet" id="Snippet8"::: :::code language="fsharp" source="~/snippets/fsharp/System/IndexOutOfRangeException/Overview/foreach2.fs" id="Snippet8"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.indexoutofrangeexception/vb/foreach2.vb" id="Snippet8"::: - -- Providing an invalid column name to the property. - -- Violating thread safety. Operations such as reading from the same object, writing to the same object from multiple threads, or enumerating the objects in a from different threads can throw an if the object isn't accessed in a thread-safe way. This exception is typically intermittent because it relies on a race condition. - - Using hard-coded index values to manipulate an array is likely to throw an exception if the index value is incorrect or invalid, or if the size of the array being manipulation is unexpected. To prevent an operation from throwing an exception, you can do the following: - -- Iterate the elements of the array using the [foreach](/dotnet/csharp/language-reference/keywords/foreach-in) statement (in C#), the [for...in](/dotnet/fsharp/language-reference/loops-for-in-expression) statement (in F#), or the [For Each...Next](/dotnet/visual-basic/language-reference/statements/for-each-next-statement) construct (in Visual Basic) instead of iterating elements by index. - -- Iterate the elements by index starting with the index returned by the method and ending with the index returned by the method. - -- If you are assigning elements in one array to another, ensure that the target array has at least as many elements as the source array by comparing their properties. - - For a list of initial property values for an instance of , see the constructors. - - The following intermediate language (IL) instructions throw : - -- ldelem.\ - -- ldelema - -- stelem.\ - - uses the HRESULT COR_E_INDEXOUTOFRANGE, which has the value 0x80131508. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.indexoutofrangeexception/vb/foreach2.vb" id="Snippet8"::: + +- Providing an invalid column name to the property. + +- Violating thread safety. Operations such as reading from the same object, writing to the same object from multiple threads, or enumerating the objects in a from different threads can throw an if the object isn't accessed in a thread-safe way. This exception is typically intermittent because it relies on a race condition. + + Using hard-coded index values to manipulate an array is likely to throw an exception if the index value is incorrect or invalid, or if the size of the array being manipulation is unexpected. To prevent an operation from throwing an exception, you can do the following: + +- Iterate the elements of the array using the [foreach](/dotnet/csharp/language-reference/keywords/foreach-in) statement (in C#), the [for...in](/dotnet/fsharp/language-reference/loops-for-in-expression) statement (in F#), or the [For Each...Next](/dotnet/visual-basic/language-reference/statements/for-each-next-statement) construct (in Visual Basic) instead of iterating elements by index. + +- Iterate the elements by index starting with the index returned by the method and ending with the index returned by the method. + +- If you are assigning elements in one array to another, ensure that the target array has at least as many elements as the source array by comparing their properties. + + For a list of initial property values for an instance of , see the constructors. + + The following intermediate language (IL) instructions throw : + +- ldelem.\ + +- ldelema + +- stelem.\ + + uses the HRESULT COR_E_INDEXOUTOFRANGE, which has the value 0x80131508. + ]]> @@ -238,18 +238,18 @@ Initializes a new instance of the class. - property of the new instance to a system-supplied message that describes the error, such as "An array index is out of range." This message takes into account the current system culture. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The localized error message string.| - + property of the new instance to a system-supplied message that describes the error, such as "An array index is out of range." This message takes into account the current system culture. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The localized error message string.| + ]]> @@ -296,18 +296,18 @@ The message that describes the error. Initializes a new instance of the class with a specified error message. - property of the new exception using the `message` parameter. The content of `message` is intended to be understood by humans. The caller of this constructor is required to ensure that this string has been localized for the current system culture. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The error message string.| - + property of the new exception using the `message` parameter. The content of `message` is intended to be understood by humans. The caller of this constructor is required to ensure that this string has been localized for the current system culture. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The error message string.| + ]]> @@ -356,18 +356,18 @@ The exception that is the cause of the current exception. If the parameter is not a null reference ( in Visual Basic), the current exception is raised in a block that handles the inner exception. Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception. - property. The `InnerException` property returns the same value that is passed into the constructor, or a null reference (`Nothing` in Visual Basic) if the `InnerException` property does not supply the inner exception value to the constructor. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||The inner exception reference.| -||The error message string.| - + property. The `InnerException` property returns the same value that is passed into the constructor, or a null reference (`Nothing` in Visual Basic) if the `InnerException` property does not supply the inner exception value to the constructor. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||The inner exception reference.| +||The error message string.| + ]]> diff --git a/xml/System/InsufficientMemoryException.xml b/xml/System/InsufficientMemoryException.xml index 0d7bac0ebdd..5ef2ecd2587 100644 --- a/xml/System/InsufficientMemoryException.xml +++ b/xml/System/InsufficientMemoryException.xml @@ -54,18 +54,18 @@ The exception that is thrown when a check for sufficient available memory fails. This class cannot be inherited. - , is thrown before starting an operation, and thus does not imply state corruption. An application can catch this exception, throttle back its memory usage, and avoid actual out of memory conditions and their potential for corrupting program state. - - This exception is thrown by the constructor when you specify a projected memory allocation larger than the amount of currently available memory. Your program can catch the exception and either delay the task that needs the memory or execute it in smaller steps that require less memory. - - See the class for a code example. - + , is thrown before starting an operation, and thus does not imply state corruption. An application can catch this exception, throttle back its memory usage, and avoid actual out of memory conditions and their potential for corrupting program state. + + This exception is thrown by the constructor when you specify a projected memory allocation larger than the amount of currently available memory. Your program can catch the exception and either delay the task that needs the memory or execute it in smaller steps that require less memory. + + See the class for a code example. + > [!NOTE] -> This exception is not included in the [.NET for Windows Store apps](https://go.microsoft.com/fwlink/?LinkID=247912) or the [Portable Class Library](/dotnet/standard/cross-platform/cross-platform-development-with-the-portable-class-library), but it is thrown by some members that are. To catch the exception in that case, write a `catch` statement for instead. - +> This exception is not included in the [.NET for Windows Store apps](https://go.microsoft.com/fwlink/?LinkID=247912) or the [Portable Class Library](/dotnet/standard/cross-platform/cross-platform-development-with-the-portable-class-library), but it is thrown by some members that are. To catch the exception in that case, write a `catch` statement for instead. + ]]> @@ -113,18 +113,18 @@ Initializes a new instance of the class with a system-supplied message that describes the error. - property of the new instance to a system-supplied message that describes the error, such as "Insufficient available memory to meet the expected demands of an operation at this time. Please try again later." This message takes into account the current system culture. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||`null`.| -||The localized error message string.| - + property of the new instance to a system-supplied message that describes the error, such as "Insufficient available memory to meet the expected demands of an operation at this time. Please try again later." This message takes into account the current system culture. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||`null`.| +||The localized error message string.| + ]]> Handling and Throwing Exceptions @@ -167,16 +167,16 @@ The message that describes the exception. The caller of this constructor is required to ensure that this string has been localized for the current system culture. Initializes a new instance of the class with a specified message that describes the error. - . - -|Property|Value| -|--------------|-----------| -||`null`.| -||The error message string specified in `message`.| - + . + +|Property|Value| +|--------------|-----------| +||`null`.| +||The error message string specified in `message`.| + ]]> Handling and Throwing Exceptions @@ -221,18 +221,18 @@ The exception that is the cause of the current exception. If the parameter is not , the current exception is raised in a block that handles the inner exception. Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception. - property. The property returns the same value that is passed into the constructor, or `null` if the property does not supply the inner exception value to the constructor. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||`null`.| -||The error message string specified in `message`.| - + property. The property returns the same value that is passed into the constructor, or `null` if the property does not supply the inner exception value to the constructor. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||`null`.| +||The error message string specified in `message`.| + ]]> Handling and Throwing Exceptions diff --git a/xml/System/Int16.xml b/xml/System/Int16.xml index addb0f137bf..011b40e7738 100644 --- a/xml/System/Int16.xml +++ b/xml/System/Int16.xml @@ -405,25 +405,34 @@ An integer to compare. Compares this instance to a specified 16-bit signed integer and returns an integer that indicates whether the value of this instance is less than, equal to, or greater than the value of the specified 16-bit signed integer. - A signed number indicating the relative values of this instance and . - - Return Value - - Description - - Less than zero - - This instance is less than . - - Zero - - This instance is equal to . - - Greater than zero - - This instance is greater than . - - + A signed number indicating the relative values of this instance and . + + Return Value + + + Description + + + + + Less than zero + + + This instance is less than . + + + Zero + + + This instance is equal to . + + + Greater than zero + + + This instance is greater than . + + An object to compare, or . Compares this instance to a specified object and returns an integer that indicates whether the value of this instance is less than, equal to, or greater than the value of the object. - A signed number indicating the relative values of this instance and . - - Return Value - - Description - - Less than zero - - This instance is less than . - - Zero - - This instance is equal to . - - Greater than zero - - This instance is greater than , or is . - - + A signed number indicating the relative values of this instance and . + + Return Value + + + Description + + + + + Less than zero + + + This instance is less than . + + + Zero + + + This instance is equal to . + + + Greater than zero + + + This instance is greater than , or is . + + - 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 language="csharp" source="~/snippets/csharp/System/Int16/Equals/equalsoverl.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.int16.equals/fs/equalsoverl.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.int16.equals/vb/equalsoverl.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 language="csharp" source="~/snippets/csharp/System/Int16/Equals/equalsoverl.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.int16.equals/fs/equalsoverl.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.int16.equals/vb/equalsoverl.vb" id="Snippet1"::: @@ -936,11 +950,7 @@ ]]> - 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 language="csharp" source="~/snippets/csharp/System/Int16/Equals/equalsoverl.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.int16.equals/fs/equalsoverl.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.int16.equals/vb/equalsoverl.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 language="csharp" source="~/snippets/csharp/System/Int16/Equals/equalsoverl.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.int16.equals/fs/equalsoverl.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.int16.equals/vb/equalsoverl.vb" id="Snippet1"::: @@ -1951,17 +1961,17 @@ For this method matches the IEE is not a value. - -or- +-or- - is not a combination of and values. + is not a combination of and values. is not in a format compliant with . represents a number less than Int16.MinValue or greater than Int16.MaxValue. - -or- +-or- - includes non-zero fractional digits. + includes non-zero fractional digits. @@ -2302,17 +2312,17 @@ For this method matches the IEE is not a value. - -or- +-or- - is not a combination of and values. + is not a combination of and values. is not in a format compliant with . represents a number less than Int16.MinValue or greater than Int16.MaxValue. - -or- +-or- - includes non-zero fractional digits. + includes non-zero fractional digits. Parsing Numeric Strings in .NET @@ -2507,8 +2517,24 @@ It is recommended that a function return `1`, `0`, and `-1`, respectively. An object to compare, or . Compares this instance to a specified object and returns an integer that indicates whether the value of this instance is less than, equal to, or greater than the value of the object. - A signed number indicating the relative values of this instance and . - Return ValueDescriptionLess than zeroThis instance is less than .ZeroThis instance is equal to .Greater than zeroThis instance is greater than , or is . + A signed number indicating the relative values of this instance and . + + Return Value + Description + + + Less than zero + This instance is less than . + + + Zero + This instance is equal to . + + + Greater than zero + This instance is greater than , or is . + + is not a value. - -or- +-or- - is not a combination of and values. + is not a combination of and values. diff --git a/xml/System/Int32.xml b/xml/System/Int32.xml index 6be6a3f1d42..3e09cd5ff5a 100644 --- a/xml/System/Int32.xml +++ b/xml/System/Int32.xml @@ -463,25 +463,34 @@ An integer to compare. Compares this instance to a specified 32-bit signed integer and returns an indication of their relative values. - A signed number indicating the relative values of this instance and . - - Return Value - - Description - - Less than zero - - This instance is less than . - - Zero - - This instance is equal to . - - Greater than zero - - This instance is greater than . - - + A signed number indicating the relative values of this instance and . + + Return Value + + + Description + + + + + Less than zero + + + This instance is less than . + + + Zero + + + This instance is equal to . + + + Greater than zero + + + This instance is greater than . + + An object to compare, or . Compares this instance to a specified object and returns an indication of their relative values. - A signed number indicating the relative values of this instance and . - - Return Value - - Description - - Less than zero - - This instance is less than . - - Zero - - This instance is equal to . - - Greater than zero - - This instance is greater than , or is . - - + A signed number indicating the relative values of this instance and . + + Return Value + + + Description + + + + + Less than zero + + + This instance is less than . + + + Zero + + + This instance is equal to . + + + Greater than zero + + + This instance is greater than , or is . + + - 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 language="csharp" source="~/snippets/csharp/System/Int32/Equals/equalsoverloads2.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.int32.equals/fs/equalsoverloads2.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.int32.equals/vb/equalsoverloads2.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 language="csharp" source="~/snippets/csharp/System/Int32/Equals/equalsoverloads2.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.int32.equals/fs/equalsoverloads2.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.int32.equals/vb/equalsoverloads2.vb" id="Snippet1"::: @@ -1005,13 +1017,7 @@ ]]> - 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 language="csharp" source="~/snippets/csharp/System/Int32/Equals/equalsoverloads2.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.int32.equals/fs/equalsoverloads2.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.int32.equals/vb/equalsoverloads2.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 language="csharp" source="~/snippets/csharp/System/Int32/Equals/equalsoverloads2.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.int32.equals/fs/equalsoverloads2.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.int32.equals/vb/equalsoverloads2.vb" id="Snippet1"::: @@ -2034,17 +2040,17 @@ For this method matches the IEE is not a value. - -or- +-or- - is not a combination of and values. + is not a combination of and values. is not in a format compliant with . represents a number less than Int32.MinValue or greater than Int32.MaxValue. - -or- +-or- - includes non-zero, fractional digits. + includes non-zero, fractional digits. Parsing Numeric Strings in .NET @@ -2391,17 +2397,17 @@ For this method matches the IEE is not a value. - -or- +-or- - is not a combination of and values. + is not a combination of and values. is not in a format compliant with . represents a number less than Int32.MinValue or greater than Int32.MaxValue. - -or- +-or- - includes non-zero, fractional digits. + includes non-zero, fractional digits. Parsing Numeric Strings in .NET @@ -2595,8 +2601,24 @@ It is recommended that a function return `1`, `0`, and `-1`, respectively. An object to compare, or . Compares this instance to a specified object and returns an indication of their relative values. - A signed number indicating the relative values of this instance and . - Return ValueDescriptionLess than zeroThis instance is less than .ZeroThis instance is equal to .Greater than zeroThis instance is greater than , or is . + A signed number indicating the relative values of this instance and . + + Return Value + Description + + + Less than zero + This instance is less than . + + + Zero + This instance is equal to . + + + Greater than zero + This instance is greater than , or is . + + is not a value. - -or- +-or- - is not a combination of and values. + is not a combination of and values. diff --git a/xml/System/Int64.xml b/xml/System/Int64.xml index 7421caf1355..b24e5715d3e 100644 --- a/xml/System/Int64.xml +++ b/xml/System/Int64.xml @@ -457,25 +457,34 @@ An integer to compare. Compares this instance to a specified 64-bit signed integer and returns an indication of their relative values. - A signed number indicating the relative values of this instance and . - - Return Value - - Description - - Less than zero - - This instance is less than . - - Zero - - This instance is equal to . - - Greater than zero - - This instance is greater than . - - + A signed number indicating the relative values of this instance and . + + Return Value + + + Description + + + + + Less than zero + + + This instance is less than . + + + Zero + + + This instance is equal to . + + + Greater than zero + + + This instance is greater than . + + An object to compare, or . Compares this instance to a specified object and returns an indication of their relative values. - A signed number indicating the relative values of this instance and . - - Return Value - - Description - - Less than zero - - This instance is less than . - - Zero - - This instance is equal to . - - Greater than zero - - This instance is greater than , or is . - - + A signed number indicating the relative values of this instance and . + + Return Value + + + Description + + + + + Less than zero + + + This instance is less than . + + + Zero + + + This instance is equal to . + + + Greater than zero + + + This instance is greater than , or is . + + - 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 language="csharp" source="~/snippets/csharp/System/Int64/Equals/equalsoverl.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.int64.equals/fs/equalsoverl.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.int64.equals/vb/equalsoverl.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 language="csharp" source="~/snippets/csharp/System/Int64/Equals/equalsoverl.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.int64.equals/fs/equalsoverl.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.int64.equals/vb/equalsoverl.vb" id="Snippet1"::: @@ -987,11 +1001,7 @@ ]]> - 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 language="csharp" source="~/snippets/csharp/System/Int64/Equals/equalsoverl.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.int64.equals/fs/equalsoverl.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.int64.equals/vb/equalsoverl.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 language="csharp" source="~/snippets/csharp/System/Int64/Equals/equalsoverl.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.int64.equals/fs/equalsoverl.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.int64.equals/vb/equalsoverl.vb" id="Snippet1"::: @@ -1980,17 +1990,17 @@ For this method matches the IEE is not a value. - -or- +-or- - is not a combination of and values. + is not a combination of and values. is not in a format compliant with . represents a number less than Int64.MinValue or greater than Int64.MaxValue. - -or- +-or- - supports fractional digits but includes non-zero fractional digits. + supports fractional digits but includes non-zero fractional digits. Parsing Numeric Strings in .NET @@ -2331,17 +2341,17 @@ For this method matches the IEE is not a value. - -or- +-or- - is not a combination of and values. + is not a combination of and values. is not in a format compliant with . represents a number less than Int64.MinValue or greater than Int64.MaxValue. - -or- +-or- - supports fractional digits, but includes non-zero fractional digits. + supports fractional digits, but includes non-zero fractional digits. Parsing Numeric Strings in .NET @@ -2535,8 +2545,24 @@ It is recommended that a function return `1`, `0`, and `-1`, respectively. An object to compare, or . Compares this instance to a specified object and returns an indication of their relative values. - A signed number indicating the relative values of this instance and . - Return ValueDescriptionLess than zeroThis instance is less than .ZeroThis instance is equal to .Greater than zeroThis instance is greater than , or is . + A signed number indicating the relative values of this instance and . + + Return Value + Description + + + Less than zero + This instance is less than . + + + Zero + This instance is equal to . + + + Greater than zero + This instance is greater than , or is . + + is not a value. - -or- +-or- - is not a combination of and values. + is not a combination of and values. Parsing Numeric Strings in .NET diff --git a/xml/System/IntPtr.xml b/xml/System/IntPtr.xml index 1cd66b990cb..c930609665b 100644 --- a/xml/System/IntPtr.xml +++ b/xml/System/IntPtr.xml @@ -687,16 +687,29 @@ A signed native integer to compare. Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object. - A value that indicates the relative order of the objects being compared. The return value has these meanings: - Value - Meaning - Less than zero - This instance precedes in the sort order. - Zero - This instance occurs in the same position in the sort order as . - Greater than zero - This instance follows in the sort order. - + A value that indicates the relative order of the objects being compared. The return value has these meanings: + + Value + + Meaning + + + + Less than zero + + This instance precedes in the sort order. + + + Zero + + This instance occurs in the same position in the sort order as . + + + Greater than zero + + This instance follows in the sort order. + + To be added. @@ -739,16 +752,29 @@ An object to compare, or . Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object. - A value that indicates the relative order of the objects being compared. The return value has these meanings: - Value - Meaning - Less than zero - This instance precedes in the sort order. - Zero - This instance occurs in the same position in the sort order as . - Greater than zero - This instance follows in the sort order. - + A value that indicates the relative order of the objects being compared. The return value has these meanings: + + Value + + Meaning + + + + Less than zero + + This instance precedes in the sort order. + + + Zero + + This instance occurs in the same position in the sort order as . + + + Greater than zero + + This instance follows in the sort order. + + To be added. @@ -2168,9 +2194,7 @@ For this method matches the IEE The signed integer to convert. - Converts the value of the specified to a pointer to an unspecified type. - - This API is not CLS-compliant. + Converts the value of the specified to a pointer to an unspecified type. This API is not CLS-compliant. The contents of . To be added. @@ -2235,9 +2259,7 @@ For this method matches the IEE A pointer to an unspecified type. - Converts the specified pointer to an unspecified type to an . - - This API is not CLS-compliant. + Converts the specified pointer to an unspecified type to an . This API is not CLS-compliant. A new instance of initialized to . To be added. @@ -5991,8 +6013,10 @@ This member is an explicit interface member implementation. It can be used only The format to use. - -or- - A reference ( in Visual Basic) to use the default format defined for the type of the implementation. + +-or- + +A reference ( in Visual Basic) to use the default format defined for the type of the implementation. An object that supplies culture-specific formatting information. Formats the value of the current instance using the specified format. The value of the current instance in the specified format. diff --git a/xml/System/InvalidOperationException.xml b/xml/System/InvalidOperationException.xml index 1eb800fb281..2e68334c1a5 100644 --- a/xml/System/InvalidOperationException.xml +++ b/xml/System/InvalidOperationException.xml @@ -70,285 +70,285 @@ The exception that is thrown when a method call is invalid for the object's current state. - is used in cases when the failure to invoke a method is caused by reasons other than invalid arguments. Typically, it is thrown when the state of an object cannot support the method call. For example, an exception is thrown by methods such as: - -- if objects of a collection are modified after the enumerator is created. For more information, see [Changing a collection while iterating it](#Iterating). - -- if the resource set is closed before the method call is made. - -- , if the object or objects to be added would result in an incorrectly structured XML document. - -- A method that attempts to manipulate the UI from a thread that is not the main or UI thread. - + is used in cases when the failure to invoke a method is caused by reasons other than invalid arguments. Typically, it is thrown when the state of an object cannot support the method call. For example, an exception is thrown by methods such as: + +- if objects of a collection are modified after the enumerator is created. For more information, see [Changing a collection while iterating it](#Iterating). + +- if the resource set is closed before the method call is made. + +- , if the object or objects to be added would result in an incorrectly structured XML document. + +- A method that attempts to manipulate the UI from a thread that is not the main or UI thread. + > [!IMPORTANT] -> Because the exception can be thrown in a wide variety of circumstances, it is important to read the exception message returned by the property. - - In this section: - - [Some common causes of InvalidOperationException exceptions](#Causes) - [Updating a UI thread from a non-UI thread](#UI) - [Changing a collection while iterating it](#Iterating) - [Sorting an array or collection whose objects cannot be compared](#Sorting) - [Casting a Nullable<T> that is null to its underlying type](#Nullable) - [Calling a System.Linq.Enumerable method on an empty collection](#Empty) - [Calling Enumerable.Single or Enumerable.SingleOrDefault on a sequence without one element](#Single) - [Dynamic cross-application domain field access](#Emit) -[Throwing an InvalidOperationException exception](#Throwing) -[Miscellaneous information](#Misc) - - -## Some common causes of InvalidOperationException exceptions - The following sections show how some common cases in which in exception is thrown in an app. How you handle the issue depends on the specific situation. Most commonly, however, the exception results from developer error, and the exception can be anticipated and avoided. - - -### Updating a UI thread from a non-UI thread - Often, worker threads are used to perform some background work that involves gathering data to be displayed in an application's user interface. However. most GUI (graphical user interface) application frameworks for .NET, such as Windows Forms and Windows Presentation Foundation (WPF), let you access GUI objects only from the thread that creates and manages the UI (the Main or UI thread). An is thrown when you try to access a UI element from a thread other than the UI thread. The text of the exception message is shown in the following table. - -|Application Type|Message| -|----------------------|-------------| -|WPF app|**The calling thread cannot access this object because a different thread owns it.**| -|UWP app|**The application called an interface that was marshaled for a different thread.**| -|Windows Forms app|**Cross-thread operation not valid: Control 'TextBox1' accessed from a thread other than the thread it was created on.**| - - UI frameworks for .NET implement a *dispatcher* pattern that includes a method to check whether a call to a member of a UI element is being executed on the UI thread, and other methods to schedule the call on the UI thread: - -- In WPF apps, call the method to determine if a method is running on a non-UI thread. It returns `true` if the method is running on the UI thread and `false` otherwise. Call one of the overloads of the method to schedule the call on the UI thread. - -- In UWP apps, check the property to determine if a method is running on a non-UI thread. Call the method to execute a delegate that updates the UI thread. - -- In Windows Forms apps, use the property to determine if a method is running on a non-UI thread. Call one of the overloads of the method to execute a delegate that updates the UI thread. - -The following examples illustrate the exception that is thrown when you attempt to update a UI element from a thread other than the thread that created it. Each example requires that you create two controls: - -- A text box control named `textBox1`. In a Windows Forms app, you should set its property to `true`. - -- A button control named `threadExampleBtn`. The example provides a handler, `ThreadsExampleBtn_Click`, for the button's `Click` event. - -In each case, the `threadExampleBtn_Click` event handler calls the `DoSomeWork` method twice. The first call runs synchronously and succeeds. But the second call, because it runs asynchronously on a thread pool thread, attempts to update the UI from a non-UI thread. This results in a exception. - - WPF and UWP apps +> Because the exception can be thrown in a wide variety of circumstances, it is important to read the exception message returned by the property. + + In this section: + + [Some common causes of InvalidOperationException exceptions](#Causes) + [Updating a UI thread from a non-UI thread](#UI) + [Changing a collection while iterating it](#Iterating) + [Sorting an array or collection whose objects cannot be compared](#Sorting) + [Casting a Nullable<T> that is null to its underlying type](#Nullable) + [Calling a System.Linq.Enumerable method on an empty collection](#Empty) + [Calling Enumerable.Single or Enumerable.SingleOrDefault on a sequence without one element](#Single) + [Dynamic cross-application domain field access](#Emit) +[Throwing an InvalidOperationException exception](#Throwing) +[Miscellaneous information](#Misc) + + +## Some common causes of InvalidOperationException exceptions + The following sections show how some common cases in which in exception is thrown in an app. How you handle the issue depends on the specific situation. Most commonly, however, the exception results from developer error, and the exception can be anticipated and avoided. + + +### Updating a UI thread from a non-UI thread + Often, worker threads are used to perform some background work that involves gathering data to be displayed in an application's user interface. However. most GUI (graphical user interface) application frameworks for .NET, such as Windows Forms and Windows Presentation Foundation (WPF), let you access GUI objects only from the thread that creates and manages the UI (the Main or UI thread). An is thrown when you try to access a UI element from a thread other than the UI thread. The text of the exception message is shown in the following table. + +|Application Type|Message| +|----------------------|-------------| +|WPF app|**The calling thread cannot access this object because a different thread owns it.**| +|UWP app|**The application called an interface that was marshaled for a different thread.**| +|Windows Forms app|**Cross-thread operation not valid: Control 'TextBox1' accessed from a thread other than the thread it was created on.**| + + UI frameworks for .NET implement a *dispatcher* pattern that includes a method to check whether a call to a member of a UI element is being executed on the UI thread, and other methods to schedule the call on the UI thread: + +- In WPF apps, call the method to determine if a method is running on a non-UI thread. It returns `true` if the method is running on the UI thread and `false` otherwise. Call one of the overloads of the method to schedule the call on the UI thread. + +- In UWP apps, check the property to determine if a method is running on a non-UI thread. Call the method to execute a delegate that updates the UI thread. + +- In Windows Forms apps, use the property to determine if a method is running on a non-UI thread. Call one of the overloads of the method to execute a delegate that updates the UI thread. + +The following examples illustrate the exception that is thrown when you attempt to update a UI element from a thread other than the thread that created it. Each example requires that you create two controls: + +- A text box control named `textBox1`. In a Windows Forms app, you should set its property to `true`. + +- A button control named `threadExampleBtn`. The example provides a handler, `ThreadsExampleBtn_Click`, for the button's `Click` event. + +In each case, the `threadExampleBtn_Click` event handler calls the `DoSomeWork` method twice. The first call runs synchronously and succeeds. But the second call, because it runs asynchronously on a thread pool thread, attempts to update the UI from a non-UI thread. This results in a exception. + + WPF and UWP apps :::code language="csharp" source="~/snippets/csharp/System/InvalidOperationException/Overview/WPF1/MainWindow.xaml.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Invalidoperationexception.threading.wpf1/vb/MainWindow.xaml.vb" id="Snippet1"::: - - The following version of the `DoSomeWork` method eliminates the exception in a WPF app. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Invalidoperationexception.threading.wpf1/vb/MainWindow.xaml.vb" id="Snippet1"::: + + The following version of the `DoSomeWork` method eliminates the exception in a WPF app. + :::code language="csharp" source="~/snippets/csharp/System/InvalidOperationException/Overview/WPF2/MainWindowDispatcher.xaml.cs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Invalidoperationexception.threading.wpf2/vb/MainWindowDispatcher.xaml.vb" id="Snippet3"::: - - The following version of the `DoSomeWork` method eliminates the exception in a UWP app. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Invalidoperationexception.threading.wpf2/vb/MainWindowDispatcher.xaml.vb" id="Snippet3"::: + + The following version of the `DoSomeWork` method eliminates the exception in a UWP app. + :::code language="csharp" source="~/snippets/csharp/System/InvalidOperationException/Overview/UWP/MainPage.xaml.cs" id="Snippet4"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.invalidoperationexception.threading.uwp/vb/MainPage.xaml.vb" id="Snippet4"::: - - Windows Forms apps + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.invalidoperationexception.threading.uwp/vb/MainPage.xaml.vb" id="Snippet4"::: + + Windows Forms apps :::code language="csharp" source="~/snippets/csharp/System/InvalidOperationException/Overview/WinForms/Form1.cs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Invalidoperationexception.threading.wf/vb/Form1.vb" id="Snippet2"::: - - The following version of the `DoSomeWork` method eliminates the exception in a Windows Forms app. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Invalidoperationexception.threading.wf/vb/Form1.vb" id="Snippet2"::: + + The following version of the `DoSomeWork` method eliminates the exception in a Windows Forms app. + :::code language="csharp" source="~/snippets/csharp/System/InvalidOperationException/Overview/WinForms/Form11.cs" id="Snippet5"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Invalidoperationexception.threading.wf2/vb/Form1.vb" id="Snippet5"::: - - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Invalidoperationexception.threading.wf2/vb/Form1.vb" id="Snippet5"::: + + ### Changing a collection while iterating it -The `foreach` statement in C#, `for...in` in F#, or `For Each` statement in Visual Basic is used to iterate the members of a collection and to read or modify its individual elements. However, it can't be used to add or remove items from the collection. Doing this throws an exception with a message that is similar to, "**Collection was modified; enumeration operation may not execute.**" - - The following example iterates a collection of integers attempts to add the square of each integer to the collection. The example throws an with the first call to the method. - +The `foreach` statement in C#, `for...in` in F#, or `For Each` statement in Visual Basic is used to iterate the members of a collection and to read or modify its individual elements. However, it can't be used to add or remove items from the collection. Doing this throws an exception with a message that is similar to, "**Collection was modified; enumeration operation may not execute.**" + + The following example iterates a collection of integers attempts to add the square of each integer to the collection. The example throws an with the first call to the method. + :::code language="csharp" source="~/snippets/csharp/System/InvalidOperationException/Overview/Iterating1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/InvalidOperationException/Overview/Iterating1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.invalidoperationexception/vb/Iterating1.vb" id="Snippet1"::: - - You can eliminate the exception in one of two ways, depending on your application logic: - -- If elements must be added to the collection while iterating it, you can iterate it by index using the `for` (`for..to` in F#) statement instead of `foreach`, `for...in`, or `For Each`. The following example uses the for statement to add the square of numbers in the collection to the collection. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.invalidoperationexception/vb/Iterating1.vb" id="Snippet1"::: + + You can eliminate the exception in one of two ways, depending on your application logic: + +- If elements must be added to the collection while iterating it, you can iterate it by index using the `for` (`for..to` in F#) statement instead of `foreach`, `for...in`, or `For Each`. The following example uses the for statement to add the square of numbers in the collection to the collection. + :::code language="csharp" source="~/snippets/csharp/System/InvalidOperationException/Overview/Iterating2.cs" interactive="try-dotnet" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/InvalidOperationException/Overview/Iterating2.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.invalidoperationexception/vb/Iterating2.vb" id="Snippet2"::: - - Note that you must establish the number of iterations before iterating the collection either by using a counter inside the loop that will exit the loop appropriately, by iterating backward, from `Count` - 1 to 0, or, as the example does, by assigning the number of elements in the array to a variable and using it to establish the upper bound of the loop. Otherwise, if an element is added to the collection on every iteration, an endless loop results. - -- If it is not necessary to add elements to the collection while iterating it, you can store the elements to be added in a temporary collection that you add when iterating the collection has finished. The following example uses this approach to add the square of numbers in a collection to a temporary collection, and then to combine the collections into a single array object. - + + Note that you must establish the number of iterations before iterating the collection either by using a counter inside the loop that will exit the loop appropriately, by iterating backward, from `Count` - 1 to 0, or, as the example does, by assigning the number of elements in the array to a variable and using it to establish the upper bound of the loop. Otherwise, if an element is added to the collection on every iteration, an endless loop results. + +- If it is not necessary to add elements to the collection while iterating it, you can store the elements to be added in a temporary collection that you add when iterating the collection has finished. The following example uses this approach to add the square of numbers in a collection to a temporary collection, and then to combine the collections into a single array object. + :::code language="csharp" source="~/snippets/csharp/System/InvalidOperationException/Overview/Iterating3.cs" interactive="try-dotnet" id="Snippet3"::: :::code language="fsharp" source="~/snippets/fsharp/System/InvalidOperationException/Overview/Iterating3.fs" id="Snippet3"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.invalidoperationexception/vb/Iterating3.vb" id="Snippet3"::: - - + + ### Sorting an array or collection whose objects cannot be compared -General-purpose sorting methods, such as the method or the method, usually require that at least one of the objects to be sorted implement the or the interface. If not, the collection or array cannot be sorted, and the method throws an exception. The following example defines a `Person` class, stores two `Person` objects in a generic object, and attempts to sort them. As the output from the example shows, the call to the method throws an . - +General-purpose sorting methods, such as the method or the method, usually require that at least one of the objects to be sorted implement the or the interface. If not, the collection or array cannot be sorted, and the method throws an exception. The following example defines a `Person` class, stores two `Person` objects in a generic object, and attempts to sort them. As the output from the example shows, the call to the method throws an . + :::code language="csharp" source="~/snippets/csharp/System/InvalidOperationException/Overview/List_Sort1.cs" id="Snippet12"::: :::code language="fsharp" source="~/snippets/fsharp/System/InvalidOperationException/Overview/List_Sort1.fs" id="Snippet12"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.invalidoperationexception/vb/List_Sort1.vb" id="Snippet12"::: - - You can eliminate the exception in any of three ways: - -- If you can own the type that you are trying to sort (that is, if you control its source code), you can modify it to implement the or the interface. This requires that you implement either the or the method. Adding an interface implementation to an existing type is not a breaking change. - - The following example uses this approach to provide an implementation for the `Person` class. You can still call the collection or array's general sorting method and, as the output from the example shows, the collection sorts successfully. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.invalidoperationexception/vb/List_Sort1.vb" id="Snippet12"::: + + You can eliminate the exception in any of three ways: + +- If you can own the type that you are trying to sort (that is, if you control its source code), you can modify it to implement the or the interface. This requires that you implement either the or the method. Adding an interface implementation to an existing type is not a breaking change. + + The following example uses this approach to provide an implementation for the `Person` class. You can still call the collection or array's general sorting method and, as the output from the example shows, the collection sorts successfully. + :::code language="csharp" source="~/snippets/csharp/System/InvalidOperationException/Overview/List_Sort2.cs" interactive="try-dotnet" id="Snippet13"::: :::code language="fsharp" source="~/snippets/fsharp/System/InvalidOperationException/Overview/List_Sort2.fs" id="Snippet13"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.invalidoperationexception/vb/List_Sort2.vb" id="Snippet13"::: - -- If you cannot modify the source code for the type you are trying to sort, you can define a special-purpose sorting class that implements the interface. You can call an overload of the `Sort` method that includes an parameter. This approach is especially useful if you want to develop a specialized sorting class that can sort objects based on multiple criteria. - - The following example uses the approach by developing a custom `PersonComparer` class that is used to sort `Person` collections. It then passes an instance of this class to the method. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.invalidoperationexception/vb/List_Sort2.vb" id="Snippet13"::: + +- If you cannot modify the source code for the type you are trying to sort, you can define a special-purpose sorting class that implements the interface. You can call an overload of the `Sort` method that includes an parameter. This approach is especially useful if you want to develop a specialized sorting class that can sort objects based on multiple criteria. + + The following example uses the approach by developing a custom `PersonComparer` class that is used to sort `Person` collections. It then passes an instance of this class to the method. + :::code language="csharp" source="~/snippets/csharp/System/InvalidOperationException/Overview/List_Sort3.cs" interactive="try-dotnet" id="Snippet14"::: :::code language="fsharp" source="~/snippets/fsharp/System/InvalidOperationException/Overview/List_Sort3.fs" id="Snippet14"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.invalidoperationexception/vb/List_Sort3.vb" id="Snippet14"::: - -- If you cannot modify the source code for the type you are trying to sort, you can create a delegate to perform the sorting. The delegate signature is - - ```vb - Function Comparison(Of T)(x As T, y As T) As Integer - ``` - - ```csharp - int Comparison(T x, T y) - ``` - - The following example uses the approach by defining a `PersonComparison` method that matches the delegate signature. It then passes this delegate to the method. - + +- If you cannot modify the source code for the type you are trying to sort, you can create a delegate to perform the sorting. The delegate signature is + + ```vb + Function Comparison(Of T)(x As T, y As T) As Integer + ``` + + ```csharp + int Comparison(T x, T y) + ``` + + The following example uses the approach by defining a `PersonComparison` method that matches the delegate signature. It then passes this delegate to the method. + :::code language="csharp" source="~/snippets/csharp/System/InvalidOperationException/Overview/List_Sort4.cs" interactive="try-dotnet" id="Snippet15"::: :::code language="fsharp" source="~/snippets/fsharp/System/InvalidOperationException/Overview/List_Sort4.fs" id="Snippet15"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.invalidoperationexception/vb/List_Sort4.vb" id="Snippet15"::: - - + + ### Casting a Nullable\ that is null to its underlying type -Attempting to cast a value that is `null` to its underlying type throws an exception and displays the error message, "**Nullable object must have a value.** - - The following example throws an exception when it attempts to iterate an array that includes a `Nullable(Of Integer)` value. - +Attempting to cast a value that is `null` to its underlying type throws an exception and displays the error message, "**Nullable object must have a value.** + + The following example throws an exception when it attempts to iterate an array that includes a `Nullable(Of Integer)` value. + :::code language="csharp" source="~/snippets/csharp/System/InvalidOperationException/Overview/Nullable1.cs" id="Snippet4"::: :::code language="fsharp" source="~/snippets/fsharp/System/InvalidOperationException/Overview/Nullable1.fs" id="Snippet4"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.invalidoperationexception/vb/Nullable1.vb" id="Snippet4"::: - - To prevent the exception: - -- Use the property to select only those elements that are not `null`. - -- Call one of the overloads to provide a default value for a `null` value. - - The following example does both to avoid the exception. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.invalidoperationexception/vb/Nullable1.vb" id="Snippet4"::: + + To prevent the exception: + +- Use the property to select only those elements that are not `null`. + +- Call one of the overloads to provide a default value for a `null` value. + + The following example does both to avoid the exception. + :::code language="csharp" source="~/snippets/csharp/System/InvalidOperationException/Overview/Nullable2.cs" interactive="try-dotnet" id="Snippet5"::: :::code language="fsharp" source="~/snippets/fsharp/System/InvalidOperationException/Overview/Nullable2.fs" id="Snippet5"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.invalidoperationexception/vb/Nullable2.vb" id="Snippet5"::: - - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.invalidoperationexception/vb/Nullable2.vb" id="Snippet5"::: + + ### Calling a System.Linq.Enumerable method on an empty collection -The , , , , , , , and methods perform operations on a sequence and return a single result. Some overloads of these methods throw an exception when the sequence is empty, while other overloads return `null`. The method also throws an exception when the sequence contains more than one element. - +The , , , , , , , and methods perform operations on a sequence and return a single result. Some overloads of these methods throw an exception when the sequence is empty, while other overloads return `null`. The method also throws an exception when the sequence contains more than one element. + > [!NOTE] -> Most of the methods that throw an exception are overloads. Be sure that you understand the behavior of the overload that you choose. - - The following table lists the exception messages from the exception objects thrown by calls to some methods. - -|Method|Message| -|------------|-------------| -|`Aggregate`
`Average`
`Last`
`Max`
`Min`|**Sequence contains no elements**| -|`First`|**Sequence contains no matching element**| -|`Single`
`SingleOrDefault`|**Sequence contains more than one matching element**| - - How you eliminate or handle the exception depends on your application's assumptions and on the particular method you call. - -- When you deliberately call one of these methods without checking for an empty sequence, you are assuming that the sequence is not empty, and that an empty sequence is an unexpected occurrence. In this case, catching or rethrowing the exception is appropriate . - -- If your failure to check for an empty sequence was inadvertent, you can call one of the overloads of the overload to determine whether a sequence contains any elements. - +> Most of the methods that throw an exception are overloads. Be sure that you understand the behavior of the overload that you choose. + + The following table lists the exception messages from the exception objects thrown by calls to some methods. + +|Method|Message| +|------------|-------------| +|`Aggregate`
`Average`
`Last`
`Max`
`Min`|**Sequence contains no elements**| +|`First`|**Sequence contains no matching element**| +|`Single`
`SingleOrDefault`|**Sequence contains more than one matching element**| + + How you eliminate or handle the exception depends on your application's assumptions and on the particular method you call. + +- When you deliberately call one of these methods without checking for an empty sequence, you are assuming that the sequence is not empty, and that an empty sequence is an unexpected occurrence. In this case, catching or rethrowing the exception is appropriate . + +- If your failure to check for an empty sequence was inadvertent, you can call one of the overloads of the overload to determine whether a sequence contains any elements. + > [!TIP] - > Calling the method before generating a sequence can improve performance if the data to be processed might contain a large number of elements or if operation that generates the sequence is expensive. - -- If you've called a method such as , , or , you can substitute an alternate method, such as , , or , that returns a default value instead of a member of the sequence. - - The examples provide additional detail. - - The following example uses the method to compute the average of a sequence whose values are greater than 4. Since no values from the original array exceed 4, no values are included in the sequence, and the method throws an exception. - + > Calling the method before generating a sequence can improve performance if the data to be processed might contain a large number of elements or if operation that generates the sequence is expensive. + +- If you've called a method such as , , or , you can substitute an alternate method, such as , , or , that returns a default value instead of a member of the sequence. + + The examples provide additional detail. + + The following example uses the method to compute the average of a sequence whose values are greater than 4. Since no values from the original array exceed 4, no values are included in the sequence, and the method throws an exception. + :::code language="csharp" source="~/snippets/csharp/System/InvalidOperationException/Overview/Enumerable1.cs" id="Snippet6"::: :::code language="fsharp" source="~/snippets/fsharp/System/InvalidOperationException/Overview/Enumerable1.fs" id="Snippet6"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.invalidoperationexception/vb/Enumerable1.vb" id="Snippet6"::: - - The exception can be eliminated by calling the method to determine whether the sequence contains any elements before calling the method that processes the sequence, as the following example shows. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.invalidoperationexception/vb/Enumerable1.vb" id="Snippet6"::: + + The exception can be eliminated by calling the method to determine whether the sequence contains any elements before calling the method that processes the sequence, as the following example shows. + :::code language="csharp" source="~/snippets/csharp/System/InvalidOperationException/Overview/Enumerable2.cs" interactive="try-dotnet" id="Snippet7"::: :::code language="fsharp" source="~/snippets/fsharp/System/InvalidOperationException/Overview/Enumerable2.fs" id="Snippet7"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.invalidoperationexception/vb/Enumerable2.vb" id="Snippet7"::: - - The method returns the first item in a sequence or the first element in a sequence that satisfies a specified condition. If the sequence is empty and therefore does not have a first element, it throws an exception. - - In the following example, the method throws an exception because the dbQueryResults array doesn't contain an element greater than 4. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.invalidoperationexception/vb/Enumerable2.vb" id="Snippet7"::: + + The method returns the first item in a sequence or the first element in a sequence that satisfies a specified condition. If the sequence is empty and therefore does not have a first element, it throws an exception. + + In the following example, the method throws an exception because the dbQueryResults array doesn't contain an element greater than 4. + :::code language="csharp" source="~/snippets/csharp/System/InvalidOperationException/Overview/Enumerable3.cs" id="Snippet8"::: :::code language="fsharp" source="~/snippets/fsharp/System/InvalidOperationException/Overview/Enumerable3.fs" id="Snippet8"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.invalidoperationexception/vb/Enumerable3.vb" id="Snippet8"::: - - You can call the method instead of to return a specified or default value. If the method does not find a first element in the sequence, it returns the default value for that data type. The default value is `null` for a reference type, zero for a numeric data type, and for the type. - + + You can call the method instead of to return a specified or default value. If the method does not find a first element in the sequence, it returns the default value for that data type. The default value is `null` for a reference type, zero for a numeric data type, and for the type. + > [!NOTE] -> Interpreting the value returned by the method is often complicated by the fact that the default value of the type can be a valid value in the sequence. In this case, you an call the method to determine whether the sequence has valid members before calling the method. - - The following example calls the method to prevent the exception thrown in the previous example. - +> Interpreting the value returned by the method is often complicated by the fact that the default value of the type can be a valid value in the sequence. In this case, you an call the method to determine whether the sequence has valid members before calling the method. + + The following example calls the method to prevent the exception thrown in the previous example. + :::code language="csharp" source="~/snippets/csharp/System/InvalidOperationException/Overview/Enumerable4.cs" interactive="try-dotnet" id="Snippet9"::: :::code language="fsharp" source="~/snippets/fsharp/System/InvalidOperationException/Overview/Enumerable4.fs" id="Snippet9"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.invalidoperationexception/vb/Enumerable4.vb" id="Snippet9"::: - - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.invalidoperationexception/vb/Enumerable4.vb" id="Snippet9"::: + + ### Calling Enumerable.Single or Enumerable.SingleOrDefault on a sequence without one element -The method returns the only element of a sequence, or the only element of a sequence that meets a specified condition. If there are no elements in the sequence, or if there is more than one element , the method throws an exception. - - You can use the method to return a default value instead of throwing an exception when the sequence contains no elements. However, the method still throws an exception when the sequence contains more than one element. - - The following table lists the exception messages from the exception objects thrown by calls to the and methods. - -|Method|Message| -|------------|-------------| -|`Single`|**Sequence contains no matching element**| -|`Single`
`SingleOrDefault`|**Sequence contains more than one matching element**| - - In the following example, the call to the method throws an exception because the sequence doesn't have an element greater than 4. - +The method returns the only element of a sequence, or the only element of a sequence that meets a specified condition. If there are no elements in the sequence, or if there is more than one element , the method throws an exception. + + You can use the method to return a default value instead of throwing an exception when the sequence contains no elements. However, the method still throws an exception when the sequence contains more than one element. + + The following table lists the exception messages from the exception objects thrown by calls to the and methods. + +|Method|Message| +|------------|-------------| +|`Single`|**Sequence contains no matching element**| +|`Single`
`SingleOrDefault`|**Sequence contains more than one matching element**| + + In the following example, the call to the method throws an exception because the sequence doesn't have an element greater than 4. + :::code language="csharp" source="~/snippets/csharp/System/InvalidOperationException/Overview/Enumerable5.cs" id="Snippet10"::: :::code language="fsharp" source="~/snippets/fsharp/System/InvalidOperationException/Overview/Enumerable5.fs" id="Snippet10"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.invalidoperationexception/vb/Enumerable5.vb" id="Snippet10"::: - - The following example attempts to prevent the exception thrown when a sequence is empty by instead calling the method. However, because this sequence returns multiple elements whose value is greater than 2, it also throws an exception. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.invalidoperationexception/vb/Enumerable5.vb" id="Snippet10"::: + + The following example attempts to prevent the exception thrown when a sequence is empty by instead calling the method. However, because this sequence returns multiple elements whose value is greater than 2, it also throws an exception. + :::code language="csharp" source="~/snippets/csharp/System/InvalidOperationException/Overview/Enumerable6.cs" id="Snippet11"::: :::code language="fsharp" source="~/snippets/fsharp/System/InvalidOperationException/Overview/Enumerable6.fs" id="Snippet11"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.invalidoperationexception/vb/Enumerable6.vb" id="Snippet11"::: - - Calling the method assumes that either a sequence or the sequence that meets specified criteria contains only one element. assumes a sequence with zero or one result, but no more. If this assumption is a deliberate one on your part and these conditions are not met, rethrowing or catching the resulting is appropriate. Otherwise, or if you expect that invalid conditions will occur with some frequency, you should consider using some other method, such as or . - - -### Dynamic cross-application domain field access - The Microsoft intermediate language (MSIL) instruction throws an exception if the object containing the field whose address you are trying to retrieve is not within the application domain in which your code is executing. The address of a field can only be accessed from the application domain in which it resides. - - -## Throwing an InvalidOperationException exception - You should throw an exception only when the state of your object for some reason does not support a particular method call. That is, the method call is valid in some circumstances or contexts, but is invalid in others. - - If the method invocation failure is due to invalid arguments, then or one of its derived classes, or , should be thrown instead. - - -## Miscellaneous information - uses the HRESULT COR_E_INVALIDOPERATION, which has the value 0x80131509. - - For a list of initial property values for an instance of , see the constructors. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.invalidoperationexception/vb/Enumerable6.vb" id="Snippet11"::: + + Calling the method assumes that either a sequence or the sequence that meets specified criteria contains only one element. assumes a sequence with zero or one result, but no more. If this assumption is a deliberate one on your part and these conditions are not met, rethrowing or catching the resulting is appropriate. Otherwise, or if you expect that invalid conditions will occur with some frequency, you should consider using some other method, such as or . + + +### Dynamic cross-application domain field access + The Microsoft intermediate language (MSIL) instruction throws an exception if the object containing the field whose address you are trying to retrieve is not within the application domain in which your code is executing. The address of a field can only be accessed from the application domain in which it resides. + + +## Throwing an InvalidOperationException exception + You should throw an exception only when the state of your object for some reason does not support a particular method call. That is, the method call is valid in some circumstances or contexts, but is invalid in others. + + If the method invocation failure is due to invalid arguments, then or one of its derived classes, or , should be thrown instead. + + +## Miscellaneous information + uses the HRESULT COR_E_INVALIDOPERATION, which has the value 0x80131509. + + For a list of initial property values for an instance of , see the constructors. + ]]>
@@ -407,18 +407,18 @@ The method Initializes a new instance of the class. - property of the new instance to a system-supplied message that describes the error, such as "The requested operation cannot be performed." This message takes into account the current system culture. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The localized error message string.| - + property of the new instance to a system-supplied message that describes the error, such as "The requested operation cannot be performed." This message takes into account the current system culture. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The localized error message string.| + ]]> @@ -465,18 +465,18 @@ The method The message that describes the error. Initializes a new instance of the class with a specified error message. - property of the new exception using the `message` parameter. The content of `message` is intended to be understood by humans. The caller of this constructor is required to ensure that this string has been localized for the current system culture. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The error message string.| - + property of the new exception using the `message` parameter. The content of `message` is intended to be understood by humans. The caller of this constructor is required to ensure that this string has been localized for the current system culture. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The error message string.| + ]]>
@@ -538,11 +538,11 @@ The method The contextual information about the source or destination. Initializes a new instance of the class with serialized data. - XML and SOAP Serialization @@ -592,18 +592,18 @@ The method The exception that is the cause of the current exception. If the parameter is not a null reference ( in Visual Basic), the current exception is raised in a block that handles the inner exception. Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception. - property. The property returns the same value that is passed into the constructor, or a null reference (`Nothing` in Visual Basic) if the property does not supply the inner exception value to the constructor. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||The inner exception reference.| -||The error message string.| - + property. The property returns the same value that is passed into the constructor, or a null reference (`Nothing` in Visual Basic) if the property does not supply the inner exception value to the constructor. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||The inner exception reference.| +||The error message string.| + ]]> diff --git a/xml/System/InvalidProgramException.xml b/xml/System/InvalidProgramException.xml index c50f9db36e4..a368d31c136 100644 --- a/xml/System/InvalidProgramException.xml +++ b/xml/System/InvalidProgramException.xml @@ -68,13 +68,13 @@ The exception that is thrown when a program contains invalid Microsoft intermediate language (MSIL) or metadata. Generally this indicates a bug in the compiler that generated the program. This exception is also thrown when internal runtime implementation limits have been exceeded by the program. - uses the HRESULT `COR_E_INVALIDPROGRAM`, which has the value 0x8013153A. - + uses the HRESULT `COR_E_INVALIDPROGRAM`, which has the value 0x8013153A. + For a list of initial property values for an instance of , see the constructors. - + ]]> @@ -127,18 +127,18 @@ Initializes a new instance of the class with default properties. - property of the new exception to a system-supplied message that describes the error, such as "Metadata is incorrect." This message takes into account the current system culture. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The localized error message string.| - + property of the new exception to a system-supplied message that describes the error, such as "Metadata is incorrect." This message takes into account the current system culture. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The localized error message string.| + ]]> @@ -183,18 +183,18 @@ The error message that explains the reason for the exception. Initializes a new instance of the class with a specified error message. - property of the new exception using the `message` parameter. The content of `message` is intended to be understood by humans. The caller of this constructor is required to ensure that this string has been localized for the current system culture. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The error message string.| - + property of the new exception using the `message` parameter. The content of `message` is intended to be understood by humans. The caller of this constructor is required to ensure that this string has been localized for the current system culture. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The error message string.| + ]]> @@ -241,18 +241,18 @@ The exception that is the cause of the current exception. If the parameter is not a null reference ( in Visual Basic), the current exception is raised in a block that handles the inner exception. Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception. - property. The `InnerException` property returns the same value that is passed into the constructor, or a null reference (`Nothing` in Visual Basic) if the `InnerException` property does not supply the inner exception value to the constructor. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||The inner exception reference.| -||The error message string.| - + property. The `InnerException` property returns the same value that is passed into the constructor, or a null reference (`Nothing` in Visual Basic) if the `InnerException` property does not supply the inner exception value to the constructor. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||The inner exception reference.| +||The error message string.| + ]]> diff --git a/xml/System/InvalidTimeZoneException.xml b/xml/System/InvalidTimeZoneException.xml index 4200fdb4d0b..cd2bf2d18cd 100644 --- a/xml/System/InvalidTimeZoneException.xml +++ b/xml/System/InvalidTimeZoneException.xml @@ -73,21 +73,21 @@ The exception that is thrown when time zone information is invalid. - object contains invalid, incomplete, or missing data. It is thrown by the method when a time zone is found in the registry but contains corrupted data. It can also be thrown by the method under any of the following conditions: - -- The adjustment rules overlap. - -- The adjustment rules contain one or more null elements. - -- The sum of the Coordinated Universal Time (UTC) offset and daylight delta is out of range. (It is either greater than 14 hours or less than -14 hours.) - -- A single date has multiple adjustment rules applied to it. - - This exception is not thrown to indicate that the time zone is not defined on a particular system; the is used for this purpose. - + object contains invalid, incomplete, or missing data. It is thrown by the method when a time zone is found in the registry but contains corrupted data. It can also be thrown by the method under any of the following conditions: + +- The adjustment rules overlap. + +- The adjustment rules contain one or more null elements. + +- The sum of the Coordinated Universal Time (UTC) offset and daylight delta is out of range. (It is either greater than 14 hours or less than -14 hours.) + +- A single date has multiple adjustment rules applied to it. + + This exception is not thrown to indicate that the time zone is not defined on a particular system; the is used for this purpose. + ]]> @@ -144,11 +144,11 @@ Initializes a new instance of the class with a system-supplied message. - class. It initializes the property of the new instance to a system-supplied message that describes the error, such as "Exception of type 'System.InvalidTimeZoneException' was thrown." This message is localized for the current system culture. - + class. It initializes the property of the new instance to a system-supplied message that describes the error, such as "Exception of type 'System.InvalidTimeZoneException' was thrown." This message is localized for the current system culture. + ]]> @@ -197,11 +197,11 @@ A string that describes the exception. Initializes a new instance of the class with the specified message string. - property. It should be localized for the current culture. - + property. It should be localized for the current culture. + ]]>
@@ -265,18 +265,18 @@ The stream that contains the serialized data. Initializes a new instance of the class from serialized data. - object. Instead, it is called by the object's method when deserializing the object from a stream. - + object. Instead, it is called by the object's method when deserializing the object from a stream. + ]]> - The parameter is . - - -or- - - The parameter is . + The parameter is . + +-or- + +The parameter is .
@@ -325,21 +325,21 @@ The exception that is the cause of the current exception. Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception. - class to handle an exception in a `try`…`catch` block. The `innerException` parameter should be a reference to the exception object handled in the `catch` block, or it can be `null`. This value is then assigned to the object's property. - - The `message` string is assigned to the property. The string should be localized for the current culture. - - - -## Examples - The following code tries to retrieve a object that represents the Central Standard Time zone. If an occurs in the `RetrieveTimeZone` method call, the exception handler wraps the exception in a new object, which it returns to the caller. The caller's exception handler then displays information about both the outer and inner exceptions. - + class to handle an exception in a `try`…`catch` block. The `innerException` parameter should be a reference to the exception object handled in the `catch` block, or it can be `null`. This value is then assigned to the object's property. + + The `message` string is assigned to the property. The string should be localized for the current culture. + + + +## Examples + The following code tries to retrieve a object that represents the Central Standard Time zone. If an occurs in the `RetrieveTimeZone` method call, the exception handler wraps the exception in a new object, which it returns to the caller. The caller's exception handler then displays information about both the outer and inner exceptions. + :::code language="csharp" source="~/snippets/csharp/System/InvalidTimeZoneException/.ctor/TimeZoneNotFoundException.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZoneNotFoundException.Class/vb/TimeZoneNotFoundException.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZoneNotFoundException.Class/vb/TimeZoneNotFoundException.vb" id="Snippet1"::: + ]]>
diff --git a/xml/System/Lazy`1.xml b/xml/System/Lazy`1.xml index 43c88940336..dbd637e0926 100644 --- a/xml/System/Lazy`1.xml +++ b/xml/System/Lazy`1.xml @@ -91,95 +91,95 @@ The type of object that is being lazily initialized. Provides support for lazy initialization. - . The type argument of the object that you create specifies the type of the object that you want to initialize lazily. The constructor that you use to create the object determines the characteristics of the initialization. Lazy initialization occurs the first time the property is accessed. - - In most cases, choosing a constructor depends on your answers to two questions: - -- Will the lazily initialized object be accessed from more than one thread? If so, the object might create it on any thread. You can use one of the simple constructors whose default behavior is to create a thread-safe object, so that only one instance of the lazily instantiated object is created no matter how many threads try to access it. To create a object that is not thread safe, you must use a constructor that enables you to specify no thread safety. - + . The type argument of the object that you create specifies the type of the object that you want to initialize lazily. The constructor that you use to create the object determines the characteristics of the initialization. Lazy initialization occurs the first time the property is accessed. + + In most cases, choosing a constructor depends on your answers to two questions: + +- Will the lazily initialized object be accessed from more than one thread? If so, the object might create it on any thread. You can use one of the simple constructors whose default behavior is to create a thread-safe object, so that only one instance of the lazily instantiated object is created no matter how many threads try to access it. To create a object that is not thread safe, you must use a constructor that enables you to specify no thread safety. + > [!CAUTION] - > Making the object thread safe does not protect the lazily initialized object. If multiple threads can access the lazily initialized object, you must make its properties and methods safe for multithreaded access. - -- Does lazy initialization require a lot of code, or does the lazily initialized object have a parameterless constructor that does everything you need and doesn't throw exceptions? If you need to write initialization code or if exceptions need to be handled, use one of the constructors that takes a factory method. Write your initialization code in the factory method. - - The following table shows which constructor to choose, based on these two factors: - -|Object will be accessed by|If no initialization code is required (parameterless constructor), use|If initialization code is required, use| -|--------------------------------|------------------------------------------------------------------------|---------------------------------------------| -|Multiple threads||| -|One thread| with `isThreadSafe` set to `false`.| with `isThreadSafe` set to `false`.| - - You can use a lambda expression to specify the factory method. This keeps all the initialization code in one place. The lambda expression captures the context, including any arguments you pass to the lazily initialized object's constructor. - - **Exception caching** When you use factory methods, exceptions are cached. That is, if the factory method throws an exception the first time a thread tries to access the property of the object, the same exception is thrown on every subsequent attempt. This ensures that every call to the property produces the same result and avoids subtle errors that might arise if different threads get different results. The stands in for an actual `T` that otherwise would have been initialized at some earlier point, usually during startup. A failure at that earlier point is usually fatal. If there is a potential for a recoverable failure, we recommend that you build the retry logic into the initialization routine (in this case, the factory method), just as you would if you weren't using lazy initialization. - - **Alternative to locking** In certain situations, you might want to avoid the overhead of the object's default locking behavior. In rare situations, there might be a potential for deadlocks. In such cases, you can use the or constructor, and specify . This enables the object to create a copy of the lazily initialized object on each of several threads if the threads call the property simultaneously. The object ensures that all threads use the same instance of the lazily initialized object and discards the instances that are not used. Thus, the cost of reducing the locking overhead is that your program might sometimes create and discard extra copies of an expensive object. In most cases, this is unlikely. The examples for the and constructors demonstrate this behavior. - + > Making the object thread safe does not protect the lazily initialized object. If multiple threads can access the lazily initialized object, you must make its properties and methods safe for multithreaded access. + +- Does lazy initialization require a lot of code, or does the lazily initialized object have a parameterless constructor that does everything you need and doesn't throw exceptions? If you need to write initialization code or if exceptions need to be handled, use one of the constructors that takes a factory method. Write your initialization code in the factory method. + + The following table shows which constructor to choose, based on these two factors: + +|Object will be accessed by|If no initialization code is required (parameterless constructor), use|If initialization code is required, use| +|--------------------------------|------------------------------------------------------------------------|---------------------------------------------| +|Multiple threads||| +|One thread| with `isThreadSafe` set to `false`.| with `isThreadSafe` set to `false`.| + + You can use a lambda expression to specify the factory method. This keeps all the initialization code in one place. The lambda expression captures the context, including any arguments you pass to the lazily initialized object's constructor. + + **Exception caching** When you use factory methods, exceptions are cached. That is, if the factory method throws an exception the first time a thread tries to access the property of the object, the same exception is thrown on every subsequent attempt. This ensures that every call to the property produces the same result and avoids subtle errors that might arise if different threads get different results. The stands in for an actual `T` that otherwise would have been initialized at some earlier point, usually during startup. A failure at that earlier point is usually fatal. If there is a potential for a recoverable failure, we recommend that you build the retry logic into the initialization routine (in this case, the factory method), just as you would if you weren't using lazy initialization. + + **Alternative to locking** In certain situations, you might want to avoid the overhead of the object's default locking behavior. In rare situations, there might be a potential for deadlocks. In such cases, you can use the or constructor, and specify . This enables the object to create a copy of the lazily initialized object on each of several threads if the threads call the property simultaneously. The object ensures that all threads use the same instance of the lazily initialized object and discards the instances that are not used. Thus, the cost of reducing the locking overhead is that your program might sometimes create and discard extra copies of an expensive object. In most cases, this is unlikely. The examples for the and constructors demonstrate this behavior. + > [!IMPORTANT] -> When you specify , exceptions are never cached, even if you specify a factory method. - - **Equivalent constructors** In addition to enabling the use of , the and constructors can duplicate the functionality of the other constructors. The following table shows the parameter values that produce equivalent behavior. - -|To create a object that is|For constructors that have a `LazyThreadSafetyMode` `mode` parameter, set `mode` to|For constructors that have a Boolean `isThreadSafe` parameter, set `isThreadSafe` to|For constructors with no thread safety parameters| -|-------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------|-------------------------------------------------------| -|Fully thread safe; uses locking to ensure that only one thread initializes the value.||`true`|All such constructors are fully thread safe.| -|Not thread safe.||`false`|Not applicable.| -|Fully thread safe; threads race to initialize the value.||Not applicable.|Not applicable.| - - **Other capabilities** For information about the use of with thread-static fields, or as the backing store for properties, see [Lazy Initialization](/dotnet/framework/performance/lazy-initialization). - - - -## Examples - The following example demonstrates the use of the class to provide lazy initialization with access from multiple threads. - +> When you specify , exceptions are never cached, even if you specify a factory method. + + **Equivalent constructors** In addition to enabling the use of , the and constructors can duplicate the functionality of the other constructors. The following table shows the parameter values that produce equivalent behavior. + +|To create a object that is|For constructors that have a `LazyThreadSafetyMode` `mode` parameter, set `mode` to|For constructors that have a Boolean `isThreadSafe` parameter, set `isThreadSafe` to|For constructors with no thread safety parameters| +|-------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------|-------------------------------------------------------| +|Fully thread safe; uses locking to ensure that only one thread initializes the value.||`true`|All such constructors are fully thread safe.| +|Not thread safe.||`false`|Not applicable.| +|Fully thread safe; threads race to initialize the value.||Not applicable.|Not applicable.| + + **Other capabilities** For information about the use of with thread-static fields, or as the backing store for properties, see [Lazy Initialization](/dotnet/framework/performance/lazy-initialization). + + + +## Examples + The following example demonstrates the use of the class to provide lazy initialization with access from multiple threads. + > [!NOTE] -> The example uses the constructor. It also demonstrates the use of the constructor (specifying `true` for `isThreadSafe`) and the constructor (specifying for `mode`). To switch to a different constructor, just change which constructors are commented out. -> -> For an example that demonstrates exception caching using the same constructors, see the constructor. - - The example defines a `LargeObject` class that will be initialized lazily by one of several threads. The four key sections of code illustrate the creation of the initializer, the factory method, the actual initialization, and the constructor of the `LargeObject` class, which displays a message when the object is created. At the beginning of the `Main` method, the example creates the thread-safe lazy initializer for `LargeObject`: - +> The example uses the constructor. It also demonstrates the use of the constructor (specifying `true` for `isThreadSafe`) and the constructor (specifying for `mode`). To switch to a different constructor, just change which constructors are commented out. +> +> For an example that demonstrates exception caching using the same constructors, see the constructor. + + The example defines a `LargeObject` class that will be initialized lazily by one of several threads. The four key sections of code illustrate the creation of the initializer, the factory method, the actual initialization, and the constructor of the `LargeObject` class, which displays a message when the object is created. At the beginning of the `Main` method, the example creates the thread-safe lazy initializer for `LargeObject`: + :::code language="csharp" source="~/snippets/csharp/System/LazyT/Overview/example.cs" id="Snippetnewlazy"::: :::code language="fsharp" source="~/snippets/fsharp/System/LazyT/Overview/example.fs" id="Snippetnewlazy"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.lazy`1/vb/example.vb" id="Snippetnewlazy"::: - - The factory method shows the creation of the object, with a placeholder for further initialization: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.lazy`1/vb/example.vb" id="Snippetnewlazy"::: + + The factory method shows the creation of the object, with a placeholder for further initialization: + :::code language="csharp" source="~/snippets/csharp/System/LazyT/Overview/example.cs" id="Snippetfactoryfunc"::: :::code language="fsharp" source="~/snippets/fsharp/System/LazyT/Overview/example.fs" id="Snippetfactoryfunc"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.lazy`1/vb/example.vb" id="Snippetfactoryfunc"::: - - Note that the first two code sections could be combined by using a lambda function, as shown here: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.lazy`1/vb/example.vb" id="Snippetfactoryfunc"::: + + Note that the first two code sections could be combined by using a lambda function, as shown here: + :::code language="csharp" source="~/snippets/csharp/System/LazyT/Overview/lambda.cs" id="Snippetinitwithlambda"::: :::code language="fsharp" source="~/snippets/fsharp/System/LazyT/Overview/lambda.fs" id="Snippetinitwithlambda"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.lazy`1/vb/lambda.vb" id="Snippetinitwithlambda"::: - - The example pauses, to indicate that an indeterminate period may elapse before lazy initialization occurs. When you press the **Enter** key, the example creates and starts three threads. The `ThreadProc` method that's used by all three threads calls the property. The first time this happens, the `LargeObject` instance is created: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.lazy`1/vb/lambda.vb" id="Snippetinitwithlambda"::: + + The example pauses, to indicate that an indeterminate period may elapse before lazy initialization occurs. When you press the **Enter** key, the example creates and starts three threads. The `ThreadProc` method that's used by all three threads calls the property. The first time this happens, the `LargeObject` instance is created: + :::code language="csharp" source="~/snippets/csharp/System/LazyT/Overview/example.cs" id="Snippetvalueprop"::: :::code language="fsharp" source="~/snippets/fsharp/System/LazyT/Overview/example.fs" id="Snippetvalueprop"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.lazy`1/vb/example.vb" id="Snippetvalueprop"::: - - The constructor of the `LargeObject` class, which includes the last key section of code, displays a message and records the identity of the initializing thread. The output from the program appears at the end of the full code listing. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.lazy`1/vb/example.vb" id="Snippetvalueprop"::: + + The constructor of the `LargeObject` class, which includes the last key section of code, displays a message and records the identity of the initializing thread. The output from the program appears at the end of the full code listing. + :::code language="csharp" source="~/snippets/csharp/System/LazyT/Overview/example.cs" id="Snippetlargector"::: :::code language="fsharp" source="~/snippets/fsharp/System/LazyT/Overview/example.fs" id="Snippetlargector"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.lazy`1/vb/example.vb" id="Snippetlargector"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.lazy`1/vb/example.vb" id="Snippetlargector"::: + > [!NOTE] -> For simplicity, this example uses a global instance of , and all the methods are `static` (`Shared` in Visual Basic). These are not requirements for the use of lazy initialization. - +> For simplicity, this example uses a global instance of , and all the methods are `static` (`Shared` in Visual Basic). These are not requirements for the use of lazy initialization. + :::code language="csharp" source="~/snippets/csharp/System/LazyT/Overview/example.cs" id="Snippetall"::: :::code language="fsharp" source="~/snippets/fsharp/System/LazyT/Overview/example.fs" id="Snippetall"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.lazy`1/vb/example.vb" id="Snippetall"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.lazy`1/vb/example.vb" id="Snippetall"::: + ]]> By default, all public and protected members of the class are thread safe and may be used concurrently from multiple threads. These thread-safety guarantees may be removed optionally and per instance, using parameters to the type's constructors. @@ -239,41 +239,41 @@ Initializes a new instance of the class. When lazy initialization occurs, the parameterless constructor of the target type is used. - instance that is initialized with this constructor is . The thread safety mode describes the behavior when multiple threads try to initialize the instance. - - A instance that is created with this constructor does not cache exceptions. For more information, see the class or the enumeration. - - - -## Examples - The following example demonstrates the use of this constructor. It also illustrates the use of the constructor (specifying `true` for `isThreadSafe`) and the constructor (specifying for `mode`). To switch to a different constructor, just change which constructors are commented out. - - The example defines a `LargeObject` class that will be initialized lazily by one of several threads. The two key lines of code in this example are the creation of the initializer and the actual initialization. At the beginning of the `Main` method, the example creates the thread-safe lazy initializer for `LargeObject`: - + instance that is initialized with this constructor is . The thread safety mode describes the behavior when multiple threads try to initialize the instance. + + A instance that is created with this constructor does not cache exceptions. For more information, see the class or the enumeration. + + + +## Examples + The following example demonstrates the use of this constructor. It also illustrates the use of the constructor (specifying `true` for `isThreadSafe`) and the constructor (specifying for `mode`). To switch to a different constructor, just change which constructors are commented out. + + The example defines a `LargeObject` class that will be initialized lazily by one of several threads. The two key lines of code in this example are the creation of the initializer and the actual initialization. At the beginning of the `Main` method, the example creates the thread-safe lazy initializer for `LargeObject`: + :::code language="csharp" source="~/snippets/csharp/System/LazyT/.ctor/example.cs" id="Snippetnewlazy"::: :::code language="fsharp" source="~/snippets/fsharp/System/LazyT/.ctor/example.fs" id="Snippetnewlazy"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.lazy`1.ctor/vb/example.vb" id="Snippetnewlazy"::: - - The example creates and starts three threads that block on a object, so that the example can release the threads all at once. The `ThreadProc` method that's used by all three threads calls the property to get the `LargeObject` instance: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.lazy`1.ctor/vb/example.vb" id="Snippetnewlazy"::: + + The example creates and starts three threads that block on a object, so that the example can release the threads all at once. The `ThreadProc` method that's used by all three threads calls the property to get the `LargeObject` instance: + :::code language="csharp" source="~/snippets/csharp/System/LazyT/.ctor/example.cs" id="Snippetvalueprop"::: :::code language="fsharp" source="~/snippets/fsharp/System/LazyT/.ctor/example.fs" id="Snippetvalueprop"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.lazy`1.ctor/vb/example.vb" id="Snippetvalueprop"::: - - The class provides locking, so that only one thread is allowed to create the `LargeObject` instance. The example demonstrates that the other threads all get the same instance. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.lazy`1.ctor/vb/example.vb" id="Snippetvalueprop"::: + + The class provides locking, so that only one thread is allowed to create the `LargeObject` instance. The example demonstrates that the other threads all get the same instance. + > [!NOTE] -> For simplicity, this example uses a global instance of , and all the methods are `static` (`Shared` in Visual Basic). These are not requirements for the use of lazy initialization. - +> For simplicity, this example uses a global instance of , and all the methods are `static` (`Shared` in Visual Basic). These are not requirements for the use of lazy initialization. + :::code language="csharp" source="~/snippets/csharp/System/LazyT/.ctor/example.cs" id="Snippetall"::: :::code language="fsharp" source="~/snippets/fsharp/System/LazyT/.ctor/example.fs" id="Snippetall"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.lazy`1.ctor/vb/example.vb" id="Snippetall"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.lazy`1.ctor/vb/example.vb" id="Snippetall"::: + ]]> Lazy Initialization @@ -322,30 +322,30 @@ to make this instance usable concurrently by multiple threads; to make the instance usable by only one thread at a time. Initializes a new instance of the class. When lazy initialization occurs, the parameterless constructor of the target type and the specified initialization mode are used. - instance that is initialized with this constructor is if `isThreadSafe` is `true`; otherwise, the mode is . The thread safety mode describes the behavior when multiple threads try to initialize the instance. To specify the mode, use the or constructor. - - A instance that is created with this constructor does not cache exceptions. For more information, see the class or the enumeration. - - - -## Examples - The following example demonstrates the use of this constructor to create a lazy initializer that is not thread safe, for scenarios where all access to the lazily initialized object occurs on the same thread. It also demonstrates the use of the constructor (specifying for `mode`. To switch to a different constructor, just change which constructor is commented out. - + instance that is initialized with this constructor is if `isThreadSafe` is `true`; otherwise, the mode is . The thread safety mode describes the behavior when multiple threads try to initialize the instance. To specify the mode, use the or constructor. + + A instance that is created with this constructor does not cache exceptions. For more information, see the class or the enumeration. + + + +## Examples + The following example demonstrates the use of this constructor to create a lazy initializer that is not thread safe, for scenarios where all access to the lazily initialized object occurs on the same thread. It also demonstrates the use of the constructor (specifying for `mode`. To switch to a different constructor, just change which constructor is commented out. + > [!NOTE] -> For code that demonstrates how to use this constructor in multithreaded scenarios (specifying `true` for `isThreadSafe`), see the example for the constructor. - - The example defines a `LargeObject` class that will be initialized lazily. In the `Main` method, the example creates a instance and then pauses. When you press the **Enter** key, the example accesses the property of the instance, which causes initialization to occur. The constructor of the `LargeObject` class displays a console message. - +> For code that demonstrates how to use this constructor in multithreaded scenarios (specifying `true` for `isThreadSafe`), see the example for the constructor. + + The example defines a `LargeObject` class that will be initialized lazily. In the `Main` method, the example creates a instance and then pauses. When you press the **Enter** key, the example accesses the property of the instance, which causes initialization to occur. The constructor of the `LargeObject` class displays a console message. + > [!NOTE] -> For simplicity, this example uses a global instance of , and all the methods are `static` (`Shared` in Visual Basic). These are not requirements for the use of lazy initialization. - +> For simplicity, this example uses a global instance of , and all the methods are `static` (`Shared` in Visual Basic). These are not requirements for the use of lazy initialization. + :::code language="csharp" source="~/snippets/csharp/System/LazyT/.ctor/example1.cs" id="Snippetall"::: :::code language="fsharp" source="~/snippets/fsharp/System/LazyT/.ctor/example1.fs" id="Snippetall"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.lazy`1.ctorbool/vb/example.vb" id="Snippetall"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.lazy`1.ctorbool/vb/example.vb" id="Snippetall"::: + ]]> Lazy Initialization @@ -393,47 +393,47 @@ The delegate that is invoked to produce the lazily initialized value when it is needed. Initializes a new instance of the class. When lazy initialization occurs, the specified initialization function is used. - instance that is initialized with this constructor is . The thread safety mode describes the behavior when multiple threads try to initialize the instance. - - Exceptions that are thrown by `valueFactory` are cached. For more information, see the class or the enumeration. - - - -## Examples - The following example demonstrates the use of this constructor to provide lazy initialization with exception caching. It also demonstrates the use of the constructor (specifying `true` for `isThreadSafe`) and the constructor (specifying for `mode`). To switch to a different constructor, just change which constructors are commented out. - - The example defines a `LargeObject` class that will be initialized lazily by one of several threads. The three key sections of code illustrate the creation of the initializer, the actual initialization, and the constructor of the `LargeObject` class, which demonstrates exception caching. At the beginning of the `Main` method, the example creates the thread-safe lazy initializer for `LargeObject`: - + instance that is initialized with this constructor is . The thread safety mode describes the behavior when multiple threads try to initialize the instance. + + Exceptions that are thrown by `valueFactory` are cached. For more information, see the class or the enumeration. + + + +## Examples + The following example demonstrates the use of this constructor to provide lazy initialization with exception caching. It also demonstrates the use of the constructor (specifying `true` for `isThreadSafe`) and the constructor (specifying for `mode`). To switch to a different constructor, just change which constructors are commented out. + + The example defines a `LargeObject` class that will be initialized lazily by one of several threads. The three key sections of code illustrate the creation of the initializer, the actual initialization, and the constructor of the `LargeObject` class, which demonstrates exception caching. At the beginning of the `Main` method, the example creates the thread-safe lazy initializer for `LargeObject`: + :::code language="csharp" source="~/snippets/csharp/System/LazyT/.ctor/example2.cs" id="Snippetnewlazy"::: :::code language="fsharp" source="~/snippets/fsharp/System/LazyT/.ctor/example2.fs" id="Snippetnewlazy"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.lazy`1.ctorfunc/vb/example.vb" id="Snippetnewlazy"::: - - The example creates and starts three threads. The `ThreadProc` method that's used by all three threads calls the property to get the `LargeObject` instance: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.lazy`1.ctorfunc/vb/example.vb" id="Snippetnewlazy"::: + + The example creates and starts three threads. The `ThreadProc` method that's used by all three threads calls the property to get the `LargeObject` instance: + :::code language="csharp" source="~/snippets/csharp/System/LazyT/.ctor/example2.cs" id="Snippetvalueprop"::: :::code language="fsharp" source="~/snippets/fsharp/System/LazyT/.ctor/example2.fs" id="Snippetvalueprop"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.lazy`1.ctorfunc/vb/example.vb" id="Snippetvalueprop"::: - - In the constructor of the `LargeObject` class, the third key section of code throws an exception the first time a `LargeObject` instance is created, but thereafter allows instance creation to occur: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.lazy`1.ctorfunc/vb/example.vb" id="Snippetvalueprop"::: + + In the constructor of the `LargeObject` class, the third key section of code throws an exception the first time a `LargeObject` instance is created, but thereafter allows instance creation to occur: + :::code language="csharp" source="~/snippets/csharp/System/LazyT/.ctor/example2.cs" id="Snippetlargector"::: :::code language="fsharp" source="~/snippets/fsharp/System/LazyT/.ctor/example2.fs" id="Snippetlargector"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.lazy`1.ctorfunc/vb/example.vb" id="Snippetlargector"::: - - When the example is run, the first thread that tries to create an instance of `LargeObject` fails, and the exception is caught. You might expect that the next thread would successfully create an instance, but the object has cached the exception. Because of this, all three threads throw the exception. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.lazy`1.ctorfunc/vb/example.vb" id="Snippetlargector"::: + + When the example is run, the first thread that tries to create an instance of `LargeObject` fails, and the exception is caught. You might expect that the next thread would successfully create an instance, but the object has cached the exception. Because of this, all three threads throw the exception. + > [!NOTE] -> For simplicity, this example uses a global instance of , and all the methods are `static` (`Shared` in Visual Basic). These are not requirements for the use of lazy initialization. - +> For simplicity, this example uses a global instance of , and all the methods are `static` (`Shared` in Visual Basic). These are not requirements for the use of lazy initialization. + :::code language="csharp" source="~/snippets/csharp/System/LazyT/.ctor/example2.cs" id="Snippetall"::: :::code language="fsharp" source="~/snippets/fsharp/System/LazyT/.ctor/example2.fs" id="Snippetall"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.lazy`1.ctorfunc/vb/example.vb" id="Snippetall"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.lazy`1.ctorfunc/vb/example.vb" id="Snippetall"::: + ]]> @@ -483,48 +483,48 @@ One of the enumeration values that specifies the thread safety mode. Initializes a new instance of the class that uses the parameterless constructor of and the specified thread-safety mode. - instance describes the behavior when multiple threads try to initialize the instance. - - A instance that is created with this constructor does not cache exceptions. For more information, see the class or the enumeration. - - - -## Examples - The following example demonstrates the use of this constructor to create a lazy initializer that enables multiple threads to race to create an object lazily. Multiple threads might succeed in creating instances, but all threads use the instance that was created first. - + instance describes the behavior when multiple threads try to initialize the instance. + + A instance that is created with this constructor does not cache exceptions. For more information, see the class or the enumeration. + + + +## Examples + The following example demonstrates the use of this constructor to create a lazy initializer that enables multiple threads to race to create an object lazily. Multiple threads might succeed in creating instances, but all threads use the instance that was created first. + > [!NOTE] -> For an example that demonstrates how to use this constructor in single-threaded scenarios (specifying for `mode`), see the constructor. For an example that demonstrates how to use this constructor to provide locking instead of race conditions in multithreaded scenarios (specifying for `mode`), see the constructor. - - The example defines a `LargeObject` class that will be initialized lazily by any of several threads. The three key sections of code illustrate the creation of the initializer, the actual initialization, and the constructor and finalizer of the `LargeObject` class. At the beginning of the `Main` method, the example creates the object that performs lazy initialization of the `LargeObject`: - +> For an example that demonstrates how to use this constructor in single-threaded scenarios (specifying for `mode`), see the constructor. For an example that demonstrates how to use this constructor to provide locking instead of race conditions in multithreaded scenarios (specifying for `mode`), see the constructor. + + The example defines a `LargeObject` class that will be initialized lazily by any of several threads. The three key sections of code illustrate the creation of the initializer, the actual initialization, and the constructor and finalizer of the `LargeObject` class. At the beginning of the `Main` method, the example creates the object that performs lazy initialization of the `LargeObject`: + :::code language="csharp" source="~/snippets/csharp/System/LazyT/.ctor/example5.cs" id="Snippetnewlazy"::: :::code language="fsharp" source="~/snippets/fsharp/System/LazyT/.ctor/example5.fs" id="Snippetnewlazy"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.lazy`1.ctorltsm/vb/example.vb" id="Snippetnewlazy"::: - - The example creates and starts three threads that block on a object, so that the example can release the threads all at once. In the `ThreadProc` method that's used by all three threads, calling the property creates the `LargeObject` instance: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.lazy`1.ctorltsm/vb/example.vb" id="Snippetnewlazy"::: + + The example creates and starts three threads that block on a object, so that the example can release the threads all at once. In the `ThreadProc` method that's used by all three threads, calling the property creates the `LargeObject` instance: + :::code language="csharp" source="~/snippets/csharp/System/LazyT/.ctor/example5.cs" id="Snippetvalueprop"::: :::code language="fsharp" source="~/snippets/fsharp/System/LazyT/.ctor/example5.fs" id="Snippetvalueprop"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.lazy`1.ctorltsm/vb/example.vb" id="Snippetvalueprop"::: - - Because the constructor for the instance specified , all three threads are allowed to create `LargeObject` instances. The example demonstrates this by displaying console messages in the constructor and in the finalizer of the `LargeObject` class: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.lazy`1.ctorltsm/vb/example.vb" id="Snippetvalueprop"::: + + Because the constructor for the instance specified , all three threads are allowed to create `LargeObject` instances. The example demonstrates this by displaying console messages in the constructor and in the finalizer of the `LargeObject` class: + :::code language="csharp" source="~/snippets/csharp/System/LazyT/.ctor/example5.cs" id="Snippetctorfinalizer"::: :::code language="fsharp" source="~/snippets/fsharp/System/LazyT/.ctor/example5.fs" id="Snippetctorfinalizer"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.lazy`1.ctorltsm/vb/example.vb" id="Snippetctorfinalizer"::: - - However, the object ensures that only one instance is used by all threads. The output from the example shows that all three threads use the same instance, and also shows that the other two instances can be reclaimed by garbage collection. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.lazy`1.ctorltsm/vb/example.vb" id="Snippetctorfinalizer"::: + + However, the object ensures that only one instance is used by all threads. The output from the example shows that all three threads use the same instance, and also shows that the other two instances can be reclaimed by garbage collection. + > [!NOTE] -> For simplicity, this example uses a global instance of , and all the methods are `static` (`Shared` in Visual Basic). These are not requirements for the use of lazy initialization. - +> For simplicity, this example uses a global instance of , and all the methods are `static` (`Shared` in Visual Basic). These are not requirements for the use of lazy initialization. + :::code language="csharp" source="~/snippets/csharp/System/LazyT/.ctor/example5.cs" id="Snippetall"::: :::code language="fsharp" source="~/snippets/fsharp/System/LazyT/.ctor/example5.fs" id="Snippetall"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.lazy`1.ctorltsm/vb/example.vb" id="Snippetall"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.lazy`1.ctorltsm/vb/example.vb" id="Snippetall"::: + ]]> @@ -620,50 +620,50 @@ An instance created with this constructor is usable by multiple threads concurre to make this instance usable concurrently by multiple threads; to make this instance usable by only one thread at a time. Initializes a new instance of the class. When lazy initialization occurs, the specified initialization function and initialization mode are used. - instance that is initialized with this constructor is if `isThreadSafe` is `true`; otherwise, the mode is . The thread safety mode describes the behavior when multiple threads try to initialize the instance. - - To specify the mode, use the or constructor. - - Exceptions that are thrown by `valueFactory` are cached. For more information, see the class or the enumeration. - - - -## Examples - The following example demonstrates the use of this constructor to provide lazy initialization with exception caching, in a scenario with a single thread. It also demonstrates the use of the constructor (specifying for `mode`). To switch to that constructor, just change which constructor is commented out. - + instance that is initialized with this constructor is if `isThreadSafe` is `true`; otherwise, the mode is . The thread safety mode describes the behavior when multiple threads try to initialize the instance. + + To specify the mode, use the or constructor. + + Exceptions that are thrown by `valueFactory` are cached. For more information, see the class or the enumeration. + + + +## Examples + The following example demonstrates the use of this constructor to provide lazy initialization with exception caching, in a scenario with a single thread. It also demonstrates the use of the constructor (specifying for `mode`). To switch to that constructor, just change which constructor is commented out. + > [!NOTE] -> For code that demonstrates how to use this constructor in multithreaded scenarios (specifying `true` for `isThreadSafe`), see the example for the constructor. - - The example defines a `LargeObject` class that will be initialized lazily by one of several threads. The three key sections of code illustrate the creation of the initializer, the actual initialization, and the constructor of the `LargeObject` class, which demonstrates exception caching. At the beginning of the `Main` method, the example creates the thread-safe lazy initializer for `LargeObject`: - +> For code that demonstrates how to use this constructor in multithreaded scenarios (specifying `true` for `isThreadSafe`), see the example for the constructor. + + The example defines a `LargeObject` class that will be initialized lazily by one of several threads. The three key sections of code illustrate the creation of the initializer, the actual initialization, and the constructor of the `LargeObject` class, which demonstrates exception caching. At the beginning of the `Main` method, the example creates the thread-safe lazy initializer for `LargeObject`: + :::code language="csharp" source="~/snippets/csharp/System/LazyT/.ctor/example3.cs" id="Snippetnewlazy"::: :::code language="fsharp" source="~/snippets/fsharp/System/LazyT/.ctor/example3.fs" id="Snippetnewlazy"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.lazy`1.ctorfuncbool/vb/example.vb" id="Snippetnewlazy"::: - - In the call to the constructor, the `isThreadSafe` parameter is `false`, so the is not thread safe. Because it's not thread safe, the example calls the property three times on the same thread: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.lazy`1.ctorfuncbool/vb/example.vb" id="Snippetnewlazy"::: + + In the call to the constructor, the `isThreadSafe` parameter is `false`, so the is not thread safe. Because it's not thread safe, the example calls the property three times on the same thread: + :::code language="csharp" source="~/snippets/csharp/System/LazyT/.ctor/example3.cs" id="Snippetvalueprop"::: :::code language="fsharp" source="~/snippets/fsharp/System/LazyT/.ctor/example3.fs" id="Snippetvalueprop"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.lazy`1.ctorfuncbool/vb/example.vb" id="Snippetvalueprop"::: - - In the constructor of the `LargeObject` class, the third key section of code throws an exception the first time a `LargeObject` instance is created, but thereafter allows instance creation to occur: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.lazy`1.ctorfuncbool/vb/example.vb" id="Snippetvalueprop"::: + + In the constructor of the `LargeObject` class, the third key section of code throws an exception the first time a `LargeObject` instance is created, but thereafter allows instance creation to occur: + :::code language="csharp" source="~/snippets/csharp/System/LazyT/.ctor/example3.cs" id="Snippetlargector"::: :::code language="fsharp" source="~/snippets/fsharp/System/LazyT/.ctor/example3.fs" id="Snippetlargector"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.lazy`1.ctorfuncbool/vb/example.vb" id="Snippetlargector"::: - - When the example is run, the first attempt to create an instance of `LargeObject` fails, and the exception is caught. You might expect that the next attempt would succeed, but the object has cached the exception. Because of this, all three attempts throw the exception. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.lazy`1.ctorfuncbool/vb/example.vb" id="Snippetlargector"::: + + When the example is run, the first attempt to create an instance of `LargeObject` fails, and the exception is caught. You might expect that the next attempt would succeed, but the object has cached the exception. Because of this, all three attempts throw the exception. + > [!NOTE] -> For simplicity, this example uses a global instance of , and all the methods are `static` (`Shared` in Visual Basic). These are not requirements for the use of lazy initialization. - +> For simplicity, this example uses a global instance of , and all the methods are `static` (`Shared` in Visual Basic). These are not requirements for the use of lazy initialization. + :::code language="csharp" source="~/snippets/csharp/System/LazyT/.ctor/example3.cs" id="Snippetall"::: :::code language="fsharp" source="~/snippets/fsharp/System/LazyT/.ctor/example3.fs" id="Snippetall"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.lazy`1.ctorfuncbool/vb/example.vb" id="Snippetall"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.lazy`1.ctorfuncbool/vb/example.vb" id="Snippetall"::: + ]]> @@ -715,61 +715,61 @@ An instance created with this constructor is usable by multiple threads concurre One of the enumeration values that specifies the thread safety mode. Initializes a new instance of the class that uses the specified initialization function and thread-safety mode. - instance describes the behavior when multiple threads try to initialize the instance. - - Exceptions that are thrown by `valueFactory` are cached, unless `mode` is . For more information, see the class or the enumeration. - - - -## Examples - The following example demonstrates the use of this constructor to create a lazy initializer that enables multiple threads to race to create an object lazily. Multiple threads might succeed in creating instances, but all threads use the instance that was created first. In addition, the example demonstrates that exceptions are never cached when you specify , even if initialization is performed by a function instead of by the parameterless constructor of the lazily created type. - + instance describes the behavior when multiple threads try to initialize the instance. + + Exceptions that are thrown by `valueFactory` are cached, unless `mode` is . For more information, see the class or the enumeration. + + + +## Examples + The following example demonstrates the use of this constructor to create a lazy initializer that enables multiple threads to race to create an object lazily. Multiple threads might succeed in creating instances, but all threads use the instance that was created first. In addition, the example demonstrates that exceptions are never cached when you specify , even if initialization is performed by a function instead of by the parameterless constructor of the lazily created type. + > [!NOTE] -> For an example that demonstrates how to use this constructor in single-threaded scenarios (specifying for `mode`), see the constructor. For an example that demonstrates how to use this constructor to provide locking instead of race conditions in multithreaded scenarios (specifying for `mode`), see the constructor. - - The example defines a `LargeObject` class that will be initialized lazily by any of several threads. The four key sections of code illustrate the creation of the initializer, the actual initialization, the initialization function, and the constructor and finalizer of the `LargeObject` class. At the beginning of the `Main` method, the example creates the object that performs lazy initialization of the `LargeObject`: - +> For an example that demonstrates how to use this constructor in single-threaded scenarios (specifying for `mode`), see the constructor. For an example that demonstrates how to use this constructor to provide locking instead of race conditions in multithreaded scenarios (specifying for `mode`), see the constructor. + + The example defines a `LargeObject` class that will be initialized lazily by any of several threads. The four key sections of code illustrate the creation of the initializer, the actual initialization, the initialization function, and the constructor and finalizer of the `LargeObject` class. At the beginning of the `Main` method, the example creates the object that performs lazy initialization of the `LargeObject`: + :::code language="csharp" source="~/snippets/csharp/System/LazyT/.ctor/example4.cs" id="Snippetnewlazy"::: :::code language="fsharp" source="~/snippets/fsharp/System/LazyT/.ctor/example4.fs" id="Snippetnewlazy"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.lazy`1.ctorfuncltsm/vb/example.vb" id="Snippetnewlazy"::: - - The lazy initializer uses a function to perform the initialization. In this case, a function is required because there is no parameterless constructor for the `LargeObject` class. - - The example creates and starts three threads that block on a object, so that the example can release the threads all at once. In the `ThreadProc` method that's used by all three threads, calling the property creates the `LargeObject` instance: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.lazy`1.ctorfuncltsm/vb/example.vb" id="Snippetnewlazy"::: + + The lazy initializer uses a function to perform the initialization. In this case, a function is required because there is no parameterless constructor for the `LargeObject` class. + + The example creates and starts three threads that block on a object, so that the example can release the threads all at once. In the `ThreadProc` method that's used by all three threads, calling the property creates the `LargeObject` instance: + :::code language="csharp" source="~/snippets/csharp/System/LazyT/.ctor/example4.cs" id="Snippetvalueprop"::: :::code language="fsharp" source="~/snippets/fsharp/System/LazyT/.ctor/example4.fs" id="Snippetvalueprop"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.lazy`1.ctorfuncltsm/vb/example.vb" id="Snippetvalueprop"::: - - In the third key section of code, the lazy initialization function is called to create the `LargeObject` instance. The function throws an exception the first time it's called: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.lazy`1.ctorfuncltsm/vb/example.vb" id="Snippetvalueprop"::: + + In the third key section of code, the lazy initialization function is called to create the `LargeObject` instance. The function throws an exception the first time it's called: + :::code language="csharp" source="~/snippets/csharp/System/LazyT/.ctor/example4.cs" id="Snippetfactoryfunc"::: :::code language="fsharp" source="~/snippets/fsharp/System/LazyT/.ctor/example4.fs" id="Snippetfactoryfunc"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.lazy`1.ctorfuncltsm/vb/example.vb" id="Snippetfactoryfunc"::: - - With any other setting, an unhandled exception in the initialization function would be cached. However, suppresses exception caching. The output from the example demonstrates that a subsequent attempt to initialize the object succeeds. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.lazy`1.ctorfuncltsm/vb/example.vb" id="Snippetfactoryfunc"::: + + With any other setting, an unhandled exception in the initialization function would be cached. However, suppresses exception caching. The output from the example demonstrates that a subsequent attempt to initialize the object succeeds. + > [!NOTE] -> The exception message usually appears after messages indicating that other threads have successfully initialized the object. This is because of the delay introduced by throwing and catching the exception. - - Because the constructor for the instance specified , all three threads are allowed to create `LargeObject` instances. The example demonstrates this by displaying console messages in the constructor and in the finalizer of the `LargeObject` class: - +> The exception message usually appears after messages indicating that other threads have successfully initialized the object. This is because of the delay introduced by throwing and catching the exception. + + Because the constructor for the instance specified , all three threads are allowed to create `LargeObject` instances. The example demonstrates this by displaying console messages in the constructor and in the finalizer of the `LargeObject` class: + :::code language="csharp" source="~/snippets/csharp/System/LazyT/.ctor/example4.cs" id="Snippetctorfinalizer"::: :::code language="fsharp" source="~/snippets/fsharp/System/LazyT/.ctor/example4.fs" id="Snippetctorfinalizer"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.lazy`1.ctorfuncltsm/vb/example.vb" id="Snippetctorfinalizer"::: - - The object ensures that only one instance is used by all threads (except the thread where the initialization function throws an exception). The output from the example shows this. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.lazy`1.ctorfuncltsm/vb/example.vb" id="Snippetctorfinalizer"::: + + The object ensures that only one instance is used by all threads (except the thread where the initialization function throws an exception). The output from the example shows this. + > [!NOTE] -> For simplicity, this example uses a global instance of , and all the methods are `static` (`Shared` in Visual Basic). These are not requirements for the use of lazy initialization. - +> For simplicity, this example uses a global instance of , and all the methods are `static` (`Shared` in Visual Basic). These are not requirements for the use of lazy initialization. + :::code language="csharp" source="~/snippets/csharp/System/LazyT/.ctor/example4.cs" id="Snippetall"::: :::code language="fsharp" source="~/snippets/fsharp/System/LazyT/.ctor/example4.fs" id="Snippetall"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.lazy`1.ctorfuncltsm/vb/example.vb" id="Snippetall"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.lazy`1.ctorfuncltsm/vb/example.vb" id="Snippetall"::: + ]]> @@ -828,15 +828,15 @@ An instance created with this constructor is usable by multiple threads concurre if a value has been created for this instance; otherwise, . - instance, it may result in either a value being created or an exception being thrown. If an exception is thrown, subsequent behavior of the instance depends on whether exception caching is in effect. If the instance was created by using a constructor that does not specify an initialization function, then exception caching is not in effect. A subsequent attempt to initialize the might succeed, and after successful initialization the property returns `true`. If the instance was created with an initialization function (specified by the `valueFactory` parameter of the constructor), then exception caching is controlled by the thread safety mode. - -- If the mode is or , there is no second chance to initialize the instance. If an exception occurs and is unhandled in the initialization function, that exception is cached and rethrown on subsequent accesses of the property. No value is created if an exception is thrown, so in such cases returns `false`. - -- If the mode is , the first thread that succeeds in running the initialization function (or the parameterless constructor) creates the value for the instance. If the initialization function throws an exception on one thread, other threads can still try to initialize the instance. Until the value is created, the property returns `false`. - + instance, it may result in either a value being created or an exception being thrown. If an exception is thrown, subsequent behavior of the instance depends on whether exception caching is in effect. If the instance was created by using a constructor that does not specify an initialization function, then exception caching is not in effect. A subsequent attempt to initialize the might succeed, and after successful initialization the property returns `true`. If the instance was created with an initialization function (specified by the `valueFactory` parameter of the constructor), then exception caching is controlled by the thread safety mode. + +- If the mode is or , there is no second chance to initialize the instance. If an exception occurs and is unhandled in the initialization function, that exception is cached and rethrown on subsequent accesses of the property. No value is created if an exception is thrown, so in such cases returns `false`. + +- If the mode is , the first thread that succeeds in running the initialization function (or the parameterless constructor) creates the value for the instance. If the initialization function throws an exception on one thread, other threads can still try to initialize the instance. Until the value is created, the property returns `false`. + ]]> @@ -893,13 +893,13 @@ An instance created with this constructor is usable by multiple threads concurre Creates and returns a string representation of the property for this instance. The result of calling the method on the property for this instance, if the value has been created (that is, if the property returns ). Otherwise, a string indicating that the value has not been created. - property can be `null` after lazy initialization if the factory method that was specified for the `valueFactory` parameter of the , , or constructor returns `null`. - + property can be `null` after lazy initialization if the factory method that was specified for the `valueFactory` parameter of the , , or constructor returns `null`. + ]]> The property is . @@ -953,13 +953,13 @@ An instance created with this constructor is usable by multiple threads concurre Gets the lazily initialized value of the current instance. The lazily initialized value of the current instance. - property is `false`, accessing the property forces initialization. - - In addition to the exceptions that are listed, the property can throw any unhandled exception that is thrown by the factory method that was passed to the `valueFactory` parameter of the , , or constructor. - + property is `false`, accessing the property forces initialization. + + In addition to the exceptions that are listed, the property can throw any unhandled exception that is thrown by the factory method that was passed to the `valueFactory` parameter of the , , or constructor. + ]]> The instance is initialized to use the parameterless constructor of the type that is being lazily initialized, and permissions to access the constructor are missing. diff --git a/xml/System/Lazy`2.xml b/xml/System/Lazy`2.xml index 36f4c1bfd05..17e064c2c8d 100644 --- a/xml/System/Lazy`2.xml +++ b/xml/System/Lazy`2.xml @@ -295,11 +295,11 @@ The thread synchronization mode. Initializes a new instance of the class with the specified metadata and thread synchronization mode. - for more information on thread synchronization and . - + for more information on thread synchronization and . + ]]> @@ -404,11 +404,11 @@ The thread synchronization mode. Initializes a new instance of the class with the specified metadata and thread synchronization mode that uses the specified function to get the referenced object. - for more information on thread synchronization and . - + for more information on thread synchronization and . + ]]>
diff --git a/xml/System/LdapStyleUriParser.xml b/xml/System/LdapStyleUriParser.xml index e6469f69323..7022c346db8 100644 --- a/xml/System/LdapStyleUriParser.xml +++ b/xml/System/LdapStyleUriParser.xml @@ -73,11 +73,11 @@ Creates a customizable parser based on the Lightweight Directory Access Protocol (LDAP) scheme. - - + + ]]> diff --git a/xml/System/LoaderOptimization.xml b/xml/System/LoaderOptimization.xml index 10a674678c1..248e6dce777 100644 --- a/xml/System/LoaderOptimization.xml +++ b/xml/System/LoaderOptimization.xml @@ -57,16 +57,16 @@ An enumeration used with the class to specify loader optimizations for an executable. - [!NOTE] -> **.NET Framework only:** If custom code access security policy is set for the , by using the property, and the is created using the `MultiDomain` flag, the effect is the same as specifying the `MultiDomainHost` flag; that is, only assemblies in the GAC are shared. When this occurs, the loader does not throw an exception and the application does not experience the performance gains associated with the `MultiDomain` flag. - +> **.NET Framework only:** If custom code access security policy is set for the , by using the property, and the is created using the `MultiDomain` flag, the effect is the same as specifying the `MultiDomainHost` flag; that is, only assemblies in the GAC are shared. When this occurs, the loader does not throw an exception and the application does not experience the performance gains associated with the `MultiDomain` flag. + For more information on assembly sharing and domain-neutral assembly loading, see [Application Domains and Assemblies](/dotnet/framework/app-domains/application-domains#application-domains-and-assemblies). - + ]]> diff --git a/xml/System/LoaderOptimizationAttribute.xml b/xml/System/LoaderOptimizationAttribute.xml index 2f5f8846a58..8287119b153 100644 --- a/xml/System/LoaderOptimizationAttribute.xml +++ b/xml/System/LoaderOptimizationAttribute.xml @@ -57,18 +57,18 @@ Used to set the default loader optimization policy for the main method of an executable application. - can only be set on the main method for an executable application and is ignored on all other methods. - - The attribute is specified with a enumeration value, which tells the loader what type of application to optimize for: `SingleDomain`, `MultiDomain`, or `MultiDomainHost`. - - This attribute is only a hint to the loader and does not affect program behavior. - + can only be set on the main method for an executable application and is ignored on all other methods. + + The attribute is specified with a enumeration value, which tells the loader what type of application to optimize for: `SingleDomain`, `MultiDomain`, or `MultiDomainHost`. + + This attribute is only a hint to the loader and does not affect program behavior. + > [!NOTE] -> If custom code access security policy is set for the , by using the property, and the is created using the flag, the effect is the same as specifying the flag; that is, only assemblies in the GAC are shared. When this occurs, the loader does not throw an exception and the application does not experience the performance gains associated with the flag. - +> If custom code access security policy is set for the , by using the property, and the is created using the flag, the effect is the same as specifying the flag; that is, only assemblies in the GAC are shared. When this occurs, the loader does not throw an exception and the application does not experience the performance gains associated with the flag. + ]]> diff --git a/xml/System/LocalDataStoreSlot.xml b/xml/System/LocalDataStoreSlot.xml index f0ce4ac9420..a7937eed265 100644 --- a/xml/System/LocalDataStoreSlot.xml +++ b/xml/System/LocalDataStoreSlot.xml @@ -46,25 +46,25 @@ Encapsulates a memory slot to store local data. This class cannot be inherited. - attribute. They provide better performance than data slots, and enable compile-time type checking. - -- Data slots are slower and more awkward to use than thread-relative static fields. Also, data is stored as type , so you must cast it to the correct type before using it. However, you can use data slots when you have insufficient information at compile time to allocate static fields. - - For more information about using TLS, see [Thread Local Storage: Thread-Relative Static Fields and Data Slots](/dotnet/standard/threading/thread-local-storage-thread-relative-static-fields-and-data-slots). - - Similarly, the .NET Framework provides two mechanisms for using context local storage: context-relative static fields and data slots. Context-relative static fields are static fields that are marked with the attribute. The trade-offs between using these two mechanisms are similar to the tradeoffs between using thread-relative static fields and data slots. - - The structure serves as a local store memory mechanism that threads and contexts can use to store thread-specific and context-specific data, respectively. The common language runtime allocates a multi-slot data store array to each process when it is created. The thread or context calls various functions to allocate a data slot in the data store, to store and retrieve a data value in the slot, and to free a data slot for reuse after the thread or context object expires. - - The data slots are unique per thread or context; their values are not shared between the thread or context objects. Data slots can be allocated by a name or by an index number. - - For more information about storing local data, see or . The class is used with methods such as , , , and ; it does not have any methods of its own that you need to use. - + attribute. They provide better performance than data slots, and enable compile-time type checking. + +- Data slots are slower and more awkward to use than thread-relative static fields. Also, data is stored as type , so you must cast it to the correct type before using it. However, you can use data slots when you have insufficient information at compile time to allocate static fields. + + For more information about using TLS, see [Thread Local Storage: Thread-Relative Static Fields and Data Slots](/dotnet/standard/threading/thread-local-storage-thread-relative-static-fields-and-data-slots). + + Similarly, the .NET Framework provides two mechanisms for using context local storage: context-relative static fields and data slots. Context-relative static fields are static fields that are marked with the attribute. The trade-offs between using these two mechanisms are similar to the tradeoffs between using thread-relative static fields and data slots. + + The structure serves as a local store memory mechanism that threads and contexts can use to store thread-specific and context-specific data, respectively. The common language runtime allocates a multi-slot data store array to each process when it is created. The thread or context calls various functions to allocate a data slot in the data store, to store and retrieve a data value in the slot, and to free a data slot for reuse after the thread or context object expires. + + The data slots are unique per thread or context; their values are not shared between the thread or context objects. Data slots can be allocated by a name or by an index number. + + For more information about storing local data, see or . The class is used with methods such as , , , and ; it does not have any methods of its own that you need to use. + ]]> @@ -106,11 +106,11 @@ Ensures that resources are freed and other cleanup operations are performed when the garbage collector reclaims the object. - when the current object is ready to be finalized. - + when the current object is ready to be finalized. + ]]> diff --git a/xml/System/MTAThreadAttribute.xml b/xml/System/MTAThreadAttribute.xml index 2cc8899a103..cfdfec9b0eb 100644 --- a/xml/System/MTAThreadAttribute.xml +++ b/xml/System/MTAThreadAttribute.xml @@ -55,32 +55,32 @@ Indicates that the COM threading model for an application is multithreaded apartment (MTA). - or method before starting the thread. - + or method before starting the thread. + > [!NOTE] -> For an overview of COM threading models, see [Understanding and Using COM Threading Models](https://docs.microsoft.com/previous-versions/ms809971(v=msdn.10)). - - COM threading models only apply to applications that use COM interop. The COM threading model can be set to single-threaded apartment or multithreaded apartment. The application thread is only initialized for COM interop if the thread actually makes a call to a COM component. If COM interop is not used, then the thread is not initialized, and the attribute, if it is present, has no effect. - - Starting with the .NET Framework version 2.0, the default threading model for COM interop depends on the language in which you are developing your application, as the following table shows. - -|Language|COM apartment model| -|--------------|-------------------------| -|C#|Multithreaded apartment| -|C++|Multithreaded apartment| -|Visual Basic|Single-threaded apartment| - - To change these defaults, you use the attribute to set the threading model for the application, or call the or method before starting the thread to set the threading model for a particular thread. In C++, you can also use the [/CLRTHREADATTRIBUTE (Set CLR Thread Attribute)](/cpp/build/reference/clrthreadattribute-set-clr-thread-attribute) linker option to specify the apartment model. - - Some of the cases in which you want to use the attribute to explicitly set the threading model to multithreaded apartment include the following: - -- You're developing a Visual Basic app that calls to a C# library that in turn relies on COM interop. Because the multithreaded apartment model is the default for C#, you should change your app's threading model to multithreaded by using the attribute. - -- Your application makes calls to COM components that use the multithreaded apartment model. - +> For an overview of COM threading models, see [Understanding and Using COM Threading Models](https://docs.microsoft.com/previous-versions/ms809971(v=msdn.10)). + + COM threading models only apply to applications that use COM interop. The COM threading model can be set to single-threaded apartment or multithreaded apartment. The application thread is only initialized for COM interop if the thread actually makes a call to a COM component. If COM interop is not used, then the thread is not initialized, and the attribute, if it is present, has no effect. + + Starting with the .NET Framework version 2.0, the default threading model for COM interop depends on the language in which you are developing your application, as the following table shows. + +|Language|COM apartment model| +|--------------|-------------------------| +|C#|Multithreaded apartment| +|C++|Multithreaded apartment| +|Visual Basic|Single-threaded apartment| + + To change these defaults, you use the attribute to set the threading model for the application, or call the or method before starting the thread to set the threading model for a particular thread. In C++, you can also use the [/CLRTHREADATTRIBUTE (Set CLR Thread Attribute)](/cpp/build/reference/clrthreadattribute-set-clr-thread-attribute) linker option to specify the apartment model. + + Some of the cases in which you want to use the attribute to explicitly set the threading model to multithreaded apartment include the following: + +- You're developing a Visual Basic app that calls to a C# library that in turn relies on COM interop. Because the multithreaded apartment model is the default for C#, you should change your app's threading model to multithreaded by using the attribute. + +- Your application makes calls to COM components that use the multithreaded apartment model. + ]]> diff --git a/xml/System/MarshalByRefObject.xml b/xml/System/MarshalByRefObject.xml index c279af5ea52..9b930f69099 100644 --- a/xml/System/MarshalByRefObject.xml +++ b/xml/System/MarshalByRefObject.xml @@ -60,45 +60,45 @@ Enables access to objects across application domain boundaries in applications that support remoting. - is the base class for objects that communicate across application domain boundaries by exchanging messages using a proxy. Objects that do not inherit from are implicitly marshal by value. When a remote application references a marshal by value object, a copy of the object is passed across application domain boundaries. - - objects are accessed directly within the boundaries of the local application domain. The first time an application in a remote application domain accesses a , a proxy is passed to the remote application. Subsequent calls on the proxy are marshaled back to the object residing in the local application domain. - - Types must inherit from when the type is used across application domain boundaries, and the state of the object must not be copied because the members of the object are not usable outside the application domain where they were created. - - When you derive an object from for use across application domain boundaries, you should not override any of its members, nor should you call its methods directly. The runtime recognizes that classes derived from should be marshaled across app domain boundaries. - - - -## Examples - This section contains two code examples. The first code example shows how to create an instance of a class in another application domain. The second code example shows a simple class that can be used for remoting. - - **Example 1** - - The following code example shows the simplest way to execute code in another application domain. The example defines a class named `Worker` that inherits , with a method that displays the name of the application domain in which it is executing. The example creates instances of `Worker` in the default application domain and in a new application domain. - + is the base class for objects that communicate across application domain boundaries by exchanging messages using a proxy. Objects that do not inherit from are implicitly marshal by value. When a remote application references a marshal by value object, a copy of the object is passed across application domain boundaries. + + objects are accessed directly within the boundaries of the local application domain. The first time an application in a remote application domain accesses a , a proxy is passed to the remote application. Subsequent calls on the proxy are marshaled back to the object residing in the local application domain. + + Types must inherit from when the type is used across application domain boundaries, and the state of the object must not be copied because the members of the object are not usable outside the application domain where they were created. + + When you derive an object from for use across application domain boundaries, you should not override any of its members, nor should you call its methods directly. The runtime recognizes that classes derived from should be marshaled across app domain boundaries. + + + +## Examples + This section contains two code examples. The first code example shows how to create an instance of a class in another application domain. The second code example shows a simple class that can be used for remoting. + + **Example 1** + + The following code example shows the simplest way to execute code in another application domain. The example defines a class named `Worker` that inherits , with a method that displays the name of the application domain in which it is executing. The example creates instances of `Worker` in the default application domain and in a new application domain. + > [!NOTE] -> The assembly that contains `Worker` must be loaded into both application domains, but it could load other assemblies that would exist only in the new application domain. - +> The assembly that contains `Worker` must be loaded into both application domains, but it could load other assemblies that would exist only in the new application domain. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/CreateInstanceAndUnwrap2/cpp/source.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/AppDomain/CreateInstanceAndUnwrap/source.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/CreateInstanceAndUnwrap/source.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/CreateInstanceAndUnwrap2/VB/source.vb" id="Snippet1"::: - - **Example 2** - - The following example demonstrates a class derived from that is used later in remoting. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/CreateInstanceAndUnwrap2/VB/source.vb" id="Snippet1"::: + + **Example 2** + + The following example demonstrates a class derived from that is used later in remoting. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/RemotingServices.SetObjectUriForMarshal/CPP/source.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/MarshalByRefObject/Overview/source.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/MarshalByRefObject/Overview/source.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/RemotingServices.SetObjectUriForMarshal/VB/source.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/RemotingServices.SetObjectUriForMarshal/VB/source.vb" id="Snippet1"::: + ]]> @@ -176,11 +176,11 @@ Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. Information required to generate a proxy. - method is called by remote object creation methods such as and . In most cases, there is no need to override this method. - + method is called by remote object creation methods such as and . In most cases, there is no need to override this method. + ]]> This instance is not a valid remoting object. @@ -238,14 +238,14 @@ Retrieves the current lifetime service object that controls the lifetime policy for this instance. An object of type used to control the lifetime policy for this instance. - class. - +For more information about lifetime services, see the class. + ]]> The immediate caller does not have infrastructure permission. @@ -300,22 +300,22 @@ For more information about lifetime services, see the Obtains a lifetime service object to control the lifetime policy for this instance. An object of type used to control the lifetime policy for this instance. This is the current lifetime service object for this instance if one exists; otherwise, a new lifetime service object initialized to the value of the property. - class. -## Examples - The following code example demonstrates creating a lease. - +## Examples + The following code example demonstrates creating a lease. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_Classic/classic MarshalByRefObject.InitializeLifetimeService Example/CPP/source.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/MarshalByRefObject/InitializeLifetimeService/source.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/MarshalByRefObject/InitializeLifetimeService/source.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_Classic/classic MarshalByRefObject.InitializeLifetimeService Example/VB/source.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_Classic/classic MarshalByRefObject.InitializeLifetimeService Example/VB/source.vb" id="Snippet1"::: + ]]> The immediate caller does not have infrastructure permission. @@ -373,15 +373,15 @@ For more information about lifetime services, see the Creates a shallow copy of the current object. A shallow copy of the current object. - method creates a shallow copy by creating a new object, and then copying the nonstatic fields of the current object to the new object. If a field is a value type, a bit-by-bit copy of the field is performed. If a field is a reference type, the reference is copied but the referred object is not; therefore, the original object and its clone refer to the same object. - - For example, consider a object called X that references objects A and B. Object B, in turn, references object C. A shallow copy of X creates new object X2 that also references objects A and B. In contrast, a deep copy of X creates a new object X2 that references the new objects A2 and B2, which are copies of A and B. B2, in turn, references the new object C2, which is a copy C. Use a class that implements the interface to perform a deep or shallow copy of an object. - - The identity of a object is defined as the remote server object that is the target of a remoting client call. By default, the memberwise clone of a object has the same identity as the original object, which is typically not the correct behavior for clones of server-side objects that are marshaled across a remoting boundary to the client side. Specify `false`, which is usually appropriate, to delete the identity of the clone and cause a new identity to be assigned when the clone is marshaled across a remoting boundary, or `true` to cause the clone to retain the identity of the original object. The method is intended to be used by developers implementing remote server objects. - + method creates a shallow copy by creating a new object, and then copying the nonstatic fields of the current object to the new object. If a field is a value type, a bit-by-bit copy of the field is performed. If a field is a reference type, the reference is copied but the referred object is not; therefore, the original object and its clone refer to the same object. + + For example, consider a object called X that references objects A and B. Object B, in turn, references object C. A shallow copy of X creates new object X2 that also references objects A and B. In contrast, a deep copy of X creates a new object X2 that references the new objects A2 and B2, which are copies of A and B. B2, in turn, references the new object C2, which is a copy C. Use a class that implements the interface to perform a deep or shallow copy of an object. + + The identity of a object is defined as the remote server object that is the target of a remoting client call. By default, the memberwise clone of a object has the same identity as the original object, which is typically not the correct behavior for clones of server-side objects that are marshaled across a remoting boundary to the client side. Specify `false`, which is usually appropriate, to delete the identity of the clone and cause a new identity to be assigned when the clone is marshaled across a remoting boundary, or `true` to cause the clone to retain the identity of the original object. The method is intended to be used by developers implementing remote server objects. + ]]> diff --git a/xml/System/Math.xml b/xml/System/Math.xml index eb7ab42d3b8..86160ec1c18 100644 --- a/xml/System/Math.xml +++ b/xml/System/Math.xml @@ -55,16 +55,16 @@ Provides constants and static methods for trigonometric, logarithmic, and other common mathematical functions. - class to calculate the inner angles of a trapezoid. + class to calculate the inner angles of a trapezoid. :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/MathSample/CPP/mathsample.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Math/Overview/mathsample.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Math/Overview/mathsample.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/MathSample/VB/mathsample.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/MathSample/VB/mathsample.vb" id="Snippet1"::: + ]]> @@ -134,19 +134,19 @@ Returns the absolute value of a number. A decimal number, x, such that 0 ≤ x ≤ Decimal.MaxValue. - is its numeric value without its sign. For example, the absolute value of both 1.2 and -1.2 is 1.2. - - - -## Examples - The following example uses the method to get the absolute value of a number of values. - + is its numeric value without its sign. For example, the absolute value of both 1.2 and -1.2 is 1.2. + + + +## Examples + The following example uses the method to get the absolute value of a number of values. + :::code language="csharp" source="~/snippets/csharp/System/Math/Abs/Abs1.cs" interactive="try-dotnet-method" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Math/Abs/Abs1.fs" id="Snippet1"::: - + ]]> @@ -204,22 +204,22 @@ Returns the absolute value of a double-precision floating-point number. A double-precision floating-point number, x, such that 0 ≤ x ≤ Double.MaxValue. - is its numeric value without its sign. For example, the absolute value of both 1.2e03 and -1.2e03 is 1.2e03. - - If `value` is equal to or , the return value is . If `value` is equal to , the return value is . - - - -## Examples - The following example uses the method to get the absolute value of a number of values. - + is its numeric value without its sign. For example, the absolute value of both 1.2e03 and -1.2e03 is 1.2e03. + + If `value` is equal to or , the return value is . If `value` is equal to , the return value is . + + + +## Examples + The following example uses the method to get the absolute value of a number of values. + :::code language="csharp" source="~/snippets/csharp/System/Math/Abs/abs2.cs" interactive="try-dotnet-method" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/Math/Abs/abs2.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Math.Abs/vb/abs2.vb" id="Snippet2"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Math.Abs/vb/abs2.vb" id="Snippet2"::: + ]]> @@ -277,20 +277,20 @@ Returns the absolute value of a 16-bit signed integer. A 16-bit signed integer, x, such that 0 ≤ x ≤ Int16.MaxValue. - is its numeric value without its sign. For example, the absolute value of both 123 and -123 is 123. - - - -## Examples - The following example uses the method to get the absolute value of a number of values. - + is its numeric value without its sign. For example, the absolute value of both 123 and -123 is 123. + + + +## Examples + The following example uses the method to get the absolute value of a number of values. + :::code language="csharp" source="~/snippets/csharp/System/Math/Abs/abs3.cs" interactive="try-dotnet-method" id="Snippet3"::: :::code language="fsharp" source="~/snippets/fsharp/System/Math/Abs/abs3.fs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Math.Abs/vb/abs3.vb" id="Snippet3"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Math.Abs/vb/abs3.vb" id="Snippet3"::: + ]]> @@ -350,20 +350,20 @@ Returns the absolute value of a 32-bit signed integer. A 32-bit signed integer, x, such that 0 ≤ x ≤ Int32.MaxValue. - is its numeric value without its sign. For example, the absolute value of both 123 and -123 is 123. - - - -## Examples - The following example uses the method to get the absolute value of a number of values. - + is its numeric value without its sign. For example, the absolute value of both 123 and -123 is 123. + + + +## Examples + The following example uses the method to get the absolute value of a number of values. + :::code language="csharp" source="~/snippets/csharp/System/Math/Abs/abs4.cs" interactive="try-dotnet-method" id="Snippet4"::: :::code language="fsharp" source="~/snippets/fsharp/System/Math/Abs/abs4.fs" id="Snippet4"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Math.Abs/vb/abs4.vb" id="Snippet4"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Math.Abs/vb/abs4.vb" id="Snippet4"::: + ]]> @@ -423,20 +423,20 @@ Returns the absolute value of a 64-bit signed integer. A 64-bit signed integer, x, such that 0 ≤ x ≤ Int64.MaxValue. - is its numeric value without its sign. For example, the absolute value of both 123 and -123 is 123. - - - -## Examples - The following example uses the method to get the absolute value of a number of values. - + is its numeric value without its sign. For example, the absolute value of both 123 and -123 is 123. + + + +## Examples + The following example uses the method to get the absolute value of a number of values. + :::code language="csharp" source="~/snippets/csharp/System/Math/Abs/abs5.cs" interactive="try-dotnet-method" id="Snippet5"::: :::code language="fsharp" source="~/snippets/fsharp/System/Math/Abs/abs5.fs" id="Snippet5"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Math.Abs/vb/abs5.vb" id="Snippet5"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Math.Abs/vb/abs5.vb" id="Snippet5"::: + ]]> @@ -550,20 +550,20 @@ Returns the absolute value of an 8-bit signed integer. An 8-bit signed integer, x, such that 0 ≤ x ≤ SByte.MaxValue. - method to get the absolute value of a number of values. - + method to get the absolute value of a number of values. + :::code language="csharp" source="~/snippets/csharp/System/Math/Abs/abs6.cs" interactive="try-dotnet-method" id="Snippet6"::: :::code language="fsharp" source="~/snippets/fsharp/System/Math/Abs/abs6.fs" id="Snippet6"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Math.Abs/vb/abs6.vb" id="Snippet6"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Math.Abs/vb/abs6.vb" id="Snippet6"::: + ]]> @@ -623,22 +623,22 @@ Returns the absolute value of a single-precision floating-point number. A single-precision floating-point number, x, such that 0 ≤ x ≤ Single.MaxValue. - is its numeric value without its sign. For example, the absolute value of both 1.2e-03 and -1.2e03 is 1.2e03. - - If `value` is equal to or , the return value is . If `value` is equal to , the return value is . - - - -## Examples - The following example uses the method to get the absolute value of a number of values. - + is its numeric value without its sign. For example, the absolute value of both 1.2e-03 and -1.2e03 is 1.2e03. + + If `value` is equal to or , the return value is . If `value` is equal to , the return value is . + + + +## Examples + The following example uses the method to get the absolute value of a number of values. + :::code language="csharp" source="~/snippets/csharp/System/Math/Abs/abs7.cs" interactive="try-dotnet-method" id="Snippet7"::: :::code language="fsharp" source="~/snippets/fsharp/System/Math/Abs/abs7.fs" id="Snippet7"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Math.Abs/vb/abs7.vb" id="Snippet7"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Math.Abs/vb/abs7.vb" id="Snippet7"::: + ]]> @@ -695,26 +695,26 @@ A number representing a cosine, where must be greater than or equal to -1, but less than or equal to 1. Returns the angle whose cosine is the specified number. An angle, θ, measured in radians, such that 0 ≤ θ ≤ π. - - -or- - - if < -1 or > 1 or equals . + +-or- + + if < -1 or > 1 or equals . - to convert from radians to degrees. - + to convert from radians to degrees. + This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures. - -## Examples - The following example uses the method to assist in the computation of the inner angles of a given trapezoid. + +## Examples + The following example uses the method to assist in the computation of the inner angles of a given trapezoid. :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/MathSample/CPP/mathsample.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Math/Overview/mathsample.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Math/Overview/mathsample.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/MathSample/VB/mathsample.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/MathSample/VB/mathsample.vb" id="Snippet1"::: + ]]> @@ -755,19 +755,19 @@ A number representing a hyperbolic cosine, where must be greater than or equal to 1, but less than or equal to . Returns the angle whose hyperbolic cosine is the specified number. - An angle, θ, measured in radians, such that 0 ≤ θ ≤ ∞. - - -or- - - if < 1 or equals . + An angle, θ, measured in radians, such that 0 ≤ θ ≤ ∞. + +-or- + + if < 1 or equals . - to convert from radians to degrees. - - This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures. - + to convert from radians to degrees. + + This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures. + ]]> @@ -824,30 +824,30 @@ A number representing a sine, where must be greater than or equal to -1, but less than or equal to 1. Returns the angle whose sine is the specified number. An angle, θ, measured in radians, such that -π/2 ≤ θ ≤ π/2. - - -or- - - if < -1 or > 1 or equals . + +-or- + + if < -1 or > 1 or equals . - to convert from radians to degrees. - - This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures. - - - -## Examples - The following example uses to assist in the computation of the inner angles of a given trapezoid. + to convert from radians to degrees. + + This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures. + + + +## Examples + The following example uses to assist in the computation of the inner angles of a given trapezoid. :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/MathSample/CPP/mathsample.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Math/Overview/mathsample.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Math/Overview/mathsample.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/MathSample/VB/mathsample.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/MathSample/VB/mathsample.vb" id="Snippet1"::: + ]]>
@@ -888,19 +888,19 @@ A number representing a hyperbolic sine, where must be greater than or equal to , but less than or equal to . Returns the angle whose hyperbolic sine is the specified number. - An angle, θ, measured in radians. - - -or- - - if equals . + An angle, θ, measured in radians. + +-or- + + if equals . - to convert from radians to degrees. - - This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures. - + to convert from radians to degrees. + + This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures. + ]]> @@ -956,31 +956,31 @@ A number representing a tangent. Returns the angle whose tangent is the specified number. - An angle, θ, measured in radians, such that -π/2 ≤ θ ≤ π/2. - - -or- - - if equals , -π/2 rounded to double precision (-1.5707963267949) if equals , or π/2 rounded to double precision (1.5707963267949) if equals . + An angle, θ, measured in radians, such that -π/2 ≤ θ ≤ π/2. + +-or- + + if equals , -π/2 rounded to double precision (-1.5707963267949) if equals , or π/2 rounded to double precision (1.5707963267949) if equals . - to convert from radians to degrees. - - This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures. - - - -## Examples - The following example demonstrates how to calculate the arctangent of a value and display it to the console. + to convert from radians to degrees. + + This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures. + + + +## Examples + The following example demonstrates how to calculate the arctangent of a value and display it to the console. :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/math.atanx/CPP/atan.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Math/Atan/atan.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Math/Atan/atan.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/math.atanx/VB/atan.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/math.atanx/VB/atan.vb" id="Snippet1"::: + ]]> @@ -1038,47 +1038,25 @@ The y coordinate of a point. The x coordinate of a point. Returns the angle whose tangent is the quotient of two specified numbers. - An angle, θ, measured in radians, such that tan(θ) = / , where (, ) is a point in the Cartesian plane. Observe the following: - -- For (, ) in quadrant 1, 0 < θ < π/2. - -- For (, ) in quadrant 2, π/2 < θ ≤ π. - -- For (, ) in quadrant 3, -π ≤ θ < -π/2. - -- For (, ) in quadrant 4, -π/2 < θ < 0. - - For points on the boundaries of the quadrants, the return value is the following: - -- If y is 0 and x is not negative, θ = 0. - -- If y is 0 and x is negative, θ = π. - -- If y is positive and x is 0, θ = π/2. - -- If y is negative and x is 0, θ = -π/2. - -- If y is 0 and x is 0, θ = 0. - - If or is , or if and are either or , the method returns . + An angle, θ, measured in radians, such that tan(θ) = / , where (, ) is a point in the Cartesian plane. Observe the following: - For (, ) in quadrant 1, 0 < θ < π/2. - For (, ) in quadrant 2, π/2 < θ ≤ π. - For (, ) in quadrant 3, -π ≤ θ < -π/2. - For (, ) in quadrant 4, -π/2 < θ < 0. For points on the boundaries of the quadrants, the return value is the following: - If y is 0 and x is not negative, θ = 0. - If y is 0 and x is negative, θ = π. - If y is positive and x is 0, θ = π/2. - If y is negative and x is 0, θ = -π/2. - If y is 0 and x is 0, θ = 0. If or is , or if and are either or , the method returns . -
@@ -1119,19 +1097,19 @@ A number representing a hyperbolic tangent, where must be greater than or equal to -1, but less than or equal to 1. Returns the angle whose hyperbolic tangent is the specified number. - An angle, θ, measured in radians, such that -∞ < θ < -1, or 1 < θ < ∞. - - -or- - - if < -1 or > 1 or equals . + An angle, θ, measured in radians, such that -∞ < θ < -1, or 1 < θ < ∞. + +-or- + + if < -1 or > 1 or equals . - to convert from radians to degrees. - - This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures. - + to convert from radians to degrees. + + This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures. + ]]> @@ -1188,16 +1166,16 @@ Produces the full product of two 32-bit numbers. The number containing the product of the specified numbers. - method to calculate the product of two integer values. + method to calculate the product of two integer values. :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/math.bigmul/CPP/bigmul.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Math/BigMul/bigmul.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Math/BigMul/bigmul.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/math.bigmul/VB/bigmul.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/math.bigmul/VB/bigmul.vb" id="Snippet1"::: + ]]>
@@ -1325,15 +1303,15 @@ The value to decrement. Returns the largest value that compares less than a specified value. - The largest value that compares less than . - - -or- - - if equals . - - -or- - - if equals . + The largest value that compares less than . + +-or- + + if equals . + +-or- + + if equals . To be added. @@ -1372,15 +1350,15 @@ The value to increment. Returns the smallest value that compares greater than a specified value. - The smallest value that compares greater than . - - -or- - - if equals . - - -or- - - if equals . + The smallest value that compares greater than . + +-or- + + if equals . + +-or- + + if equals . To be added. @@ -1420,17 +1398,17 @@ The number whose cube root is to be found. Returns the cube root of a specified number. - The cube root of . - - -or- - - if equals . + The cube root of . + +-or- + + if equals . - @@ -1446,10 +1424,10 @@ Returns the smallest integral value greater than or equal to the specified number. - @@ -1501,18 +1479,18 @@ Returns the smallest integral value that is greater than or equal to the specified decimal number. The smallest integral value that is greater than or equal to . Note that this method returns a instead of an integral type. - method, which supports rounding toward negative infinity. - -## Examples - The following example illustrates the method and contrasts it with the method. - + method, which supports rounding toward negative infinity. + +## Examples + The following example illustrates the method and contrasts it with the method. + :::code language="csharp" source="~/snippets/csharp/System/Math/Ceiling/Ceiling1.cs" interactive="try-dotnet-method" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Math/Ceiling/Ceiling1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Math.Ceiling/vb/Ceiling1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Math.Ceiling/vb/Ceiling1.vb" id="Snippet1"::: + ]]> @@ -1572,28 +1550,28 @@ Returns the smallest integral value that is greater than or equal to the specified double-precision floating-point number. The smallest integral value that is greater than or equal to . If is equal to , , or , that value is returned. Note that this method returns a instead of an integral type. - method, which supports rounding toward negative infinity. - + method, which supports rounding toward negative infinity. + Starting with Visual Basic 15.8, the performance of Double-to-integer conversion is optimized if you pass the value returned by the `Ceiling` method to the any of the [integral conversion functions](/dotnet/visual-basic/language-reference/functions/conversion-functions), or if the Double value returned by `Ceiling` is automatically converted to an integer with [Option Strict](/dotnet/visual-basic/language-reference/statements/option-strict-statement) set to Off. This optimization allows code to run faster -- up to twice as fast for code that does a large number of conversions to integer types. The following example illustrates such optimized conversions: - + ```vb Dim d1 As Double = 1043.75133 Dim i1 As Integer = CInt(Math.Ceiling(d1)) ' Result: 1044 Dim d2 As Double = 7968.4136 Dim i2 As Integer = CInt(Math.Ceiling(d2)) ' Result: 7969 -``` +``` + +## Examples + The following example illustrates the method and contrasts it with the method. -## Examples - The following example illustrates the method and contrasts it with the method. - :::code language="csharp" source="~/snippets/csharp/System/Math/Ceiling/Ceiling1.cs" interactive="try-dotnet-method" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/Math/Ceiling/Ceiling1.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Math.Ceiling/vb/Ceiling1.vb" id="Snippet2"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Math.Ceiling/vb/Ceiling1.vb" id="Snippet2"::: + ]]> @@ -1697,14 +1675,14 @@ Dim i2 As Integer = CInt(Math.Ceiling(d2)) ' Result: 7969 Returns clamped to the inclusive range of and . if . - - -or- - - if <. - - -or- - - if < . + +-or- + + if <. + +-or- + + if < . To be added. @@ -1751,18 +1729,18 @@ Dim i2 As Integer = CInt(Math.Ceiling(d2)) ' Result: 7969 Returns clamped to the inclusive range of and . if . - - -or- - - if < . - - -or- - - if < . - - -or- - - if equals . + +-or- + + if < . + +-or- + + if < . + +-or- + + if equals . To be added. @@ -1809,14 +1787,14 @@ Dim i2 As Integer = CInt(Math.Ceiling(d2)) ' Result: 7969 Returns clamped to the inclusive range of and . if . - - -or- - - if < . - - -or- - - if < . + +-or- + + if < . + +-or- + + if < . To be added.
@@ -1863,14 +1841,14 @@ Dim i2 As Integer = CInt(Math.Ceiling(d2)) ' Result: 7969 Returns clamped to the inclusive range of and . if . - - -or- - - if < . - - -or- - - if < . + +-or- + + if < . + +-or- + + if < . To be added.
@@ -1917,14 +1895,14 @@ Dim i2 As Integer = CInt(Math.Ceiling(d2)) ' Result: 7969 Returns clamped to the inclusive range of and . if . - - -or- - - if < . - - -or- - - if < . + +-or- + + if < . + +-or- + + if < . To be added.
@@ -2054,14 +2032,14 @@ Dim i2 As Integer = CInt(Math.Ceiling(d2)) ' Result: 7969 Returns clamped to the inclusive range of and . if . - - -or- - - if < . - - -or- - - if < . + +-or- + + if < . + +-or- + + if < . To be added.
@@ -2107,19 +2085,19 @@ Dim i2 As Integer = CInt(Math.Ceiling(d2)) ' Result: 7969 The upper bound of the result. Returns clamped to the inclusive range of and . - if . - - -or- - - if < . - - -or- - - if < . - - -or- - - if equals . + if . + +-or- + + if < . + +-or- + + if < . + +-or- + + if equals . To be added.
@@ -2171,15 +2149,15 @@ Dim i2 As Integer = CInt(Math.Ceiling(d2)) ' Result: 7969 The upper bound of the result. Returns clamped to the inclusive range of and . - if . - - -or- - - if < . - - -or- - - if < . + if . + +-or- + + if < . + +-or- + + if < . To be added. @@ -2231,15 +2209,15 @@ Dim i2 As Integer = CInt(Math.Ceiling(d2)) ' Result: 7969 The upper bound of the result. Returns clamped to the inclusive range of and . - if . - - -or- - - if < . - - -or- - - if < . + if . + +-or- + + if < . + +-or- + + if < . To be added. @@ -2292,14 +2270,14 @@ Dim i2 As Integer = CInt(Math.Ceiling(d2)) ' Result: 7969 Returns clamped to the inclusive range of and . if . - - -or- - - if < . - - -or- - - if < . + +-or- + + if < . + +-or- + + if < . To be added. @@ -2480,23 +2458,23 @@ Dim i2 As Integer = CInt(Math.Ceiling(d2)) ' Result: 7969 Returns the cosine of the specified angle. The cosine of . If is equal to , , or , this method returns . - /180 to convert degrees to radians. - - This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures. - - - -## Examples - The following example uses to evaluate certain trigonometric identities for selected angles. + /180 to convert degrees to radians. + + This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures. + + + +## Examples + The following example uses to evaluate certain trigonometric identities for selected angles. :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Math.SinCos/CPP/sincos.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Math/Cos/sincos.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Math/Cos/sincos.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Math.SinCos/VB/sincos.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Math.SinCos/VB/sincos.vb" id="Snippet1"::: + ]]> @@ -2554,23 +2532,23 @@ Dim i2 As Integer = CInt(Math.Ceiling(d2)) ' Result: 7969 Returns the hyperbolic cosine of the specified angle. The hyperbolic cosine of . If is equal to or , is returned. If is equal to , is returned. - /180 to convert degrees to radians. - - This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures. - - - -## Examples - The following example uses to evaluate certain hyperbolic identities for selected values. - + /180 to convert degrees to radians. + + This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures. + + + +## Examples + The following example uses to evaluate certain hyperbolic identities for selected values. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Math.SinhCosh/CPP/sinhcosh.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Math/Cosh/sinhcosh.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Math/Cosh/sinhcosh.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Math.SinhCosh/VB/sinhcosh.vb" id="Snippet1"::: - + ]]> @@ -3147,18 +3125,18 @@ Dim i2 As Integer = CInt(Math.Ceiling(d2)) ' Result: 7969 Calculates the quotient of two 32-bit signed integers and also returns the remainder in an output parameter. The quotient of the specified numbers. - method. + method. :::code language="csharp" source="~/snippets/csharp/System/Math/DivRem/divrem1.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Math/DivRem/divrem1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.math.divrem/vb/divrem1.vb" id="Snippet1"::: - + ]]> @@ -3220,18 +3198,18 @@ Dim i2 As Integer = CInt(Math.Ceiling(d2)) ' Result: 7969 Calculates the quotient of two 64-bit signed integers and also returns the remainder in an output parameter. The quotient of the specified numbers. - method. + +## Examples + The following example demonstrates the method. :::code language="csharp" source="~/snippets/csharp/System/Math/DivRem/divrem2.cs" interactive="try-dotnet" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/Math/DivRem/divrem2.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.math.divrem/vb/divrem2.vb" id="Snippet2"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.math.divrem/vb/divrem2.vb" id="Snippet2"::: + ]]> @@ -3282,21 +3260,21 @@ Dim i2 As Integer = CInt(Math.Ceiling(d2)) ' Result: 7969 Represents the natural logarithmic base, specified by the constant, . - with the value calculated from a power series. + with the value calculated from a power series. :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Math.E/CPP/efield.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Math/E/efield.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Math/E/efield.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Math.E/VB/efield.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Math.E/VB/efield.vb" id="Snippet1"::: + ]]> @@ -3354,27 +3332,27 @@ Dim i2 As Integer = CInt(Math.Ceiling(d2)) ' Result: 7969 Returns raised to the specified power. The number raised to the power . If equals or , that value is returned. If equals , 0 is returned. - method to calculate powers of other bases. - - is the inverse of . - - This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures. - - - -## Examples - The following example uses to evaluate certain exponential and logarithmic identities for selected values. + method to calculate powers of other bases. + + is the inverse of . + + This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures. + + + +## Examples + The following example uses to evaluate certain exponential and logarithmic identities for selected values. :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Math.Exp/CPP/exp.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Math/Exp/exp.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Math/Exp/exp.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Math.Exp/VB/exp.vb" id="Snippet1"::: - + ]]> @@ -3392,10 +3370,10 @@ Dim i2 As Integer = CInt(Math.Ceiling(d2)) ' Result: 7969 Returns the largest integral value less than or equal to the specified number. - @@ -3445,20 +3423,20 @@ Dim i2 As Integer = CInt(Math.Ceiling(d2)) ' Result: 7969 A decimal number. Returns the largest integral value less than or equal to the specified decimal number. - The largest integral value less than or equal to . Note that the method returns an integral value of type . + The largest integral value less than or equal to . Note that the method returns an integral value of type . - method, which supports rounding toward positive infinity. - -## Examples - The following example illustrates the method and contrasts it with the method. - + method, which supports rounding toward positive infinity. + +## Examples + The following example illustrates the method and contrasts it with the method. + :::code language="csharp" source="~/snippets/csharp/System/Math/Ceiling/Ceiling1.cs" interactive="try-dotnet-method" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Math/Ceiling/Ceiling1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Math.Ceiling/vb/Ceiling1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Math.Ceiling/vb/Ceiling1.vb" id="Snippet1"::: + ]]> @@ -3519,13 +3497,13 @@ Dim i2 As Integer = CInt(Math.Ceiling(d2)) ' Result: 7969 Returns the largest integral value less than or equal to the specified double-precision floating-point number. The largest integral value less than or equal to . If is equal to , , or , that value is returned. - method, which supports rounding toward positive infinity. + method, which supports rounding toward positive infinity. Starting with Visual Basic 15.8, the performance of Double-to-integer conversion is optimized if you pass the value returned by the `Floor` method to the any of the [integral conversion functions](/dotnet/visual-basic/language-reference/functions/conversion-functions), or if the Double value returned by `Floor` is automatically converted to an integer with [Option Strict](/dotnet/visual-basic/language-reference/statements/option-strict-statement) set to Off. This optimization allows code to run faster -- up to twice as fast for code that does a large number of conversions to integer types. The following example illustrates such optimized conversions: - + ```vb Dim d1 As Double = 1043.75133 Dim i1 As Integer = CInt(Math.Floor(d1)) ' Result: 1043 @@ -3534,13 +3512,13 @@ Dim d2 As Double = 7968.4136 Dim i2 As Integer = CInt(Math.Floor(d2)) ' Result: 7968 ``` -## Examples - The following example illustrates the method and contrasts it with the method. - +## Examples + The following example illustrates the method and contrasts it with the method. + :::code language="csharp" source="~/snippets/csharp/System/Math/Ceiling/Ceiling1.cs" interactive="try-dotnet-method" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/Math/Ceiling/Ceiling1.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Math.Ceiling/vb/Ceiling1.vb" id="Snippet2"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Math.Ceiling/vb/Ceiling1.vb" id="Snippet2"::: + ]]> @@ -3588,13 +3566,13 @@ Dim i2 As Integer = CInt(Math.Floor(d2)) ' Result: 7968 Returns (x * y) + z, rounded as one ternary operation. (x * y) + z, rounded as one ternary operation. - @@ -3652,40 +3630,36 @@ Dim i2 As Integer = CInt(Math.Floor(d2)) ' Result: 7968 A dividend. A divisor. Returns the remainder resulting from the division of a specified number by another specified number. - A number equal to - ( Q), where Q is the quotient of / rounded to the nearest integer (if / falls halfway between two integers, the even integer is returned). - - If - ( Q) is zero, the value +0 is returned if is positive, or -0 if is negative. - - If = 0, is returned. + A number equal to - ( Q), where Q is the quotient of / rounded to the nearest integer (if / falls halfway between two integers, the even integer is returned). If - ( Q) is zero, the value +0 is returned if is positive, or -0 if is negative. If = 0, is returned. - method is not the same as the [remainder operator](/dotnet/csharp/language-reference/operators/remainder-operator). Although both return the remainder after division, the formulas they use are different. The formula for the method is: - -``` -IEEERemainder = dividend - (divisor * Math.Round(dividend / divisor)) -``` - - In contrast, the formula for the remainder operator is: - -``` -Remainder = (Math.Abs(dividend) - (Math.Abs(divisor) * - (Math.Floor(Math.Abs(dividend) / Math.Abs(divisor))))) * - Math.Sign(dividend) -``` - - - -## Examples - The following example contrasts the remainder returned by the method with the remainder returned by the [remainder operator](/dotnet/csharp/language-reference/operators/remainder-operator). - + method is not the same as the [remainder operator](/dotnet/csharp/language-reference/operators/remainder-operator). Although both return the remainder after division, the formulas they use are different. The formula for the method is: + +``` +IEEERemainder = dividend - (divisor * Math.Round(dividend / divisor)) +``` + + In contrast, the formula for the remainder operator is: + +``` +Remainder = (Math.Abs(dividend) - (Math.Abs(divisor) * + (Math.Floor(Math.Abs(dividend) / Math.Abs(divisor))))) * + Math.Sign(dividend) +``` + + + +## Examples + The following example contrasts the remainder returned by the method with the remainder returned by the [remainder operator](/dotnet/csharp/language-reference/operators/remainder-operator). + :::code language="csharp" source="~/snippets/csharp/System/Math/IEEERemainder/ieeeremainder1.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Math/IEEERemainder/ieeeremainder1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.math.ieeeremainder/vb/ieeeremainder1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.math.ieeeremainder/vb/ieeeremainder1.vb" id="Snippet1"::: + ]]> @@ -3725,27 +3699,42 @@ Remainder = (Math.Abs(dividend) - (Math.Abs(divisor) * The number whose logarithm is to be found. Returns the base 2 integer logarithm of a specified number. - One of the values in the following table. - - parameter - - Return value - - Default - - The base 2 integer log of ; that is, (int)log2(). - - Zero - - Int32.MinValue Equal to or or Int32.MaxValue + One of the values in the following table. + + parameter + Return value + + + + + Default + + + The base 2 integer log of ; that is, (int)log2(). + + + Zero + + + + Int32.MinValue + + + + Equal to or or + + Int32.MaxValue + + + - @@ -3813,38 +3802,67 @@ Remainder = (Math.Abs(dividend) - (Math.Abs(divisor) * The number whose logarithm is to be found. Returns the natural (base ) logarithm of a specified number. - One of the values in the following table. - - parameter - - Return value - - Positive - - The natural logarithm of ; that is, ln , or log e Zero - - Negative - - Equal to Equal to + One of the values in the following table. + + parameter + Return value + + + + + Positive + + + The natural logarithm of ; that is, ln , or log e + + + Zero + + + + + + + + Negative + + + + + + + + Equal to + + + + + + Equal to + + + + + - method. + method. :::code language="csharp" source="~/snippets/csharp/System/Math/LogMethod/log1.cs" interactive="try-dotnet" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/Math/LogMethod/log1.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Math.Log_Overloads/VB/log1.vb" id="Snippet2"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Math.Log_Overloads/VB/log1.vb" id="Snippet2"::: + ]]> @@ -3898,111 +3916,147 @@ Remainder = (Math.Abs(dividend) - (Math.Abs(divisor) * The number whose logarithm is to be found. The base of the logarithm. Returns the logarithm of a specified number in a specified base. - One of the values in the following table. (+Infinity denotes , -Infinity denotes , and NaN denotes .) - - Return value - - > 0 - - (0 << 1) -or- (> 1) - - lognewBase(a) - - < 0 - - (any value) - - NaN - - (any value) - - < 0 - - NaN - - != 1 - - = 0 - - NaN - - != 1 - - = +Infinity - - NaN - - = NaN - - (any value) - - NaN - - (any value) - - = NaN - - NaN - - (any value) - - = 1 - - NaN - - = 0 - - 0 << 1 - - +Infinity - - = 0 - - > 1 - - -Infinity - - = +Infinity - - 0 << 1 - - -Infinity - - = +Infinity - - > 1 - - +Infinity - - = 1 - - = 0 - - 0 - - = 1 - - = +Infinity - - 0 - - + One of the values in the following table. (+Infinity denotes , -Infinity denotes , and NaN denotes .) + + + + + + + + Return value + + + + + > 0 + (0 << 1) + +-or- + +(> 1) + lognewBase(a) + + + + + < 0 + (any value) + + + NaN + + + + + (any value) + + + < 0 + NaN + + + + + != 1 + = 0 + NaN + + + + + != 1 + = +Infinity + NaN + + + + + = NaN + (any value) + + + NaN + + + + + (any value) + + + = NaN + NaN + + + + + (any value) + + + = 1 + NaN + + + + + = 0 + 0 << 1 + +Infinity + + + + + = 0 + > 1 + -Infinity + + + + + = +Infinity + 0 << 1 + -Infinity + + + + + = +Infinity + > 1 + +Infinity + + + + + = 1 + = 0 + 0 + + + + + = 1 + = +Infinity + 0 + + + + - to evaluate certain logarithmic identities for selected values. + to evaluate certain logarithmic identities for selected values. :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Math.Log_Overloads/CPP/loggen.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Math/LogMethod/loggen.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Math/LogMethod/loggen.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Math.Log_Overloads/VB/loggen.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Math.Log_Overloads/VB/loggen.vb" id="Snippet1"::: + ]]> @@ -4058,38 +4112,65 @@ Remainder = (Math.Abs(dividend) - (Math.Abs(divisor) * A number whose logarithm is to be found. Returns the base 10 logarithm of a specified number. - One of the values in the following table. - - parameter - - Return value - - Positive - - The base 10 log of ; that is, log 10. - - Zero - - Negative - - Equal to Equal to + One of the values in the following table. + + parameter + Return value + + + + + Positive + + + The base 10 log of ; that is, log 10. + + + Zero + + + + + + + + Negative + + + + + + + + Equal to + + + + + + Equal to + + + + + - method to return the base 10 logarithm for selected values. + method to return the base 10 logarithm for selected values. :::code language="csharp" source="~/snippets/csharp/System/Math/Log10/log10.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Math/Log10/log10.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Math.Log10/VB/log10.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Math.Log10/VB/log10.vb" id="Snippet1"::: + ]]> @@ -4129,29 +4210,56 @@ Remainder = (Math.Abs(dividend) - (Math.Abs(divisor) * A number whose logarithm is to be found. Returns the base 2 logarithm of a specified number. - One of the values in the following table. - - parameter - - Return value - - Positive - - The base 2 log of ; that is, log 2. - - Zero - - Negative - - Equal to Equal to + One of the values in the following table. + + parameter + Return value + + + + + Positive + + + The base 2 log of ; that is, log 2. + + + Zero + + + + + + + + Negative + + + + + + + + Equal to + + + + + + Equal to + + + + + - @@ -4167,8 +4275,8 @@ Remainder = (Math.Abs(dividend) - (Math.Abs(divisor) * Returns the larger of two specified numbers. - method to return and display the greater of two variables: @@ -4176,8 +4284,8 @@ The following example demonstrates how to use the meth :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/math.max/CPP/max.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Math/Max/max.cs" interactive="try-dotnet-method" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Math/Max/max.fs" id="Snippet1"::: -:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/math.max/VB/max.vb" id="Snippet1"::: - +:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/math.max/VB/max.vb" id="Snippet1"::: + ]]> @@ -5045,7 +5153,7 @@ The following example demonstrates how to use the meth Returns the smaller of two numbers. - meth :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/math.min/CPP/min.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Math/Min/min.cs" interactive="try-dotnet-method" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Math/Min/min.fs" id="Snippet1"::: -:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/math.min/VB/min.vb" id="Snippet1"::: - +:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/math.min/VB/min.vb" id="Snippet1"::: + ]]> @@ -5955,21 +6063,21 @@ The following example demonstrates how to use the meth Represents the ratio of the circumference of a circle to its diameter, specified by the constant, π. - to assist in the computation of the inner angles of a given trapezoid. + to assist in the computation of the inner angles of a given trapezoid. :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/MathSample/CPP/mathsample.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Math/Overview/mathsample.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Math/Overview/mathsample.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/MathSample/VB/mathsample.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/MathSample/VB/mathsample.vb" id="Snippet1"::: + ]]> @@ -6029,10 +6137,10 @@ The following example demonstrates how to use the meth Returns a specified number raised to the specified power. The number raised to the power . - , , and . + , , and . | x | y | Return value | |--------------------------------|-----------------------------------------------------------|--------------------------------| @@ -6055,19 +6163,19 @@ The following example demonstrates how to use the meth | 0 | > 0 | 0 | | `PositiveInfinity` | < 0 | 0 | | `PositiveInfinity` | > 0 | `PositiveInfinity` | - - This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures. - - - -## Examples - - The following example uses the method to calculate the value that results from raising 2 to a power ranging from 0 to 32. - + + This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures. + + + +## Examples + + The following example uses the method to calculate the value that results from raising 2 to a power ranging from 0 to 32. + :::code language="csharp" source="~/snippets/csharp/System/Math/Pow/pow1.cs" interactive="try-dotnet-method" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Math/Pow/pow1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.math.pow/vb/pow1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.math.pow/vb/pow1.vb" id="Snippet1"::: + ]]> @@ -6179,16 +6287,16 @@ On hardware without specialized support, this may just return `1.0 / Sqrt(d)`. Rounds a value to the nearest integer or to the specified number of fractional digits. - -## Remarks + +## Remarks In this section: - [Which method do I call?](#which-method-do-i-call) -- [Midpoint values and rounding conventions](#midpoint-values-and-rounding-conventions) -- [Rounding and precision](#rounding-and-precision) +- [Midpoint values and rounding conventions](#midpoint-values-and-rounding-conventions) +- [Rounding and precision](#rounding-and-precision) - [Rounding and single-precision floating point values](#rounding-and-single-precision-floating-point-values) - [Examples of individual overloads](#round-examples) @@ -6196,111 +6304,111 @@ In this section: You can use the following table to select an appropriate rounding method. In addition to the `Math.Round` methods, it also includes and . -|To|Call| -|--------|----------| -|Round a number to an integer by using the rounding-to-nearest convention.|
-or-
| -|Round a number to an integer by using a specified rounding convention.|
-or-
| -|Round a number to a specified number of fractional digits by using the rounding to nearest convention.|
-or-
| -|Round a number to a specified number of fractional digits by using a specified rounding convention.|
-or-
| -|Round a value to a specified number of fractional digits by using a specified rounding convention and minimizing the loss of precision.|Convert the to a and call .| -|Round a number to a specified number of fractional digits while minimizing problems of precision in rounding midpoint values.|Call a rounding method that implements a "greater than or approximately equal to" comparison. See [Rounding and precision](#precision).| -|Round a fractional value to an integer that is greater than the fractional value. For example, round 3.1 to 4.|| -|Round a fractional value to an integer that is less than the fractional value. For example, round 3.9 to 3.|| - -### Midpoint values and rounding conventions - -Rounding involves converting a numeric value with a specified precision to a value with less precision. For example, you can use the method to round a value of 3.4 to 3.0, and the method to round a value of 3.579 to 3.58. - +|To|Call| +|--------|----------| +|Round a number to an integer by using the rounding-to-nearest convention.|
-or-
| +|Round a number to an integer by using a specified rounding convention.|
-or-
| +|Round a number to a specified number of fractional digits by using the rounding to nearest convention.|
-or-
| +|Round a number to a specified number of fractional digits by using a specified rounding convention.|
-or-
| +|Round a value to a specified number of fractional digits by using a specified rounding convention and minimizing the loss of precision.|Convert the to a and call .| +|Round a number to a specified number of fractional digits while minimizing problems of precision in rounding midpoint values.|Call a rounding method that implements a "greater than or approximately equal to" comparison. See [Rounding and precision](#precision).| +|Round a fractional value to an integer that is greater than the fractional value. For example, round 3.1 to 4.|| +|Round a fractional value to an integer that is less than the fractional value. For example, round 3.9 to 3.|| + +### Midpoint values and rounding conventions + +Rounding involves converting a numeric value with a specified precision to a value with less precision. For example, you can use the method to round a value of 3.4 to 3.0, and the method to round a value of 3.579 to 3.58. + In a midpoint value, the value after the least significant digit in the result is precisely half way between two numbers. For example, 3.47500 is a midpoint value if it is to be rounded to two decimal places, and 7.500 is a midpoint value if it is to be rounded to an integer. In these cases, if the round-to-nearest strategy is used, the nearest value can't be easily identified without a rounding convention. -The method supports two rounding conventions for handling midpoint values: - -- **Rounding away from zero** +The method supports two rounding conventions for handling midpoint values: + +- **Rounding away from zero** Midpoint values are rounded to the next number away from zero. For example, 3.75 rounds to 3.8, 3.85 rounds to 3.9, -3.75 rounds to -3.8, and -3.85 rounds to -3.9. This form of rounding is represented by the enumeration member. -- **Rounding to nearest even, or banker's rounding** +- **Rounding to nearest even, or banker's rounding** Midpoint values are rounded to the nearest even number. For example, both 3.75 and 3.85 round to 3.8, and both -3.75 and -3.85 round to -3.8. This form of rounding is represented by the enumeration member. > [!NOTE] > In .NET Core 3.0 and later versions, three additional rounding strategies are available through the enumeration. These strategies are used in all cases, not just for midpoint values as and are. -Rounding away from zero is the most widely known form of rounding, while rounding to nearest even is the standard in financial and statistical operations. It conforms to IEEE Standard 754, section 4. When used in multiple rounding operations, rounding to nearest even reduces the rounding error that is caused by consistently rounding midpoint values in a single direction. In some cases, this rounding error can be significant. - -The following example illustrates the bias that can result from consistently rounding midpoint values in a single direction. The example computes the true mean of an array of values, and then computes the mean when the values in the array are rounded by using the two conventions. In this example, the true mean and the mean that results when rounding to nearest are the same. However, the mean that results when rounding away from zero differs by .05 (or by 3.6%) from the true mean. - +Rounding away from zero is the most widely known form of rounding, while rounding to nearest even is the standard in financial and statistical operations. It conforms to IEEE Standard 754, section 4. When used in multiple rounding operations, rounding to nearest even reduces the rounding error that is caused by consistently rounding midpoint values in a single direction. In some cases, this rounding error can be significant. + +The following example illustrates the bias that can result from consistently rounding midpoint values in a single direction. The example computes the true mean of an array of values, and then computes the mean when the values in the array are rounded by using the two conventions. In this example, the true mean and the mean that results when rounding to nearest are the same. However, the mean that results when rounding away from zero differs by .05 (or by 3.6%) from the true mean. + :::code language="csharp" source="~/snippets/csharp/System/Decimal/Round/mean1.cs" interactive="try-dotnet-method" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/Round/mean1.fs" id="Snippet2"::: -:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.math.round.overload/vb/mean1.vb" id="Snippet2"::: - -By default, the method uses the round to nearest even convention. The following table lists the overloads of the method and the rounding convention that each uses. - -|Overload|Rounding convention| -|--------------|-------------------------| -||| -||| -||| -||| -||Determined by `mode` parameter.| -||Determined by `mode` parameter| -||Determined by `mode` parameter| -||Determined by `mode` parameter| +:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.math.round.overload/vb/mean1.vb" id="Snippet2"::: + +By default, the method uses the round to nearest even convention. The following table lists the overloads of the method and the rounding convention that each uses. + +|Overload|Rounding convention| +|--------------|-------------------------| +||| +||| +||| +||| +||Determined by `mode` parameter.| +||Determined by `mode` parameter| +||Determined by `mode` parameter| +||Determined by `mode` parameter| -### Rounding and precision +### Rounding and precision In order to determine whether a rounding operation involves a midpoint value, the method multiplies the original value to be rounded by 10n, where *n* is the desired number of fractional digits in the return value, and then determines whether the remaining fractional portion of the value is greater than or equal to .5. This is a slight variation on a test for equality, and as discussed in the "Testing for Equality" section of the reference topic, tests for equality with floating-point values are problematic because of the floating-point format's issues with binary representation and precision. This means that any fractional portion of a number that is slightly less than .5 (because of a loss of precision) will not be rounded upward. -The following example illustrates the problem. It repeatedly adds .1 to 11.0 and rounds the result to the nearest integer. 11.5 should round to 12 using either of the midpoint-rounding conventions (`ToEven` or `AwayFromZero`). However, as the output from the example shows, it does not. The example uses the "R" [standard numeric format string](/dotnet/standard/base-types/standard-numeric-format-strings) to display the floating point value's full precision, and shows that the value to be rounded has lost precision during repeated additions, and its value is actually 11.499999999999998. Because .499999999999998 is less than .5, the midpoint-rounding conventions don't come into play and the value is rounded down. As the example also shows, this problem does not occur if you assign the constant value 11.5 to a variable. - +The following example illustrates the problem. It repeatedly adds .1 to 11.0 and rounds the result to the nearest integer. 11.5 should round to 12 using either of the midpoint-rounding conventions (`ToEven` or `AwayFromZero`). However, as the output from the example shows, it does not. The example uses the "R" [standard numeric format string](/dotnet/standard/base-types/standard-numeric-format-strings) to display the floating point value's full precision, and shows that the value to be rounded has lost precision during repeated additions, and its value is actually 11.499999999999998. Because .499999999999998 is less than .5, the midpoint-rounding conventions don't come into play and the value is rounded down. As the example also shows, this problem does not occur if you assign the constant value 11.5 to a variable. + :::code language="csharp" source="~/snippets/csharp/System/Decimal/Round/precision1.cs" interactive="try-dotnet" id="Snippet7"::: :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/Round/precision1.fs" id="Snippet7"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.math.round.overload/vb/precision1.vb" id="Snippet7"::: - -Problems of precision in rounding midpoint values are most likely to arise in the following conditions: - -- When a fractional value cannot be expressed precisely in the floating-point type's binary format. - -- When the value to be rounded is calculated from one or more floating-point operations. - -- When the value to be rounded is a rather than a or . For more information, see the next section, [Rounding and single-precision floating-point values](#rounding-and-single-precision-floating-point-values). - - In cases where the lack of precision in rounding operations is problematic, you can do the following: - -- If the rounding operation calls an overload that rounds a value, you can change the to a value and call an overload that rounds a value instead. Although the data type also has problems of representation and loss of precision, these issues are far less common. - -- Define a custom rounding algorithm that performs a "nearly equal" test to determine whether the value to be rounded is acceptably close to a midpoint value. The following example defines a `RoundApproximate` method that examines whether a fractional value is sufficiently near to a midpoint value to be subject to midpoint rounding. As the output from the example shows, it corrects the rounding problem shown in the previous example. - + +Problems of precision in rounding midpoint values are most likely to arise in the following conditions: + +- When a fractional value cannot be expressed precisely in the floating-point type's binary format. + +- When the value to be rounded is calculated from one or more floating-point operations. + +- When the value to be rounded is a rather than a or . For more information, see the next section, [Rounding and single-precision floating-point values](#rounding-and-single-precision-floating-point-values). + + In cases where the lack of precision in rounding operations is problematic, you can do the following: + +- If the rounding operation calls an overload that rounds a value, you can change the to a value and call an overload that rounds a value instead. Although the data type also has problems of representation and loss of precision, these issues are far less common. + +- Define a custom rounding algorithm that performs a "nearly equal" test to determine whether the value to be rounded is acceptably close to a midpoint value. The following example defines a `RoundApproximate` method that examines whether a fractional value is sufficiently near to a midpoint value to be subject to midpoint rounding. As the output from the example shows, it corrects the rounding problem shown in the previous example. + :::code language="csharp" source="~/snippets/csharp/System/Decimal/Round/precision2.cs" interactive="try-dotnet" id="Snippet8"::: :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/Round/precision2.fs" id="Snippet8"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.math.round.overload/vb/precision2.vb" id="Snippet8"::: - -#### Rounding and single-precision floating-point values -The method includes overloads that accept arguments of type and . There are no methods that round values of type . If you pass a value to one of the overloads of the method, it is cast (in C#) or converted (in Visual Basic) to a , and the corresponding overload with a parameter is called. Although this is a widening conversion, it often involves a loss of precision, as the following example illustrates. When a value of 16.325 is passed to the method and rounded to two decimal places using the rounding to nearest convention, the result is 16.33 and not the expected result of 16.32. +#### Rounding and single-precision floating-point values + +The method includes overloads that accept arguments of type and . There are no methods that round values of type . If you pass a value to one of the overloads of the method, it is cast (in C#) or converted (in Visual Basic) to a , and the corresponding overload with a parameter is called. Although this is a widening conversion, it often involves a loss of precision, as the following example illustrates. When a value of 16.325 is passed to the method and rounded to two decimal places using the rounding to nearest convention, the result is 16.33 and not the expected result of 16.32. :::code language="csharp" source="~/snippets/csharp/System/Decimal/Round/single1.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/Round/single1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.math.round.overload/vb/single1.vb" id="Snippet1"::: - -This unexpected result is due to a loss of precision in the conversion of the value to a . Because the resulting value of 16.325000762939453 is not a midpoint value and is greater than 16.325, it is always rounded upward. - -In many cases, as the example illustrates, the loss of precision can be minimized or eliminated by casting or converting the value to a . Note that, because this is a narrowing conversion, it requires using a cast operator or calling a conversion method. - -## Examples +This unexpected result is due to a loss of precision in the conversion of the value to a . Because the resulting value of 16.325000762939453 is not a midpoint value and is greater than 16.325, it is always rounded upward. + +In many cases, as the example illustrates, the loss of precision can be minimized or eliminated by casting or converting the value to a . Note that, because this is a narrowing conversion, it requires using a cast operator or calling a conversion method. + + +## Examples In addition to the examples in the [Remarks](#remarks-round) section, this article includes examples that illustrate the following overloads of the `Math.Round` method: -[Math.Round(Decimal)](#Round1_Example) -[Math.Round(Double)](#Round2_Example) -[Math.Round(Decimal, Int32)](#Round3_Example) -[Math.Round(Decimal, MidpointRounding)](#Round4_Example) -[Math.Round(Double, Int32)](#Round5_Example) -[Math.Round(Double, MidpointRounding)](#Round6_Example) -[Math.Round(Decimal, Int32, MidpointRounding)](#Round7_Example) -[Math.Round(Double, Int32, MidpointRounding)](#Round8_Example) +[Math.Round(Decimal)](#Round1_Example) +[Math.Round(Double)](#Round2_Example) +[Math.Round(Decimal, Int32)](#Round3_Example) +[Math.Round(Decimal, MidpointRounding)](#Round4_Example) +[Math.Round(Double, Int32)](#Round5_Example) +[Math.Round(Double, MidpointRounding)](#Round6_Example) +[Math.Round(Decimal, Int32, MidpointRounding)](#Round7_Example) +[Math.Round(Double, Int32, MidpointRounding)](#Round8_Example) ]]>
@@ -6357,22 +6465,22 @@ In addition to the examples in the [Remarks](#remarks-round) section, this artic Rounds a decimal value to the nearest integral value, and rounds midpoint values to the nearest even number. The integer nearest the parameter. If the fractional component of is halfway between two integers, one of which is even and the other odd, the even number is returned. Note that this method returns a instead of an integral type. - . For information about rounding numbers with midpoint values, see [Midpoint values and rounding conventions](#midpoint-values-and-rounding-conventions). [!INCLUDE[midpoint-rounding](~/includes/floating-point-equality.md)] - + ## Examples -The following example demonstrates the method. The value of 4.5 rounds to 4 rather than 5, because this overload uses the default convention. - +The following example demonstrates the method. The value of 4.5 rounds to 4 rather than 5, because this overload uses the default convention. + :::code language="csharp" source="~/snippets/csharp/System/Math/Round/rounddecimal1.cs" interactive="try-dotnet-method" id="Snippet6"::: :::code language="fsharp" source="~/snippets/fsharp/System/Math/Round/rounddecimal1.fs" id="Snippet6"::: -:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.math.round/vb/rounddecimal1.vb" id="Snippet6"::: +:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.math.round/vb/rounddecimal1.vb" id="Snippet6"::: ]]> @@ -6435,18 +6543,18 @@ The following example demonstrates the Rounds a double-precision floating-point value to the nearest integral value, and rounds midpoint values to the nearest even number. The integer nearest . If the fractional component of is halfway between two integers, one of which is even and the other odd, then the even number is returned. Note that this method returns a instead of an integral type. - . For information about rounding numbers with midpoint values, see [Midpoint values and rounding conventions](#midpoint-values-and-rounding-conventions). [!INCLUDE[midpoint-rounding](~/includes/floating-point-equality.md)] -If the value of the `a` argument is , the method returns . If `a` is or , the method returns or , respectively. +If the value of the `a` argument is , the method returns . If `a` is or , the method returns or , respectively. Starting with Visual Basic 15.8, the performance of Double-to-integer conversion is optimized if you pass the value returned by the `Round` method to the any of the [integral conversion functions](/dotnet/visual-basic/language-reference/functions/conversion-functions), or if the Double value returned by `Round` is automatically converted to an integer with [Option Strict](/dotnet/visual-basic/language-reference/statements/option-strict-statement) set to Off. This optimization allows code to run faster -- up to twice as fast for code that does a large number of conversions to integer types. The following example illustrates such optimized conversions: - + ```vb Dim d1 As Double = 1043.75133 Dim i1 As Integer = CInt(Math.Ceiling(d1)) ' Result: 1044 @@ -6455,26 +6563,20 @@ Dim d2 As Double = 7968.4136 Dim i2 As Integer = CInt(Math.Ceiling(d2)) ' Result: 7968 ``` - -## Example + +## Example + +The following example demonstrates rounding to the nearest integer value. -The following example demonstrates rounding to the nearest integer value. - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_Classic/classic Math.Round Example/CPP/source.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Math/Round/source.cs" interactive="try-dotnet-method" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Math/Round/source.fs" id="Snippet1"::: -:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_Classic/classic Math.Round Example/VB/source.vb" id="Snippet1"::: +:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_Classic/classic Math.Round Example/VB/source.vb" id="Snippet1"::: ]]> - Because of the loss of precision that can result from representing decimal values as floating-point numbers or performing arithmetic operations on floating-point values, in some cases the method may not appear to round midpoint values to the nearest even integer. In the following example, because the floating-point value .1 has no finite binary representation, the first call to the method with a value of 11.5 returns 11 instead of 12. - - :::code language="csharp" source="~/snippets/csharp/System/Math/Round/round2.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/Math/Round/round2.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.math.round/vb/round2.vb" id="Snippet1"::: - - + Because of the loss of precision that can result from representing decimal values as floating-point numbers or performing arithmetic operations on floating-point values, in some cases the method may not appear to round midpoint values to the nearest even integer. In the following example, because the floating-point value .1 has no finite binary representation, the first call to the method with a value of 11.5 returns 11 instead of 12. :::code language="csharp" source="~/snippets/csharp/System/Math/Round/round2.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Math/Round/round2.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.math.round/vb/round2.vb" id="Snippet1"::: @@ -6530,25 +6632,25 @@ The following example demonstrates rounding to the nearest integer value. Rounds a decimal value to a specified number of fractional digits, and rounds midpoint values to the nearest even number. The number nearest to that contains a number of fractional digits equal to . - . For information about rounding numbers with midpoint values, see [Midpoint values and rounding conventions](#midpoint-values-and-rounding-conventions). [!INCLUDE[midpoint-rounding](~/includes/floating-point-equality.md)] - -## Example + +## Example + +The following example rounds decimal values with two fractional digits to values that have a single fractional digit. -The following example rounds decimal values with two fractional digits to values that have a single fractional digit. - :::code language="csharp" source="~/snippets/csharp/System/Decimal/Round/source.cs" interactive="try-dotnet-method" id="Snippet3"::: :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/Round/source.fs" id="Snippet3"::: -:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.math.round.overload/vb/source.vb" id="Snippet3"::: - +:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.math.round.overload/vb/source.vb" id="Snippet3"::: + ]]> @@ -6613,23 +6715,23 @@ The following example rounds decimal values with two fractional digits to values Rounds a decimal value an integer using the specified rounding convention. The integer that is rounded to. This method returns a instead of an integral type. - -## Example + +## Example The following example displays values returned by the method with different `mode` values. :::code language="csharp" source="~/snippets/csharp/System/Decimal/Round/midpoint1.cs" interactive="try-dotnet" id="Snippet5"::: :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/Round/midpoint1.fs" id="Snippet5"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.math.round.overload/vb/midpoint1.vb" id="Snippet5"::: - + ]]> @@ -6689,40 +6791,34 @@ The following example displays values returned by the Rounds a double-precision floating-point value to a specified number of fractional digits, and rounds midpoint values to the nearest even number. The number nearest to that contains a number of fractional digits equal to . - type is 15. This method uses the default rounding convention of . See [Midpoint values and rounding conventions](#midpoint-values-and-rounding-conventions) for information about rounding numbers with midpoint values. [!INCLUDE[midpoint-rounding](~/includes/floating-point-equality.md)] -If the value of the `value` argument is , the method returns . If `value` is or , the method returns or , respectively. +If the value of the `value` argument is , the method returns . If `value` is or , the method returns or , respectively. - -## Example + +## Example + +The following example rounds double values with two fractional digits to doubles that have a single fractional digit. -The following example rounds double values with two fractional digits to doubles that have a single fractional digit. - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_Classic/classic Math.Round2 Example/CPP/source.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Math/Round/source1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Math/Round/source1.fs" id="Snippet1"::: -:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_Classic/classic Math.Round2 Example/VB/source.vb" id="Snippet1"::: - +:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_Classic/classic Math.Round2 Example/VB/source.vb" id="Snippet1"::: + ]]> is less than 0 or greater than 15. - Because of the loss of precision that can result from representing decimal values as floating-point numbers or performing arithmetic operations on floating-point values, in some cases the method may not appear to round midpoint values to the nearest even value in the decimal position. This is illustrated in the following example, where 2.135 is rounded to 2.13 instead of 2.14. This occurs because internally the method multiplies by 10digits, and the multiplication operation in this case suffers from a loss of precision. - - :::code language="csharp" source="~/snippets/csharp/System/Math/Round/round3.cs" interactive="try-dotnet" id="Snippet2"::: - :::code language="fsharp" source="~/snippets/fsharp/System/Math/Round/round3.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.math.round/vb/round3.vb" id="Snippet2"::: - - + Because of the loss of precision that can result from representing decimal values as floating-point numbers or performing arithmetic operations on floating-point values, in some cases the method may not appear to round midpoint values to the nearest even value in the decimal position. This is illustrated in the following example, where 2.135 is rounded to 2.13 instead of 2.14. This occurs because internally the method multiplies by 10digits, and the multiplication operation in this case suffers from a loss of precision. :::code language="csharp" source="~/snippets/csharp/System/Math/Round/round3.cs" interactive="try-dotnet" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/Math/Round/round3.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.math.round/vb/round3.vb" id="Snippet2"::: @@ -6777,37 +6873,31 @@ The following example rounds double values with two fractional digits to doubles Rounds a double-precision floating-point value to an integer using the specified rounding convention. The integer that is rounded to. This method returns a instead of an integral type. - , the method returns . If `value` is or , the method returns or , respectively. +If the value of the `value` argument is , the method returns . If `value` is or , the method returns or , respectively. - + ## Example The following example displays values returned by the method with different `mode` values. - + :::code language="csharp" source="~/snippets/csharp/System/Decimal/Round/midpoint2.cs" interactive="try-dotnet" id="Snippet6"::: :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/Round/midpoint2.fs" id="Snippet6"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.math.round.overload/vb/midpoint2.vb" id="Snippet6"::: - + ]]> is not a valid value of . - Because of the loss of precision that can result from representing decimal values as floating-point numbers or performing arithmetic operations on floating-point values, in some cases the method may not appear to round midpoint values to the nearest even integer. In the following example, because the floating-point value .1 has no finite binary representation, the first call to the method with a value of 11.5 returns 11 instead of 12. - - :::code language="csharp" source="~/snippets/csharp/System/Math/Round/round5.cs" interactive="try-dotnet" id="Snippet4"::: - :::code language="fsharp" source="~/snippets/fsharp/System/Math/Round/round5.fs" id="Snippet4"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.math.round/vb/round5.vb" id="Snippet4"::: - - + Because of the loss of precision that can result from representing decimal values as floating-point numbers or performing arithmetic operations on floating-point values, in some cases the method may not appear to round midpoint values to the nearest even integer. In the following example, because the floating-point value .1 has no finite binary representation, the first call to the method with a value of 11.5 returns 11 instead of 12. :::code language="csharp" source="~/snippets/csharp/System/Math/Round/round5.cs" interactive="try-dotnet" id="Snippet4"::: :::code language="fsharp" source="~/snippets/fsharp/System/Math/Round/round5.fs" id="Snippet4"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.math.round/vb/round5.vb" id="Snippet4"::: @@ -6876,18 +6966,18 @@ The following example displays values returned by the -## Example + +## Example The following example demonstrates how to use the method with the enumeration. :::code language="csharp" source="~/snippets/csharp/System/Decimal/Round/mpr.cs" interactive="try-dotnet-method" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/Round/mpr.fs" id="Snippet1"::: -:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.math.round.overload/vb/mpr.vb" id="Snippet1"::: +:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.math.round.overload/vb/mpr.vb" id="Snippet1"::: ]]> @@ -6951,9 +7041,9 @@ The following example demonstrates how to use the me Rounds a double-precision floating-point value to a specified number of fractional digits using the specified rounding convention. The number that has fractional digits that is rounded to. If has fewer fractional digits than , is returned unchanged. - type is 15. @@ -6961,17 +7051,17 @@ See [Midpoint values and rounding conventions](#midpoint-values-and-rounding-con [!INCLUDE[midpoint-rounding](~/includes/floating-point-equality.md)] -If the value of the `value` argument is , the method returns . If `value` is or , the method returns or , respectively. +If the value of the `value` argument is , the method returns . If `value` is or , the method returns or , respectively. + + +## Example - -## Example +The following example demonstrates how to use the method with the enumeration. -The following example demonstrates how to use the method with the enumeration. - :::code language="csharp" source="~/snippets/csharp/System/Decimal/Round/mpr.cs" interactive="try-dotnet-method" id="Snippet4"::: :::code language="fsharp" source="~/snippets/fsharp/System/Decimal/Round/mpr.fs" id="Snippet4"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.math.round.overload/vb/mpr.vb" id="Snippet4"::: - + ]]> @@ -6979,13 +7069,7 @@ The following example demonstrates how to use the is not a valid value of . - Because of the loss of precision that can result from representing decimal values as floating-point numbers or performing arithmetic operations on floating-point values, in some cases the method may not appear to round midpoint values as specified by the parameter. This is illustrated in the following example, where 2.135 is rounded to 2.13 instead of 2.14. This occurs because internally the method multiplies by 10digits, and the multiplication operation in this case suffers from a loss of precision. - - :::code language="csharp" source="~/snippets/csharp/System/Math/Round/round4.cs" interactive="try-dotnet-method" id="Snippet3"::: - :::code language="fsharp" source="~/snippets/fsharp/System/Math/Round/round4.fs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.math.round/vb/round4.vb" id="Snippet3"::: - - + Because of the loss of precision that can result from representing decimal values as floating-point numbers or performing arithmetic operations on floating-point values, in some cases the method may not appear to round midpoint values as specified by the parameter. This is illustrated in the following example, where 2.135 is rounded to 2.13 instead of 2.14. This occurs because internally the method multiplies by 10digits, and the multiplication operation in this case suffers from a loss of precision. :::code language="csharp" source="~/snippets/csharp/System/Math/Round/round4.cs" interactive="try-dotnet-method" id="Snippet3"::: :::code language="fsharp" source="~/snippets/fsharp/System/Math/Round/round4.fs" id="Snippet3"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.math.round/vb/round4.vb" id="Snippet3"::: @@ -7031,11 +7115,11 @@ The following example demonstrates how to use the Returns x * 2^n computed efficiently. x * 2^n computed efficiently. -
@@ -7103,36 +7187,45 @@ The following example demonstrates how to use the A signed decimal number. Returns an integer that indicates the sign of a decimal number. - A number that indicates the sign of , as shown in the following table. - - Return value - - Meaning - - -1 - - is less than zero. - - 0 - - is equal to zero. - - 1 - - is greater than zero. - - + A number that indicates the sign of , as shown in the following table. + + Return value + + + Meaning + + + + + -1 + + + is less than zero. + + + 0 + + + is equal to zero. + + + 1 + + + is greater than zero. + + - method to determine the sign of a value and display it to the console. + method to determine the sign of a value and display it to the console. :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/math.sign/CPP/sign.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Math/Sign/sign.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Math/Sign/sign.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/math.sign/VB/sign.vb" id="Snippet1"::: - + ]]> @@ -7188,36 +7281,45 @@ The following example demonstrates how to use the A signed number. Returns an integer that indicates the sign of a double-precision floating-point number. - A number that indicates the sign of , as shown in the following table. - - Return value - - Meaning - - -1 - - is less than zero. - - 0 - - is equal to zero. - - 1 - - is greater than zero. - - + A number that indicates the sign of , as shown in the following table. + + Return value + + + Meaning + + + + + -1 + + + is less than zero. + + + 0 + + + is equal to zero. + + + 1 + + + is greater than zero. + + - method to determine the sign of a value and display it to the console. + method to determine the sign of a value and display it to the console. :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/math.sign/CPP/sign.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Math/Sign/sign.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Math/Sign/sign.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/math.sign/VB/sign.vb" id="Snippet1"::: - + ]]> @@ -7275,36 +7377,45 @@ The following example demonstrates how to use the A signed number. Returns an integer that indicates the sign of a 16-bit signed integer. - A number that indicates the sign of , as shown in the following table. - - Return value - - Meaning - - -1 - - is less than zero. - - 0 - - is equal to zero. - - 1 - - is greater than zero. - - + A number that indicates the sign of , as shown in the following table. + + Return value + + + Meaning + + + + + -1 + + + is less than zero. + + + 0 + + + is equal to zero. + + + 1 + + + is greater than zero. + + - method to determine the sign of an value and display it to the console. + method to determine the sign of an value and display it to the console. :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/math.sign/CPP/sign.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Math/Sign/sign.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Math/Sign/sign.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/math.sign/VB/sign.vb" id="Snippet1"::: - + ]]> @@ -7360,36 +7471,45 @@ The following example demonstrates how to use the A signed number. Returns an integer that indicates the sign of a 32-bit signed integer. - A number that indicates the sign of , as shown in the following table. - - Return value - - Meaning - - -1 - - is less than zero. - - 0 - - is equal to zero. - - 1 - - is greater than zero. - - + A number that indicates the sign of , as shown in the following table. + + Return value + + + Meaning + + + + + -1 + + + is less than zero. + + + 0 + + + is equal to zero. + + + 1 + + + is greater than zero. + + - method to determine the sign of an value and display it to the console. - + method to determine the sign of an value and display it to the console. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/math.sign/CPP/sign.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Math/Sign/sign.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Math/Sign/sign.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/math.sign/VB/sign.vb" id="Snippet1"::: - + ]]> @@ -7445,36 +7565,45 @@ The following example demonstrates how to use the A signed number. Returns an integer that indicates the sign of a 64-bit signed integer. - A number that indicates the sign of , as shown in the following table. - - Return value - - Meaning - - -1 - - is less than zero. - - 0 - - is equal to zero. - - 1 - - is greater than zero. - - + A number that indicates the sign of , as shown in the following table. + + Return value + + + Meaning + + + + + -1 + + + is less than zero. + + + 0 + + + is equal to zero. + + + 1 + + + is greater than zero. + + - method to determine the sign of an value and display it to the console. + method to determine the sign of an value and display it to the console. :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/math.sign/CPP/sign.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Math/Sign/sign.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Math/Sign/sign.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/math.sign/VB/sign.vb" id="Snippet1"::: - + ]]> @@ -7519,34 +7648,43 @@ The following example demonstrates how to use the A signed number. Returns an integer that indicates the sign of a native sized signed integer. - A number that indicates the sign of , as shown in the following table. - - Return value - - Meaning - - -1 - - is less than zero. - - 0 - - is equal to zero. - - 1 - - is greater than zero. - - + A number that indicates the sign of , as shown in the following table. + + Return value + + + Meaning + + + + + -1 + + + is less than zero. + + + 0 + + + is equal to zero. + + + 1 + + + is greater than zero. + + - method to determine the sign of an value and display it to the console. + method to determine the sign of an value and display it to the console. :::code language="csharp" source="~/snippets/csharp/System/Math/Sign/sign.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Math/Sign/sign.fs" id="Snippet1"::: - + ]]> @@ -7606,36 +7744,45 @@ The following example demonstrates how to use the A signed number. Returns an integer that indicates the sign of an 8-bit signed integer. - A number that indicates the sign of , as shown in the following table. - - Return value - - Meaning - - -1 - - is less than zero. - - 0 - - is equal to zero. - - 1 - - is greater than zero. - - + A number that indicates the sign of , as shown in the following table. + + Return value + + + Meaning + + + + + -1 + + + is less than zero. + + + 0 + + + is equal to zero. + + + 1 + + + is greater than zero. + + - method to determine the sign of an value and display it to the console. + method to determine the sign of an value and display it to the console. :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/math.sign/CPP/sign.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Math/Sign/sign.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Math/Sign/sign.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/math.sign/VB/sign.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/math.sign/VB/sign.vb" id="Snippet1"::: + ]]> @@ -7691,36 +7838,45 @@ The following example demonstrates how to use the A signed number. Returns an integer that indicates the sign of a single-precision floating-point number. - A number that indicates the sign of , as shown in the following table. - - Return value - - Meaning - - -1 - - is less than zero. - - 0 - - is equal to zero. - - 1 - - is greater than zero. - - + A number that indicates the sign of , as shown in the following table. + + Return value + + + Meaning + + + + + -1 + + + is less than zero. + + + 0 + + + is equal to zero. + + + 1 + + + is greater than zero. + + - method to determine the sign of a value and display it to the console. + method to determine the sign of a value and display it to the console. :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/math.sign/CPP/sign.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Math/Sign/sign.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Math/Sign/sign.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/math.sign/VB/sign.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/math.sign/VB/sign.vb" id="Snippet1"::: + ]]> @@ -7780,23 +7936,23 @@ The following example demonstrates how to use the Returns the sine of the specified angle. The sine of . If is equal to , , or , this method returns . - /180 to convert degrees to radians. - - This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures. - - - -## Examples - The following example uses to evaluate certain trigonometric identities for selected angles. + /180 to convert degrees to radians. + + This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures. + + + +## Examples + The following example uses to evaluate certain trigonometric identities for selected angles. :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Math.SinCos/CPP/sincos.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Math/Cos/sincos.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Math/Cos/sincos.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Math.SinCos/VB/sincos.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Math.SinCos/VB/sincos.vb" id="Snippet1"::: + ]]> @@ -7841,21 +7997,21 @@ The following example demonstrates how to use the Returns the sine and cosine of the specified angle. The sine and cosine of . If is equal to , , or , this method returns . - /180 to convert degrees to radians. - - This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures. - - - -## Examples - The following example uses to evaluate certain trigonometric identities for selected angles. + /180 to convert degrees to radians. + + This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures. + + + +## Examples + The following example uses to evaluate certain trigonometric identities for selected angles. :::code language="csharp" source="~/snippets/csharp/System/Math/Cos/sincos.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Math/Cos/sincos.fs" id="Snippet1"::: - + ]]> @@ -7913,23 +8069,23 @@ The following example demonstrates how to use the Returns the hyperbolic sine of the specified angle. The hyperbolic sine of . If is equal to , , or , this method returns a equal to . - /180 to convert degrees to radians. - - This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures. - - - -## Examples - The following example uses to evaluate certain hyperbolic identities for selected values. + /180 to convert degrees to radians. + + This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures. + + + +## Examples + The following example uses to evaluate certain hyperbolic identities for selected values. :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Math.SinhCosh/CPP/sinhcosh.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Math/Cosh/sinhcosh.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Math/Cosh/sinhcosh.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Math.SinhCosh/VB/sinhcosh.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Math.SinhCosh/VB/sinhcosh.vb" id="Snippet1"::: + ]]> @@ -7989,30 +8145,51 @@ The following example demonstrates how to use the The number whose square root is to be found. Returns the square root of a specified number. - One of the values in the following table. - - parameter - - Return value - - Zero or positive - - The positive square root of . - - Negative - - Equals Equals + One of the values in the following table. + + parameter + Return value + + + + + Zero or positive + + + The positive square root of . + + + Negative + + + + + + + + Equals + + + + + + Equals + + + + + - @@ -8071,23 +8248,23 @@ The following example demonstrates how to use the Returns the tangent of the specified angle. The tangent of . If is equal to , , or , this method returns . - /180 to convert degrees to radians. - - This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures. - - - -## Examples - The following example demonstrates how to calculate the tangent of an angle and display it to the console. + /180 to convert degrees to radians. + + This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures. + + + +## Examples + The following example demonstrates how to calculate the tangent of an angle and display it to the console. :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/math.atanx/CPP/atan.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Math/Atan/atan.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Math/Atan/atan.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/math.atanx/VB/atan.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/math.atanx/VB/atan.vb" id="Snippet1"::: + ]]> @@ -8145,23 +8322,23 @@ The following example demonstrates how to use the Returns the hyperbolic tangent of the specified angle. The hyperbolic tangent of . If is equal to , this method returns -1. If value is equal to , this method returns 1. If is equal to , this method returns . - /180 to convert degrees to radians. - - This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures. - - - -## Examples - The following example uses to evaluate certain hyperbolic tangent identities for selected values. + /180 to convert degrees to radians. + + This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures. + + + +## Examples + The following example uses to evaluate certain hyperbolic tangent identities for selected values. :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Math.Tanh/CPP/tanh.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Math/Tanh/tanh.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Math/Tanh/tanh.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Math.Tanh/VB/tanh.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Math.Tanh/VB/tanh.vb" id="Snippet1"::: + ]]> @@ -8209,11 +8386,11 @@ The following example demonstrates how to use the Calculates the integral part of a number. - @@ -8264,20 +8441,20 @@ The following example demonstrates how to use the Calculates the integral part of a specified decimal number. The integral part of ; that is, the number that remains after any fractional digits have been discarded. - rounds `d` to the nearest integer towards zero. - - - -## Examples - The following example calls the method to truncate both a positive and a negative value. - + rounds `d` to the nearest integer towards zero. + + + +## Examples + The following example calls the method to truncate both a positive and a negative value. + :::code language="csharp" source="~/snippets/csharp/System/Math/Truncate/Truncate1.cs" interactive="try-dotnet-method" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/Math/Truncate/Truncate1.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Math.Truncate/vb/Truncate1.vb" id="Snippet2"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Math.Truncate/vb/Truncate1.vb" id="Snippet2"::: + ]]> @@ -8329,32 +8506,61 @@ The following example demonstrates how to use the A number to truncate. Calculates the integral part of a specified double-precision floating-point number. - The integral part of ; that is, the number that remains after any fractional digits have been discarded, or one of the values listed in the following table. - - Return value - - + The integral part of ; that is, the number that remains after any fractional digits have been discarded, or one of the values listed in the following table. + + + + + Return value + + + + + + + + + + + + + + + + + + + + + + + + + + + + - rounds `d` to the nearest integer towards zero. - + rounds `d` to the nearest integer towards zero. + Starting with Visual Basic 15.8, the performance of Double-to-integer conversion is optimized if you pass the value returned by the `Truncate` method to the any of the [integral conversion functions](/dotnet/visual-basic/language-reference/functions/conversion-functions), or if the Double value returned by `Truncate` is automatically converted to an integer with [Option Strict](/dotnet/visual-basic/language-reference/statements/option-strict-statement) set to Off. This optimization allows code to run faster -- up to twice as fast for code that does a large number of conversions to integer types. The following example illustrates such an optimized conversion: - + ```vb Dim d As Double = 164.7194 Dim i As Integer = CInt(Math.Truncate(d)) ' Result: 164 ``` -## Examples - The following example calls the method to truncate both a positive and a negative value. - +## Examples + The following example calls the method to truncate both a positive and a negative value. + :::code language="csharp" source="~/snippets/csharp/System/Math/Truncate/Truncate1.cs" interactive="try-dotnet-method" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Math/Truncate/Truncate1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Math.Truncate/vb/Truncate1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Math.Truncate/vb/Truncate1.vb" id="Snippet1"::: + ]]> diff --git a/xml/System/MathF.xml b/xml/System/MathF.xml index bf16ba184a8..7b7facb9914 100644 --- a/xml/System/MathF.xml +++ b/xml/System/MathF.xml @@ -39,7 +39,7 @@ Provides constants and static methods for trigonometric, logarithmic, and other common mathematical functions. - class, except that their parameters are of type rather than , and they return rather than values. @@ -83,13 +83,13 @@ The static fields and methods of the `MathF` class correspond to those of the Returns the absolute value of a single-precision floating-point number. A single-precision floating-point number, x, such that 0 ≤ x ≤ Single.MaxValue. - is its numeric value without its sign. For example, the absolute value of both 1.2e-03 and -1.2e03 is 1.2e03. - - If `x` is equal to or , the return value is . If `x` is equal to , the return value is . - + is its numeric value without its sign. For example, the absolute value of both 1.2e-03 and -1.2e03 is 1.2e03. + + If `x` is equal to or , the return value is . If `x` is equal to , the return value is . + ]]> @@ -129,18 +129,18 @@ The static fields and methods of the `MathF` class correspond to those of the A number representing a cosine, where must be greater than or equal to -1, but less than or equal to 1. Returns the angle whose cosine is the specified number. An angle, θ, measured in radians, such that 0 ≤ θ ≤ π. - - -or- - - if < -1 or > 1 or equals . + +-or- + + if < -1 or > 1 or equals . - to convert from radians to degrees. - - This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures. - + to convert from radians to degrees. + + This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures. + ]]> @@ -179,18 +179,18 @@ The static fields and methods of the `MathF` class correspond to those of the A number representing a hyperbolic cosine, where must be greater than or equal to 1, but less than or equal to . Returns the angle whose hyperbolic cosine is the specified number. An angle, θ, measured in radians, such that 0 ≤ θ ≤ ∞. - - -or- - - if < 1 or equals . + +-or- + + if < 1 or equals . - to convert from radians to degrees. - - This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures. - + to convert from radians to degrees. + + This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures. + ]]> @@ -230,20 +230,20 @@ The static fields and methods of the `MathF` class correspond to those of the A number representing a sine, where must be greater than or equal to -1, but less than or equal to 1. Returns the angle whose sine is the specified number. An angle, θ, measured in radians, such that -π/2 ≤ θ ≤ π/2. - - -or- - - if < -1 or > 1 or equals . + +-or- + + if < -1 or > 1 or equals . - to convert from radians to degrees. - - This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures. - + to convert from radians to degrees. + + This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures. + ]]> @@ -281,19 +281,19 @@ The static fields and methods of the `MathF` class correspond to those of the A number representing a hyperbolic sine, where must be greater than or equal to , but less than or equal to . Returns the angle whose hyperbolic sine is the specified number. - An angle, θ, measured in radians. - - -or- - - if equals . + An angle, θ, measured in radians. + +-or- + + if equals . - to convert from radians to degrees. - - This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures. - + to convert from radians to degrees. + + This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures. + ]]> @@ -332,21 +332,21 @@ The static fields and methods of the `MathF` class correspond to those of the A number representing a tangent. Returns the angle whose tangent is the specified number. - An angle, θ, measured in radians, such that -π/2 ≤ θ ≤ π/2. - - -or- - - if equals , -π/2 rounded to double precision (-1.5707963267949) if equals , or π/2 rounded to double precision (1.5707963267949) if equals . + An angle, θ, measured in radians, such that -π/2 ≤ θ ≤ π/2. + +-or- + + if equals , -π/2 rounded to double precision (-1.5707963267949) if equals , or π/2 rounded to double precision (1.5707963267949) if equals . - to convert from radians to degrees. - - This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures. - + to convert from radians to degrees. + + This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures. + ]]> @@ -387,37 +387,15 @@ The static fields and methods of the `MathF` class correspond to those of the The y coordinate of a point. The x coordinate of a point. Returns the angle whose tangent is the quotient of two specified numbers. - An angle, θ, measured in radians, such that -π ≤ θ ≤ π, and tan(θ) = / , where (, ) is a point in the Cartesian plane. Observe the following: - -- For (, ) in quadrant 1, 0 < θ < π/2. - -- For (, ) in quadrant 2, π/2 < θ ≤ π. - -- For (, ) in quadrant 3, -π < θ < -π/2. - -- For (, ) in quadrant 4, -π/2 < θ < 0. - - For points on the boundaries of the quadrants, the return value is the following: - -- If y is 0 and x is not negative, θ = 0. - -- If y is 0 and x is negative, θ = π. - -- If y is positive and x is 0, θ = π/2. - -- If y is negative and x is 0, θ = -π/2. - -- If y is 0 and x is 0, θ = 0. - - If or is , or if and are either or , the method returns . + An angle, θ, measured in radians, such that -π ≤ θ ≤ π, and tan(θ) = / , where (, ) is a point in the Cartesian plane. Observe the following: - For (, ) in quadrant 1, 0 < θ < π/2. - For (, ) in quadrant 2, π/2 < θ ≤ π. - For (, ) in quadrant 3, -π < θ < -π/2. - For (, ) in quadrant 4, -π/2 < θ < 0. For points on the boundaries of the quadrants, the return value is the following: - If y is 0 and x is not negative, θ = 0. - If y is 0 and x is negative, θ = π. - If y is positive and x is 0, θ = π/2. - If y is negative and x is 0, θ = -π/2. - If y is 0 and x is 0, θ = 0. If or is , or if and are either or , the method returns . - @@ -455,19 +433,19 @@ The static fields and methods of the `MathF` class correspond to those of the A number representing a hyperbolic tangent, where must be greater than or equal to -1, but less than or equal to 1. Returns the angle whose hyperbolic tangent is the specified number. - An angle, θ, measured in radians, such that -∞ < θ <-1, or 1 < θ < ∞. - - -or- - - if < -1 or > 1 or equals . + An angle, θ, measured in radians, such that -∞ < θ <-1, or 1 < θ < ∞. + +-or- + + if < -1 or > 1 or equals . - to convert from radians to degrees. - - This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures. - + to convert from radians to degrees. + + This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures. + ]]> @@ -505,14 +483,14 @@ The static fields and methods of the `MathF` class correspond to those of the The value to decrement. Returns the largest value that compares less than a specified value. The largest value that compares less than . - - -or- - - if is equals . - - -or- - - if equals . + +-or- + + if is equals . + +-or- + + if equals . To be added. @@ -549,14 +527,14 @@ The static fields and methods of the `MathF` class correspond to those of the The value to increment. Returns the smallest value that compares greater than a specified value. The smallest value that compares greater than . - - -or- - - if equals . - - -or- - - if is equals . + +-or- + + if equals . + +-or- + + if is equals . To be added. @@ -594,16 +572,16 @@ The static fields and methods of the `MathF` class correspond to those of the The number whose cube root is to be found. Returns the cube root of a specified number. The cube root of . - - -or- - - if is equals . + +-or- + + if is equals . - @@ -645,11 +623,11 @@ The static fields and methods of the `MathF` class correspond to those of the Returns the smallest integral value that is greater than or equal to the specified single-precision floating-point number. The smallest integral value that is greater than or equal to . If is equal to , , or , that value is returned. Note that this method returns a instead of an integral type. - method, which supports rounding toward negative infinity. - + method, which supports rounding toward negative infinity. + ]]> @@ -730,13 +708,13 @@ The static fields and methods of the `MathF` class correspond to those of the Returns the cosine of the specified angle. The cosine of . If is equal to , , or , this method returns . - /180 to convert degrees to radians. - - This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures. - + /180 to convert degrees to radians. + + This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures. + ]]> @@ -777,13 +755,13 @@ The static fields and methods of the `MathF` class correspond to those of the Returns the hyperbolic cosine of the specified angle. The hyperbolic cosine of . If is equal to or , is returned. If is equal to , is returned. - /180 to convert degrees to radians. - - This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures. - + /180 to convert degrees to radians. + + This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures. + ]]> @@ -820,7 +798,7 @@ The static fields and methods of the `MathF` class correspond to those of the Represents the natural logarithmic base, specified by the constant, . - Returns raised to the specified power. The number raised to the power . If equals or , that value is returned. If equals , 0 is returned. - method to calculate powers of other bases. - - is the inverse of . - - This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures. - + method to calculate powers of other bases. + + is the inverse of . + + This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures. + ]]> @@ -918,11 +896,11 @@ The value of this constant is 2.71828175. Returns the largest integral value less than or equal to the specified single-precision floating-point number. The largest integral value less than or equal to . If is equal to , , or , that value is returned. - method, which supports rounding toward positive infinity. - + method, which supports rounding toward positive infinity. + ]]> @@ -967,13 +945,13 @@ The value of this constant is 2.71828175. Returns (x * y) + z, rounded as one ternary operation. (x * y) + z, rounded as one ternary operation. - @@ -1014,31 +992,27 @@ The value of this constant is 2.71828175. A dividend. A divisor. Returns the remainder resulting from the division of a specified number by another specified number. - A number equal to - ( Q), where Q is the quotient of / rounded to the nearest integer (if / falls halfway between two integers, the even integer is returned). - - If - ( Q) is zero, the value +0 is returned if is positive, or -0 if is negative. - - If = 0, is returned. + A number equal to - ( Q), where Q is the quotient of / rounded to the nearest integer (if / falls halfway between two integers, the even integer is returned). If - ( Q) is zero, the value +0 is returned if is positive, or -0 if is negative. If = 0, is returned. - method is not the same as the [remainder operator](/dotnet/csharp/language-reference/operators/remainder-operator). Although both return the remainder after division, the formulas they use are different. The formula for the method is: - -``` -IEEERemainder = dividend - (divisor * MathF.Round(dividend / divisor)) -``` - - In contrast, the formula for the remainder operator is: - -``` -Remainder = (MathF.Abs(dividend) - (MathF.Abs(divisor) * - (MathF.Floor(MathF.Abs(dividend) / MathF.Abs(divisor))))) * - MathF.Sign(dividend) -``` - + method is not the same as the [remainder operator](/dotnet/csharp/language-reference/operators/remainder-operator). Although both return the remainder after division, the formulas they use are different. The formula for the method is: + +``` +IEEERemainder = dividend - (divisor * MathF.Round(dividend / divisor)) +``` + + In contrast, the formula for the remainder operator is: + +``` +Remainder = (MathF.Abs(dividend) - (MathF.Abs(divisor) * + (MathF.Floor(MathF.Abs(dividend) / MathF.Abs(divisor))))) * + MathF.Sign(dividend) +``` + ]]> @@ -1075,27 +1049,42 @@ Remainder = (MathF.Abs(dividend) - (MathF.Abs(divisor) * The number whose logarithm is to be found. Returns the base 2 integer logarithm of a specified number. - One of the values in the following table. - - parameter - - Return value - - Default - - The base 2 integer log of ; that is, (int)log2(). - - Zero - - Int32.MinValue Equal to or or Int32.MaxValue + One of the values in the following table. + + parameter + Return value + + + + + Default + + + The base 2 integer log of ; that is, (int)log2(). + + + Zero + + + + Int32.MinValue + + + + Equal to or or + + Int32.MaxValue + + + - @@ -1134,27 +1123,56 @@ Remainder = (MathF.Abs(dividend) - (MathF.Abs(divisor) * The number whose logarithm is to be found. Returns the natural (base ) logarithm of a specified number. - One of the values in the following table. - - parameter - - Return value - - Positive - - The natural logarithm of ; that is, ln , or log e Zero - - Negative - - Equal to Equal to + One of the values in the following table. + + parameter + Return value + + + + + Positive + + + The natural logarithm of ; that is, ln , or log e + + + Zero + + + + + + + + Negative + + + + + + + + Equal to + + + + + + Equal to + + + + + - @@ -1197,101 +1215,133 @@ Remainder = (MathF.Abs(dividend) - (MathF.Abs(divisor) * The number whose logarithm is to be found. The base. Returns the logarithm of a specified number in a specified base. - One of the values in the following table. (+Infinity denotes , -Infinity denotes , and NaN denotes .) - - Return value - - > 0 - - (0 << 1) -or-(> 1) - - lognewBase(a) - - < 0 - - (any value) - - NaN - - (any value) - - < 0 - - NaN - - != 1 - - = 0 - - NaN - - != 1 - - = +Infinity - - NaN - - = NaN - - (any value) - - NaN - - (any value) - - = NaN - - NaN - - (any value) - - = 1 - - NaN - - = 0 - - 0 << 1 - - +Infinity - - = 0 - - > 1 - - -Infinity - - = +Infinity - - 0 << 1 - - -Infinity - - = +Infinity - - > 1 - - +Infinity - - = 1 - - = 0 - - 0 - - = 1 - - = +Infinity - - 0 - - + One of the values in the following table. (+Infinity denotes , -Infinity denotes , and NaN denotes .) + + + + + + + + Return value + + + + + > 0 + (0 << 1) -or-(> 1) + lognewBase(a) + + + + + < 0 + (any value) + + + NaN + + + + + (any value) + + + < 0 + NaN + + + + + != 1 + = 0 + NaN + + + + + != 1 + = +Infinity + NaN + + + + + = NaN + (any value) + + + NaN + + + + + (any value) + + + = NaN + NaN + + + + + (any value) + + + = 1 + NaN + + + + + = 0 + 0 << 1 + +Infinity + + + + + = 0 + > 1 + -Infinity + + + + + = +Infinity + 0 << 1 + -Infinity + + + + + = +Infinity + > 1 + +Infinity + + + + + = 1 + = 0 + 0 + + + + + = 1 + = +Infinity + 0 + + + + - @@ -1330,29 +1380,56 @@ Remainder = (MathF.Abs(dividend) - (MathF.Abs(divisor) * A number whose logarithm is to be found. Returns the base 10 logarithm of a specified number. - One of the values in the following table. - - parameter - - Return value - - Positive - - The base 10 log of ; that is, log 10. - - Zero - - Negative - - Equal to Equal to + One of the values in the following table. + + parameter + Return value + + + + + Positive + + + The base 10 log of ; that is, log 10. + + + Zero + + + + + + + + Negative + + + + + + + + Equal to + + + + + + Equal to + + + + + - @@ -1389,29 +1466,56 @@ Remainder = (MathF.Abs(dividend) - (MathF.Abs(divisor) * A number whose logarithm is to be found. Returns the base 2 logarithm of a specified number. - One of the values in the following table. - - parameter - - Return value - - Positive - - The base 2 log of ; that is, log 2. - - Zero - - Negative - - Equal to Equal to + One of the values in the following table. + + parameter + Return value + + + + + Positive + + + The base 2 log of ; that is, log 2. + + + Zero + + + + + + + + Negative + + + + + + + + Equal to + + + + + + Equal to + + + + + - @@ -1604,7 +1708,7 @@ Remainder = (MathF.Abs(dividend) - (MathF.Abs(divisor) * Represents the ratio of the circumference of a circle to its diameter, specified by the constant, p. - Returns a specified number raised to the specified power. The number raised to the power . - , , and . - -|Parameters|Return value| -|----------------|------------------| -|`x` or `y` = `NaN`.|`NaN`| -|`x` = Any value except `NaN`; `y` = 0.|1| -|`x` = `NegativeInfinity`; `y` < 0.|0| -|`x` = `NegativeInfinity`; `y` is a positive odd integer.|`NegativeInfinity`| -|`x` = `NegativeInfinity`; `y` is positive but not an odd integer.|`PositiveInfinity`| -|`x` < 0 but not `NegativeInfinity`; `y` is not an integer, `NegativeInfinity`, or `PositiveInfinity`.|`NaN`| -|`x` = -1; `y` = `NegativeInfinity` or `PositiveInfinity`.|`NaN`| -|-1 < `x` < 1; `y` = `NegativeInfinity`.|`PositiveInfinity`| -|-1 < `x` < 1; `y` = `PositiveInfinity`.|0| -|`x` < -1 or `x` > 1; `y` = `NegativeInfinity`.|0| -|`x` < -1 or `x` > 1; `y` = `PositiveInfinity`.|`PositiveInfinity`| -|`x` = 0; `y` < 0.|`PositiveInfinity`| -|`x` = 0; `y` > 0.|0| -|`x` = 1; `y` is any value except `NaN`.|1| -|`x` = `PositiveInfinity`; `y` < 0.|0| -|`x` = `PositiveInfinity`; `y` > 0.|`PositiveInfinity`| - - This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures. - + , , and . + +|Parameters|Return value| +|----------------|------------------| +|`x` or `y` = `NaN`.|`NaN`| +|`x` = Any value except `NaN`; `y` = 0.|1| +|`x` = `NegativeInfinity`; `y` < 0.|0| +|`x` = `NegativeInfinity`; `y` is a positive odd integer.|`NegativeInfinity`| +|`x` = `NegativeInfinity`; `y` is positive but not an odd integer.|`PositiveInfinity`| +|`x` < 0 but not `NegativeInfinity`; `y` is not an integer, `NegativeInfinity`, or `PositiveInfinity`.|`NaN`| +|`x` = -1; `y` = `NegativeInfinity` or `PositiveInfinity`.|`NaN`| +|-1 < `x` < 1; `y` = `NegativeInfinity`.|`PositiveInfinity`| +|-1 < `x` < 1; `y` = `PositiveInfinity`.|0| +|`x` < -1 or `x` > 1; `y` = `NegativeInfinity`.|0| +|`x` < -1 or `x` > 1; `y` = `PositiveInfinity`.|`PositiveInfinity`| +|`x` = 0; `y` < 0.|`PositiveInfinity`| +|`x` = 0; `y` > 0.|0| +|`x` = 1; `y` is any value except `NaN`.|1| +|`x` = `PositiveInfinity`; `y` < 0.|0| +|`x` = `PositiveInfinity`; `y` > 0.|`PositiveInfinity`| + + This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures. + ]]> @@ -1811,16 +1915,16 @@ On hardware without specialized support, this may just return `1.0 / Sqrt(x)`. Rounds a single-precision floating-point value to the nearest integral value, and rounds midpoint values to the nearest even number. The integer nearest . If the fractional component of is halfway between two integers, one of which is even and the other odd, then the even number is returned. Note that this method returns a instead of an integral type. - . [!INCLUDE[midpoint-rounding](~/includes/floating-point-equality.md)] -If the value of the `x` argument is , the method returns . If `x` is or , the method returns or , respectively. - +If the value of the `x` argument is , the method returns . If `x` is or , the method returns or , respectively. + ]]> @@ -1868,18 +1972,18 @@ If the value of the `x` argument is Rounds a single-precision floating-point value to a specified number of fractional digits, and rounds midpoint values to the nearest even number. The number nearest to that contains a number of fractional digits equal to . - type. -This method uses the default rounding convention of . +This method uses the default rounding convention of . [!INCLUDE[midpoint-rounding](~/includes/floating-point-equality.md)] -If the value of the `x` argument is , the method returns . If `x` is or , the method returns or , respectively. - +If the value of the `x` argument is , the method returns . If `x` is or , the method returns or , respectively. + ]]> @@ -1926,14 +2030,14 @@ If the value of the `x` argument is Rounds a single-precision floating-point value to an integer using the specified rounding convention. The integer that is rounded to using the rounding convention. This method returns a instead of an integral type. - , the method returns . If `x` is or , the method returns or , respectively. - +If the value of the `x` argument is , the method returns . If `x` is or , the method returns or , respectively. + ]]> @@ -1982,16 +2086,16 @@ If the value of the `x` argument is Rounds a single-precision floating-point value to a specified number of fractional digits using the specified rounding convention. The number that is rounded to that has fractional digits. If has fewer fractional digits than , is returned unchanged. - type is 6. [!INCLUDE[midpoint-rounding](~/includes/floating-point-equality.md)] -If the value of the `x` argument is , the method returns . If `x` is or , the method returns or , respectively. - +If the value of the `x` argument is , the method returns . If `x` is or , the method returns or , respectively. + ]]> @@ -2074,31 +2178,40 @@ If the value of the `x` argument is A signed number. Returns an integer that indicates the sign of a single-precision floating-point number. - A number that indicates the sign of , as shown in the following table. - - Return value - - Meaning - - -1 - - is less than zero. - - 0 - - is equal to zero. - - 1 - - is greater than zero. - - + A number that indicates the sign of , as shown in the following table. + + Return value + + + Meaning + + + + + -1 + + + is less than zero. + + + 0 + + + is equal to zero. + + + 1 + + + is greater than zero. + + - @@ -2141,13 +2254,13 @@ If the value of the `x` argument is Returns the sine of the specified angle. The sine of . If is equal to , , or , this method returns . - /180 to convert degrees to radians. - - This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures. - + /180 to convert degrees to radians. + + This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures. + ]]> @@ -2189,13 +2302,13 @@ If the value of the `x` argument is Returns the sine and cosine of the specified angle. The sine and cosine of . If is equal to , , or , this method returns . - /180 to convert degrees to radians. - - This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures. - + /180 to convert degrees to radians. + + This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures. + ]]> @@ -2236,13 +2349,13 @@ If the value of the `x` argument is Returns the hyperbolic sine of the specified angle. The hyperbolic sine of . If is equal to , , or , this method returns a equal to . - /180 to convert degrees to radians. - - This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures. - + /180 to convert degrees to radians. + + This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures. + ]]> @@ -2281,19 +2394,40 @@ If the value of the `x` argument is The number whose square root is to be found. Returns the square root of a specified number. - One of the values in the following table. - - parameter - - Return value - - Zero or positive - - The positive square root of . - - Negative - - Equals Equals + One of the values in the following table. + + parameter + Return value + + + + + Zero or positive + + + The positive square root of . + + + Negative + + + + + + + + Equals + + + + + + Equals + + + + + To be added. @@ -2334,13 +2468,13 @@ If the value of the `x` argument is Returns the tangent of the specified angle. The tangent of . If is equal to , , or , this method returns . - /180 to convert degrees to radians. - - This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures. - + /180 to convert degrees to radians. + + This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures. + ]]> @@ -2381,13 +2515,13 @@ If the value of the `x` argument is Returns the hyperbolic tangent of the specified angle. The hyperbolic tangent of . If is equal to , this method returns -1. If value is equal to , this method returns 1. If is equal to , this method returns . - /180 to convert degrees to radians. - - This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures. - + /180 to convert degrees to radians. + + This method calls into the underlying C runtime, and the exact result or valid input range may differ between different operating systems or architectures. + ]]> @@ -2456,18 +2590,47 @@ If the value of the `x` argument is A number to truncate. Calculates the integral part of a specified single-precision floating-point number. - The integral part of ; that is, the number that remains after any fractional digits have been discarded, or one of the values listed in the following table. - - Return value - - + The integral part of ; that is, the number that remains after any fractional digits have been discarded, or one of the values listed in the following table. + + + + + Return value + + + + + + + + + + + + + + + + + + + + + + + + + + + + - rounds `x` to the nearest integer towards zero. - + rounds `x` to the nearest integer towards zero. + ]]> diff --git a/xml/System/MemberAccessException.xml b/xml/System/MemberAccessException.xml index af97fbff89c..3f1ab2e6ab6 100644 --- a/xml/System/MemberAccessException.xml +++ b/xml/System/MemberAccessException.xml @@ -70,21 +70,21 @@ The exception that is thrown when an attempt to access a class member fails. - is the base class for , , , , and , and (.NET Native only). These exceptions are thrown when a class member is not found or access to the member is not permitted. - - is thrown by the following methods: - - of the classes, of the class, and of the class. - - Apps compiled by using the .NET Native tool chain may throw a [MissingRuntimeArtifactException](/windows/uwp/dotnet-native/missingruntimeartifactexception-class-net-native) exception at run time. `MissingRuntimeArtifactException` is an internal-only exception type derived from . The exception indicates that metadata needed for the successful execution of an app is not present at run time. You should not use a `try`/`catch` block to handle the exception. Instead, you should determine what metadata is missing and modify your app's runtime directives file to ensure that it is present at run time. - - uses the HRESULT COR_E_MEMBERACCESS, that has the value 0x8013151A. - - For a list of initial property values for an instance of , see the constructors. - + is the base class for , , , , and , and (.NET Native only). These exceptions are thrown when a class member is not found or access to the member is not permitted. + + is thrown by the following methods: + + of the classes, of the class, and of the class. + + Apps compiled by using the .NET Native tool chain may throw a [MissingRuntimeArtifactException](/windows/uwp/dotnet-native/missingruntimeartifactexception-class-net-native) exception at run time. `MissingRuntimeArtifactException` is an internal-only exception type derived from . The exception indicates that metadata needed for the successful execution of an app is not present at run time. You should not use a `try`/`catch` block to handle the exception. Instead, you should determine what metadata is missing and modify your app's runtime directives file to ensure that it is present at run time. + + uses the HRESULT COR_E_MEMBERACCESS, that has the value 0x8013151A. + + For a list of initial property values for an instance of , see the constructors. + ]]> @@ -141,18 +141,18 @@ Initializes a new instance of the class. - property of the new instance to a system-supplied message that describes the error, such as "Cannot access member." This message takes into account the current system culture. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The localized error message string.| - + property of the new instance to a system-supplied message that describes the error, such as "Cannot access member." This message takes into account the current system culture. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The localized error message string.| + ]]> @@ -199,18 +199,18 @@ The message that describes the error. Initializes a new instance of the class with a specified error message. - . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The error message string.| - + . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The error message string.| + ]]> @@ -272,11 +272,11 @@ The contextual information about the source or destination. Initializes a new instance of the class with serialized data. - XML and SOAP Serialization @@ -326,18 +326,18 @@ The exception that is the cause of the current exception. If the parameter is not a null reference ( in Visual Basic), the current exception is raised in a block that handles the inner exception. Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception. - property. The property returns the same value that is passed into the constructor, or a null reference (`Nothing` in Visual Basic) if the property does not supply the inner exception value to the constructor. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||The inner exception reference.| -||The error message string.| - + property. The property returns the same value that is passed into the constructor, or a null reference (`Nothing` in Visual Basic) if the property does not supply the inner exception value to the constructor. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||The inner exception reference.| +||The error message string.| + ]]> diff --git a/xml/System/MemoryExtensions.xml b/xml/System/MemoryExtensions.xml index 642fcff5641..2ebf76216d7 100644 --- a/xml/System/MemoryExtensions.xml +++ b/xml/System/MemoryExtensions.xml @@ -2040,7 +2040,7 @@ Returns `default` when `array` is `null`. The first sequence to compare. The second sequence to compare. Finds the length of any common prefix shared between and . - The length of the common prefix shared by the two spans. If there's no shared prefix, 0 is returned. + The length of the common prefix shared by the two spans. If there's no shared prefix, 0 is returned. To be added. @@ -2095,7 +2095,7 @@ Returns `default` when `array` is `null`. The first sequence to compare. The second sequence to compare. Finds the length of any common prefix shared between and . - The length of the common prefix shared by the two spans. If there's no shared prefix, 0 is returned. + The length of the common prefix shared by the two spans. If there's no shared prefix, 0 is returned. To be added. @@ -2159,7 +2159,7 @@ Returns `default` when `array` is `null`. The second sequence to compare. The implementation to use when comparing elements, or to use the default for the type of an element. Determines the length of any common prefix shared between and . - The length of the common prefix shared by the two spans. If there's no shared prefix, 0 is returned. + The length of the common prefix shared by the two spans. If there's no shared prefix, 0 is returned. To be added. @@ -2223,7 +2223,7 @@ Returns `default` when `array` is `null`. The second sequence to compare. The implementation to use when comparing elements, or to use the default for the type of an element. Finds the length of any common prefix shared between and . - The length of the common prefix shared by the two spans. If there's no shared prefix, 0 is returned. + The length of the common prefix shared by the two spans. If there's no shared prefix, 0 is returned. To be added. @@ -2262,7 +2262,7 @@ Returns `default` when `array` is `null`. The value to compare with the source span. An enumeration value that determines how and are compared. Compares one character span with another using a specified string comparison, and returns an integer that indicates their relative position in the sort order. - A signed integer that indicates the relative order of and :
- If less than 0, precedes than .
- If 0, equals .
- If greater than 0, follows .
+ A signed integer that indicates the relative order of and :
- If less than 0, precedes than .
- If 0, equals .
- If greater than 0, follows .
To be added. @@ -2924,8 +2924,7 @@ Returns `default` when `array` is `null`. The set of values to exclude from the search. Searches for any value other than the specified . - if any value other than those in is present in the span. - If all of the values are in , returns . + if any value other than those in is present in the span. If all of the values are in , returns . To be added. @@ -2978,8 +2977,7 @@ Returns `default` when `array` is `null`. The set of values to exclude from the search. Searches for any value other than the specified . - if any value other than those in is present in the span. - If all of the values are in , returns . + if any value other than those in is present in the span. If all of the values are in , returns . To be added. @@ -3032,8 +3030,7 @@ Returns `default` when `array` is `null`. The value to exclude from the search. Searches for any value other than the specified . - if any value other than is present in the span. - If all of the values are , returns . + if any value other than is present in the span. If all of the values are , returns . To be added. @@ -3252,8 +3249,7 @@ Returns `default` when `array` is `null`. The value to exclude from the search. Searches for any value other than or . - if any value other than or is present in the span. - If all of the values are or , returns . + if any value other than or is present in the span. If all of the values are or , returns . To be added. @@ -3375,8 +3371,7 @@ Returns `default` when `array` is `null`. The value to exclude from the search. Searches for any value other than , , or . - if any value other than , , or is present in the span. - If all of the values are , , or , returns . + if any value other than , , or is present in the span. If all of the values are , , or , returns . To be added. @@ -3498,8 +3493,7 @@ Returns `default` when `array` is `null`. The upper bound, inclusive, of the excluded range. Searches for any value outside of the range between and , inclusive. - if any value other than those in the specified range is present in the span. - If all of the values are inside of the specified range, returns . + if any value other than those in the specified range is present in the span. If all of the values are inside of the specified range, returns . To be added. @@ -5201,8 +5195,7 @@ Invalid sequences will be represented in the enumeration by The span to search. The values to exclude from the search. Searches for the first index of any value other than the specified . - The index in the span of the first occurrence of any value other than those in . - If all of the values are in , returns -1. + The index in the span of the first occurrence of any value other than those in . If all of the values are in , returns -1. To be added. @@ -5255,8 +5248,7 @@ Invalid sequences will be represented in the enumeration by The span to search. The values to avoid. Searches for the first index of any value other than the specified . - The index in the span of the first occurrence of any value other than those in . - If all of the values are in , returns -1. + The index in the span of the first occurrence of any value other than those in . If all of the values are in , returns -1. To be added. @@ -5309,8 +5301,7 @@ Invalid sequences will be represented in the enumeration by The span to search. A value to avoid. Searches for the first index of any value other than the specified . - The index in the span of the first occurrence of any value other than . - If all of the values are , returns -1. + The index in the span of the first occurrence of any value other than . If all of the values are , returns -1. To be added. @@ -5362,8 +5353,7 @@ Invalid sequences will be represented in the enumeration by The span to search. The values to exclude from the search. Searches for the first index of any value other than the specified . - The index in the span of the first occurrence of any value other than those in . - If all of the values are in , returns -1. + The index in the span of the first occurrence of any value other than those in . If all of the values are in , returns -1. To be added. @@ -5416,8 +5406,7 @@ Invalid sequences will be represented in the enumeration by The span to search. The values to avoid. Searches for the first index of any value other than the specified . - The index in the span of the first occurrence of any value other than those in . - If all of the values are in , returns -1. + The index in the span of the first occurrence of any value other than those in . If all of the values are in , returns -1. To be added. @@ -5470,8 +5459,7 @@ Invalid sequences will be represented in the enumeration by The span to search. A value to avoid. Searches for the first index of any value other than the specified . - The index in the span of the first occurrence of any value other than . - If all of the values are , returns -1. + The index in the span of the first occurrence of any value other than . If all of the values are , returns -1. To be added. @@ -5531,8 +5519,7 @@ Invalid sequences will be represented in the enumeration by A value to avoid. A value to avoid Searches for the first index of any value other than the specified or . - The index in the span of the first occurrence of any value other than and . - If all of the values are or , returns -1. + The index in the span of the first occurrence of any value other than and . If all of the values are or , returns -1. To be added. @@ -5592,8 +5579,7 @@ Invalid sequences will be represented in the enumeration by A value to avoid. A value to avoid Searches for the first index of any value other than the specified or . - The index in the span of the first occurrence of any value other than and . - If all of the values are or , returns -1. + The index in the span of the first occurrence of any value other than and . If all of the values are or , returns -1. To be added. @@ -5655,8 +5641,7 @@ Invalid sequences will be represented in the enumeration by A value to avoid A value to avoid Searches for the first index of any value other than the specified , , or . - The index in the span of the first occurrence of any value other than , , and . - If all of the values are , , and , returns -1. + The index in the span of the first occurrence of any value other than , , and . If all of the values are , , and , returns -1. To be added. @@ -5718,8 +5703,7 @@ Invalid sequences will be represented in the enumeration by A value to avoid A value to avoid Searches for the first index of any value other than the specified , , or . - The index in the span of the first occurrence of any value other than , , and . - If all of the values are , , and , returns -1. + The index in the span of the first occurrence of any value other than , , and . If all of the values are , , and , returns -1. To be added. @@ -5779,7 +5763,7 @@ Invalid sequences will be represented in the enumeration by The upper bound, inclusive, of the excluded range. Searches for the first index of any value outside of the range between and , inclusive. The index in the span of the first occurrence of any value outside of the specified range. - If all of the values are inside of the specified range, returns -1. + If all of the values are inside of the specified range, returns -1. To be added. @@ -5899,7 +5883,7 @@ Invalid sequences will be represented in the enumeration by The upper bound, inclusive, of the range for which to search. Searches for the first index of any value in the range between and , inclusive. The index in the span of the first occurrence of any value in the specified range. - If all of the values are outside of the specified range, returns -1. + If all of the values are outside of the specified range, returns -1. To be added. @@ -6810,8 +6794,7 @@ Invalid sequences will be represented in the enumeration by The span to search. The values to exclude from the search. Searches for the last index of any value other than the specified . - The index in the span of the last occurrence of any value other than those in . - If all of the values are in , returns -1. + The index in the span of the last occurrence of any value other than those in . If all of the values are in , returns -1. To be added. @@ -6864,8 +6847,7 @@ Invalid sequences will be represented in the enumeration by The span to search. The values to avoid. Searches for the last index of any value other than the specified . - The index in the span of the first occurrence of any value other than those in . - If all of the values are in , returns -1. + The index in the span of the first occurrence of any value other than those in . If all of the values are in , returns -1. To be added. @@ -6918,8 +6900,7 @@ Invalid sequences will be represented in the enumeration by The span to search. A value to avoid. Searches for the last index of any value other than the specified . - The index in the span of the last occurrence of any value other than . - If all of the values are , returns -1. + The index in the span of the last occurrence of any value other than . If all of the values are , returns -1. To be added. @@ -6971,8 +6952,7 @@ Invalid sequences will be represented in the enumeration by The span to search. The values to exclude from the search. Searches for the last index of any value other than the specified . - The index in the span of the last occurrence of any value other than those in . - If all of the values are in , returns -1. + The index in the span of the last occurrence of any value other than those in . If all of the values are in , returns -1. To be added. @@ -7025,8 +7005,7 @@ Invalid sequences will be represented in the enumeration by The span to search. The values to avoid. Searches for the last index of any value other than the specified . - The index in the span of the last occurrence of any value other than those in . - If all of the values are in , returns -1. + The index in the span of the last occurrence of any value other than those in . If all of the values are in , returns -1. To be added. @@ -7079,8 +7058,7 @@ Invalid sequences will be represented in the enumeration by The span to search. A value to avoid. Searches for the last index of any value other than the specified . - The index in the span of the last occurrence of any value other than . - If all of the values are , returns -1. + The index in the span of the last occurrence of any value other than . If all of the values are , returns -1. To be added. @@ -7140,8 +7118,7 @@ Invalid sequences will be represented in the enumeration by A value to avoid. A value to avoid Searches for the last index of any value other than the specified or . - The index in the span of the last occurrence of any value other than and . - If all of the values are or , returns -1. + The index in the span of the last occurrence of any value other than and . If all of the values are or , returns -1. To be added. @@ -7201,8 +7178,7 @@ Invalid sequences will be represented in the enumeration by A value to avoid. A value to avoid Searches for the last index of any value other than the specified or . - The index in the span of the last occurrence of any value other than and . - If all of the values are or , returns -1. + The index in the span of the last occurrence of any value other than and . If all of the values are or , returns -1. To be added. @@ -7264,8 +7240,7 @@ Invalid sequences will be represented in the enumeration by A value to avoid A value to avoid Searches for the last index of any value other than the specified , , or . - The index in the span of the last occurrence of any value other than , , and . - If all of the values are , , and , returns -1. + The index in the span of the last occurrence of any value other than , , and . If all of the values are , , and , returns -1. To be added. @@ -7327,8 +7302,7 @@ Invalid sequences will be represented in the enumeration by A value to avoid A value to avoid Searches for the last index of any value other than the specified , , or . - The index in the span of the last occurrence of any value other than , , and . - If all of the values are , , and , returns -1. + The index in the span of the last occurrence of any value other than , , and . If all of the values are , , and , returns -1. To be added. @@ -7388,7 +7362,7 @@ Invalid sequences will be represented in the enumeration by The upper bound, inclusive, of the excluded range. Searches for the last index of any value outside of the range between and , inclusive. The index in the span of the last occurrence of any value outside of the specified range. - If all of the values are inside of the specified range, returns -1. + If all of the values are inside of the specified range, returns -1. To be added. @@ -7508,7 +7482,7 @@ Invalid sequences will be represented in the enumeration by The upper bound, inclusive, of the range for which to search. Searches for the last index of any value in the range between and , inclusive. The index in the span of the last occurrence of any value in the specified range. - If all of the values are outside of the specified range, returns -1. + If all of the values are outside of the specified range, returns -1. To be added. @@ -7948,9 +7922,10 @@ Invalid sequences will be represented in the enumeration by Copies to , replacing all occurrences of with . To be added. The span is shorter than the span. - -or- - and overlap but don't refer to the same starting location. - + +-or- + + and overlap but don't refer to the same starting location.
@@ -8059,7 +8034,7 @@ Invalid sequences will be represented in the enumeration by The first sequence to compare. The second sequence to compare. Determines the relative order of two read-only sequences by comparing their elements using IComparable{T}.CompareTo(T). - A signed integer that indicates the relative order of and :
- If less than 0, precedes than .
- If 0, equals .
- If greater than 0, follows .
+ A signed integer that indicates the relative order of and :
- If less than 0, precedes than .
- If 0, equals .
- If greater than 0, follows .
To be added.
@@ -8118,7 +8093,7 @@ Invalid sequences will be represented in the enumeration by The span to compare. The read-only span to compare. Determines the relative order of a span and a read-only span by comparing the elements using IComparable{T}.CompareTo(T). - A signed integer that indicates the relative order of and :
- If less than 0, precedes than .
- If 0, equals .
- If greater than 0, follows .
+ A signed integer that indicates the relative order of and :
- If less than 0, precedes than .
- If 0, equals .
- If greater than 0, follows .
To be added. @@ -8788,13 +8763,10 @@ Invalid sequences will be represented in the enumeration by The number of ranges written into . Delimiter characters are not included in the elements of the returned array. - - If the span is empty, or if the specifies and is empty, or if specifies both and and the is entirely whitespace, no ranges are written to the destination. - - If the span does not contain , or if 's length is 1, a single range will be output containing the entire , subject to the processing implied by . - - If there are more regions in than will fit in , the first length minus 1 ranges are stored in , and a range for the remainder of is stored in . - + + If the span is empty, or if the specifies and is empty, or if specifies both and and the is entirely whitespace, no ranges are written to the destination. + If the span does not contain , or if 's length is 1, a single range will be output containing the entire , subject to the processing implied by . + If there are more regions in than will fit in , the first length minus 1 ranges are stored in , and a range for the remainder of is stored in . @@ -8830,13 +8802,10 @@ Invalid sequences will be represented in the enumeration by The number of ranges written into . Delimiter characters are not included in the elements of the returned array. - - If the span is empty, or if the specifies and is empty, or if specifies both and and the is entirely whitespace, no ranges are written to the destination. - - If the span does not contain , or if 's length is 1, a single range will be output containing the entire , subject to the processing implied by . - - If there are more regions in than will fit in , the first length minus 1 ranges are stored in , and a range for the remainder of is stored in . - + + If the span is empty, or if the specifies and is empty, or if specifies both and and the is entirely whitespace, no ranges are written to the destination. + If the span does not contain , or if 's length is 1, a single range will be output containing the entire , subject to the processing implied by . + If there are more regions in than will fit in , the first length minus 1 ranges are stored in , and a range for the remainder of is stored in . @@ -8872,13 +8841,10 @@ Invalid sequences will be represented in the enumeration by The number of ranges written into . Delimiter characters are not included in the elements of the returned array. - - If the span is empty, or if the specifies and is empty, or if specifies both and and the is entirely whitespace, no ranges are written to the destination. - - If the span does not contain any of the , or if 's length is 1, a single range will be output containing the entire , subject to the processing implied by . - - If there are more regions in than will fit in , the first length minus 1 ranges are stored in , and a range for the remainder of is stored in . - + + If the span is empty, or if the specifies and is empty, or if specifies both and and the is entirely whitespace, no ranges are written to the destination. + If the span does not contain any of the , or if 's length is 1, a single range will be output containing the entire , subject to the processing implied by . + If there are more regions in than will fit in , the first length minus 1 ranges are stored in , and a range for the remainder of is stored in . @@ -8915,19 +8881,16 @@ Invalid sequences will be represented in the enumeration by The source span to parse. The destination span into which the resulting ranges are written. - Any number of strings that may delimit the regions in this instance. If empty, all Unicode whitespace characters are used as the separators. + Any number of strings that may delimit the regions in this instance. If empty, all Unicode whitespace characters are used as the separators. A bitwise combination of the enumeration values that specifies whether to trim whitespace and include empty ranges. Parses the source for one of the specified , populating the span with instances representing the regions between the separators. The number of ranges written into . Delimiter characters are not included in the elements of the returned array. - - If the span is empty, or if the specifies and is empty, or if specifies both and and the is entirely whitespace, no ranges are written to the destination. - - If the span does not contain any of the , or if 's length is 1, a single range will be output containing the entire , subject to the processing implied by . - - If there are more regions in than will fit in , the first length minus 1 ranges are stored in , and a range for the remainder of is stored in . - + + If the span is empty, or if the specifies and is empty, or if specifies both and and the is entirely whitespace, no ranges are written to the destination. + If the span does not contain any of the , or if 's length is 1, a single range will be output containing the entire , subject to the processing implied by . + If there are more regions in than will fit in , the first length minus 1 ranges are stored in , and a range for the remainder of is stored in . diff --git a/xml/System/Memory`1.xml b/xml/System/Memory`1.xml index 6abffbb0bc7..e1c9df1bd43 100644 --- a/xml/System/Memory`1.xml +++ b/xml/System/Memory`1.xml @@ -74,10 +74,10 @@ The type of items in the . Represents a contiguous region of memory. - , `Memory` represents a contiguous region of memory. Unlike , however, `Memory` is not a [ref struct](/dotnet/csharp/language-reference/builtin-types/ref-struct). This means that `Memory` can be placed on the managed heap, whereas cannot. As a result, the `Memory` structure does not have the same restrictions as a instance. In particular: - It can be used as a field in a class. @@ -131,7 +131,7 @@ In addition to `Memory`, you can use The array from which to create the object. Creates a new object over the entirety of a specified array. - object with a `default` value. @@ -139,7 +139,7 @@ If `array` is `null`, this constructor returns a object is a reference type, and is not an array of type . - + -or- The array is covariant. @@ -188,7 +188,7 @@ The array is The number of elements to include in the new . Creates a new object that includes a specified number of elements of an array beginning at a specified index. - object with a `default` value. @@ -197,15 +197,13 @@ If `array` is `null`, this constructor returns a objec is , but or is non-zero. - -or- is outside the bounds of the array. -or- - and exceeds the number of elements in the array. - + and exceeds the number of elements in the array.
is a reference type, and is not an array of type . @@ -251,7 +249,7 @@ If `array` is `null`, this constructor returns a objec The destination object. Copies the contents of a object into a destination object. - instance to `destination` even if the contents of the current instance and `destination` overlap. @@ -347,12 +345,12 @@ This method copies all of the contents of the current i if the current instance and are equal; otherwise, . - or object. - + - Both objects point to the same array and have the same length. The `Equals(Memory)` method performs a test for reference equality; it does not compare the elements of for equality. @@ -415,10 +413,10 @@ The `Equals(Memory)` method performs a test for reference equality; it does n if the current instance and are equal; otherwise, . - objects are equal if both objects point to the same array and have the same length. Note that the test for equality does not check whether the contents are equal. - + ]]> @@ -695,7 +693,7 @@ Two objects are equal if both objects point to the same Creates a handle for the object. A handle for the object. - objects are equal if both objects point to the same The garbage collector will not move the memory until the returned object is disposed. This enables you to retrieve and use the memory's address. - + ]]> @@ -865,11 +863,11 @@ The garbage collector will not move the memory until the returned Copies the contents from the memory into a new array. An array containing the elements in the current memory. - @@ -907,7 +905,7 @@ Each call to the `ToArray` method returns a new array. Returns the string representation of this object. the string representation of this object. - `, the `ToString` method returns a that contains the characters pointed to by the . Otherwise, it returns a with the name of the type and the number of elements that the contains. @@ -958,7 +956,7 @@ For a `Memory`, the `ToString` method returns a that if the copy operation succeeds; otherwise, . - instance to `destination` even if the contents of the current instance and `destination` overlap. diff --git a/xml/System/MethodAccessException.xml b/xml/System/MethodAccessException.xml index 24a4b0d4c0f..4bbab3f2d63 100644 --- a/xml/System/MethodAccessException.xml +++ b/xml/System/MethodAccessException.xml @@ -62,28 +62,28 @@ The exception that is thrown when there is an invalid attempt to access a method, such as accessing a private method from partially trusted code. - [!NOTE] -> This exception is not included in the [.NET for Windows Store apps](https://go.microsoft.com/fwlink/?LinkID=247912) or the [Portable Class Library](/dotnet/standard/cross-platform/cross-platform-development-with-the-portable-class-library), but it is thrown by some members that are. To catch the exception in that case, write a `catch` statement for instead. - - This exception is thrown in situations such as the following: - -- A private, protected, or internal method that would not be accessible from normal compiled code is accessed from partially trusted code by using reflection. - -- A security-critical method is accessed from transparent code. - -- The access level of a method in a class library has changed, and one or more assemblies that reference the library have not been recompiled. - +> This exception is not included in the [.NET for Windows Store apps](https://go.microsoft.com/fwlink/?LinkID=247912) or the [Portable Class Library](/dotnet/standard/cross-platform/cross-platform-development-with-the-portable-class-library), but it is thrown by some members that are. To catch the exception in that case, write a `catch` statement for instead. + + This exception is thrown in situations such as the following: + +- A private, protected, or internal method that would not be accessible from normal compiled code is accessed from partially trusted code by using reflection. + +- A security-critical method is accessed from transparent code. + +- The access level of a method in a class library has changed, and one or more assemblies that reference the library have not been recompiled. + > [!NOTE] -> Beginning with the .NET Framework 4, the common language runtime treats application code as transparent when it is run with partial trust. See [Security Considerations for Reflection](/dotnet/framework/reflection-and-codedom/security-considerations-for-reflection). - - uses the HRESULT COR_E_METHODACCESS, that has the value 0x80131510. - - For a list of initial property values for an instance of , see the constructors. - +> Beginning with the .NET Framework 4, the common language runtime treats application code as transparent when it is run with partial trust. See [Security Considerations for Reflection](/dotnet/framework/reflection-and-codedom/security-considerations-for-reflection). + + uses the HRESULT COR_E_METHODACCESS, that has the value 0x80131510. + + For a list of initial property values for an instance of , see the constructors. + ]]> @@ -136,16 +136,16 @@ Initializes a new instance of the class, setting the property of the new instance to a system-supplied message that describes the error, such as "Attempt to access the method failed." This message takes into account the current system culture. - . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The localized error message string.| - + . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The localized error message string.| + ]]> @@ -190,18 +190,18 @@ A that describes the error. Initializes a new instance of the class with a specified error message. - . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The error message string.| - + . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The error message string.| + ]]> @@ -263,11 +263,11 @@ The contextual information about the source or destination. Initializes a new instance of the class with serialized data. - XML and SOAP Serialization @@ -315,18 +315,18 @@ The exception that is the cause of the current exception. If the parameter is not a null reference ( in Visual Basic), the current exception is raised in a block that handles the inner exception. Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception. - property. The property returns the same value that is passed into the constructor, or a null reference (`Nothing` in Visual Basic) if the property does not supply the inner exception value to the constructor. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||The inner exception reference.| -||The error message string.| - + property. The property returns the same value that is passed into the constructor, or a null reference (`Nothing` in Visual Basic) if the property does not supply the inner exception value to the constructor. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||The inner exception reference.| +||The error message string.| + ]]> diff --git a/xml/System/MidpointRounding.xml b/xml/System/MidpointRounding.xml index 3bbeaed2bd7..ae2d20eece7 100644 --- a/xml/System/MidpointRounding.xml +++ b/xml/System/MidpointRounding.xml @@ -78,17 +78,17 @@ If the next digit is from 0 through 4 or 6 through 9, the `MidpointRounding.Away The following table demonstrates the results of rounding some negative and positive numbers in conjunction with round-to-nearest modes. The precision used to round the numbers is zero, which means the number after the decimal point affects the rounding operation. For example, for the number -2.5, the digit after the decimal point is 5. Because that digit is the midpoint, you can use a `MidpointRounding` value to determine the result of rounding. If `AwayFromZero` is specified, -3 is returned because it is the nearest number away from zero with a precision of zero. If `ToEven` is specified, -2 is returned because it is the nearest even number with a precision of zero. -|Original number|AwayFromZero|ToEven| -|---------------------|------------------|------------| -|3.5|4|4| -|2.8|3|3| -|2.5|3|2| -|2.1|2|2| -|-2.1|-2|-2| -|-2.5|-3|-2| -|-2.8|-3|-3| -|-3.5|-4|-4| - +|Original number|AwayFromZero|ToEven| +|---------------------|------------------|------------| +|3.5|4|4| +|2.8|3|3| +|2.5|3|2| +|2.1|2|2| +|-2.1|-2|-2| +|-2.5|-3|-2| +|-2.8|-3|-3| +|-3.5|-4|-4| + ## Directed rounding Fields: @@ -100,17 +100,17 @@ Fields: A directed-rounding operation takes an original number with an implicit or specified precision and returns the next closest number in a specific direction with the same precision as the original number. Directed modes on `MidpointRounding` control toward which predefined number the rounding is performed. The following table demonstrates the results of rounding some negative and positive numbers in conjunction with directed-rounding modes. The precision used to round the numbers is zero, which means the number before the decimal point is affected by the rounding operation. - -|Original number|ToNegativeInfinity|ToPositiveInfinity|ToZero| -|---------------------|------------------|------------|------| -|3.5|3|4|3| -|2.8|2|3|2| -|2.5|2|3|2| -|2.1|2|3|2| -|-2.1|-3|-2|-2| -|-2.5|-3|-2|-2| -|-2.8|-3|-2|-2| -|-3.5|-4|-3|-3| + +|Original number|ToNegativeInfinity|ToPositiveInfinity|ToZero| +|---------------------|------------------|------------|------| +|3.5|3|4|3| +|2.8|2|3|2| +|2.5|2|3|2| +|2.1|2|3|2| +|-2.1|-3|-2|-2| +|-2.5|-3|-2|-2| +|-2.8|-3|-2|-2| +|-3.5|-4|-3|-3| ## Examples diff --git a/xml/System/MissingFieldException.xml b/xml/System/MissingFieldException.xml index 396dc906076..41a9cf365c0 100644 --- a/xml/System/MissingFieldException.xml +++ b/xml/System/MissingFieldException.xml @@ -68,25 +68,25 @@ The exception that is thrown when there is an attempt to dynamically access a field that does not exist. If a field in a class library has been removed or renamed, recompile any assemblies that reference that library. - is designed to handle cases where an attempt is made to dynamically access a renamed or deleted field of an assembly that is not referenced by its strong name. The is thrown when code in a dependent assembly attempts to access a missing field in an assembly that was modified. - - uses the HRESULT COR_E_MISSINGFIELD, that has the value 0x80131511. - - For a list of initial property values for an instance of , see the constructors. - - - -## Examples - This example shows what happens if you attempt to use reflection to call a method that does not exist and access a field that does not exist. The application recovers by catching the , , and . - + is designed to handle cases where an attempt is made to dynamically access a renamed or deleted field of an assembly that is not referenced by its strong name. The is thrown when code in a dependent assembly attempts to access a missing field in an assembly that was modified. + + uses the HRESULT COR_E_MISSINGFIELD, that has the value 0x80131511. + + For a list of initial property values for an instance of , see the constructors. + + + +## Examples + This example shows what happens if you attempt to use reflection to call a method that does not exist and access a field that does not exist. The application recovers by catching the , , and . + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/MissingMethodException/cpp/MissingMethodException.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/MissingFieldException/Overview/MissingMethodException.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/MissingFieldException/Overview/MissingMethodException.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/MissingMethodException/vb/missingmethodexception.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/MissingMethodException/vb/missingmethodexception.vb" id="Snippet1"::: + ]]> @@ -139,18 +139,18 @@ Initializes a new instance of the class. - property of the new instance to a system-supplied message that describes the error, such as "Attempted to access a non-existing field." This message takes into account the current system culture. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The localized error message string.| - + property of the new instance to a system-supplied message that describes the error, such as "Attempted to access a non-existing field." This message takes into account the current system culture. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The localized error message string.| + ]]> @@ -201,18 +201,18 @@ A that describes the error. Initializes a new instance of the class with a specified error message. - . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The error message string.| - + . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The error message string.| + ]]> @@ -270,11 +270,11 @@ The contextual information about the source or destination. Initializes a new instance of the class with serialized data. - XML and SOAP Serialization @@ -328,18 +328,18 @@ The exception that is the cause of the current exception. If the parameter is not a null reference ( in Visual Basic), the current exception is raised in a block that handles the inner exception. Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception. - property. The property returns the same value that is passed into the constructor, or a null reference (`Nothing` in Visual Basic) if the property does not supply the inner exception value to the constructor. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||The inner exception reference.| -||The error message string.| - + property. The property returns the same value that is passed into the constructor, or a null reference (`Nothing` in Visual Basic) if the property does not supply the inner exception value to the constructor. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||The inner exception reference.| +||The error message string.| + ]]> @@ -438,21 +438,21 @@ Gets the text string showing the signature of the missing field, the class name, and the field name. This property is read-only. The error message string. - . The error message should be localized. - - - -## Examples - The following example demonstrates the property. This code example is part of a larger example provided for the class. - + . The error message should be localized. + + + +## Examples + The following example demonstrates the property. This code example is part of a larger example provided for the class. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/MissingMethodException/cpp/MissingMethodException.cpp" id="Snippet3"::: :::code language="csharp" source="~/snippets/csharp/System/MissingFieldException/Overview/MissingMethodException.cs" id="Snippet3"::: :::code language="fsharp" source="~/snippets/fsharp/System/MissingFieldException/Overview/MissingMethodException.fs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/MissingMethodException/vb/missingmethodexception.vb" id="Snippet3"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/MissingMethodException/vb/missingmethodexception.vb" id="Snippet3"::: + ]]> diff --git a/xml/System/MissingMemberException.xml b/xml/System/MissingMemberException.xml index 0df88a3313e..91497b47b09 100644 --- a/xml/System/MissingMemberException.xml +++ b/xml/System/MissingMemberException.xml @@ -70,27 +70,27 @@ The exception that is thrown when there is an attempt to dynamically access a class member that does not exist or that is not declared as public. If a member in a class library has been removed or renamed, recompile any assemblies that reference that library. - is designed to handle cases where a field or a method is deleted or renamed in one assembly and the change is not reflected in a second assembly. At runtime, will be thrown when the code in the second assembly attempts to access the missing member in the first assembly. - - is the base class for and . In general it is better to use one of the derived classes of to more precisely indicate the exact nature of the error. Throw a if you are only interested in capturing the general case of a missing member error. - - uses the HRESULT COR_E_MISSINGMEMBER, that has the value 0x80131512. - - For a list of initial property values for an instance of , see the constructors. - - - -## Examples - This example shows what happens if you attempt to use reflection to call a method that does not exist and access a field that does not exist. The application recovers by catching the , , and . - + is designed to handle cases where a field or a method is deleted or renamed in one assembly and the change is not reflected in a second assembly. At runtime, will be thrown when the code in the second assembly attempts to access the missing member in the first assembly. + + is the base class for and . In general it is better to use one of the derived classes of to more precisely indicate the exact nature of the error. Throw a if you are only interested in capturing the general case of a missing member error. + + uses the HRESULT COR_E_MISSINGMEMBER, that has the value 0x80131512. + + For a list of initial property values for an instance of , see the constructors. + + + +## Examples + This example shows what happens if you attempt to use reflection to call a method that does not exist and access a field that does not exist. The application recovers by catching the , , and . + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/MissingMethodException/cpp/MissingMethodException.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/MissingFieldException/Overview/MissingMethodException.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/MissingFieldException/Overview/MissingMethodException.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/MissingMethodException/vb/missingmethodexception.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/MissingMethodException/vb/missingmethodexception.vb" id="Snippet1"::: + ]]> @@ -149,18 +149,18 @@ Initializes a new instance of the class. - property of the new instance to a system-supplied message that describes the error, such as "Attempted to access a missing member." This message takes into account the current system culture. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The localized error message string.| - + property of the new instance to a system-supplied message that describes the error, such as "Attempted to access a missing member." This message takes into account the current system culture. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The localized error message string.| + ]]> @@ -207,18 +207,18 @@ The message that describes the error. Initializes a new instance of the class with a specified error message. - . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The error message string.| - + . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The error message string.| + ]]> @@ -280,11 +280,11 @@ The contextual information about the source or destination. Initializes a new instance of the class with serialized data. - XML and SOAP Serialization @@ -334,18 +334,18 @@ An instance of that is the cause of the current . If is not a null reference ( in Visual Basic), then the current is raised in a catch block handling . Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the root cause of this exception. - property. The property returns the same value that is passed into the constructor, or a null reference (`Nothing` in Visual Basic) if the property does not supply the inner exception value to the constructor. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||The inner exception reference.| -||The error message string.| - + property. The property returns the same value that is passed into the constructor, or a null reference (`Nothing` in Visual Basic) if the property does not supply the inner exception value to the constructor. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||The inner exception reference.| +||The error message string.| + ]]> @@ -496,13 +496,13 @@ The contextual information about the source or destination. Sets the object with the class name, the member name, the signature of the missing member, and additional exception information. - sets a with all the exception object data targeted for serialization. During deserialization, the exception object is reconstituted from the transmitted over the stream. - - For more information, see . - + sets a with all the exception object data targeted for serialization. During deserialization, the exception object is reconstituted from the transmitted over the stream. + + For more information, see . + ]]> The object is . @@ -604,25 +604,25 @@ Gets the text string showing the class name, the member name, and the signature of the missing member. The error message string. - . The error message should be localized. - - This property is read-only. - - - -## Examples - The following example demonstrates the property. This code example is part of a larger example provided for the class. - + . The error message should be localized. + + This property is read-only. + + + +## Examples + The following example demonstrates the property. This code example is part of a larger example provided for the class. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/MissingMethodException/cpp/MissingMethodException.cpp" id="Snippet4"::: :::code language="csharp" source="~/snippets/csharp/System/MissingFieldException/Overview/MissingMethodException.cs" id="Snippet4"::: :::code language="fsharp" source="~/snippets/fsharp/System/MissingFieldException/Overview/MissingMethodException.fs" id="Snippet4"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/MissingMethodException/vb/missingmethodexception.vb" id="Snippet4"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/MissingMethodException/vb/missingmethodexception.vb" id="Snippet4"::: + ]]> @@ -668,13 +668,13 @@ Holds the signature of the missing member. - contains a value that represents the signature of the missing member. - - is used to format the signature. For additional information, see , , and . - + contains a value that represents the signature of the missing member. + + is used to format the signature. For additional information, see , , and . + ]]> diff --git a/xml/System/MissingMethodException.xml b/xml/System/MissingMethodException.xml index 7c2225859a0..149fff380e0 100644 --- a/xml/System/MissingMethodException.xml +++ b/xml/System/MissingMethodException.xml @@ -68,25 +68,25 @@ The exception that is thrown when there is an attempt to dynamically access a method that does not exist. - is designed to handle cases where an attempt is made to dynamically access a renamed or deleted method of an assembly that is not referenced by its strong name. is thrown when code in a dependent assembly attempts to access a missing method in an assembly that was modified. - - uses the HRESULT COR_E_MISSINGMETHOD, that has the value 0x80131513. - - For a list of initial property values for an instance of , see the constructors. - + is designed to handle cases where an attempt is made to dynamically access a renamed or deleted method of an assembly that is not referenced by its strong name. is thrown when code in a dependent assembly attempts to access a missing method in an assembly that was modified. + + uses the HRESULT COR_E_MISSINGMETHOD, that has the value 0x80131513. + + For a list of initial property values for an instance of , see the constructors. + The exact timing of when statically referenced methods are loaded is unspecified. This exception may be thrown before the method that references the missing method starts executing. - + > [!NOTE] -> This exception is not included in [.NET for Windows Store apps](https://go.microsoft.com/fwlink/?LinkID=247912) or the [Portable Class Library](/dotnet/standard/cross-platform/cross-platform-development-with-the-portable-class-library), but it is thrown by some members that are. To catch the exception in that case, write a `catch` statement for instead. - - - -## Examples - This example shows what happens if you attempt to use reflection to call a method that does not exist and access a field that does not exist. The application recovers by catching the , , and . - +> This exception is not included in [.NET for Windows Store apps](https://go.microsoft.com/fwlink/?LinkID=247912) or the [Portable Class Library](/dotnet/standard/cross-platform/cross-platform-development-with-the-portable-class-library), but it is thrown by some members that are. To catch the exception in that case, write a `catch` statement for instead. + + + +## Examples + This example shows what happens if you attempt to use reflection to call a method that does not exist and access a field that does not exist. The application recovers by catching the , , and . + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/MissingMethodException/cpp/MissingMethodException.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/MissingFieldException/Overview/MissingMethodException.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/MissingFieldException/Overview/MissingMethodException.fs" id="Snippet1"::: @@ -144,18 +144,18 @@ The exact timing of when statically referenced methods are loaded is unspecified Initializes a new instance of the class. - property of the new instance to a system-supplied message that describes the error, such as "Attempted to access a missing method." This message takes into account the current system culture. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The localized error message string.| - + property of the new instance to a system-supplied message that describes the error, such as "Attempted to access a missing method." This message takes into account the current system culture. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The localized error message string.| + ]]> @@ -206,18 +206,18 @@ The exact timing of when statically referenced methods are loaded is unspecified A that describes the error. Initializes a new instance of the class with a specified error message. - . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The error message string.| - + . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The error message string.| + ]]> XML and SOAP Serialization @@ -276,11 +276,11 @@ The exact timing of when statically referenced methods are loaded is unspecified The contextual information about the source or destination. Initializes a new instance of the class with serialized data. - XML and SOAP Serialization @@ -334,18 +334,18 @@ The exact timing of when statically referenced methods are loaded is unspecified The exception that is the cause of the current exception. If the parameter is not a null reference ( in Visual Basic), the current exception is raised in a block that handles the inner exception. Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception. - property. The property returns the same value that is passed into the constructor, or a null reference (`Nothing` in Visual Basic) if the property does not supply the inner exception value to the constructor. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||The inner exception reference.| -||The error message string.| - + property. The property returns the same value that is passed into the constructor, or a null reference (`Nothing` in Visual Basic) if the property does not supply the inner exception value to the constructor. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||The inner exception reference.| +||The error message string.| + ]]> @@ -445,23 +445,23 @@ The exact timing of when statically referenced methods are loaded is unspecified Gets the text string showing the class name, the method name, and the signature of the missing method. This property is read-only. The error message string. - . The error message should be localized. - - - -## Examples - The following example demonstrates the property. This code example is part of a larger example provided for the class. - + . The error message should be localized. + + + +## Examples + The following example demonstrates the property. This code example is part of a larger example provided for the class. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/MissingMethodException/cpp/MissingMethodException.cpp" id="Snippet2"::: :::code language="csharp" source="~/snippets/csharp/System/MissingFieldException/Overview/MissingMethodException.cs" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/MissingFieldException/Overview/MissingMethodException.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/MissingMethodException/vb/missingmethodexception.vb" id="Snippet2"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/MissingMethodException/vb/missingmethodexception.vb" id="Snippet2"::: + ]]> diff --git a/xml/System/ModuleHandle.xml b/xml/System/ModuleHandle.xml index 5c8bf9daa73..dcce2eb522d 100644 --- a/xml/System/ModuleHandle.xml +++ b/xml/System/ModuleHandle.xml @@ -61,11 +61,11 @@ Represents a runtime handle for a module. - , , and methods provide efficient resolution of metadata tokens to runtime handles for fields, methods, and types in the current module. - + , , and methods provide efficient resolution of metadata tokens to runtime handles for fields, methods, and types in the current module. + ]]> @@ -455,13 +455,13 @@ Gets the metadata stream version. A 32-bit integer representing the metadata stream version. The high-order two bytes represent the major version number, and the low-order two bytes represent the minor version number. - [!NOTE] -> For more information on the metadata header, see the metadata specification in Partition II of [ECMA-335 Common Language Infrastructure (CLI)](https://www.ecma-international.org/publications-and-standards/standards/ecma-335/). - +> For more information on the metadata header, see the metadata specification in Partition II of [ECMA-335 Common Language Infrastructure (CLI)](https://www.ecma-international.org/publications-and-standards/standards/ecma-335/). + ]]> @@ -616,26 +616,26 @@ Returns a runtime handle for the field identified by the specified metadata token. A for the field identified by . - method overload, which allows you to supply the necessary context. - + method overload, which allows you to supply the necessary context. + > [!NOTE] > Information about metadata tokens can be found in the [Common Language Infrastructure (CLI) documentation](https://www.ecma-international.org/publications-and-standards/standards/ecma-335/), especially "Partition II: Metadata Definition and Semantics". - + ]]> - is not a valid token in the scope of the current module. - - -or- - - is not a token for a field in the scope of the current module. - - -or- - - identifies a field whose parent has a signature containing element type or . + is not a valid token in the scope of the current module. + +-or- + + is not a token for a field in the scope of the current module. + +-or- + + identifies a field whose parent has a signature containing element type or .
The method is called on an empty field handle. @@ -690,25 +690,25 @@ Returns a runtime field handle for the field identified by the specified metadata token, specifying the generic type arguments of the type and method where the token is in scope. A for the field identified by . - [!NOTE] > Information about metadata tokens can be found in the [Common Language Infrastructure (CLI) documentation](https://www.ecma-international.org/publications-and-standards/standards/ecma-335/), especially "Partition II: Metadata Definition and Semantics". - + ]]> - is not a valid token in the scope of the current module. - - -or- - - is not a token for a field in the scope of the current module. - - -or- - - identifies a field whose parent has a signature containing element type or . + is not a valid token in the scope of the current module. + +-or- + + is not a token for a field in the scope of the current module. + +-or- + + identifies a field whose parent has a signature containing element type or .
The method is called on an empty field handle. is not a valid token. @@ -770,26 +770,26 @@ Returns a runtime method handle for the method or constructor identified by the specified metadata token. A for the method or constructor identified by . - method overload, which allows you to supply the necessary context. - + method overload, which allows you to supply the necessary context. + > [!NOTE] -> Information about metadata tokens can be found in the [Common Language Infrastructure (CLI) documentation](https://www.ecma-international.org/publications-and-standards/standards/ecma-335/), especially "Partition II: Metadata Definition and Semantics". - +> Information about metadata tokens can be found in the [Common Language Infrastructure (CLI) documentation](https://www.ecma-international.org/publications-and-standards/standards/ecma-335/), especially "Partition II: Metadata Definition and Semantics". + ]]> - is not a valid metadata token for a method in the current module. - - -or- - - is not a token for a method or constructor in the scope of the current module. - - -or- - - is a whose signature contains element type or . + is not a valid metadata token for a method in the current module. + +-or- + + is not a token for a method or constructor in the scope of the current module. + +-or- + + is a whose signature contains element type or . The method is called on an empty method handle. @@ -848,25 +848,25 @@ Returns a runtime method handle for the method or constructor identified by the specified metadata token, specifying the generic type arguments of the type and method where the token is in scope. A for the method or constructor identified by . - [!NOTE] -> Information about metadata tokens can be found in the [Common Language Infrastructure (CLI) documentation](https://www.ecma-international.org/publications-and-standards/standards/ecma-335/), especially "Partition II: Metadata Definition and Semantics". - +> Information about metadata tokens can be found in the [Common Language Infrastructure (CLI) documentation](https://www.ecma-international.org/publications-and-standards/standards/ecma-335/), especially "Partition II: Metadata Definition and Semantics". + ]]> - is not a valid metadata token for a method in the current module. - - -or- - - is not a token for a method or constructor in the scope of the current module. - - -or- - - is a whose signature contains element type or . + is not a valid metadata token for a method in the current module. + +-or- + + is not a token for a method or constructor in the scope of the current module. + +-or- + + is a whose signature contains element type or . The method is called on an empty method handle. is not a valid token. @@ -928,26 +928,26 @@ Returns a runtime type handle for the type identified by the specified metadata token. A for the type identified by . - method overload, which allows you to supply the necessary context. - + method overload, which allows you to supply the necessary context. + > [!NOTE] -> Information about metadata tokens can be found in the [Common Language Infrastructure (CLI) documentation](https://www.ecma-international.org/publications-and-standards/standards/ecma-335/), especially "Partition II: Metadata Definition and Semantics". - +> Information about metadata tokens can be found in the [Common Language Infrastructure (CLI) documentation](https://www.ecma-international.org/publications-and-standards/standards/ecma-335/), especially "Partition II: Metadata Definition and Semantics". + ]]> - is not a valid metadata token for a type in the current module. - - -or- - - is not a token for a type in the scope of the current module. - - -or- - - is a whose signature contains element type or . + is not a valid metadata token for a type in the current module. + +-or- + + is not a token for a type in the scope of the current module. + +-or- + + is a whose signature contains element type or . The method is called on an empty type handle. @@ -1002,25 +1002,25 @@ Returns a runtime type handle for the type identified by the specified metadata token, specifying the generic type arguments of the type and method where the token is in scope. A for the type identified by . - [!NOTE] -> Information about metadata tokens can be found in the [Common Language Infrastructure (CLI) documentation](https://www.ecma-international.org/publications-and-standards/standards/ecma-335/), especially "Partition II: Metadata Definition and Semantics". - +> Information about metadata tokens can be found in the [Common Language Infrastructure (CLI) documentation](https://www.ecma-international.org/publications-and-standards/standards/ecma-335/), especially "Partition II: Metadata Definition and Semantics". + ]]> - is not a valid metadata token for a type in the current module. - - -or- - - is not a token for a type in the scope of the current module. - - -or- - - is a whose signature contains element type or . + is not a valid metadata token for a type in the current module. + +-or- + + is not a token for a type in the scope of the current module. + +-or- + + is a whose signature contains element type or . The method is called on an empty type handle. is not a valid token. diff --git a/xml/System/MulticastDelegate.xml b/xml/System/MulticastDelegate.xml index bf123be7b55..c529633f11a 100644 --- a/xml/System/MulticastDelegate.xml +++ b/xml/System/MulticastDelegate.xml @@ -65,30 +65,30 @@ Represents a multicast delegate; that is, a delegate that can have more than one element in its invocation list. - is a special class. Compilers and other tools can derive from this class, but you cannot derive from it explicitly. The same is true of the class. - - In addition to the methods that delegate types inherit from , the common language runtime provides two special methods: `BeginInvoke` and `EndInvoke`. For more information about these methods, see [Calling Synchronous Methods Asynchronously](/dotnet/standard/asynchronous-programming-patterns/calling-synchronous-methods-asynchronously). - - A has a linked list of delegates, called an invocation list, consisting of one or more elements. When a multicast delegate is invoked, the delegates in the invocation list are called synchronously in the order in which they appear. If an error occurs during execution of the list then an exception is thrown. - - - -## Examples - The following example defines a class, `StringContainer`, which includes a collection of strings. One of its members is the `CheckAndDisplayDelegate` delegate, which is used to display strings stored in a `StringContainer` object that satisfy particular criteria. The delegate takes a single string as a parameter and returns `void` (or, in Visual Basic, it's a `Sub` procedure). It also includes a method, `DisplayAllQualified`, that has a single parameter, a `CheckAndDisplayDelegate` delegate. This allows the method to be called and to display a set of strings that are filtered based on the methods that the delegate contains. - - The example also defines a utility class, `StringExtensions`, that has two methods: - -- `ConStart`, which displays strings that begin with a consonant. - -- `VowelStart`, which displays strings that begin with a vowel. - - Note that both methods include a single string parameter and return `void`. In other words, both methods can be assigned to the `CheckAndDisplayDelegate` delegate. - - The `Test.Main` method is the application entry point. It instantiates a `StringContainer` object, populates it with strings, and creates two `CheckAndDisplayDelegate` delegates, `conStart` and `vowelStart`, that invoke a single method. It then calls the method to create the `multipleDelegates` delegate, which initially contains the `ConStart` and `VowelStart` delegates. Note that when the `multipleDelegates` delegate is invoked, it displays all the strings in the collection in their original order. This is because each letter is passed separately to each delegate, and each letter meets the filtering criteria of only one of the two delegates. Finally, after calls to and , `multipleDelegates` contains two `conStart` delegates. When it is invoked, each string in the `StringContainer` object is displayed twice. - + is a special class. Compilers and other tools can derive from this class, but you cannot derive from it explicitly. The same is true of the class. + + In addition to the methods that delegate types inherit from , the common language runtime provides two special methods: `BeginInvoke` and `EndInvoke`. For more information about these methods, see [Calling Synchronous Methods Asynchronously](/dotnet/standard/asynchronous-programming-patterns/calling-synchronous-methods-asynchronously). + + A has a linked list of delegates, called an invocation list, consisting of one or more elements. When a multicast delegate is invoked, the delegates in the invocation list are called synchronously in the order in which they appear. If an error occurs during execution of the list then an exception is thrown. + + + +## Examples + The following example defines a class, `StringContainer`, which includes a collection of strings. One of its members is the `CheckAndDisplayDelegate` delegate, which is used to display strings stored in a `StringContainer` object that satisfy particular criteria. The delegate takes a single string as a parameter and returns `void` (or, in Visual Basic, it's a `Sub` procedure). It also includes a method, `DisplayAllQualified`, that has a single parameter, a `CheckAndDisplayDelegate` delegate. This allows the method to be called and to display a set of strings that are filtered based on the methods that the delegate contains. + + The example also defines a utility class, `StringExtensions`, that has two methods: + +- `ConStart`, which displays strings that begin with a consonant. + +- `VowelStart`, which displays strings that begin with a vowel. + + Note that both methods include a single string parameter and return `void`. In other words, both methods can be assigned to the `CheckAndDisplayDelegate` delegate. + + The `Test.Main` method is the application entry point. It instantiates a `StringContainer` object, populates it with strings, and creates two `CheckAndDisplayDelegate` delegates, `conStart` and `vowelStart`, that invoke a single method. It then calls the method to create the `multipleDelegates` delegate, which initially contains the `ConStart` and `VowelStart` delegates. Note that when the `multipleDelegates` delegate is invoked, it displays all the strings in the collection in their original order. This is because each letter is passed separately to each delegate, and each letter meets the filtering criteria of only one of the two delegates. Finally, after calls to and , `multipleDelegates` contains two `conStart` delegates. When it is invoked, each string in the `StringContainer` object is displayed twice. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Multicast Delegate Introduction/CPP/delegatestring.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/MulticastDelegate/Overview/delegatestring.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/MulticastDelegate/Overview/delegatestring.fs" id="Snippet1"::: @@ -153,11 +153,11 @@ The name of the method for which a delegate is created. Initializes a new instance of the class. - method that specifies a method name and a target object. For example, the method overload creates a delegate for an instance method with a specified name. - + method that specifies a method name and a target object. For example, the method overload creates a delegate for an instance method with a specified name. + ]]> Cannot create an instance of an abstract class, or this member was invoked with a late-binding mechanism. @@ -209,11 +209,11 @@ The name of the static method for which a delegate is created. Initializes a new instance of the class. - method that specifies a method name but does not specify a target object. For example, the method overload creates a static delegate for a method with a specified name. - + method that specifies a method name but does not specify a target object. For example, the method overload creates a static delegate for a method with a specified name. + ]]> Cannot create an instance of an abstract class, or this member was invoked with a late-binding mechanism. @@ -385,13 +385,13 @@ if and this instance have the same invocation lists; otherwise, . - Cannot create an instance of an abstract class, or this member was invoked with a late-binding mechanism. @@ -496,11 +496,11 @@ Returns the invocation list of this multicast delegate, in invocation order. An array of delegates whose invocation lists collectively match the invocation list of this instance. - Cannot create an instance of an abstract class, or this member was invoked with a late-binding mechanism. @@ -549,11 +549,11 @@ Returns a method represented by the current . A method represented by the current . - represents multiple methods, only one method is returned. - + represents multiple methods, only one method is returned. + ]]> @@ -614,13 +614,13 @@ (Reserved) The location where serialized data is stored and retrieved. Populates a object with all the data needed to serialize this instance. - @@ -686,13 +686,13 @@ if and have the same invocation lists; otherwise, . - ]]> Cannot create an instance of an abstract class, or this member was invoked with a late-binding mechanism. @@ -753,13 +753,13 @@ if and do not have the same invocation lists; otherwise, . - ]]> Cannot create an instance of an abstract class, or this member was invoked with a late-binding mechanism. diff --git a/xml/System/MulticastNotSupportedException.xml b/xml/System/MulticastNotSupportedException.xml index bfa185186ee..10feb62659a 100644 --- a/xml/System/MulticastNotSupportedException.xml +++ b/xml/System/MulticastNotSupportedException.xml @@ -59,15 +59,15 @@ The exception that is thrown when there is an attempt to combine two delegates based on the type instead of the type. This class cannot be inherited. - type can be combined. Two multicast delegates can be combined using the method. - - uses the HRESULT COR_E_MULTICASTNOTSUPPORTED, which has the value 0x80131514. - - For a list of initial property values for an instance of , see the constructors. - + type can be combined. Two multicast delegates can be combined using the method. + + uses the HRESULT COR_E_MULTICASTNOTSUPPORTED, which has the value 0x80131514. + + For a list of initial property values for an instance of , see the constructors. + ]]> @@ -118,18 +118,18 @@ Initializes a new instance of the class. - property of the new instance to a system-supplied message that describes the error, such as "This operation cannot be performed with the specified delegates." This message takes into account the current system culture. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The localized error message string.| - + property of the new instance to a system-supplied message that describes the error, such as "This operation cannot be performed with the specified delegates." This message takes into account the current system culture. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The localized error message string.| + ]]> @@ -172,18 +172,18 @@ The message that describes the error. Initializes a new instance of the class with a specified error message. - . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The error message string.| - + . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The error message string.| + ]]> @@ -228,18 +228,18 @@ The exception that is the cause of the current exception. If the parameter is not a null reference ( in Visual Basic), the current exception is raised in a block that handles the inner exception. Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception. - property. The property returns the same value that is passed into the constructor, or a null reference (`Nothing` in Visual Basic) if the property does not supply the inner exception value to the constructor. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||The inner exception reference.| -||The error message string.| - + property. The property returns the same value that is passed into the constructor, or a null reference (`Nothing` in Visual Basic) if the property does not supply the inner exception value to the constructor. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||The inner exception reference.| +||The error message string.| + ]]> diff --git a/xml/System/NetPipeStyleUriParser.xml b/xml/System/NetPipeStyleUriParser.xml index 728ba27d58b..384df893a2f 100644 --- a/xml/System/NetPipeStyleUriParser.xml +++ b/xml/System/NetPipeStyleUriParser.xml @@ -39,11 +39,11 @@ A parser based on the NetPipe scheme for the "Indigo" system. - @@ -80,11 +80,11 @@ Create a parser based on the NetPipe scheme for the "Indigo" system. - . - + . + ]]> diff --git a/xml/System/NetTcpStyleUriParser.xml b/xml/System/NetTcpStyleUriParser.xml index f51e117066f..4085e0d5205 100644 --- a/xml/System/NetTcpStyleUriParser.xml +++ b/xml/System/NetTcpStyleUriParser.xml @@ -39,11 +39,11 @@ A parser based on the NetTcp scheme for the "Indigo" system. - @@ -80,11 +80,11 @@ Create a parser based on the NetTcp scheme for the "Indigo" system. - . - + . + ]]> diff --git a/xml/System/NewsStyleUriParser.xml b/xml/System/NewsStyleUriParser.xml index 2933b0c1bb1..7d23597faf3 100644 --- a/xml/System/NewsStyleUriParser.xml +++ b/xml/System/NewsStyleUriParser.xml @@ -73,11 +73,11 @@ Create a customizable parser based on the news scheme using the Network News Transfer Protocol (NNTP). - - + + ]]> diff --git a/xml/System/NonSerializedAttribute.xml b/xml/System/NonSerializedAttribute.xml index d8db79eb793..4996ef6c539 100644 --- a/xml/System/NonSerializedAttribute.xml +++ b/xml/System/NonSerializedAttribute.xml @@ -70,38 +70,38 @@ Indicates that a field of a serializable class should not be serialized. This class cannot be inherited. - or classes to serialize an object, use the attribute to prevent a field from being serialized. For example, you can use this attribute to prevent the serialization of sensitive data. - - The target objects for the attribute are public and private fields of a serializable class. By default, classes are not serializable unless they are marked with . During the serialization process all the public and private fields of a class are serialized by default. Fields marked with are excluded during serialization. If you are using the class to serialize an object, use the class to get the same functionality. Alternatively, implement the interface to explicitly control the serialization process. Note that classes that implement must still be marked with . - - To apply the class to an event, set the attribute location to field, as shown in the following C# code. - -```csharp -[field:NonSerializedAttribute()] -public event ChangedEventHandler Changed; -``` - - If a field is not serialized, but it still requires a default value that must be supplied after deserialization, you can create a method that supplies the field with a value, then apply the to the method. - + or classes to serialize an object, use the attribute to prevent a field from being serialized. For example, you can use this attribute to prevent the serialization of sensitive data. + + The target objects for the attribute are public and private fields of a serializable class. By default, classes are not serializable unless they are marked with . During the serialization process all the public and private fields of a class are serialized by default. Fields marked with are excluded during serialization. If you are using the class to serialize an object, use the class to get the same functionality. Alternatively, implement the interface to explicitly control the serialization process. Note that classes that implement must still be marked with . + + To apply the class to an event, set the attribute location to field, as shown in the following C# code. + +```csharp +[field:NonSerializedAttribute()] +public event ChangedEventHandler Changed; +``` + + If a field is not serialized, but it still requires a default value that must be supplied after deserialization, you can create a method that supplies the field with a value, then apply the to the method. + For more information about using attributes, see [Attributes](/dotnet/standard/attributes/). > [!NOTE] > This attribute does not apply to JSON serialization using . - -## Examples - The following example demonstrates SOAP serialization of an object marked with the attribute, and the behavior of a field marked with the in the serialized object. - + +## Examples + The following example demonstrates SOAP serialization of an object marked with the attribute, and the behavior of a field marked with the in the serialized object. + > [!NOTE] -> The code uses the class to serialize the object. The class is found in the system.runtime.serialization.formatters.soap.dll file, which is not loaded by default into a project. To run the code, you must add a reference to the DLL to your project. - +> The code uses the class to serialize the object. The class is found in the system.runtime.serialization.formatters.soap.dll file, which is not loaded by default into a project. To run the code, you must add a reference to the DLL to your project. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_Remoting/SerializationAttributes/CPP/s.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/NonSerializedAttribute/Overview/s.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/NonSerializedAttribute/Overview/s.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_Remoting/SerializationAttributes/VB/s.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_Remoting/SerializationAttributes/VB/s.vb" id="Snippet1"::: + ]]> diff --git a/xml/System/NotFiniteNumberException.xml b/xml/System/NotFiniteNumberException.xml index 4491ab9ff58..8fb9461a1e9 100644 --- a/xml/System/NotFiniteNumberException.xml +++ b/xml/System/NotFiniteNumberException.xml @@ -59,15 +59,15 @@ The exception that is thrown when a floating-point value is positive infinity, negative infinity, or Not-a-Number (NaN). - is available for programming languages that do not support the concepts of infinity and Not-a-Number in floating-point operations. - - uses the HRESULT COR_E_NOTFINITENUMBER, which has the value 0x80131528. - - For a list of initial property values for an instance of , see the constructors. - + is available for programming languages that do not support the concepts of infinity and Not-a-Number in floating-point operations. + + uses the HRESULT COR_E_NOTFINITENUMBER, which has the value 0x80131528. + + For a list of initial property values for an instance of , see the constructors. + ]]> @@ -119,18 +119,18 @@ Initializes a new instance of the class. - property of the new instance to a system-supplied message that describes the error, such as "The number encountered was not a finite quantity." This message takes into account the current system culture. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The localized error message string.| - + property of the new instance to a system-supplied message that describes the error, such as "The number encountered was not a finite quantity." This message takes into account the current system culture. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The localized error message string.| + ]]> @@ -172,18 +172,18 @@ The value of the argument that caused the exception. Initializes a new instance of the class with the invalid number. - and an invalid number. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The invalid number.| - + and an invalid number. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The invalid number.| + ]]> @@ -226,18 +226,18 @@ The message that describes the error. Initializes a new instance of the class with a specified error message. - . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The error message string.| - + . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The error message string.| + ]]> @@ -299,11 +299,11 @@ The contextual information about the source or destination. Initializes a new instance of the class with serialized data. - @@ -348,19 +348,19 @@ The value of the argument that caused the exception. Initializes a new instance of the class with a specified error message and the invalid number. - . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The error message string.| -||The invalid number.| - + . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The error message string.| +||The invalid number.| + ]]> @@ -404,18 +404,18 @@ The exception that is the cause of the current exception. If the parameter is not a null reference ( in Visual Basic), the current exception is raised in a block that handles the inner exception. Initializes a new instance of the class with a specified error message and a reference to the inner exception that is root cause of this exception. - property. The property returns the same value that is passed into the constructor, or `null` if the property does not supply the inner exception value to the constructor. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||The inner exception reference.| -||The error message string.| - + property. The property returns the same value that is passed into the constructor, or `null` if the property does not supply the inner exception value to the constructor. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||The inner exception reference.| +||The error message string.| + ]]> @@ -462,19 +462,19 @@ The exception that is the cause of the current exception. If the parameter is not a null reference ( in Visual Basic), the current exception is raised in a block that handles the inner exception. Initializes a new instance of the class with a specified error message, the invalid number, and a reference to the inner exception that is root cause of this exception. - property. The property returns the same value that is passed into the constructor, or `null` if the property does not supply the inner exception value to the constructor. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||The inner exception reference.| -||The error message string.| -||The invalid number.| - + property. The property returns the same value that is passed into the constructor, or `null` if the property does not supply the inner exception value to the constructor. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||The inner exception reference.| +||The error message string.| +||The invalid number.| + ]]> @@ -541,13 +541,13 @@ The contextual information about the source or destination. Sets the object with the invalid number and additional exception information. - sets a with all the exception object data targeted for serialization. During deserialization, the exception object is reconstituted from the transmitted over the stream. - - For more information, see . - + sets a with all the exception object data targeted for serialization. During deserialization, the exception object is reconstituted from the transmitted over the stream. + + For more information, see . + ]]> The object is . @@ -592,13 +592,13 @@ Gets the invalid number that is a positive infinity, a negative infinity, or Not-a-Number (NaN). The invalid number. - property returns the same value as was passed into the constructor, or zero if no value was supplied. Override the property to customize the content or format of the invalid value. - - This property is read-only. - + property returns the same value as was passed into the constructor, or zero if no value was supplied. Override the property to customize the content or format of the invalid value. + + This property is read-only. + ]]> diff --git a/xml/System/NotImplementedException.xml b/xml/System/NotImplementedException.xml index de6228624dc..4834af3ed02 100644 --- a/xml/System/NotImplementedException.xml +++ b/xml/System/NotImplementedException.xml @@ -70,41 +70,41 @@ The exception that is thrown when a requested method or operation is not implemented. - exception is thrown when a particular method, get accessor, or set accessor is present as a member of a type but is not implemented. - - uses the default implementation, which supports reference equality. For a list of initial values for an instance of , see the constructors. - -## Throwing the exception - You might choose to throw a exception in properties or methods in your own types when the that member is still in development and will only later be implemented in production code. In other words, a exception should be synonymous with "still in development." - -## Handling the exception - The exception indicates that the method or property that you are attempting to invoke has no implementation and therefore provides no functionality. As a result, you should not handle this error in a `try/catch` block. Instead, you should remove the member invocation from your code. You can include a call to the member when it is implemented in the production version of a library. - - In some cases, a exception may not be used to indicate functionality that is still in development in a pre-production library. However, this still indicates that the functionality is unavailable, and you should remove the member invocation from your code. - -## NotImplementedException and other exception types - The .NET Framework also includes two other exception types, and , that indicate that no implementation exists for a particular member of a type. You should throw one of these instead of a exception under the following conditions. - - exception - If you've designed a type with one or more members that are available on some platforms or in some versions but not on others, you can throw this exception on platforms on which the functionality is not supported. - - exception - Throw a exception if the implementation of an interface member or an override to an abstract base class method is not possible. For example, the method throws a exception because no meaningful conversion between a date and time and a 32-bit signed integer exists. The method must be present in this case because the class implements the interface. - - You should also throw a exception if you've implemented an abstract base class and add a new member to it that must be overridden by derived classes. In that case, making the member abstract causes existing subclasses to fail to load. - - - -## Examples - The following example throws this exception for a method that has not been developed. - + exception is thrown when a particular method, get accessor, or set accessor is present as a member of a type but is not implemented. + + uses the default implementation, which supports reference equality. For a list of initial values for an instance of , see the constructors. + +## Throwing the exception + You might choose to throw a exception in properties or methods in your own types when the that member is still in development and will only later be implemented in production code. In other words, a exception should be synonymous with "still in development." + +## Handling the exception + The exception indicates that the method or property that you are attempting to invoke has no implementation and therefore provides no functionality. As a result, you should not handle this error in a `try/catch` block. Instead, you should remove the member invocation from your code. You can include a call to the member when it is implemented in the production version of a library. + + In some cases, a exception may not be used to indicate functionality that is still in development in a pre-production library. However, this still indicates that the functionality is unavailable, and you should remove the member invocation from your code. + +## NotImplementedException and other exception types + The .NET Framework also includes two other exception types, and , that indicate that no implementation exists for a particular member of a type. You should throw one of these instead of a exception under the following conditions. + + exception + If you've designed a type with one or more members that are available on some platforms or in some versions but not on others, you can throw this exception on platforms on which the functionality is not supported. + + exception + Throw a exception if the implementation of an interface member or an override to an abstract base class method is not possible. For example, the method throws a exception because no meaningful conversion between a date and time and a 32-bit signed integer exists. The method must be present in this case because the class implements the interface. + + You should also throw a exception if you've implemented an abstract base class and add a new member to it that must be overridden by derived classes. In that case, making the member abstract causes existing subclasses to fail to load. + + + +## Examples + The following example throws this exception for a method that has not been developed. + :::code language="csharp" source="~/snippets/csharp/System/NotImplementedException/Overview/program.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/NotImplementedException/Overview/program.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.notimplementedexception/vb/program.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.notimplementedexception/vb/program.vb" id="Snippet1"::: + ]]> @@ -161,16 +161,16 @@ Initializes a new instance of the class with default properties. - . - -|Property|Value| -|--------------|-----------| -||`null`.| -||The empty string ("").| - + . + +|Property|Value| +|--------------|-----------| +||`null`.| +||The empty string ("").| + ]]> @@ -217,16 +217,16 @@ The error message that explains the reason for the exception. Initializes a new instance of the class with a specified error message. - . - -|Property|Value| -|--------------|-----------| -||`null`.| -||The error message string.| - + . + +|Property|Value| +|--------------|-----------| +||`null`.| +||The error message string.| + ]]> @@ -334,18 +334,18 @@ The exception that is the cause of the current exception. If the parameter is not , the current exception is raised in a block that handles the inner exception. Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception. - property. The property returns the same value that is passed into the constructor, or `null` if the property does not supply the inner exception value to the constructor. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||The inner exception reference.| -||The error message string.| - + property. The property returns the same value that is passed into the constructor, or `null` if the property does not supply the inner exception value to the constructor. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||The inner exception reference.| +||The error message string.| + ]]> diff --git a/xml/System/NotSupportedException.xml b/xml/System/NotSupportedException.xml index 7390f2097ed..22a4ee17cee 100644 --- a/xml/System/NotSupportedException.xml +++ b/xml/System/NotSupportedException.xml @@ -70,93 +70,93 @@ The exception that is thrown when an invoked method is not supported, or when there is an attempt to read, seek, or write to a stream that does not support the invoked functionality. - indicates that no implementation exists for an invoked method or property. - - uses the HRESULT COR_E_NOTSUPPORTED, which has the value 0x80131515. - - For a list of initial property values for an instance of , see the constructors. - -## Throwing a NotSupportedException exception - You might consider throwing a exception in the following cases: - -- You are implementing a general-purpose interface, and number of the methods have no meaningful implementation. For example, if you are creating a date and time type that implements the interface, you would throw a exception for most of the conversions. - -- You've inherited from an abstract class that requires that you override a number of methods. However, you're only prepared to provide an implementation for a subset of these. For the methods that you decide not to implement, you can choose to throw a . - -- You are defining a general-purpose type with a state that enables operations conditionally. For example, your type can be either read-only or read-write. In that case: - - - If the object is read-only, attempting to assign values to the properties of an instance or call methods that modify instance state should throw a exception. - - - You should implement a property that returns a value that indicates whether particular functionality is available. For example, for a type that can be either read-only or read-write, you could implement a `IsReadOnly` property that indicates whether the set of read-write methods are available or unavailable. - -## Handling a NotSupportedException exception - The exception indicates that a method has no implementation and that you should not call it. You should not handle the exception. Instead, what you should do depends on the cause of the exception: whether an implementation is completely absent , or the member invocation is inconsistent with the purpose of an object (such as a call to the method on a read-only object . - - **An implementation has not been provided because the operation cannot be performed in a meaningful way.** - This is a common exception when you are calling methods on an object that provides implementations for the methods of an abstract base class, or that implements a general-purpose interface, and the method has no meaningful implementation. - - For example, the class implements the interface, which means that it must include a method to convert every primitive type to every other primitive type. Many of those conversions, however, are not possible. As a result, a call to the method, for instance, throws a exception because there is no possible conversion between a and a value - - To eliminate the exception, you should eliminate the method call. - - **The method call is not supported given the state of the object.** - You are attempting to invoke a member whose functionality is unavailable because of the object's state. You can eliminate the exception in one of three ways: - -- You know the state of the object in advance, but you've invoked an unsupported method or property. In this case, the member invocation is an error, and you can eliminate it. - -- You know the state of the object in advance (usually because your code has instantiated it), but the object is mis-configured. The following example illustrates this issue. It creates a read-only object and then attempts to write to it. - + indicates that no implementation exists for an invoked method or property. + + uses the HRESULT COR_E_NOTSUPPORTED, which has the value 0x80131515. + + For a list of initial property values for an instance of , see the constructors. + +## Throwing a NotSupportedException exception + You might consider throwing a exception in the following cases: + +- You are implementing a general-purpose interface, and number of the methods have no meaningful implementation. For example, if you are creating a date and time type that implements the interface, you would throw a exception for most of the conversions. + +- You've inherited from an abstract class that requires that you override a number of methods. However, you're only prepared to provide an implementation for a subset of these. For the methods that you decide not to implement, you can choose to throw a . + +- You are defining a general-purpose type with a state that enables operations conditionally. For example, your type can be either read-only or read-write. In that case: + + - If the object is read-only, attempting to assign values to the properties of an instance or call methods that modify instance state should throw a exception. + + - You should implement a property that returns a value that indicates whether particular functionality is available. For example, for a type that can be either read-only or read-write, you could implement a `IsReadOnly` property that indicates whether the set of read-write methods are available or unavailable. + +## Handling a NotSupportedException exception + The exception indicates that a method has no implementation and that you should not call it. You should not handle the exception. Instead, what you should do depends on the cause of the exception: whether an implementation is completely absent , or the member invocation is inconsistent with the purpose of an object (such as a call to the method on a read-only object . + + **An implementation has not been provided because the operation cannot be performed in a meaningful way.** + This is a common exception when you are calling methods on an object that provides implementations for the methods of an abstract base class, or that implements a general-purpose interface, and the method has no meaningful implementation. + + For example, the class implements the interface, which means that it must include a method to convert every primitive type to every other primitive type. Many of those conversions, however, are not possible. As a result, a call to the method, for instance, throws a exception because there is no possible conversion between a and a value + + To eliminate the exception, you should eliminate the method call. + + **The method call is not supported given the state of the object.** + You are attempting to invoke a member whose functionality is unavailable because of the object's state. You can eliminate the exception in one of three ways: + +- You know the state of the object in advance, but you've invoked an unsupported method or property. In this case, the member invocation is an error, and you can eliminate it. + +- You know the state of the object in advance (usually because your code has instantiated it), but the object is mis-configured. The following example illustrates this issue. It creates a read-only object and then attempts to write to it. + :::code language="csharp" source="~/snippets/csharp/System/NotSupportedException/Overview/BadState1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/NotSupportedException/Overview/BadState1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.NotSupportedException/vb/BadState1.vb" id="Snippet1"::: - - You can eliminate the exception by ensuring that the instantiated object supports the functionality you intend. The following example addresses the problem of the read-only object by providing the correct arguments to the constructor. - -- You don't know the state of the object in advance, and the object doesn't support a particular operation. In most cases, the object should include a property or method that indicates whether it supports a particular set of operations. You can eliminate the exception by checking the value of the object and invoking the member only if appropriate. - - The following example defines a `DetectEncoding` method that throws a exception when it attempts to read from the beginning of a stream that does not support read access. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.NotSupportedException/vb/BadState1.vb" id="Snippet1"::: + + You can eliminate the exception by ensuring that the instantiated object supports the functionality you intend. The following example addresses the problem of the read-only object by providing the correct arguments to the constructor. + +- You don't know the state of the object in advance, and the object doesn't support a particular operation. In most cases, the object should include a property or method that indicates whether it supports a particular set of operations. You can eliminate the exception by checking the value of the object and invoking the member only if appropriate. + + The following example defines a `DetectEncoding` method that throws a exception when it attempts to read from the beginning of a stream that does not support read access. + :::code language="csharp" source="~/snippets/csharp/System/NotSupportedException/Overview/TestProp1.cs" id="Snippet3"::: :::code language="fsharp" source="~/snippets/fsharp/System/NotSupportedException/Overview/TestProp1.fs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.NotSupportedException/vb/TestProp1.vb" id="Snippet3"::: - - You can eliminate the exception by examining the value of the property and exiting the method if the stream is read-only. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.NotSupportedException/vb/TestProp1.vb" id="Snippet3"::: + + You can eliminate the exception by examining the value of the property and exiting the method if the stream is read-only. + :::code language="csharp" source="~/snippets/csharp/System/NotSupportedException/Overview/TestProp2.cs" id="Snippet4"::: :::code language="fsharp" source="~/snippets/fsharp/System/NotSupportedException/Overview/TestProp2.fs" id="Snippet4"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.NotSupportedException/vb/TestProp2.vb" id="Snippet4"::: - -## Related exception types - The exception is closely related to two other exception types; - - . - This exception is thrown when a method could be implemented but is not, either because the member will be implemented in a later version, the member is not available on a particular platform, or the member belongs to an abstract class and a derived class must provide an implementation. - - - This exception is thrown in scenarios in which it is generally sometimes possible for the object to perform the requested operation, and the object state determines whether the operation can be performed. - -## .NET Compact Framework notes - When working with the .NET Compact Framework and using P/Invoke on a native function, this exception may be thrown if: - -- The declaration in managed code is incorrect. - -- The .NET Compact Framework does not support what you are trying to do. - -- The DLL names are mangled on export. - - If a exception is thrown, check: - -- For any violations of the .NET Compact Framework P/Invoke restrictions. - -- For any arguments that require pre-allocated memory. If these exist, you should pass a reference to an existing variable. - -- That the names of the exported functions are correct. This can be verified with [DumpBin.exe](/cpp/build/reference/dumpbin-reference). - -- That you are not attempting to pass too many arguments. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.NotSupportedException/vb/TestProp2.vb" id="Snippet4"::: + +## Related exception types + The exception is closely related to two other exception types; + + . + This exception is thrown when a method could be implemented but is not, either because the member will be implemented in a later version, the member is not available on a particular platform, or the member belongs to an abstract class and a derived class must provide an implementation. + + + This exception is thrown in scenarios in which it is generally sometimes possible for the object to perform the requested operation, and the object state determines whether the operation can be performed. + +## .NET Compact Framework notes + When working with the .NET Compact Framework and using P/Invoke on a native function, this exception may be thrown if: + +- The declaration in managed code is incorrect. + +- The .NET Compact Framework does not support what you are trying to do. + +- The DLL names are mangled on export. + + If a exception is thrown, check: + +- For any violations of the .NET Compact Framework P/Invoke restrictions. + +- For any arguments that require pre-allocated memory. If these exist, you should pass a reference to an existing variable. + +- That the names of the exported functions are correct. This can be verified with [DumpBin.exe](/cpp/build/reference/dumpbin-reference). + +- That you are not attempting to pass too many arguments. + ]]> @@ -214,16 +214,16 @@ Initializes a new instance of the class, setting the property of the new instance to a system-supplied message that describes the error. This message takes into account the current system culture. - . - -|Property|Value| -|--------------|-----------| -||`null`.| -||The localized error message string.| - + . + +|Property|Value| +|--------------|-----------| +||`null`.| +||The localized error message string.| + ]]> @@ -270,16 +270,16 @@ A that describes the error. The content of is intended to be understood by humans. The caller of this constructor is required to ensure that this string has been localized for the current system culture. Initializes a new instance of the class with a specified error message. - . - -|Property|Value| -|--------------|-----------| -||`null`.| -||The error message string.| - + . + +|Property|Value| +|--------------|-----------| +||`null`.| +||The error message string.| + ]]> @@ -341,11 +341,11 @@ The contextual information about the source or destination. Initializes a new instance of the class with serialized data. - XML and SOAP Serialization @@ -395,18 +395,18 @@ The exception that is the cause of the current exception. If the parameter is not a null reference, the current exception is raised in a block that handles the inner exception. Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception. - property. The property returns the same value that is passed into the constructor, or `null` if the property does not supply the inner exception value to the constructor. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||The inner exception reference.| -||The error message string.| - + property. The property returns the same value that is passed into the constructor, or `null` if the property does not supply the inner exception value to the constructor. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||The inner exception reference.| +||The error message string.| + ]]> diff --git a/xml/System/NullReferenceException.xml b/xml/System/NullReferenceException.xml index 96a21a981e6..1aa8daaaa30 100644 --- a/xml/System/NullReferenceException.xml +++ b/xml/System/NullReferenceException.xml @@ -70,107 +70,107 @@ The exception that is thrown when there is an attempt to dereference a null object reference. - exception is thrown when you try to access a member on a type whose value is `null`. A exception typically reflects developer error and is thrown in the following scenarios: - -- You've forgotten to instantiate a reference type. In the following example, `names` is declared but never instantiated: - + exception is thrown when you try to access a member on a type whose value is `null`. A exception typically reflects developer error and is thrown in the following scenarios: + +- You've forgotten to instantiate a reference type. In the following example, `names` is declared but never instantiated: + :::code language="csharp" source="~/snippets/csharp/System/NullReferenceException/Overview/example1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/NullReferenceException/Overview/example1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.nullreferenceexception.class/vb/example1.vb" id="Snippet1"::: - - Some compilers issue a warning when they compile this code. Others issue an error, and the compilation fails. To address this problem, instantiate the object so that its value is no longer `null`. The following example does this by calling a type's class constructor. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.nullreferenceexception.class/vb/example1.vb" id="Snippet1"::: + + Some compilers issue a warning when they compile this code. Others issue an error, and the compilation fails. To address this problem, instantiate the object so that its value is no longer `null`. The following example does this by calling a type's class constructor. + :::code language="csharp" source="~/snippets/csharp/System/NullReferenceException/Overview/example1a.cs" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/NullReferenceException/Overview/example1a.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.nullreferenceexception.class/vb/example1a.vb" id="Snippet2"::: - -- You've forgotten to dimension an array before initializing it. In the following example, `values` is declared to be an integer array, but the number of elements that it contains is never specified. The attempt to initialize its values therefore thrown a exception. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.nullreferenceexception.class/vb/example1a.vb" id="Snippet2"::: + +- You've forgotten to dimension an array before initializing it. In the following example, `values` is declared to be an integer array, but the number of elements that it contains is never specified. The attempt to initialize its values therefore thrown a exception. + :::code language="csharp" source="~/snippets/csharp/System/NullReferenceException/Overview/Array3.cs" id="Snippet10"::: :::code language="fsharp" source="~/snippets/fsharp/System/NullReferenceException/Overview/Array3.fs" id="Snippet10"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.nullreferenceexception.class/vb/Array3.vb" id="Snippet10"::: - - You can eliminate the exception by declaring the number of elements in the array before initializing it, as the following example does. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.nullreferenceexception.class/vb/Array3.vb" id="Snippet10"::: + + You can eliminate the exception by declaring the number of elements in the array before initializing it, as the following example does. + :::code language="csharp" source="~/snippets/csharp/System/NullReferenceException/Overview/Array4.cs" id="Snippet11"::: :::code language="fsharp" source="~/snippets/fsharp/System/NullReferenceException/Overview/Array4.fs" id="Snippet11"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.nullreferenceexception.class/vb/Array4.vb" id="Snippet11"::: - - For more information on declaring and initializing arrays, see [Arrays](/dotnet/csharp/programming-guide/arrays/) and [Arrays](/dotnet/visual-basic/programming-guide/language-features/arrays/). - -- You get a **null** return value from a method, and then call a method on the returned type. This sometimes is the result of a documentation error; the documentation fails to note that a method call can return `null`. In other cases, your code erroneously assumes that the method will always return a non-**null** value. - - The code in the following example assumes that the method always returns `Person` object whose `FirstName` field matches a search string. Because there is no match, the runtime throws a exception. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.nullreferenceexception.class/vb/Array4.vb" id="Snippet11"::: + + For more information on declaring and initializing arrays, see [Arrays](/dotnet/csharp/programming-guide/arrays/) and [Arrays](/dotnet/visual-basic/programming-guide/language-features/arrays/). + +- You get a **null** return value from a method, and then call a method on the returned type. This sometimes is the result of a documentation error; the documentation fails to note that a method call can return `null`. In other cases, your code erroneously assumes that the method will always return a non-**null** value. + + The code in the following example assumes that the method always returns `Person` object whose `FirstName` field matches a search string. Because there is no match, the runtime throws a exception. + :::code language="csharp" source="~/snippets/csharp/System/NullReferenceException/Overview/nullreturn2.cs" id="Snippet4"::: :::code language="fsharp" source="~/snippets/fsharp/System/NullReferenceException/Overview/nullreturn2.fs" id="Snippet4"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.nullreferenceexception.class/vb/nullreturn2.vb" id="Snippet4"::: - - To address this problem, test the method's return value to ensure that it is not `null` before calling any of its members, as the following example does. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.nullreferenceexception.class/vb/nullreturn2.vb" id="Snippet4"::: + + To address this problem, test the method's return value to ensure that it is not `null` before calling any of its members, as the following example does. + :::code language="csharp" source="~/snippets/csharp/System/NullReferenceException/Overview/nullreturn2a.cs" id="Snippet5"::: :::code language="fsharp" source="~/snippets/fsharp/System/NullReferenceException/Overview/nullreturn2a.fs" id="Snippet5"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.nullreferenceexception.class/vb/nullreturn2a.vb" id="Snippet5"::: - -- You're using an expression (for example, you're chaining a list of methods or properties together) to retrieve a value and, although you're checking whether the value is `null`, the runtime still throws a exception. This occurs because one of the intermediate values in the expression returns `null`. As a result, your test for `null` is never evaluated. - - The following example defines a `Pages` object that caches information about web pages, which are presented by `Page` objects. The `Example.Main` method checks whether the current web page has a non-null title and, if it does, displays the title. Despite this check, however, the method throws a exception. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.nullreferenceexception.class/vb/nullreturn2a.vb" id="Snippet5"::: + +- You're using an expression (for example, you're chaining a list of methods or properties together) to retrieve a value and, although you're checking whether the value is `null`, the runtime still throws a exception. This occurs because one of the intermediate values in the expression returns `null`. As a result, your test for `null` is never evaluated. + + The following example defines a `Pages` object that caches information about web pages, which are presented by `Page` objects. The `Example.Main` method checks whether the current web page has a non-null title and, if it does, displays the title. Despite this check, however, the method throws a exception. + :::code language="csharp" source="~/snippets/csharp/System/NullReferenceException/Overview/Chain1.cs" id="Snippet6"::: :::code language="fsharp" source="~/snippets/fsharp/System/NullReferenceException/Overview/Chain1.fs" id="Snippet6"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.nullreferenceexception.class/vb/Chain1.vb" id="Snippet6"::: - - The exception is thrown because `pages.CurrentPage` returns `null` if no page information is stored in the cache. This exception can be corrected by testing the value of the `CurrentPage` property before retrieving the current `Page` object's `Title` property, as the following example does: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.nullreferenceexception.class/vb/Chain1.vb" id="Snippet6"::: + + The exception is thrown because `pages.CurrentPage` returns `null` if no page information is stored in the cache. This exception can be corrected by testing the value of the `CurrentPage` property before retrieving the current `Page` object's `Title` property, as the following example does: + :::code language="csharp" source="~/snippets/csharp/System/NullReferenceException/Overview/Chain2.cs" id="Snippet7"::: :::code language="fsharp" source="~/snippets/fsharp/System/NullReferenceException/Overview/Chain2.fs" id="Snippet7"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.nullreferenceexception.class/vb/Chain2.vb" id="Snippet7"::: - -- You're enumerating the elements of an array that contains reference types, and your attempt to process one of the elements throws a exception. - - The following example defines a string array. A `for` statement enumerates the elements in the array and calls each string's method before displaying the string. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.nullreferenceexception.class/vb/Chain2.vb" id="Snippet7"::: + +- You're enumerating the elements of an array that contains reference types, and your attempt to process one of the elements throws a exception. + + The following example defines a string array. A `for` statement enumerates the elements in the array and calls each string's method before displaying the string. + :::code language="csharp" source="~/snippets/csharp/System/NullReferenceException/Overview/Array1.cs" id="Snippet8"::: :::code language="fsharp" source="~/snippets/fsharp/System/NullReferenceException/Overview/Array1.fs" id="Snippet8"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.nullreferenceexception.class/vb/Array1.vb" id="Snippet8"::: - - This exception occurs if you assume that each element of the array must contain a non-null value, and the value of the array element is in fact `null`. The exception can be eliminated by testing whether the element is `null` before performing any operation on that element, as the following example shows. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.nullreferenceexception.class/vb/Array1.vb" id="Snippet8"::: + + This exception occurs if you assume that each element of the array must contain a non-null value, and the value of the array element is in fact `null`. The exception can be eliminated by testing whether the element is `null` before performing any operation on that element, as the following example shows. + :::code language="csharp" source="~/snippets/csharp/System/NullReferenceException/Overview/Array2.cs" id="Snippet9"::: :::code language="fsharp" source="~/snippets/fsharp/System/NullReferenceException/Overview/Array2.fs" id="Snippet9"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.nullreferenceexception.class/vb/Array2.vb" id="Snippet9"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.nullreferenceexception.class/vb/Array2.vb" id="Snippet9"::: + - A exception can be thrown by a method when it accesses a member of one of its arguments, but that argument is `null`. The `PopulateNames` method in the following example throws the exception at the line `names.Add(arrName);`. - + :::code language="csharp" source="~/snippets/csharp/System/NullReferenceException/Overview/example2.cs" id="Snippet3"::: :::code language="fsharp" source="~/snippets/fsharp/System/NullReferenceException/Overview/example2.fs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.nullreferenceexception.class/vb/example2.vb" id="Snippet3"::: - - To address this issue, make sure that the argument passed to the method is not `null`, or handle the thrown exception in a `try…catch…finally` block. For more information, see [Exceptions](/dotnet/standard/exceptions/). - - The following Microsoft intermediate language (MSIL) instructions throw : `callvirt`, `cpblk`, `cpobj`, `initblk`, `ldelem.`, `ldelema`, `ldfld`, `ldflda`, `ldind.`, `ldlen`, `stelem.`, `stfld`, `stind.`, `throw`, and `unbox`. - - uses the HRESULT COR_E_NULLREFERENCE, which has the value 0x80004003. - - For a list of initial property values for an instance of , see the constructors. - - **Handling NullReferenceException in release code** - - It's usually better to avoid a NullReferenceException than to handle it after it occurs. Handling an exception can make your code harder to maintain and understand, and can sometimes introduce other bugs. A NullReferenceException is often a non-recoverable error. In these cases, letting the exception stop the app might be the best alternative. - - However, there are many situations where handling the error can be useful: - -- Your app can ignore objects that are null. For example, if your app retrieves and processes records in a database, you might be able to ignore some number of bad records that result in null objects. Recording the bad data in a log file or in the application UI might be all you have to do. - -- You can recover from the exception. For example, a call to a web service that returns a reference type might return null if the connection is lost or the connection times out. You can attempt to reestablish the connection and try the call again. - -- You can restore the state of your app to a valid state. For example, you might be performing a multi-step task that requires you to save information to a data store before you call a method that throws a NullReferenceException. If the uninitialized object would corrupt the data record, you can remove the previous data before you close the app. - -- You want to report the exception. For example, if the error was caused by a mistake from the user of your app, you can generate a message to help them supply the correct information. You can also log information about the error to help you fix the problem. Some frameworks, like ASP.NET, have a high-level exception handler that captures all errors to that the app never crashes; in that case, logging the exception might be the only way you can know that it occurs. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.nullreferenceexception.class/vb/example2.vb" id="Snippet3"::: + + To address this issue, make sure that the argument passed to the method is not `null`, or handle the thrown exception in a `try…catch…finally` block. For more information, see [Exceptions](/dotnet/standard/exceptions/). + + The following Microsoft intermediate language (MSIL) instructions throw : `callvirt`, `cpblk`, `cpobj`, `initblk`, `ldelem.`, `ldelema`, `ldfld`, `ldflda`, `ldind.`, `ldlen`, `stelem.`, `stfld`, `stind.`, `throw`, and `unbox`. + + uses the HRESULT COR_E_NULLREFERENCE, which has the value 0x80004003. + + For a list of initial property values for an instance of , see the constructors. + + **Handling NullReferenceException in release code** + + It's usually better to avoid a NullReferenceException than to handle it after it occurs. Handling an exception can make your code harder to maintain and understand, and can sometimes introduce other bugs. A NullReferenceException is often a non-recoverable error. In these cases, letting the exception stop the app might be the best alternative. + + However, there are many situations where handling the error can be useful: + +- Your app can ignore objects that are null. For example, if your app retrieves and processes records in a database, you might be able to ignore some number of bad records that result in null objects. Recording the bad data in a log file or in the application UI might be all you have to do. + +- You can recover from the exception. For example, a call to a web service that returns a reference type might return null if the connection is lost or the connection times out. You can attempt to reestablish the connection and try the call again. + +- You can restore the state of your app to a valid state. For example, you might be performing a multi-step task that requires you to save information to a data store before you call a method that throws a NullReferenceException. If the uninitialized object would corrupt the data record, you can remove the previous data before you close the app. + +- You want to report the exception. For example, if the error was caused by a mistake from the user of your app, you can generate a message to help them supply the correct information. You can also log information about the error to help you fix the problem. Some frameworks, like ASP.NET, have a high-level exception handler that captures all errors to that the app never crashes; in that case, logging the exception might be the only way you can know that it occurs. + ]]> @@ -227,16 +227,16 @@ Initializes a new instance of the class, setting the property of the new instance to a system-supplied message that describes the error, such as "The value 'null' was found where an instance of an object was required." This message takes into account the current system culture. - . - -|Property|Value| -|--------------|-----------| -||`null`.| -||The localized error message string.| - + . + +|Property|Value| +|--------------|-----------| +||`null`.| +||The localized error message string.| + ]]> @@ -283,16 +283,16 @@ A that describes the error. The content of is intended to be understood by humans. The caller of this constructor is required to ensure that this string has been localized for the current system culture. Initializes a new instance of the class with a specified error message. - . - -|Property|Value| -|--------------|-----------| -||`null`.| -||The error message string.| - + . + +|Property|Value| +|--------------|-----------| +||`null`.| +||The error message string.| + ]]> @@ -354,11 +354,11 @@ The contextual information about the source or destination. Initializes a new instance of the class with serialized data. - XML and SOAP Serialization @@ -408,18 +408,18 @@ The exception that is the cause of the current exception. If the parameter is not , the current exception is raised in a block that handles the inner exception. Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception. - property. The property returns the same value that is passed into the constructor, or `null` if the property does not supply the inner exception value to the constructor. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||The inner exception reference.| -||The error message string.| - + property. The property returns the same value that is passed into the constructor, or `null` if the property does not supply the inner exception value to the constructor. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||The inner exception reference.| +||The error message string.| + ]]> diff --git a/xml/System/Nullable.xml b/xml/System/Nullable.xml index 7767f737233..ef8dc607654 100644 --- a/xml/System/Nullable.xml +++ b/xml/System/Nullable.xml @@ -50,20 +50,20 @@ Supports a value type that can be assigned . This class cannot be inherited. - , are nullable, but all value types, such as , are not. - - In C# and Visual Basic, you mark a value type as nullable by using the `?` notation after the value type. For example, `int?` in C# or `Integer?` in Visual Basic declares an integer value type that can be assigned `null`. - - The class provides complementary support for the structure. The class supports obtaining the underlying type of a nullable type, and comparison and equality operations on pairs of nullable types whose underlying value type does not support generic comparison and equality operations. - -## Boxing and Unboxing + , are nullable, but all value types, such as , are not. + + In C# and Visual Basic, you mark a value type as nullable by using the `?` notation after the value type. For example, `int?` in C# or `Integer?` in Visual Basic declares an integer value type that can be assigned `null`. + + The class provides complementary support for the structure. The class supports obtaining the underlying type of a nullable type, and comparison and equality operations on pairs of nullable types whose underlying value type does not support generic comparison and equality operations. + +## Boxing and Unboxing When a nullable type is boxed, the common language runtime automatically boxes the underlying value of the object, not the object itself. That is, if the property is `true`, the contents of the property is boxed. - - If the `HasValue` property of a nullable type is `false`, the result of the boxing operation is `null`. When the underlying value of a nullable type is unboxed, the common language runtime creates a new structure initialized to the underlying value. - + + If the `HasValue` property of a nullable type is `false`, the result of the boxing operation is `null`. When the underlying value of a nullable type is unboxed, the common language runtime creates a new structure initialized to the underlying value. + ]]> @@ -135,25 +135,34 @@ A object. A object. Compares the relative values of two objects. - An integer that indicates the relative values of the and parameters. - - Return Value - - Description - - Less than zero - - The property for is , and the property for is , or the properties for and are , and the value of the property for is less than the value of the property for . - - Zero - - The properties for and are , or the properties for and are , and the value of the property for is equal to the value of the property for . - - Greater than zero - - The property for is , and the property for is , or the properties for and are , and the value of the property for is greater than the value of the property for . - - + An integer that indicates the relative values of the and parameters. + + Return Value + + + Description + + + + + Less than zero + + + The property for is , and the property for is , or the properties for and are , and the value of the property for is less than the value of the property for . + + + Zero + + + The properties for and are , or the properties for and are , and the value of the property for is equal to the value of the property for . + + + Greater than zero + + + The property for is , and the property for is , or the properties for and are , and the value of the property for is greater than the value of the property for . + + To be added. @@ -222,19 +231,28 @@ A object. Indicates whether two specified objects are equal. - if the parameter is equal to the parameter; otherwise, . - - The return value depends on the and properties of the two parameters that are compared. - - Return Value - - Description - - The properties for and are , or the properties for and are , and the properties of the parameters are equal. - - The property is for one parameter and for the other parameter, or the properties for and are , and the properties of the parameters are unequal. - - + if the parameter is equal to the parameter; otherwise, . The return value depends on the and properties of the two parameters that are compared. + + Return Value + + + Description + + + + + + + + The properties for and are , or the properties for and are , and the properties of the parameters are equal. + + + + + + The property is for one parameter and for the other parameter, or the properties for and are , and the properties of the parameters are unequal. + + To be added. @@ -289,18 +307,18 @@ Returns the underlying type argument of the specified nullable type. The type argument of the parameter, if the parameter is a closed generic nullable type; otherwise, . - , that contains a type parameter list, and the type parameter list declares one or more type parameters. A closed generic type is a type declaration where a particular type is specified for a type parameter. - - For example, if the `nullableType` parameter is the type of `Nullable` in C# (`Nullable(Of Int32)` in Visual Basic), the return value is the type of (that is, the type argument of the closed generic type). - - - -## Examples - The following code example defines a method whose return value is of type of . The code example uses the method to display the type argument of the return value. - + , that contains a type parameter list, and the type parameter list declares one or more type parameters. A closed generic type is a type declaration where a particular type is specified for a type parameter. + + For example, if the `nullableType` parameter is the type of `Nullable` in C# (`Nullable(Of Int32)` in Visual Basic), the return value is the type of (that is, the type argument of the closed generic type). + + + +## Examples + The following code example defines a method whose return value is of type of . The code example uses the method to display the type argument of the return value. + :::code language="csharp" source="~/snippets/csharp/System/Nullable/GetUnderlyingType/gut.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Nullable/GetUnderlyingType/gut.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.nullable_GetUnderlyingType/vb/gut.vb" id="Snippet1"::: diff --git a/xml/System/Nullable`1.xml b/xml/System/Nullable`1.xml index ce6431b9081..cb6c110eb1d 100644 --- a/xml/System/Nullable`1.xml +++ b/xml/System/Nullable`1.xml @@ -65,33 +65,33 @@ The underlying value type of the generic type. Represents a value type that can be assigned . - , are nullable, but all value types, such as , are not. - - In C# and Visual Basic, you mark a value type as nullable by using the `?` notation after the value type. For example, `int?` in C# or `Integer?` in Visual Basic declares an integer value type that can be assigned `null`. - - The structure supports using only a value type as a nullable type because reference types are nullable by design. - - The class provides complementary support for the structure. The class supports obtaining the underlying type of a nullable type, and comparison and equality operations on pairs of nullable types whose underlying value type does not support generic comparison and equality operations. - -## Fundamental Properties - The two fundamental members of the structure are the and properties. If the property for a object is `true`, the value of the object can be accessed with the property. If the property is `false`, the value of the object is undefined and an attempt to access the property throws an . - -## Boxing and Unboxing - When a nullable type is boxed, the common language runtime automatically boxes the underlying value of the object, not the object itself. That is, if the property is `true`, the contents of the property is boxed. When the underlying value of a nullable type is unboxed, the common language runtime creates a new structure initialized to the underlying value. - - If the `HasValue` property of a nullable type is `false`, the result of a boxing operation is `null`. Consequently, if a boxed nullable type is passed to a method that expects an object argument, that method must be prepared to handle the case where the argument is `null`. When `null` is unboxed into a nullable type, the common language runtime creates a new structure and initializes its `HasValue` property to `false`. - -## .NET Framework 4.5.1 and Windows Runtime Components - Starting with the .NET Framework 4.5.1, you can include a type as a member of a structure exported in a WinMD library. Previously, this was not supported. - - - -## Examples - The following code example defines three rows of a table in the Microsoft Pubs sample database. The table contains two columns that are not nullable and two columns that are nullable. - + , are nullable, but all value types, such as , are not. + + In C# and Visual Basic, you mark a value type as nullable by using the `?` notation after the value type. For example, `int?` in C# or `Integer?` in Visual Basic declares an integer value type that can be assigned `null`. + + The structure supports using only a value type as a nullable type because reference types are nullable by design. + + The class provides complementary support for the structure. The class supports obtaining the underlying type of a nullable type, and comparison and equality operations on pairs of nullable types whose underlying value type does not support generic comparison and equality operations. + +## Fundamental Properties + The two fundamental members of the structure are the and properties. If the property for a object is `true`, the value of the object can be accessed with the property. If the property is `false`, the value of the object is undefined and an attempt to access the property throws an . + +## Boxing and Unboxing + When a nullable type is boxed, the common language runtime automatically boxes the underlying value of the object, not the object itself. That is, if the property is `true`, the contents of the property is boxed. When the underlying value of a nullable type is unboxed, the common language runtime creates a new structure initialized to the underlying value. + + If the `HasValue` property of a nullable type is `false`, the result of a boxing operation is `null`. Consequently, if a boxed nullable type is passed to a method that expects an object argument, that method must be prepared to handle the case where the argument is `null`. When `null` is unboxed into a nullable type, the common language runtime creates a new structure and initializes its `HasValue` property to `false`. + +## .NET Framework 4.5.1 and Windows Runtime Components + Starting with the .NET Framework 4.5.1, you can include a type as a member of a structure exported in a WinMD library. Previously, this was not supported. + + + +## Examples + The following code example defines three rows of a table in the Microsoft Pubs sample database. The table contains two columns that are not nullable and two columns that are nullable. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.nullableOfT.class/cpp/tarow.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/NullableT/Overview/tarow.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/NullableT/Overview/tarow.fs" id="Snippet1"::: @@ -150,11 +150,11 @@ A value type. Initializes a new instance of the structure to the specified value. - constructor initializes the property of the new object to `true`, and the property to the value of the `value` parameter. - + constructor initializes the property of the new object to `true`, and the property to the value of the `value` parameter. + ]]> @@ -209,32 +209,41 @@ An object. Indicates whether the current object is equal to a specified object. - if the parameter is equal to the current object; otherwise, . - - This table describes how equality is defined for the compared values: - - Return Value - - Description - - The property is , and the parameter is (that is, two null values are equal by definition), OR the property is , and the value returned by the property is equal to the parameter. - - The property for the current structure is , and the parameter is , OR the property for the current structure is , and the parameter is not , OR the property for the current structure is , and the value returned by the property is not equal to the parameter. - - + if the parameter is equal to the current object; otherwise, . This table describes how equality is defined for the compared values: + + Return Value + + + Description + + + + + + + + The property is , and the parameter is (that is, two null values are equal by definition), OR the property is , and the value returned by the property is equal to the parameter. + + + + + + The property for the current structure is , and the parameter is , OR the property for the current structure is , and the parameter is not , OR the property for the current structure is , and the value returned by the property is not equal to the parameter. + + - property of the current structure is `true` and the `other` argument is not `null`, equality is determined by passing the `other` parameter to the `Equals` method of the underlying value of the current structure. - -## Examples - The following code example determines whether an object and a object are equal to the current object. - + +## Examples + The following code example determines whether an object and a object are equal to the current object. + :::code language="csharp" source="~/snippets/csharp/System/NullableT/Equals/eq.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/NullableT/Equals/eq.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.nullableOfT.Equals/vb/eq.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.nullableOfT.Equals/vb/eq.vb" id="Snippet1"::: + ]]> @@ -294,11 +303,11 @@ Retrieves the value of the current object, or a default value. - object if that value is defined; otherwise, it retrieves the default value or a specific default value. - + object if that value is defined; otherwise, it retrieves the default value or a specific default value. + :::code language="csharp" source="~/snippets/csharp/System/NullableT/GetValueOrDefault/gvod.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/NullableT/GetValueOrDefault/gvod.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.nullableOfT.GetValueOrDefault/vb/gvod.vb" id="Snippet1"::: @@ -357,13 +366,13 @@ Retrieves the value of the current object, or the default value of the underlying type. - The value of the property if the property is ; otherwise, the default value of the underlying type. + The value of the property if the property is ; otherwise, the default value of the underlying type. - method returns a value even if the property is `false` (unlike the property, which throws an exception). If the property is `false`, the method returns the [default](/dotnet/csharp/language-reference/keywords/default-values-table) value of the underlying type. - + method returns a value even if the property is `false` (unlike the property, which throws an exception). If the property is `false`, the method returns the [default](/dotnet/csharp/language-reference/keywords/default-values-table) value of the underlying type. + ]]> @@ -420,11 +429,11 @@ Retrieves the value of the current object, or the specified default value. The value of the property if the property is ; otherwise, the parameter. - method returns a value even if the property is `false` (unlike the property, which throws an exception). - + method returns a value even if the property is `false` (unlike the property, which throws an exception). + ]]> @@ -477,20 +486,20 @@ if the current object has a value; if the current object has no value. - property is `true`, the value of the current object can be accessed with the property. Otherwise, attempting to access its value throws an exception. - - - -## Examples - The following example uses the property of a `Nullable` (`Nullable(Of Integer)` in Visual Basic) object to determine whether it should display the object's property or its property. - + property is `true`, the value of the current object can be accessed with the property. Otherwise, attempting to access its value throws an exception. + + + +## Examples + The following example uses the property of a `Nullable` (`Nullable(Of Integer)` in Visual Basic) object to determine whether it should display the object's property or its property. + :::code language="csharp" source="~/snippets/csharp/System/NullableT/HasValue/hasvalue2.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/NullableT/HasValue/hasvalue2.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.nullable~1.hasvalue/vb/hasvalue2.vb" id="Snippet1"::: - + ]]> @@ -539,20 +548,20 @@ Defines an explicit conversion of a instance to its underlying value. The value of the property for the parameter. - instance to type `T`, the type of . The syntax for such explicit conversions is language-dependent. You may also be able to perform the conversion by calling the method. - - The equivalent method for this operator is - -## Examples - The operator enables code such as the following, which converts a `Nullable(Of Int32)` value to an value. - + instance to type `T`, the type of . The syntax for such explicit conversions is language-dependent. You may also be able to perform the conversion by calling the method. + + The equivalent method for this operator is + +## Examples + The operator enables code such as the following, which converts a `Nullable(Of Int32)` value to an value. + :::code language="csharp" source="~/snippets/csharp/System/NullableT/op_Explicit/explicit1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/NullableT/op_Explicit/explicit1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.nullable~1.conversion/vb/explicit1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.nullable~1.conversion/vb/explicit1.vb" id="Snippet1"::: + ]]> @@ -601,11 +610,11 @@ Creates a new object initialized to a specified value. A object whose property is initialized with the parameter. - property of the new value is initialized to the `value` parameter and the property is initialized to `true`. - + property of the new value is initialized to the `value` parameter and the property is initialized to `true`. + The equivalent method for this operator is > [!NOTE] @@ -666,20 +675,20 @@ Returns the text representation of the value of the current object. The text representation of the value of the current object if the property is , or an empty string ("") if the property is . - property returns the string yielded by calling the `ToString` property of the object returned by the property. - - - -## Examples - The following code example displays the value of the current object. - + property returns the string yielded by calling the `ToString` property of the object returned by the property. + + + +## Examples + The following code example displays the value of the current object. + :::code language="csharp" source="~/snippets/csharp/System/NullableT/ToString/ts.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/NullableT/ToString/ts.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.nullableOfT.ToString/vb/ts.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.nullableOfT.ToString/vb/ts.vb" id="Snippet1"::: + ]]> @@ -734,16 +743,16 @@ Gets the value of the current object if it has been assigned a valid underlying value. The value of the current object if the property is . An exception is thrown if the property is . - object, you can compare it to `null` and retrieve its property, but you cannot access its property or call its other members. - - - -## Examples - The following example uses the property of a `Nullable` (`Nullable(Of Integer)` in Visual Basic) object to determine whether it should display the object's property or its property. - + object, you can compare it to `null` and retrieve its property, but you cannot access its property or call its other members. + + + +## Examples + The following example uses the property of a `Nullable` (`Nullable(Of Integer)` in Visual Basic) object to determine whether it should display the object's property or its property. + :::code language="csharp" source="~/snippets/csharp/System/NullableT/HasValue/hasvalue2.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/NullableT/HasValue/hasvalue2.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.nullable~1.hasvalue/vb/hasvalue2.vb" id="Snippet1"::: diff --git a/xml/System/Object.xml b/xml/System/Object.xml index a74bd963622..5c4009893ee 100644 --- a/xml/System/Object.xml +++ b/xml/System/Object.xml @@ -61,40 +61,40 @@ Supports all classes in the .NET class hierarchy and provides low-level services to derived classes. This is the ultimate base class of all .NET classes; it is the root of the type hierarchy. - because the inheritance is implicit. - - Because all classes in .NET are derived from , every method defined in the class is available in all objects in the system. Derived classes can and do override some of these methods, including: - -- - Supports comparisons between objects. - -- - Performs cleanup operations before an object is automatically reclaimed. - -- - Generates a number corresponding to the value of the object to support the use of a hash table. - -- - Manufactures a human-readable text string that describes an instance of the class. - -## Performance Considerations - If you are designing a class, such as a collection, that must handle any type of object, you can create class members that accept instances of the class. However, the process of boxing and unboxing a type carries a performance cost. If you know your new class will frequently handle certain value types you can use one of two tactics to minimize the cost of boxing. - -- Create a general method that accepts an type, and a set of type-specific method overloads that accept each value type you expect your class to frequently handle. If a type-specific method exists that accepts the calling parameter type, no boxing occurs and the type-specific method is invoked. If there is no method argument that matches the calling parameter type, the parameter is boxed and the general method is invoked. - -- Design your type and its members to use generics. The common language runtime creates a closed generic type when you create an instance of your class and specify a generic type argument. The generic method is type-specific and can be invoked without boxing the calling parameter. - - Although it is sometimes necessary to develop general purpose classes that accept and return types, you can improve performance by also providing a type-specific class to handle a frequently used type. For example, providing a class that is specific to setting and getting Boolean values eliminates the cost of boxing and unboxing Boolean values. - - - -## Examples - The following example defines a Point type derived from the class and overrides many of the virtual methods of the class. In addition, the example shows how to call many of the static and instance methods of the class. - + because the inheritance is implicit. + + Because all classes in .NET are derived from , every method defined in the class is available in all objects in the system. Derived classes can and do override some of these methods, including: + +- - Supports comparisons between objects. + +- - Performs cleanup operations before an object is automatically reclaimed. + +- - Generates a number corresponding to the value of the object to support the use of a hash table. + +- - Manufactures a human-readable text string that describes an instance of the class. + +## Performance Considerations + If you are designing a class, such as a collection, that must handle any type of object, you can create class members that accept instances of the class. However, the process of boxing and unboxing a type carries a performance cost. If you know your new class will frequently handle certain value types you can use one of two tactics to minimize the cost of boxing. + +- Create a general method that accepts an type, and a set of type-specific method overloads that accept each value type you expect your class to frequently handle. If a type-specific method exists that accepts the calling parameter type, no boxing occurs and the type-specific method is invoked. If there is no method argument that matches the calling parameter type, the parameter is boxed and the general method is invoked. + +- Design your type and its members to use generics. The common language runtime creates a closed generic type when you create an instance of your class and specify a generic type argument. The generic method is type-specific and can be invoked without boxing the calling parameter. + + Although it is sometimes necessary to develop general purpose classes that accept and return types, you can improve performance by also providing a type-specific class to handle a frequently used type. For example, providing a class that is specific to setting and getting Boolean values eliminates the cost of boxing and unboxing Boolean values. + + + +## Examples + The following example defines a Point type derived from the class and overrides many of the virtual methods of the class. In addition, the example shows how to call many of the static and instance methods of the class. + :::code language="csharp" source="~/snippets/csharp/System/Object/Overview/ObjectX.cs" interactive="try-dotnet" id="snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Object/Overview/ObjectX.fs" id="snippet1"::: :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/ObjectX/cpp/ObjectX.cpp" id="snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ObjectX/vb/objectX.vb" id="snippet1"::: - + ]]> Public static ( in Visual Basic) members of this type are thread safe. Instance members are not guaranteed to be thread-safe. @@ -143,11 +143,11 @@ Initializes a new instance of the class. - class. - + class. + ]]> @@ -217,148 +217,148 @@ The object to compare with the current object. Determines whether the specified object is equal to the current object. - if the specified object is equal to the current object; otherwise, . + if the specified object is equal to the current object; otherwise, . - method tests for reference equality, and a call to the method is equivalent to a call to the method. Reference equality means that the object variables that are compared refer to the same object. The following example illustrates the result of such a comparison. It defines a `Person` class, which is a reference type, and calls the `Person` class constructor to instantiate two new `Person` objects, `person1a` and `person2`, which have the same value. It also assigns `person1a` to another object variable, `person1b`. As the output from the example shows, `person1a` and `person1b` are equal because they reference the same object. However, `person1a` and `person2` are not equal, although they have the same value. -- If the current instance is a reference type, the method tests for reference equality, and a call to the method is equivalent to a call to the method. Reference equality means that the object variables that are compared refer to the same object. The following example illustrates the result of such a comparison. It defines a `Person` class, which is a reference type, and calls the `Person` class constructor to instantiate two new `Person` objects, `person1a` and `person2`, which have the same value. It also assigns `person1a` to another object variable, `person1b`. As the output from the example shows, `person1a` and `person1b` are equal because they reference the same object. However, `person1a` and `person2` are not equal, although they have the same value. - :::code language="csharp" source="~/snippets/csharp/System/Object/Equals/equals_ref.cs" interactive="try-dotnet" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/Object/Equals/equals_ref.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.object.equals/vb/equals_ref.vb" id="Snippet2"::: - -- If the current instance is a value type, the method tests for value equality. Value equality means the following: - - - The two objects are of the same type. As the following example shows, a object that has a value of 12 does not equal an object that has a value of 12, because the two objects have different run-time types. - + +- If the current instance is a value type, the method tests for value equality. Value equality means the following: + + - The two objects are of the same type. As the following example shows, a object that has a value of 12 does not equal an object that has a value of 12, because the two objects have different run-time types. + :::code language="csharp" source="~/snippets/csharp/System/Object/Equals/equals_val1.cs" interactive="try-dotnet-method" id="Snippet3"::: :::code language="fsharp" source="~/snippets/fsharp/System/Object/Equals/equals_val1.fs" id="Snippet3"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.object.equals/vb/equals_val1.vb" id="Snippet3"::: - - - The values of the public and private fields of the two objects are equal. The following example tests for value equality. It defines a `Person` structure, which is a value type, and calls the `Person` class constructor to instantiate two new `Person` objects, `person1` and `person2`, which have the same value. As the output from the example shows, although the two object variables refer to different objects, `person1` and `person2` are equal because they have the same value for the private `personName` field. - + + - The values of the public and private fields of the two objects are equal. The following example tests for value equality. It defines a `Person` structure, which is a value type, and calls the `Person` class constructor to instantiate two new `Person` objects, `person1` and `person2`, which have the same value. As the output from the example shows, although the two object variables refer to different objects, `person1` and `person2` are equal because they have the same value for the private `personName` field. + :::code language="csharp" source="~/snippets/csharp/System/Object/Equals/equals_val2.cs" id="Snippet4"::: :::code language="fsharp" source="~/snippets/fsharp/System/Object/Equals/equals_val2.fs" id="Snippet4"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.object.equals/vb/equals_val2.vb" id="Snippet4"::: - - Because the class is the base class for all types in the .NET Framework, the method provides the default equality comparison for all other types. However, types often override the method to implement value equality. For more information, see the Notes for Callers and Notes for Inheritors sections. - -## Notes for the Windows Runtime - When you call the method overload on a class in the Windows Runtime, it provides the default behavior for classes that don't override . This is part of the support that the .NET Framework provides for the Windows Runtime (see [.NET Framework Support for Windows Store Apps and Windows Runtime](/dotnet/standard/cross-platform/support-for-windows-store-apps-and-windows-runtime)). Classes in the Windows Runtime don't inherit , and currently don't implement an method. However, they appear to have , , and methods when you use them in your C# or Visual Basic code, and the .NET Framework provides the default behavior for these methods. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.object.equals/vb/equals_val2.vb" id="Snippet4"::: + + Because the class is the base class for all types in the .NET Framework, the method provides the default equality comparison for all other types. However, types often override the method to implement value equality. For more information, see the Notes for Callers and Notes for Inheritors sections. + +## Notes for the Windows Runtime + When you call the method overload on a class in the Windows Runtime, it provides the default behavior for classes that don't override . This is part of the support that the .NET Framework provides for the Windows Runtime (see [.NET Framework Support for Windows Store Apps and Windows Runtime](/dotnet/standard/cross-platform/support-for-windows-store-apps-and-windows-runtime)). Classes in the Windows Runtime don't inherit , and currently don't implement an method. However, they appear to have , , and methods when you use them in your C# or Visual Basic code, and the .NET Framework provides the default behavior for these methods. + > [!NOTE] -> Windows Runtime classes that are written in C# or Visual Basic can override the method overload. - -## Notes for Callers - Derived classes frequently override the method to implement value equality. In addition, types also frequently provide an additional strongly typed overload to the `Equals` method, typically by implementing the interface. When you call the `Equals` method to test for equality, you should know whether the current instance overrides and understand how a particular call to an `Equals` method is resolved. Otherwise, you may be performing a test for equality that is different from what you intended, and the method may return an unexpected value. - - The following example provides an illustration. It instantiates three objects with identical strings, and then makes four calls to `Equals` methods. The first method call returns `true`, and the remaining three return `false`. - +> Windows Runtime classes that are written in C# or Visual Basic can override the method overload. + +## Notes for Callers + Derived classes frequently override the method to implement value equality. In addition, types also frequently provide an additional strongly typed overload to the `Equals` method, typically by implementing the interface. When you call the `Equals` method to test for equality, you should know whether the current instance overrides and understand how a particular call to an `Equals` method is resolved. Otherwise, you may be performing a test for equality that is different from what you intended, and the method may return an unexpected value. + + The following example provides an illustration. It instantiates three objects with identical strings, and then makes four calls to `Equals` methods. The first method call returns `true`, and the remaining three return `false`. + :::code language="csharp" source="~/snippets/csharp/System/Object/Equals/equalssb1.cs" interactive="try-dotnet" id="Snippet5"::: :::code language="fsharp" source="~/snippets/fsharp/System/Object/Equals/equalssb1.fs" id="Snippet5"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.object.equals/vb/equalssb1.vb" id="Snippet5"::: - - In the first case, the strongly typed method overload, which tests for value equality, is called. Because the strings assigned to the two objects are equal, the method returns `true`. However, does not override . Because of this, when the object is cast to an , when a instance is assigned to a variable of type , and when the method is passed two objects, the default method is called. Because is a reference type, this is equivalent to passing the two objects to the method. Although all three objects contain identical strings, they refer to three distinct objects. As a result, these three method calls return `false`. - - You can compare the current object to another object for reference equality by calling the method. In Visual Basic, you can also use the `is` keyword (for example, `If Me Is otherObject Then ...`). - -## Notes for Inheritors - When you define your own type, that type inherits the functionality defined by the `Equals` method of its base type. The following table lists the default implementation of the `Equals` method for the major categories of types in the .NET Framework. - -|Type category|Equality defined by|Comments| -|-------------------|-------------------------|--------------| -|Class derived directly from ||Reference equality; equivalent to calling .| -|Structure||Value equality; either direct byte-by-byte comparison or field-by-field comparison using reflection.| -|Enumeration||Values must have the same enumeration type and the same underlying value.| -|Delegate||Delegates must have the same type with identical invocation lists.| -|Interface||Reference equality.| - - For a value type, you should always override , because tests for equality that rely on reflection offer poor performance. You can also override the default implementation of for reference types to test for value equality instead of reference equality and to define the precise meaning of value equality. Such implementations of return `true` if the two objects have the same value, even if they are not the same instance. The type's implementer decides what constitutes an object's value, but it is typically some or all the data stored in the instance variables of the object. For example, the value of a object is based on the characters of the string; the method overrides the method to return `true` for any two string instances that contain the same characters in the same order. - - The following example shows how to override the method to test for value equality. It overrides the method for the `Person` class. If `Person` accepted its base class implementation of equality, two `Person` objects would be equal only if they referenced a single object. However, in this case, two `Person` objects are equal if they have the same value for the `Person.Id` property. - + + In the first case, the strongly typed method overload, which tests for value equality, is called. Because the strings assigned to the two objects are equal, the method returns `true`. However, does not override . Because of this, when the object is cast to an , when a instance is assigned to a variable of type , and when the method is passed two objects, the default method is called. Because is a reference type, this is equivalent to passing the two objects to the method. Although all three objects contain identical strings, they refer to three distinct objects. As a result, these three method calls return `false`. + + You can compare the current object to another object for reference equality by calling the method. In Visual Basic, you can also use the `is` keyword (for example, `If Me Is otherObject Then ...`). + +## Notes for Inheritors + When you define your own type, that type inherits the functionality defined by the `Equals` method of its base type. The following table lists the default implementation of the `Equals` method for the major categories of types in the .NET Framework. + +|Type category|Equality defined by|Comments| +|-------------------|-------------------------|--------------| +|Class derived directly from ||Reference equality; equivalent to calling .| +|Structure||Value equality; either direct byte-by-byte comparison or field-by-field comparison using reflection.| +|Enumeration||Values must have the same enumeration type and the same underlying value.| +|Delegate||Delegates must have the same type with identical invocation lists.| +|Interface||Reference equality.| + + For a value type, you should always override , because tests for equality that rely on reflection offer poor performance. You can also override the default implementation of for reference types to test for value equality instead of reference equality and to define the precise meaning of value equality. Such implementations of return `true` if the two objects have the same value, even if they are not the same instance. The type's implementer decides what constitutes an object's value, but it is typically some or all the data stored in the instance variables of the object. For example, the value of a object is based on the characters of the string; the method overrides the method to return `true` for any two string instances that contain the same characters in the same order. + + The following example shows how to override the method to test for value equality. It overrides the method for the `Person` class. If `Person` accepted its base class implementation of equality, two `Person` objects would be equal only if they referenced a single object. However, in this case, two `Person` objects are equal if they have the same value for the `Person.Id` property. + :::code language="csharp" source="~/snippets/csharp/System/Object/Equals/equalsoverride.cs" id="Snippet6"::: :::code language="fsharp" source="~/snippets/fsharp/System/Object/Equals/equalsoverride.fs" id="Snippet6"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.object.equals/vb/equalsoverride.vb" id="Snippet6"::: - - In addition to overriding , you can implement the interface to provide a strongly typed test for equality. - - The following statements must be true for all implementations of the method. In the list, `x`, `y`, and `z` represent object references that are not **null**. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.object.equals/vb/equalsoverride.vb" id="Snippet6"::: + + In addition to overriding , you can implement the interface to provide a strongly typed test for equality. + + The following statements must be true for all implementations of the method. In the list, `x`, `y`, and `z` represent object references that are not **null**. + - `x.Equals(x)` returns `true`. - -- `x.Equals(y)` returns the same value as `y.Equals(x)`. - -- `x.Equals(y)` returns `true` if both `x` and `y` are `NaN`. - -- If `(x.Equals(y) && y.Equals(z))` returns `true`, then `x.Equals(z)` returns `true`. - -- Successive calls to `x.Equals(y)` return the same value as long as the objects referenced by `x` and `y` are not modified. - -- `x.Equals(null)` returns `false`. - - Implementations of must not throw exceptions; they should always return a value. For example, if `obj` is `null`, the method should return `false` instead of throwing an . - - Follow these guidelines when overriding : - -- Types that implement must override . - -- Types that override must also override ; otherwise, hash tables might not work correctly. - -- You should consider implementing the interface to support strongly typed tests for equality. Your implementation should return results that are consistent with . - -- If your programming language supports operator overloading and you overload the equality operator for a given type, you must also override the method to return the same result as the equality operator. This helps ensure that class library code that uses (such as and ) behaves in a manner that is consistent with the way the equality operator is used by application code. - -### Guidelines for Reference Types - The following guidelines apply to overriding for a reference type: - -- Consider overriding if the semantics of the type are based on the fact that the type represents some value(s). - -- Most reference types must not overload the equality operator, even if they override . However, if you are implementing a reference type that is intended to have value semantics, such as a complex number type, you must override the equality operator. - -- You should not override on a mutable reference type. This is because overriding requires that you also override the method, as discussed in the previous section. This means that the hash code of an instance of a mutable reference type can change during its lifetime, which can cause the object to be lost in a hash table. - -### Guidelines for Value Types - The following guidelines apply to overriding for a value type: - -- If you are defining a value type that includes one or more fields whose values are reference types, you should override . The implementation provided by performs a byte-by-byte comparison for value types whose fields are all value types, but it uses reflection to perform a field-by-field comparison of value types whose fields include reference types. - -- If you override and your development language supports operator overloading, you must overload the equality operator. - -- You should implement the interface. Calling the strongly typed method avoids boxing the `obj` argument. - - - -## Examples - The following example shows a `Point` class that overrides the method to provide value equality, and a `Point3D` class that is derived from `Point`. Because `Point` overrides to test for value equality, the method is not called. However, `Point3D.Equals` calls `Point.Equals` because `Point` implements in a manner that provides value equality. - + +- `x.Equals(y)` returns the same value as `y.Equals(x)`. + +- `x.Equals(y)` returns `true` if both `x` and `y` are `NaN`. + +- If `(x.Equals(y) && y.Equals(z))` returns `true`, then `x.Equals(z)` returns `true`. + +- Successive calls to `x.Equals(y)` return the same value as long as the objects referenced by `x` and `y` are not modified. + +- `x.Equals(null)` returns `false`. + + Implementations of must not throw exceptions; they should always return a value. For example, if `obj` is `null`, the method should return `false` instead of throwing an . + + Follow these guidelines when overriding : + +- Types that implement must override . + +- Types that override must also override ; otherwise, hash tables might not work correctly. + +- You should consider implementing the interface to support strongly typed tests for equality. Your implementation should return results that are consistent with . + +- If your programming language supports operator overloading and you overload the equality operator for a given type, you must also override the method to return the same result as the equality operator. This helps ensure that class library code that uses (such as and ) behaves in a manner that is consistent with the way the equality operator is used by application code. + +### Guidelines for Reference Types + The following guidelines apply to overriding for a reference type: + +- Consider overriding if the semantics of the type are based on the fact that the type represents some value(s). + +- Most reference types must not overload the equality operator, even if they override . However, if you are implementing a reference type that is intended to have value semantics, such as a complex number type, you must override the equality operator. + +- You should not override on a mutable reference type. This is because overriding requires that you also override the method, as discussed in the previous section. This means that the hash code of an instance of a mutable reference type can change during its lifetime, which can cause the object to be lost in a hash table. + +### Guidelines for Value Types + The following guidelines apply to overriding for a value type: + +- If you are defining a value type that includes one or more fields whose values are reference types, you should override . The implementation provided by performs a byte-by-byte comparison for value types whose fields are all value types, but it uses reflection to perform a field-by-field comparison of value types whose fields include reference types. + +- If you override and your development language supports operator overloading, you must overload the equality operator. + +- You should implement the interface. Calling the strongly typed method avoids boxing the `obj` argument. + + + +## Examples + The following example shows a `Point` class that overrides the method to provide value equality, and a `Point3D` class that is derived from `Point`. Because `Point` overrides to test for value equality, the method is not called. However, `Point3D.Equals` calls `Point.Equals` because `Point` implements in a manner that provides value equality. + :::code language="csharp" source="~/snippets/csharp/System/Object/Equals/equals2.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Object/Equals/equals2.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ECMA-System.Object.Equals2/VB/equals2.vb" id="Snippet1"::: - - The `Point.Equals` method checks to make sure that the `obj` argument is not **null** and that it references an instance of the same type as this object. If either check fails, the method returns `false`. - - The `Point.Equals` method calls the method to determine whether the run-time types of the two objects are identical. If the method used a check of the form `obj is Point` in C# or `TryCast(obj, Point)` in Visual Basic, the check would return `true` in cases where `obj` is an instance of a derived class of `Point`, even though `obj` and the current instance are not of the same run-time type. Having verified that both objects are of the same type, the method casts `obj` to type `Point` and returns the result of comparing the instance fields of the two objects. - - In `Point3D.Equals`, the inherited `Point.Equals` method, which overrides , is invoked before anything else is done. Because `Point3D` is a sealed class (`NotInheritable` in Visual Basic), a check in the form `obj is Point` in C# or `TryCast(obj, Point)` in Visual Basic is adequate to ensure that `obj` is a `Point3D` object. If it is a `Point3D` object, it is cast to a `Point` object and passed to the base class implementation of . Only when the inherited `Point.Equals` method returns `true` does the method compare the `z` instance fields introduced in the derived class. - - The following example defines a `Rectangle` class that internally implements a rectangle as two `Point` objects. The `Rectangle` class also overrides to provide for value equality. - + + The `Point.Equals` method checks to make sure that the `obj` argument is not **null** and that it references an instance of the same type as this object. If either check fails, the method returns `false`. + + The `Point.Equals` method calls the method to determine whether the run-time types of the two objects are identical. If the method used a check of the form `obj is Point` in C# or `TryCast(obj, Point)` in Visual Basic, the check would return `true` in cases where `obj` is an instance of a derived class of `Point`, even though `obj` and the current instance are not of the same run-time type. Having verified that both objects are of the same type, the method casts `obj` to type `Point` and returns the result of comparing the instance fields of the two objects. + + In `Point3D.Equals`, the inherited `Point.Equals` method, which overrides , is invoked before anything else is done. Because `Point3D` is a sealed class (`NotInheritable` in Visual Basic), a check in the form `obj is Point` in C# or `TryCast(obj, Point)` in Visual Basic is adequate to ensure that `obj` is a `Point3D` object. If it is a `Point3D` object, it is cast to a `Point` object and passed to the base class implementation of . Only when the inherited `Point.Equals` method returns `true` does the method compare the `z` instance fields introduced in the derived class. + + The following example defines a `Rectangle` class that internally implements a rectangle as two `Point` objects. The `Rectangle` class also overrides to provide for value equality. + :::code language="csharp" source="~/snippets/csharp/System/Object/Equals/equals3.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Object/Equals/equals3.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ECMA-System.Object.Equals3/VB/equals3.vb" id="Snippet1"::: - Some languages such as C# and Visual Basic support operator overloading. When a type overloads the equality operator, it must also override the method to provide the same functionality. This is typically accomplished by writing the method in terms of the overloaded equality operator, as in the following example. - + Some languages such as C# and Visual Basic support operator overloading. When a type overloads the equality operator, it must also override the method to provide the same functionality. This is typically accomplished by writing the method in terms of the overloaded equality operator, as in the following example. + :::code language="csharp" source="~/snippets/csharp/System/Object/Equals/equals4.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Object/Equals/equals4.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ECMA-System.Object.Equals4/vb/equals4.vb" id="Snippet1"::: - - Because `Complex` is a value type, it cannot be derived from. Therefore, the override to method need not call to determine the precise run-time type of each object, but can instead use the `is` operator in C# or the `TypeOf` operator in Visual Basic to check the type of the `obj` parameter. - + + Because `Complex` is a value type, it cannot be derived from. Therefore, the override to method need not call to determine the precise run-time type of each object, but can instead use the `is` operator in C# or the `TypeOf` operator in Visual Basic to check the type of the `obj` parameter. + ]]> @@ -424,26 +424,26 @@ if the objects are considered equal; otherwise, . If both and are **null**, the method returns . - method indicates whether two objects, `objA` and `objB`, are equal. It also enables you to test objects whose value is **null** for equality. It compares `objA` and `objB` for equality as follows: - -- It determines whether the two objects represent the same object reference. If they do, the method returns `true`. This test is equivalent to calling the method. In addition, if both `objA` and `objB` are **null**, the method returns `true`. - -- It determines whether either `objA` or `objB` is **null**. If so, it returns `false`. - -- If the two objects do not represent the same object reference and neither is **null**, it calls `objA`.`Equals`(`objB`) and returns the result. This means that if `objA` overrides the method, this override is called. - - - -## Examples - The following example illustrates the method and compares it with the method. - + method indicates whether two objects, `objA` and `objB`, are equal. It also enables you to test objects whose value is **null** for equality. It compares `objA` and `objB` for equality as follows: + +- It determines whether the two objects represent the same object reference. If they do, the method returns `true`. This test is equivalent to calling the method. In addition, if both `objA` and `objB` are **null**, the method returns `true`. + +- It determines whether either `objA` or `objB` is **null**. If so, it returns `false`. + +- If the two objects do not represent the same object reference and neither is **null**, it calls `objA`.`Equals`(`objB`) and returns the result. This means that if `objA` overrides the method, this override is called. + + + +## Examples + The following example illustrates the method and compares it with the method. + :::code language="csharp" source="~/snippets/csharp/System/Object/Equals/equals_static2.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Object/Equals/equals_static2.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.object.equals/vb/equals_static2.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.object.equals/vb/equals_static2.vb" id="Snippet1"::: + ]]> @@ -498,107 +498,107 @@ Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. - method is used to perform cleanup operations on unmanaged resources held by the current object before the object is destroyed. The method is protected and therefore is accessible only through this class or through a derived class. - - In this section: - -- [How finalization works](#How) - -- [Notes for implementers](#Notes) - -- [The SafeHandle alternative](#SafeHandle) - - -## How finalization works - The class provides no implementation for the method, and the garbage collector does not mark types derived from for finalization unless they override the method. - - If a type does override the method, the garbage collector adds an entry for each instance of the type to an internal structure called the finalization queue. The finalization queue contains entries for all the objects in the managed heap whose finalization code must run before the garbage collector can reclaim their memory. The garbage collector then calls the method automatically under the following conditions: - -- After the garbage collector has discovered that an object is inaccessible, unless the object has been exempted from finalization by a call to the method. - -- **On .NET Framework only**, during shutdown of an application domain, unless the object is exempt from finalization. During shutdown, even objects that are still accessible are finalized. - - is automatically called only once on a given instance, unless the object is re-registered by using a mechanism such as and the method has not been subsequently called. - - operations have the following limitations: - -- The exact time when the finalizer executes is undefined. To ensure deterministic release of resources for instances of your class, implement a `Close` method or provide a implementation. - -- The finalizers of two objects are not guaranteed to run in any specific order, even if one object refers to the other. That is, if Object A has a reference to Object B and both have finalizers, Object B might have already been finalized when the finalizer of Object A starts. - -- The thread on which the finalizer runs is unspecified. - - The method might not run to completion or might not run at all under the following exceptional circumstances: - -- If another finalizer blocks indefinitely (goes into an infinite loop, tries to obtain a lock it can never obtain, and so on). Because the runtime tries to run finalizers to completion, other finalizers might not be called if a finalizer blocks indefinitely. - -- If the process terminates without giving the runtime a chance to clean up. In this case, the runtime's first notification of process termination is a DLL_PROCESS_DETACH notification. - - The runtime continues to finalize objects during shutdown only while the number of finalizable objects continues to decrease. - - If or an override of throws an exception, and the runtime is not hosted by an application that overrides the default policy, the runtime terminates the process and no active `try`/`finally` blocks or finalizers are executed. This behavior ensures process integrity if the finalizer cannot free or destroy resources. - - -## Overriding the Finalize method - You should override for a class that uses unmanaged resources, such as file handles or database connections that must be released when the managed object that uses them is discarded during garbage collection. You shouldn't implement a method for managed objects because the garbage collector releases managed resources automatically. - + method is used to perform cleanup operations on unmanaged resources held by the current object before the object is destroyed. The method is protected and therefore is accessible only through this class or through a derived class. + + In this section: + +- [How finalization works](#How) + +- [Notes for implementers](#Notes) + +- [The SafeHandle alternative](#SafeHandle) + + +## How finalization works + The class provides no implementation for the method, and the garbage collector does not mark types derived from for finalization unless they override the method. + + If a type does override the method, the garbage collector adds an entry for each instance of the type to an internal structure called the finalization queue. The finalization queue contains entries for all the objects in the managed heap whose finalization code must run before the garbage collector can reclaim their memory. The garbage collector then calls the method automatically under the following conditions: + +- After the garbage collector has discovered that an object is inaccessible, unless the object has been exempted from finalization by a call to the method. + +- **On .NET Framework only**, during shutdown of an application domain, unless the object is exempt from finalization. During shutdown, even objects that are still accessible are finalized. + + is automatically called only once on a given instance, unless the object is re-registered by using a mechanism such as and the method has not been subsequently called. + + operations have the following limitations: + +- The exact time when the finalizer executes is undefined. To ensure deterministic release of resources for instances of your class, implement a `Close` method or provide a implementation. + +- The finalizers of two objects are not guaranteed to run in any specific order, even if one object refers to the other. That is, if Object A has a reference to Object B and both have finalizers, Object B might have already been finalized when the finalizer of Object A starts. + +- The thread on which the finalizer runs is unspecified. + + The method might not run to completion or might not run at all under the following exceptional circumstances: + +- If another finalizer blocks indefinitely (goes into an infinite loop, tries to obtain a lock it can never obtain, and so on). Because the runtime tries to run finalizers to completion, other finalizers might not be called if a finalizer blocks indefinitely. + +- If the process terminates without giving the runtime a chance to clean up. In this case, the runtime's first notification of process termination is a DLL_PROCESS_DETACH notification. + + The runtime continues to finalize objects during shutdown only while the number of finalizable objects continues to decrease. + + If or an override of throws an exception, and the runtime is not hosted by an application that overrides the default policy, the runtime terminates the process and no active `try`/`finally` blocks or finalizers are executed. This behavior ensures process integrity if the finalizer cannot free or destroy resources. + + +## Overriding the Finalize method + You should override for a class that uses unmanaged resources, such as file handles or database connections that must be released when the managed object that uses them is discarded during garbage collection. You shouldn't implement a method for managed objects because the garbage collector releases managed resources automatically. + > [!IMPORTANT] -> If a object is available that wraps your unmanaged resource, the recommended alternative is to implement the dispose pattern with a safe handle and not override . For more information, see [The SafeHandle alternative](#SafeHandle) section. - - The method does nothing by default, but you should override only if necessary, and only to release unmanaged resources. Reclaiming memory tends to take much longer if a finalization operation runs, because it requires at least two garbage collections. In addition, you should override the method for reference types only. The common language runtime only finalizes reference types. It ignores finalizers on value types. +> If a object is available that wraps your unmanaged resource, the recommended alternative is to implement the dispose pattern with a safe handle and not override . For more information, see [The SafeHandle alternative](#SafeHandle) section. + + The method does nothing by default, but you should override only if necessary, and only to release unmanaged resources. Reclaiming memory tends to take much longer if a finalization operation runs, because it requires at least two garbage collections. In addition, you should override the method for reference types only. The common language runtime only finalizes reference types. It ignores finalizers on value types. The scope of the method is `protected`. You should maintain this limited scope when you override the method in your class. By keeping a method protected, you prevent users of your application from calling an object's method directly. - - Every implementation of in a derived type must call its base type's implementation of . This is the only case in which application code is allowed to call . An object's method shouldn't call a method on any objects other than that of its base class. This is because the other objects being called could be collected at the same time as the calling object, such as in the case of a common language runtime shutdown. - + + Every implementation of in a derived type must call its base type's implementation of . This is the only case in which application code is allowed to call . An object's method shouldn't call a method on any objects other than that of its base class. This is because the other objects being called could be collected at the same time as the calling object, such as in the case of a common language runtime shutdown. + > [!NOTE] -> The C# compiler does not allow you to override the method. Instead, you provide a finalizer by implementing a [destructor](/dotnet/csharp/programming-guide/classes-and-structs/destructors) for your class. A C# destructor automatically calls the destructor of its base class. -> -> Visual C++ also provides its own syntax for implementing the method. For more information, see the "Destructors and finalizers" section of [How to: Define and Consume Classes and Structs (C++/CLI)](/cpp/dotnet/how-to-define-and-consume-classes-and-structs-cpp-cli). - +> The C# compiler does not allow you to override the method. Instead, you provide a finalizer by implementing a [destructor](/dotnet/csharp/programming-guide/classes-and-structs/destructors) for your class. A C# destructor automatically calls the destructor of its base class. +> +> Visual C++ also provides its own syntax for implementing the method. For more information, see the "Destructors and finalizers" section of [How to: Define and Consume Classes and Structs (C++/CLI)](/cpp/dotnet/how-to-define-and-consume-classes-and-structs-cpp-cli). + Because garbage collection is non-deterministic, you do not know precisely when the garbage collector performs finalization. To release resources immediately, you can also choose to implement the [dispose pattern](/dotnet/standard/garbage-collection/implementing-dispose) -and the interface. The implementation can be called by consumers of your class to free unmanaged resources, and you can use the method to free unmanaged resources in the event that the method is not called. - +and the interface. The implementation can be called by consumers of your class to free unmanaged resources, and you can use the method to free unmanaged resources in the event that the method is not called. + can take almost any action, including resurrecting an object (that is, making the object accessible again) after it has been cleaned up during garbage collection. However, the object can only be resurrected once; cannot be called on resurrected objects during garbage collection. - - -## The SafeHandle alternative - Creating reliable finalizers is often difficult, because you cannot make assumptions about the state of your application, and because unhandled system exceptions such as and terminate the finalizer. Instead of implementing a finalizer for your class to release unmanaged resources, you can use an object that is derived from the class to wrap your unmanaged resources, and then implement the dispose pattern without a finalizer. The .NET Framework provides the following classes in the namespace that are derived from : - -- is a wrapper class for a file handle. - -- is a wrapper class for memory-mapped file handles. - -- is a wrapper class for a pointer to a block of unmanaged memory. - -- , , and are wrapper classes for cryptographic handles. - -- is a wrapper class for pipe handles. - -- is a wrapper class for a handle to a registry key. - -- is a wrapper class for a wait handle. - - The following example uses the [dispose pattern](/dotnet/standard/garbage-collection/implementing-dispose) with safe handles instead of overriding the method. It defines a `FileAssociation` class that wraps registry information about the application that handles files with a particular file extension. The two registry handles returned as `out` parameters by Windows [RegOpenKeyEx](/windows/win32/api/winreg/nf-winreg-regopenkeyexa) function calls are passed to the constructor. The type's protected `Dispose` method then calls the `SafeRegistryHandle.Dispose` method to free these two handles. - + + +## The SafeHandle alternative + Creating reliable finalizers is often difficult, because you cannot make assumptions about the state of your application, and because unhandled system exceptions such as and terminate the finalizer. Instead of implementing a finalizer for your class to release unmanaged resources, you can use an object that is derived from the class to wrap your unmanaged resources, and then implement the dispose pattern without a finalizer. The .NET Framework provides the following classes in the namespace that are derived from : + +- is a wrapper class for a file handle. + +- is a wrapper class for memory-mapped file handles. + +- is a wrapper class for a pointer to a block of unmanaged memory. + +- , , and are wrapper classes for cryptographic handles. + +- is a wrapper class for pipe handles. + +- is a wrapper class for a handle to a registry key. + +- is a wrapper class for a wait handle. + + The following example uses the [dispose pattern](/dotnet/standard/garbage-collection/implementing-dispose) with safe handles instead of overriding the method. It defines a `FileAssociation` class that wraps registry information about the application that handles files with a particular file extension. The two registry handles returned as `out` parameters by Windows [RegOpenKeyEx](/windows/win32/api/winreg/nf-winreg-regopenkeyexa) function calls are passed to the constructor. The type's protected `Dispose` method then calls the `SafeRegistryHandle.Dispose` method to free these two handles. + :::code language="csharp" source="~/snippets/csharp/System/Object/Finalize/finalize_safe.cs" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/Object/Finalize/finalize_safe.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.object.finalize/vb/finalize_safe.vb" id="Snippet2"::: - - - -## Examples - The following example verifies that the method is called when an object that overrides is destroyed. Note that, in a production application, the method would be overridden to release unmanaged resources held by the object. Also note that the C# example provides a destructor instead of overriding the method. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.object.finalize/vb/finalize_safe.vb" id="Snippet2"::: + + + +## Examples + The following example verifies that the method is called when an object that overrides is destroyed. Note that, in a production application, the method would be overridden to release unmanaged resources held by the object. Also note that the C# example provides a destructor instead of overriding the method. + :::code language="csharp" source="~/snippets/csharp/System/Object/Finalize/finalize1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Object/Finalize/finalize1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.object.finalize/vb/finalize1.vb" id="Snippet1"::: - - For an additional example that overrides the method, see the method. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.object.finalize/vb/finalize1.vb" id="Snippet1"::: + + For an additional example that overrides the method, see the method. + ]]> @@ -655,115 +655,79 @@ and the interface. The Serves as the default hash function. A hash code for the current object. - class, the class, or a type derived from the class. The method provides this hash code for algorithms that need quick checks of object equality. - + class, the class, or a type derived from the class. The method provides this hash code for algorithms that need quick checks of object equality. + > [!NOTE] -> For information about how hash codes are used in hash tables and for some additional hash code algorithms, see the [Hash Function](https://en.wikipedia.org/wiki/Hash_function) entry in Wikipedia. - - Two objects that are equal return hash codes that are equal. However, the reverse is not true: equal hash codes do not imply object equality, because different (unequal) objects can have identical hash codes. Furthermore, .NET does not guarantee the default implementation of the method, and the value this method returns may differ between .NET implementations, such as different versions of .NET Framework and .NET Core, and platforms, such as 32-bit and 64-bit platforms. For these reasons, do not use the default implementation of this method as a unique object identifier for hashing purposes. Two consequences follow from this: - -- You should not assume that equal hash codes imply object equality. - -- You should never persist or use a hash code outside the application domain in which it was created, because the same object may hash across application domains, processes, and platforms. - +> For information about how hash codes are used in hash tables and for some additional hash code algorithms, see the [Hash Function](https://en.wikipedia.org/wiki/Hash_function) entry in Wikipedia. + + Two objects that are equal return hash codes that are equal. However, the reverse is not true: equal hash codes do not imply object equality, because different (unequal) objects can have identical hash codes. Furthermore, .NET does not guarantee the default implementation of the method, and the value this method returns may differ between .NET implementations, such as different versions of .NET Framework and .NET Core, and platforms, such as 32-bit and 64-bit platforms. For these reasons, do not use the default implementation of this method as a unique object identifier for hashing purposes. Two consequences follow from this: + +- You should not assume that equal hash codes imply object equality. + +- You should never persist or use a hash code outside the application domain in which it was created, because the same object may hash across application domains, processes, and platforms. + > [!WARNING] -> A hash code is intended for efficient insertion and lookup in collections that are based on a hash table. A hash code is not a permanent value. For this reason: -> -> - Do not serialize hash code values or store them in databases. -> - Do not use the hash code as the key to retrieve an object from a keyed collection. -> - Do not send hash codes across application domains or processes. In some cases, hash codes may be computed on a per-process or per-application domain basis. -> - Do not use the hash code instead of a value returned by a cryptographic hashing function if you need a cryptographically strong hash. For cryptographic hashes, use a class derived from the or class. -> - Do not test for equality of hash codes to determine whether two objects are equal. (Unequal objects can have identical hash codes.) To test for equality, call the or method. - - The method can be overridden by a derived type. If is not overridden, hash codes for reference types are computed by calling the method of the base class, which computes a hash code based on an object's reference; for more information, see . In other words, two objects for which the method returns `true` have identical hash codes. If value types do not override , the method of the base class uses reflection to compute the hash code based on the values of the type's fields. In other words, value types whose fields have equal values have equal hash codes. For more information about overriding , see the "Notes to Inheritors" section. - +> A hash code is intended for efficient insertion and lookup in collections that are based on a hash table. A hash code is not a permanent value. For this reason: +> +> - Do not serialize hash code values or store them in databases. +> - Do not use the hash code as the key to retrieve an object from a keyed collection. +> - Do not send hash codes across application domains or processes. In some cases, hash codes may be computed on a per-process or per-application domain basis. +> - Do not use the hash code instead of a value returned by a cryptographic hashing function if you need a cryptographically strong hash. For cryptographic hashes, use a class derived from the or class. +> - Do not test for equality of hash codes to determine whether two objects are equal. (Unequal objects can have identical hash codes.) To test for equality, call the or method. + + The method can be overridden by a derived type. If is not overridden, hash codes for reference types are computed by calling the method of the base class, which computes a hash code based on an object's reference; for more information, see . In other words, two objects for which the method returns `true` have identical hash codes. If value types do not override , the method of the base class uses reflection to compute the hash code based on the values of the type's fields. In other words, value types whose fields have equal values have equal hash codes. For more information about overriding , see the "Notes to Inheritors" section. + > [!WARNING] -> If you override the method, you should also override , and vice versa. If your overridden method returns `true` when two objects are tested for equality, your overridden method must return the same value for the two objects. - - If an object that is used as a key in a hash table does not provide a useful implementation of , you can specify a hash code provider by supplying an implementation to one of the overloads of the class constructor. - -## Notes for the Windows Runtime - When you call the method on a class in the Windows Runtime, it provides the default behavior for classes that don't override . This is part of the support that the .NET Framework provides for the Windows Runtime (see [.NET Framework Support for Windows Store Apps and Windows Runtime](/dotnet/standard/cross-platform/support-for-windows-store-apps-and-windows-runtime)). Classes in the Windows Runtime don't inherit , and currently don't implement a . However, they appear to have , , and methods when you use them in your C# or Visual Basic code, and the .NET Framework provides the default behavior for these methods. - +> If you override the method, you should also override , and vice versa. If your overridden method returns `true` when two objects are tested for equality, your overridden method must return the same value for the two objects. + + If an object that is used as a key in a hash table does not provide a useful implementation of , you can specify a hash code provider by supplying an implementation to one of the overloads of the class constructor. + +## Notes for the Windows Runtime + When you call the method on a class in the Windows Runtime, it provides the default behavior for classes that don't override . This is part of the support that the .NET Framework provides for the Windows Runtime (see [.NET Framework Support for Windows Store Apps and Windows Runtime](/dotnet/standard/cross-platform/support-for-windows-store-apps-and-windows-runtime)). Classes in the Windows Runtime don't inherit , and currently don't implement a . However, they appear to have , , and methods when you use them in your C# or Visual Basic code, and the .NET Framework provides the default behavior for these methods. + > [!NOTE] -> Windows Runtime classes that are written in C# or Visual Basic can override the method. - - - -## Examples - One of the simplest ways to compute a hash code for a numeric value that has the same or a smaller range than the type is to simply return that value. The following example shows such an implementation for a `Number` structure. - +> Windows Runtime classes that are written in C# or Visual Basic can override the method. + + + +## Examples + One of the simplest ways to compute a hash code for a numeric value that has the same or a smaller range than the type is to simply return that value. The following example shows such an implementation for a `Number` structure. + :::code language="csharp" source="~/snippets/csharp/System/Object/GetHashCode/direct1.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Object/GetHashCode/direct1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.object.gethashcode/vb/direct1.vb" id="Snippet1"::: - - Frequently, a type has multiple data fields that can participate in generating the hash code. One way to generate a hash code is to combine these fields using an `XOR (eXclusive OR)` operation, as shown in the following example. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.object.gethashcode/vb/direct1.vb" id="Snippet1"::: + + Frequently, a type has multiple data fields that can participate in generating the hash code. One way to generate a hash code is to combine these fields using an `XOR (eXclusive OR)` operation, as shown in the following example. + :::code language="csharp" source="~/snippets/csharp/System/Object/GetHashCode/xor1.cs" interactive="try-dotnet" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/Object/GetHashCode/xor1.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.object.gethashcode/vb/xor1.vb" id="Snippet2"::: - - The previous example returns the same hash code for (n1, n2) and (n2, n1), and so may generate more collisions than are desirable. A number of solutions are available so that hash codes in these cases are not identical. One is to return the hash code of a `Tuple` object that reflects the order of each field. The following example shows a possible implementation that uses the class. Note, though, that the performance overhead of instantiating a `Tuple` object may significantly impact the overall performance of an application that stores large numbers of objects in hash tables. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.object.gethashcode/vb/xor1.vb" id="Snippet2"::: + + The previous example returns the same hash code for (n1, n2) and (n2, n1), and so may generate more collisions than are desirable. A number of solutions are available so that hash codes in these cases are not identical. One is to return the hash code of a `Tuple` object that reflects the order of each field. The following example shows a possible implementation that uses the class. Note, though, that the performance overhead of instantiating a `Tuple` object may significantly impact the overall performance of an application that stores large numbers of objects in hash tables. + :::code language="csharp" source="~/snippets/csharp/System/Object/GetHashCode/xor2.cs" interactive="try-dotnet" id="Snippet3"::: :::code language="fsharp" source="~/snippets/fsharp/System/Object/GetHashCode/xor2.fs" id="Snippet3"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.object.gethashcode/vb/xor2.vb" id="Snippet3"::: - - A second alternative solution involves weighting the individual hash codes by left-shifting the hash codes of successive fields by two or more bits. Optimally, bits shifted beyond bit 31 should wrap around rather than be discarded. Since bits are discarded by the left-shift operators in both C# and Visual Basic, this requires creating a left shift-and-wrap method like the following: - + + A second alternative solution involves weighting the individual hash codes by left-shifting the hash codes of successive fields by two or more bits. Optimally, bits shifted beyond bit 31 should wrap around rather than be discarded. Since bits are discarded by the left-shift operators in both C# and Visual Basic, this requires creating a left shift-and-wrap method like the following: + :::code language="csharp" source="~/snippets/csharp/System/Object/GetHashCode/shift1.cs" id="Snippet4"::: :::code language="fsharp" source="~/snippets/fsharp/System/Object/GetHashCode/shift1.fs" id="Snippet4"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.object.gethashcode/vb/shift1.vb" id="Snippet4"::: - - The following example then uses this shift-and-wrap method to compute the hash code of the `Point` structure used in the previous examples. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.object.gethashcode/vb/shift1.vb" id="Snippet4"::: + + The following example then uses this shift-and-wrap method to compute the hash code of the `Point` structure used in the previous examples. + :::code language="csharp" source="~/snippets/csharp/System/Object/GetHashCode/shift1.cs" interactive="try-dotnet" id="Snippet5"::: :::code language="fsharp" source="~/snippets/fsharp/System/Object/GetHashCode/shift1.fs" id="Snippet5"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.object.gethashcode/vb/shift1.vb" id="Snippet5"::: - + ]]> - A hash function is used to quickly generate a number (hash code) that corresponds to the value of an object. Hash functions are usually specific to each type and, for uniqueness, must use at least one of the instance fields as input. Hash codes should not be computed by using the values of static fields. - - For classes derived from , the method can delegate to the base class implementation only if the derived class defines equality to be reference equality. The default implementation of for reference types returns a hash code that is equivalent to the one returned by the method. You can override for immutable reference types. In general, for mutable reference types, you should override only if: - -- You can compute the hash code from fields that are not mutable; or - -- You can ensure that the hash code of a mutable object does not change while the object is contained in a collection that relies on its hash code. - - Otherwise, you might think that the mutable object is lost in the hash table. If you do choose to override for a mutable reference type, your documentation should make it clear that users of your type should not modify object values while the object is stored in a hash table. - - For value types, provides a default hash code implementation that uses reflection. You should consider overriding it for better performance. - - For more information and examples that compute hash codes in a variety of ways, see the Examples section. - - A hash function must have the following properties: - -- If two objects compare as equal, the method for each object must return the same value. However, if two objects do not compare as equal, the methods for the two objects do not have to return different values. - -- The method for an object must consistently return the same hash code as long as there is no modification to the object state that determines the return value of the object's [System.Object.Equals](xref:System.Object.Equals*) method. Note that this is true only for the current execution of an application, and that a different hash code can be returned if the application is run again. - -- For the best performance, a hash function should generate an even distribution for all input, including input that is heavily clustered. An implication is that small modifications to object state should result in large modifications to the resulting hash code for best hash table performance. - -- Hash functions should be inexpensive to compute. - -- The method should not throw exceptions. - - For example, the implementation of the method provided by the class returns identical hash codes for identical string values. Therefore, two objects return the same hash code if they represent the same string value. Also, the method uses all the characters in the string to generate reasonably randomly distributed output, even when the input is clustered in certain ranges (for example, many users might have strings that contain only the lower 128 ASCII characters, even though a string can contain any of the 65,535 Unicode characters). - - Providing a good hash function on a class can significantly affect the performance of adding those objects to a hash table. In a hash table with keys that provide a good implementation of a hash function, searching for an element takes constant time (for example, an O(1) operation). In a hash table with a poor implementation of a hash function, the performance of a search depends on the number of items in the hash table (for example, an O(`n`) operation, where `n` is the number of items in the hash table). A malicious user can input data that increases the number of collisions, which can significantly degrade the performance of applications that depend on hash tables, under the following conditions: - -- When hash functions produce frequent collisions. - -- When a large proportion of objects in a hash table produce hash codes that are equal or approximately equal to one another. - -- When users input the data from which the hash code is computed. - - Derived classes that override must also override to guarantee that two objects considered equal have the same hash code; otherwise, the type might not work correctly. + A hash function is used to quickly generate a number (hash code) that corresponds to the value of an object. Hash functions are usually specific to each type and, for uniqueness, must use at least one of the instance fields as input. Hash codes should not be computed by using the values of static fields. For classes derived from , the method can delegate to the base class implementation only if the derived class defines equality to be reference equality. The default implementation of for reference types returns a hash code that is equivalent to the one returned by the method. You can override for immutable reference types. In general, for mutable reference types, you should override only if: - You can compute the hash code from fields that are not mutable; or - You can ensure that the hash code of a mutable object does not change while the object is contained in a collection that relies on its hash code. Otherwise, you might think that the mutable object is lost in the hash table. If you do choose to override for a mutable reference type, your documentation should make it clear that users of your type should not modify object values while the object is stored in a hash table. For value types, provides a default hash code implementation that uses reflection. You should consider overriding it for better performance. For more information and examples that compute hash codes in a variety of ways, see the Examples section. A hash function must have the following properties: - If two objects compare as equal, the method for each object must return the same value. However, if two objects do not compare as equal, the methods for the two objects do not have to return different values. - The method for an object must consistently return the same hash code as long as there is no modification to the object state that determines the return value of the object's [System.Object.Equals](xref:System.Object.Equals*) method. Note that this is true only for the current execution of an application, and that a different hash code can be returned if the application is run again. - For the best performance, a hash function should generate an even distribution for all input, including input that is heavily clustered. An implication is that small modifications to object state should result in large modifications to the resulting hash code for best hash table performance. - Hash functions should be inexpensive to compute. - The method should not throw exceptions. For example, the implementation of the method provided by the class returns identical hash codes for identical string values. Therefore, two objects return the same hash code if they represent the same string value. Also, the method uses all the characters in the string to generate reasonably randomly distributed output, even when the input is clustered in certain ranges (for example, many users might have strings that contain only the lower 128 ASCII characters, even though a string can contain any of the 65,535 Unicode characters). Providing a good hash function on a class can significantly affect the performance of adding those objects to a hash table. In a hash table with keys that provide a good implementation of a hash function, searching for an element takes constant time (for example, an O(1) operation). In a hash table with a poor implementation of a hash function, the performance of a search depends on the number of items in the hash table (for example, an O(`n`) operation, where `n` is the number of items in the hash table). A malicious user can input data that increases the number of collisions, which can significantly degrade the performance of applications that depend on hash tables, under the following conditions: - When hash functions produce frequent collisions. - When a large proportion of objects in a hash table produce hash codes that are equal or approximately equal to one another. - When users input the data from which the hash code is computed. Derived classes that override must also override to guarantee that two objects considered equal have the same hash code; otherwise, the type might not work correctly. @@ -822,49 +786,49 @@ and the interface. The Gets the of the current instance. The exact runtime type of the current instance. - is the base class for all types in the .NET type system, the method can be used to return objects that represent all .NET types. .NET recognizes the following five categories of types: - -- Classes, which are derived from , - -- Value types, which are derived from . - -- Interfaces, which are derived from starting with the .NET Framework 2.0. - -- Enumerations, which are derived from . - -- Delegates, which are derived from . - - For two objects `x` and `y` that have identical runtime types, `Object.ReferenceEquals(x.GetType(),y.GetType())` returns `true`. The following example uses the method with the method to determine whether one numeric value is the same type as two other numeric values. + is the base class for all types in the .NET type system, the method can be used to return objects that represent all .NET types. .NET recognizes the following five categories of types: + +- Classes, which are derived from , + +- Value types, which are derived from . + +- Interfaces, which are derived from starting with the .NET Framework 2.0. + +- Enumerations, which are derived from . + +- Delegates, which are derived from . + + For two objects `x` and `y` that have identical runtime types, `Object.ReferenceEquals(x.GetType(),y.GetType())` returns `true`. The following example uses the method with the method to determine whether one numeric value is the same type as two other numeric values. :::code language="csharp" source="~/snippets/csharp/System/Object/GetType/gettype1.cs" interactive="try-dotnet-method" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Object/GetType/gettype1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.object.gettype/vb/gettype1.vb" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.object.gettype/vb/gettype1.vb" id="Snippet1"::: > [!NOTE] -> To determine whether an object is a specific type, you can use your language's type comparison keyword or construct. For example, you can use the `TypeOf…Is` construct in Visual Basic or the `is` keyword in C#. - - The method is inherited by all types that derive from . This means that, in addition to using your own language's comparison keyword, you can use the method to determine the type of a particular object, as the following example shows. +> To determine whether an object is a specific type, you can use your language's type comparison keyword or construct. For example, you can use the `TypeOf…Is` construct in Visual Basic or the `is` keyword in C#. + + The method is inherited by all types that derive from . This means that, in addition to using your own language's comparison keyword, you can use the method to determine the type of a particular object, as the following example shows. :::code language="csharp" source="~/snippets/csharp/System/Object/GetType/GetTypeEx2.cs" interactive="try-dotnet-method" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/Object/GetType/GetTypeEx2.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.object.gettype/vb/GetTypeEx2.vb" id="Snippet2"::: - - The object exposes the metadata associated with the class of the current . - - - -## Examples - The following code example demonstrates that returns the runtime type of the current instance. + The object exposes the metadata associated with the class of the current . + + + +## Examples + + The following code example demonstrates that returns the runtime type of the current instance. - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/ECMA-System.Object.GetType/CPP/gettype.cpp" id="Snippet1"::: + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/ECMA-System.Object.GetType/CPP/gettype.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Object/GetType/gettype.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Object/GetType/gettype.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ECMA-System.Object.GetType/VB/gettype.vb" id="Snippet1"::: - + ]]> @@ -922,34 +886,34 @@ and the interface. The Creates a shallow copy of the current . A shallow copy of the current . - method creates a shallow copy by creating a new object, and then copying the nonstatic fields of the current object to the new object. If a field is a value type, a bit-by-bit copy of the field is performed. If a field is a reference type, the reference is copied but the referred object is not; therefore, the original object and its clone refer to the same object. - - For example, consider an object called X that references objects A and B. Object B, in turn, references object C. A shallow copy of X creates new object X2 that also references objects A and B. In contrast, a deep copy of X creates a new object X2 that references the new objects A2 and B2, which are copies of A and B. B2, in turn, references the new object C2, which is a copy of C. The example illustrates the difference between a shallow and a deep copy operation. - - There are numerous ways to implement a deep copy operation if the shallow copy operation performed by the method does not meet your needs. These include the following: - -- Call a class constructor of the object to be copied to create a second object with property values taken from the first object. This assumes that the values of an object are entirely defined by its class constructor. - -- Call the method to create a shallow copy of an object, and then assign new objects whose values are the same as the original object to any properties or fields whose values are reference types. The `DeepCopy` method in the example illustrates this approach. - -- Serialize the object to be deep copied, and then restore the serialized data to a different object variable. - -- Use reflection with recursion to perform the deep copy operation. - - - -## Examples - The following example illustrates the method. It defines a `ShallowCopy` method that calls the method to perform a shallow copy operation on a `Person` object. It also defines a `DeepCopy` method that performs a deep copy operation on a `Person` object. - + method creates a shallow copy by creating a new object, and then copying the nonstatic fields of the current object to the new object. If a field is a value type, a bit-by-bit copy of the field is performed. If a field is a reference type, the reference is copied but the referred object is not; therefore, the original object and its clone refer to the same object. + + For example, consider an object called X that references objects A and B. Object B, in turn, references object C. A shallow copy of X creates new object X2 that also references objects A and B. In contrast, a deep copy of X creates a new object X2 that references the new objects A2 and B2, which are copies of A and B. B2, in turn, references the new object C2, which is a copy of C. The example illustrates the difference between a shallow and a deep copy operation. + + There are numerous ways to implement a deep copy operation if the shallow copy operation performed by the method does not meet your needs. These include the following: + +- Call a class constructor of the object to be copied to create a second object with property values taken from the first object. This assumes that the values of an object are entirely defined by its class constructor. + +- Call the method to create a shallow copy of an object, and then assign new objects whose values are the same as the original object to any properties or fields whose values are reference types. The `DeepCopy` method in the example illustrates this approach. + +- Serialize the object to be deep copied, and then restore the serialized data to a different object variable. + +- Use reflection with recursion to perform the deep copy operation. + + + +## Examples + The following example illustrates the method. It defines a `ShallowCopy` method that calls the method to perform a shallow copy operation on a `Person` object. It also defines a `DeepCopy` method that performs a deep copy operation on a `Person` object. + :::code language="csharp" source="~/snippets/csharp/System/Object/MemberwiseClone/memberwiseclone1.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Object/MemberwiseClone/memberwiseclone1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.object.memberwiseclone/vb/memberwiseclone1.vb" id="Snippet1"::: - - In this example, the `Person.IdInfo` property returns an `IdInfo` object. As the output from the example shows, when a `Person` object is cloned by calling the method, the cloned `Person` object is an independent copy of the original object, except that they share the same `Person.IdInfo` object reference. As a result, modifying the clone's `Person.IdInfo` property changes the original object's `Person.IdInfo` property. On the other hand, when a deep copy operation is performed, the cloned `Person` object, including its `Person.IdInfo` property, can be modified without affecting the original object. - + + In this example, the `Person.IdInfo` property returns an `IdInfo` object. As the output from the example shows, when a `Person` object is cloned by calling the method, the cloned `Person` object is an independent copy of the original object, except that they share the same `Person.IdInfo` object reference. As a result, modifying the clone's `Person.IdInfo` property changes the original object's `Person.IdInfo` property. On the other hand, when a deep copy operation is performed, the cloned `Person` object, including its `Person.IdInfo` property, can be modified without affecting the original object. + ]]> @@ -1008,45 +972,45 @@ and the interface. The The first object to compare. - The second object to compare. + The second object to compare. Determines whether the specified instances are the same instance. if is the same instance as or if both are **null**; otherwise, . - method and the equality operator, the method cannot be overridden. Because of this, if you want to test two object references for equality and you are unsure about the implementation of the `Equals` method, you can call the method. - - However, the return value of the method may appear to be anomalous in these two scenarios: - -- When comparing value types. If `objA` and `objB` are value types, they are boxed before they are passed to the method. This means that if both `objA` and `objB` represent the same instance of a value type, the method nevertheless returns `false`, as the following example shows. - + method and the equality operator, the method cannot be overridden. Because of this, if you want to test two object references for equality and you are unsure about the implementation of the `Equals` method, you can call the method. + + However, the return value of the method may appear to be anomalous in these two scenarios: + +- When comparing value types. If `objA` and `objB` are value types, they are boxed before they are passed to the method. This means that if both `objA` and `objB` represent the same instance of a value type, the method nevertheless returns `false`, as the following example shows. + :::code language="csharp" source="~/snippets/csharp/System/Object/ReferenceEquals/referenceequals4.cs" interactive="try-dotnet-method" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Object/ReferenceEquals/referenceequals4.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.object.referenceequals/vb/referenceequals4.vb" id="Snippet1"::: - - For information on boxing value types, see [Boxing and Unboxing](/dotnet/csharp/programming-guide/types/boxing-and-unboxing). - -- When comparing strings. If `objA` and `objB` are strings, the method returns `true` if the string is interned. It does not perform a test for value equality. In the following example, `s1` and `s2` are equal because they are two instances of a single interned string. However, `s3` and `s4` are not equal, because although they have identical string values, that string is not interned. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.object.referenceequals/vb/referenceequals4.vb" id="Snippet1"::: + + For information on boxing value types, see [Boxing and Unboxing](/dotnet/csharp/programming-guide/types/boxing-and-unboxing). + +- When comparing strings. If `objA` and `objB` are strings, the method returns `true` if the string is interned. It does not perform a test for value equality. In the following example, `s1` and `s2` are equal because they are two instances of a single interned string. However, `s3` and `s4` are not equal, because although they have identical string values, that string is not interned. + :::code language="csharp" source="~/snippets/csharp/System/Object/ReferenceEquals/referenceequalsa.cs" interactive="try-dotnet-method" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/Object/ReferenceEquals/referenceequalsa.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.object.referenceequals/vb/referenceequalsa.vb" id="Snippet2"::: - - For more information about string interning, see . - - - -## Examples - - The following example uses to determine if two objects are the same instance. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.object.referenceequals/vb/referenceequalsa.vb" id="Snippet2"::: + + For more information about string interning, see . + + + +## Examples + + The following example uses to determine if two objects are the same instance. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/ECMA-System.Object.ReferenceEquals/CPP/referenceequals.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Object/ReferenceEquals/referenceequals.cs" interactive="try-dotnet-method" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Object/ReferenceEquals/referenceequals.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ECMA-System.Object.ReferenceEquals/vb/referenceequals.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ECMA-System.Object.ReferenceEquals/vb/referenceequals.vb" id="Snippet1"::: + ]]> @@ -1095,130 +1059,130 @@ and the interface. The Returns a string that represents the current object. A string that represents the current object. - is the major formatting method in the .NET Framework. It converts an object to its string representation so that it is suitable for display. (For information about formatting support in the .NET Framework, see [Formatting Types](/dotnet/standard/base-types/formatting-types).) Default implementations of the method return the fully qualified name of the object's type. - + is the major formatting method in the .NET Framework. It converts an object to its string representation so that it is suitable for display. (For information about formatting support in the .NET Framework, see [Formatting Types](/dotnet/standard/base-types/formatting-types).) Default implementations of the method return the fully qualified name of the object's type. + > [!IMPORTANT] -> You may have reached this page by following the link from the member list of another type. That is because that type does not override . Instead, it inherits the functionality of the method. - - Types frequently override the method to provide a more suitable string representation of a particular type. Types also frequently overload the method to provide support for format strings or culture-sensitive formatting. - - In this section: - - [The default Object.ToString() method](#Default) - [Overriding the Object.ToString() method](#Overriding) - [Overloading the ToString method](#Overloading) - [Extending the Object.ToString method](#Extending) - [Notes for the Windows Runtime](#WinRT) - - -## The default Object.ToString() method - The default implementation of the method returns the fully qualified name of the type of the , as the following example shows. - +> You may have reached this page by following the link from the member list of another type. That is because that type does not override . Instead, it inherits the functionality of the method. + + Types frequently override the method to provide a more suitable string representation of a particular type. Types also frequently overload the method to provide support for format strings or culture-sensitive formatting. + + In this section: + + [The default Object.ToString() method](#Default) + [Overriding the Object.ToString() method](#Overriding) + [Overloading the ToString method](#Overloading) + [Extending the Object.ToString method](#Extending) + [Notes for the Windows Runtime](#WinRT) + + +## The default Object.ToString() method + The default implementation of the method returns the fully qualified name of the type of the , as the following example shows. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.object.tostring/cpp/tostring1.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Object/ToString/tostring1.cs" interactive="try-dotnet-method" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Object/ToString/tostring1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.object.tostring/vb/tostring1.vb" id="Snippet1"::: - - Because is the base class of all reference types in the .NET Framework, this behavior is inherited by reference types that do not override the method. The following example illustrates this. It defines a class named `Object1` that accepts the default implementation of all members. Its method returns the object's fully qualified type name. - + + Because is the base class of all reference types in the .NET Framework, this behavior is inherited by reference types that do not override the method. The following example illustrates this. It defines a class named `Object1` that accepts the default implementation of all members. Its method returns the object's fully qualified type name. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.object.tostring/cpp/tostring2.cpp" id="Snippet2"::: :::code language="csharp" source="~/snippets/csharp/System/Object/ToString/tostring2.cs" interactive="try-dotnet" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/Object/ToString/tostring2.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.object.tostring/vb/tostring2.vb" id="Snippet2"::: - - -## Overriding the Object.ToString() method - Types commonly override the method to return a string that represents the object instance. For example, the base types such as , , and provide implementations that return the string form of the value that the object represents. The following example defines a class, `Object2`, that overrides the method to return the type name along with its value. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.object.tostring/vb/tostring2.vb" id="Snippet2"::: + + +## Overriding the Object.ToString() method + Types commonly override the method to return a string that represents the object instance. For example, the base types such as , , and provide implementations that return the string form of the value that the object represents. The following example defines a class, `Object2`, that overrides the method to return the type name along with its value. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.object.tostring/cpp/tostring3.cpp" id="Snippet3"::: :::code language="csharp" source="~/snippets/csharp/System/Object/ToString/tostring3.cs" interactive="try-dotnet" id="Snippet3"::: :::code language="fsharp" source="~/snippets/fsharp/System/Object/ToString/tostring3.fs" id="Snippet3"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.object.tostring/vb/tostring3.vb" id="Snippet3"::: - - The following table lists the type categories in .NET and indicates whether or not they override the method. - -|Type category|Overrides Object.ToString()|Behavior| -|-------------------|-----------------------------------|--------------| -|Class|n/a|n/a| -|Structure|Yes ()|Same as `Object.ToString()`| -|Enumeration|Yes ()|The member name| -|Interface|No|n/a| -|Delegate|No|n/a| - - See the Notes to Inheritors section for additional information on overriding . - - -## Overloading the ToString method - In addition to overriding the parameterless method, many types overload the `ToString` method to provide versions of the method that accept parameters. Most commonly, this is done to provide support for variable formatting and culture-sensitive formatting. - - The following example overloads the `ToString` method to return a result string that includes the value of various fields of an `Automobile` class. It defines four format strings: G, which returns the model name and year; D, which returns the model name, year, and number of doors; C, which returns the model name, year, and number of cylinders; and A, which returns a string with all four field values. - + + The following table lists the type categories in .NET and indicates whether or not they override the method. + +|Type category|Overrides Object.ToString()|Behavior| +|-------------------|-----------------------------------|--------------| +|Class|n/a|n/a| +|Structure|Yes ()|Same as `Object.ToString()`| +|Enumeration|Yes ()|The member name| +|Interface|No|n/a| +|Delegate|No|n/a| + + See the Notes to Inheritors section for additional information on overriding . + + +## Overloading the ToString method + In addition to overriding the parameterless method, many types overload the `ToString` method to provide versions of the method that accept parameters. Most commonly, this is done to provide support for variable formatting and culture-sensitive formatting. + + The following example overloads the `ToString` method to return a result string that includes the value of various fields of an `Automobile` class. It defines four format strings: G, which returns the model name and year; D, which returns the model name, year, and number of doors; C, which returns the model name, year, and number of cylinders; and A, which returns a string with all four field values. + :::code language="csharp" source="~/snippets/csharp/System/Object/ToString/tostringoverload1.cs" interactive="try-dotnet" id="Snippet4"::: :::code language="fsharp" source="~/snippets/fsharp/System/Object/ToString/tostringoverload1.fs" id="Snippet4"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.object.tostring/vb/tostringoverload1.vb" id="Snippet4"::: - - The following example calls the overloaded method to display culture-sensitive formatting of a currency value. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.object.tostring/vb/tostringoverload1.vb" id="Snippet4"::: + + The following example calls the overloaded method to display culture-sensitive formatting of a currency value. + :::code language="csharp" source="~/snippets/csharp/System/Object/ToString/tostringoverload2.cs" id="Snippet5"::: :::code language="fsharp" source="~/snippets/fsharp/System/Object/ToString/tostringoverload2.fs" id="Snippet5"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.object.tostring/vb/tostringoverload2.vb" id="Snippet5"::: - - For more information on format strings and culture-sensitive formatting, see [Formatting Types](/dotnet/standard/base-types/formatting-types). For the format strings supported by numeric values, see [Standard Numeric Format Strings](/dotnet/standard/base-types/standard-numeric-format-strings) and [Custom Numeric Format Strings](/dotnet/standard/base-types/custom-numeric-format-strings). For the format strings supported by date and time values, see [Standard Date and Time Format Strings](/dotnet/standard/base-types/standard-date-and-time-format-strings) and [Custom Date and Time Format Strings](/dotnet/standard/base-types/custom-date-and-time-format-strings). - - -## Extending the Object.ToString method - Because a type inherits the default method, you may find its behavior undesirable and want to change it. This is particularly true of arrays and collection classes. While you may expect the `ToString` method of an array or collection class to display the values of its members, it instead displays the type fully qualified type name, as the following example shows. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.object.tostring/vb/tostringoverload2.vb" id="Snippet5"::: + + For more information on format strings and culture-sensitive formatting, see [Formatting Types](/dotnet/standard/base-types/formatting-types). For the format strings supported by numeric values, see [Standard Numeric Format Strings](/dotnet/standard/base-types/standard-numeric-format-strings) and [Custom Numeric Format Strings](/dotnet/standard/base-types/custom-numeric-format-strings). For the format strings supported by date and time values, see [Standard Date and Time Format Strings](/dotnet/standard/base-types/standard-date-and-time-format-strings) and [Custom Date and Time Format Strings](/dotnet/standard/base-types/custom-date-and-time-format-strings). + + +## Extending the Object.ToString method + Because a type inherits the default method, you may find its behavior undesirable and want to change it. This is particularly true of arrays and collection classes. While you may expect the `ToString` method of an array or collection class to display the values of its members, it instead displays the type fully qualified type name, as the following example shows. + :::code language="csharp" source="~/snippets/csharp/System/Object/ToString/array1.cs" interactive="try-dotnet-method" id="Snippet6"::: :::code language="fsharp" source="~/snippets/fsharp/System/Object/ToString/array1.fs" id="Snippet6"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.object.tostring/vb/array1.vb" id="Snippet6"::: - - You have several options to produce the result string that you'd like. - -- If the type is an array, a collection object, or an object that implements the or interfaces, you can enumerate its elements by using the `foreach` statement in C# or the `For Each...Next` construct in Visual Basic. - -- If the class is not `sealed` (in C#) or `NotInheritable` (in Visual Basic), you can develop a wrapper class that inherits from the base class whose method you want to customize. At a minimum, this requires that you do the following: - - 1. Implement any necessary constructors. Derived classes do not inherit their base class constructors. - - 2. Override the method to return the result string that you'd like. - - The following example defines a wrapper class for the class. It overrides the method to display the value of each method of the collection rather than the fully qualified type name. - + + You have several options to produce the result string that you'd like. + +- If the type is an array, a collection object, or an object that implements the or interfaces, you can enumerate its elements by using the `foreach` statement in C# or the `For Each...Next` construct in Visual Basic. + +- If the class is not `sealed` (in C#) or `NotInheritable` (in Visual Basic), you can develop a wrapper class that inherits from the base class whose method you want to customize. At a minimum, this requires that you do the following: + + 1. Implement any necessary constructors. Derived classes do not inherit their base class constructors. + + 2. Override the method to return the result string that you'd like. + + The following example defines a wrapper class for the class. It overrides the method to display the value of each method of the collection rather than the fully qualified type name. + :::code language="csharp" source="~/snippets/csharp/System/Object/ToString/customize1.cs" interactive="try-dotnet" id="Snippet7"::: :::code language="fsharp" source="~/snippets/fsharp/System/Object/ToString/customize1.fs" id="Snippet7"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.object.tostring/vb/customize1.vb" id="Snippet7"::: - -- Develop an [extension method](/dotnet/standard/design-guidelines/extension-methods) that returns the result string that you want. Note that you can't override the default method in this way (that is, your extension class (in C#) or module (in Visual Basic) cannot have a parameterless method named `ToString` that is called in place of the original type's `ToString` method. You'll have to provide some other name for your parameterless `ToString` replacement. - - The following example defines two methods that extend the class: a parameterless `ToString2` method, and a `ToString` method with a parameter that represents a format string. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.object.tostring/vb/customize1.vb" id="Snippet7"::: + +- Develop an [extension method](/dotnet/standard/design-guidelines/extension-methods) that returns the result string that you want. Note that you can't override the default method in this way (that is, your extension class (in C#) or module (in Visual Basic) cannot have a parameterless method named `ToString` that is called in place of the original type's `ToString` method. You'll have to provide some other name for your parameterless `ToString` replacement. + + The following example defines two methods that extend the class: a parameterless `ToString2` method, and a `ToString` method with a parameter that represents a format string. + :::code language="csharp" source="~/snippets/csharp/System/Object/ToString/customize2.cs" interactive="try-dotnet" id="Snippet8"::: :::code language="fsharp" source="~/snippets/fsharp/System/Object/ToString/customize2.fs" id="Snippet8"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.object.tostring/vb/customize2.vb" id="Snippet8"::: - - -## Notes for the Windows Runtime - When you call the method on a class in the Windows Runtime, it provides the default behavior for classes that don't override . This is part of the support that the .NET Framework provides for the Windows Runtime (see [.NET Framework Support for Windows Store Apps and Windows Runtime](/dotnet/standard/cross-platform/support-for-windows-store-apps-and-windows-runtime)). Classes in the Windows Runtime don't inherit , and don't always implement a . However, they always appear to have , , and methods when you use them in your C# or Visual Basic code, and the .NET Framework provides a default behavior for these methods. - - Starting with .NET Framework 4.5.1, the common language runtime uses [IStringable.ToString](xref:Windows.Foundation.IStringable.ToString) on a Windows Runtime object before falling back to the default implementation of . - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.object.tostring/vb/customize2.vb" id="Snippet8"::: + + +## Notes for the Windows Runtime + When you call the method on a class in the Windows Runtime, it provides the default behavior for classes that don't override . This is part of the support that the .NET Framework provides for the Windows Runtime (see [.NET Framework Support for Windows Store Apps and Windows Runtime](/dotnet/standard/cross-platform/support-for-windows-store-apps-and-windows-runtime)). Classes in the Windows Runtime don't inherit , and don't always implement a . However, they always appear to have , , and methods when you use them in your C# or Visual Basic code, and the .NET Framework provides a default behavior for these methods. + + Starting with .NET Framework 4.5.1, the common language runtime uses [IStringable.ToString](xref:Windows.Foundation.IStringable.ToString) on a Windows Runtime object before falling back to the default implementation of . + > [!NOTE] -> Windows Runtime classes that are written in C# or Visual Basic can override the method. - -### The Windows Runtime and the IStringable Interface - Starting with Windows 8.1, the Windows Runtime includes an [IStringable](xref:Windows.Foundation.IStringable) interface whose single method, [IStringable.ToString](xref:Windows.Foundation.IStringable.ToString), provides basic formatting support comparable to that provided by . To prevent ambiguity, you should not implement [IStringable](xref:Windows.Foundation.IStringable) on managed types. - - When managed objects are called by native code or by code written in languages such as JavaScript or C++/CX, they appear to implement [IStringable](xref:Windows.Foundation.IStringable). The common language runtime automatically routes calls from [IStringable.ToString](xref:Windows.Foundation.IStringable.ToString) to if [IStringable](xref:Windows.Foundation.IStringable) is not implemented on the managed object. - +> Windows Runtime classes that are written in C# or Visual Basic can override the method. + +### The Windows Runtime and the IStringable Interface + Starting with Windows 8.1, the Windows Runtime includes an [IStringable](xref:Windows.Foundation.IStringable) interface whose single method, [IStringable.ToString](xref:Windows.Foundation.IStringable.ToString), provides basic formatting support comparable to that provided by . To prevent ambiguity, you should not implement [IStringable](xref:Windows.Foundation.IStringable) on managed types. + + When managed objects are called by native code or by code written in languages such as JavaScript or C++/CX, they appear to implement [IStringable](xref:Windows.Foundation.IStringable). The common language runtime automatically routes calls from [IStringable.ToString](xref:Windows.Foundation.IStringable.ToString) to if [IStringable](xref:Windows.Foundation.IStringable) is not implemented on the managed object. + > [!WARNING] -> Because the common language runtime auto-implements [IStringable](xref:Windows.Foundation.IStringable) for all managed types in Windows Store apps, we recommend that you do not provide your own `IStringable` implementation. Implementing `IStringable` may result in unintended behavior when calling `ToString` from the Windows Runtime, C++/CX, or JavaScript. - - If you do choose to implement [IStringable](xref:Windows.Foundation.IStringable) in a public managed type that's exported in a Windows Runtime component, the following restrictions apply: - +> Because the common language runtime auto-implements [IStringable](xref:Windows.Foundation.IStringable) for all managed types in Windows Store apps, we recommend that you do not provide your own `IStringable` implementation. Implementing `IStringable` may result in unintended behavior when calling `ToString` from the Windows Runtime, C++/CX, or JavaScript. + + If you do choose to implement [IStringable](xref:Windows.Foundation.IStringable) in a public managed type that's exported in a Windows Runtime component, the following restrictions apply: + - You can define the [IStringable](xref:Windows.Foundation.IStringable) interface only in a "class implements" relationship, as follows: ```csharp @@ -1229,54 +1193,34 @@ and the interface. The - When you implement your own types, you should override the method to return values that are meaningful for those types. Derived classes that require more control over formatting than provides can implement the interface. Its method enables you to define format strings that control formatting and to use an object that can provide for culture-specific formatting. - - Overrides of the method should follow these guidelines: - -- The returned string should be friendly and readable by humans. - -- The returned string should uniquely identify the value of the object instance. - -- The returned string should be as short as possible so that it is suitable for display by a debugger. - -- Your override should not return or a null string. - -- Your override should not throw an exception. - -- If the string representation of an instance is culture-sensitive or can be formatted in multiple ways, implement the interface. - -- If the returned string includes sensitive information, you should first demand an appropriate permission. If the demand succeeds, you can return the sensitive information; otherwise, you should return a string that excludes the sensitive information. - -- Your override should have no observable side effects to avoid complications in debugging. For example, a call to the method should not change the value of instance fields. - -- If your type implements a parsing method (or or method, a constructor, or some other static method that instantiates an instance of the type from a string), you should ensure that the string returned by the method can be converted to an object instance. + When you implement your own types, you should override the method to return values that are meaningful for those types. Derived classes that require more control over formatting than provides can implement the interface. Its method enables you to define format strings that control formatting and to use an object that can provide for culture-specific formatting. Overrides of the method should follow these guidelines: - The returned string should be friendly and readable by humans. - The returned string should uniquely identify the value of the object instance. - The returned string should be as short as possible so that it is suitable for display by a debugger. - Your override should not return or a null string. - Your override should not throw an exception. - If the string representation of an instance is culture-sensitive or can be formatted in multiple ways, implement the interface. - If the returned string includes sensitive information, you should first demand an appropriate permission. If the demand succeeds, you can return the sensitive information; otherwise, you should return a string that excludes the sensitive information. - Your override should have no observable side effects to avoid complications in debugging. For example, a call to the method should not change the value of instance fields. - If your type implements a parsing method (or or method, a constructor, or some other static method that instantiates an instance of the type from a string), you should ensure that the string returned by the method can be converted to an object instance. Formatting Types in .NET diff --git a/xml/System/ObjectDisposedException.xml b/xml/System/ObjectDisposedException.xml index a21d760c780..abcc3d83e40 100644 --- a/xml/System/ObjectDisposedException.xml +++ b/xml/System/ObjectDisposedException.xml @@ -64,40 +64,40 @@ The exception that is thrown when an operation is performed on a disposed object. - is thrown when you try to access a member of an object that implements the interface or interface, and that object has been disposed. Typically, this exception is caused by one of the following conditions: - -- You've called an `IDisposable` object's `Dispose` method (or an `IDisposableAsync` object's `DisposeAsync` method), and you're trying to access an instance member that gets or sets the object's state. The following example illustrates the that is thrown when you try to reset the frequency of timer notifications after you call the method. - + is thrown when you try to access a member of an object that implements the interface or interface, and that object has been disposed. Typically, this exception is caused by one of the following conditions: + +- You've called an `IDisposable` object's `Dispose` method (or an `IDisposableAsync` object's `DisposeAsync` method), and you're trying to access an instance member that gets or sets the object's state. The following example illustrates the that is thrown when you try to reset the frequency of timer notifications after you call the method. + :::code language="csharp" source="~/snippets/csharp/System/ObjectDisposedException/Overview/dispose1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/ObjectDisposedException/Overview/dispose1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.objectdisposedexception/vb/dispose1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.objectdisposedexception/vb/dispose1.vb" id="Snippet1"::: + - You've called an object's `Close` method, and you're trying to access an instance member that gets or sets the object's state. Often, the `Close` method provides a type's public implementation of the method. The same is true for `CloseAsync` and ``. - -- You've called an object's `Dispose` or `DisposeAsync` methods multiple times. Typically, this doesn't throw an exception. However, depending on how a type implements or , it may not allow multiple calls to that method. - In most cases, this exception results from developer error. Instead of handling the error in a `try`/`catch` block, you should correct the error, typically by reinstantiating the object. - - - -## Examples - The following example demonstrates an error that causes the `ObjectDisposedException` exception to be thrown. - +- You've called an object's `Dispose` or `DisposeAsync` methods multiple times. Typically, this doesn't throw an exception. However, depending on how a type implements or , it may not allow multiple calls to that method. + + In most cases, this exception results from developer error. Instead of handling the error in a `try`/`catch` block, you should correct the error, typically by reinstantiating the object. + + + +## Examples + The following example demonstrates an error that causes the `ObjectDisposedException` exception to be thrown. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/ObjDispEx/CPP/objdispexc.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/ObjectDisposedException/Overview/objdispexc.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/ObjectDisposedException/Overview/objdispexc.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ObjDispEx/VB/objdispexc.vb" id="Snippet1"::: - This code produces the following output: - -``` -Caught: - Cannot access a closed Stream. -``` - + This code produces the following output: + +``` +Caught: + Cannot access a closed Stream. +``` + ]]> @@ -164,15 +164,15 @@ Caught: A string containing the name of the disposed object. Initializes a new instance of the class with a string containing the name of the disposed object. - property is initialized to a system-supplied message that describes the error and includes the `objectName` parameter. This message takes into account the current system culture. - - The `InnerException` property of the new instance is initialized to `null`. - - If `objectName` is `null`, the `Message` property contains only an error message. - + property is initialized to a system-supplied message that describes the error and includes the `objectName` parameter. This message takes into account the current system culture. + + The `InnerException` property of the new instance is initialized to `null`. + + If `objectName` is `null`, the `Message` property contains only an error message. + ]]> @@ -281,11 +281,11 @@ Caught: The exception that is the cause of the current exception. If is not , the current exception is raised in a block that handles the inner exception. Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception. - property. The property returns the same value that is passed into the constructor. - + property. The property returns the same value that is passed into the constructor. + ]]> @@ -340,13 +340,13 @@ Caught: The error message that explains the reason for the exception. Initializes a new instance of the class with the specified object name and message. - @@ -456,13 +456,13 @@ Caught: Gets the message that describes the error. A string that describes the error. - property is not `null`, the message includes the name of the object. - - This property overrides . - + property is not `null`, the message includes the name of the object. + + This property overrides . + ]]> @@ -508,11 +508,11 @@ Caught: Gets the name of the disposed object. A string containing the name of the disposed object. - , the value of this property is included in the string returned by the property. - + , the value of this property is included in the string returned by the property. + ]]> diff --git a/xml/System/OperationCanceledException.xml b/xml/System/OperationCanceledException.xml index 7b51213ab49..3c9efbeddcb 100644 --- a/xml/System/OperationCanceledException.xml +++ b/xml/System/OperationCanceledException.xml @@ -74,11 +74,11 @@ The exception that is thrown in a thread upon cancellation of an operation that the thread was executing. - property, and the property of the token is set to `true`. - + property, and the property of the token is set to `true`. + ]]> @@ -133,19 +133,19 @@ Initializes a new instance of the class with a system-supplied error message. - property of the new instance to a system-supplied message that describes the error, such as "The operation was canceled." This message takes into account the current system culture. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||A nullreference (`Nothing` in Visual Basic).| -||The localized error message string.| -||A cancellation token created in the non-canceled state.| - + property of the new instance to a system-supplied message that describes the error, such as "The operation was canceled." This message takes into account the current system culture. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||A nullreference (`Nothing` in Visual Basic).| +||The localized error message string.| +||A cancellation token created in the non-canceled state.| + ]]> @@ -194,19 +194,19 @@ A that describes the error. Initializes a new instance of the class with a specified error message. - . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The error message string.| -||A cancellation token created in the non-canceled state.| - + . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The error message string.| +||A cancellation token created in the non-canceled state.| + ]]> @@ -253,19 +253,19 @@ A cancellation token associated with the operation that was canceled. Initializes a new instance of the class with a cancellation token. - property of the new instance to a system-supplied message that describes the error, such as "The operation was canceled." This message takes into account the current system culture. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||A nullreference (`Nothing` in Visual Basic).| -||The localized error message string.| -||`token`.| - + property of the new instance to a system-supplied message that describes the error, such as "The operation was canceled." This message takes into account the current system culture. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||A nullreference (`Nothing` in Visual Basic).| +||The localized error message string.| +||`token`.| + ]]> @@ -327,11 +327,11 @@ The contextual information about the source or destination. Initializes a new instance of the class with serialized data. - XML and SOAP Serialization @@ -381,21 +381,21 @@ The exception that is the cause of the current exception. If the parameter is not , the current exception is raised in a block that handles the inner exception. Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception. - property. The property returns the same value that is passed into the constructor, or `null` if the property does not supply the inner exception value to the constructor. - - The following table shows the initial property values for an instance of . - -|Property Type|Condition| -|-------------------|---------------| -||`innerException`.| -||`message`.| -||A cancellation token created in the non-canceled state.| - + property. The property returns the same value that is passed into the constructor, or `null` if the property does not supply the inner exception value to the constructor. + + The following table shows the initial property values for an instance of . + +|Property Type|Condition| +|-------------------|---------------| +||`innerException`.| +||`message`.| +||A cancellation token created in the non-canceled state.| + ]]> @@ -445,19 +445,19 @@ A cancellation token associated with the operation that was canceled. Initializes a new instance of the class with a specified error message and a cancellation token. - . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||`message`.| -||`token`.| - + . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||`message`.| +||`token`.| + ]]> @@ -509,21 +509,21 @@ A cancellation token associated with the operation that was canceled. Initializes a new instance of the class with a specified error message, a reference to the inner exception that is the cause of this exception, and a cancellation token. - property. The property returns the same value that is passed into the constructor, or `null` if the property does not supply the inner exception value to the constructor. - - The following table shows the initial property values for an instance of . - -|Property Type|Condition| -|-------------------|---------------| -||`innerException`.| -||`message`.| -||`token`.| - + property. The property returns the same value that is passed into the constructor, or `null` if the property does not supply the inner exception value to the constructor. + + The following table shows the initial property values for an instance of . + +|Property Type|Condition| +|-------------------|---------------| +||`innerException`.| +||`message`.| +||`token`.| + ]]> @@ -570,11 +570,11 @@ Gets a token associated with the operation that was canceled. A token associated with the operation that was canceled, or a default token. - property of the token returns `true`. - + property of the token returns `true`. + ]]> diff --git a/xml/System/OutOfMemoryException.xml b/xml/System/OutOfMemoryException.xml index 6d81d1480af..0b0555d157a 100644 --- a/xml/System/OutOfMemoryException.xml +++ b/xml/System/OutOfMemoryException.xml @@ -70,106 +70,106 @@ The exception that is thrown when there is not enough memory to continue the execution of a program. - uses the HRESULT `COR_E_OUTOFMEMORY`, which has the value 0x8007000E. - -For a list of initial property values for an instance of , see the constructors. - + uses the HRESULT `COR_E_OUTOFMEMORY`, which has the value 0x8007000E. + +For a list of initial property values for an instance of , see the constructors. + > [!NOTE] -> The value of the inherited property is always `null`. - -An exception has two major causes: - -- You are attempting to expand a object beyond the length defined by its property. - -- The common language runtime cannot allocate enough contiguous memory to successfully perform an operation. This exception can be thrown by any property assignment or method call that requires a memory allocation. For more information on the cause of the exception, see the blog post ["Out of Memory" Does Not Refer to Physical Memory](https://docs.microsoft.com/archive/blogs/ericlippert/out-of-memory-does-not-refer-to-physical-memory). - - This type of exception represents a catastrophic failure. If you choose to handle the exception, you should include a `catch` block that calls the method to terminate your app and add an entry to the system event log, as the following example does. - +> The value of the inherited property is always `null`. + +An exception has two major causes: + +- You are attempting to expand a object beyond the length defined by its property. + +- The common language runtime cannot allocate enough contiguous memory to successfully perform an operation. This exception can be thrown by any property assignment or method call that requires a memory allocation. For more information on the cause of the exception, see the blog post ["Out of Memory" Does Not Refer to Physical Memory](https://docs.microsoft.com/archive/blogs/ericlippert/out-of-memory-does-not-refer-to-physical-memory). + + This type of exception represents a catastrophic failure. If you choose to handle the exception, you should include a `catch` block that calls the method to terminate your app and add an entry to the system event log, as the following example does. + :::code language="csharp" source="~/snippets/csharp/System/OutOfMemoryException/Overview/failfast1.cs" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/OutOfMemoryException/Overview/failfast1.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.outofmemoryexception/vb/failfast1.vb" id="Snippet2"::: - - Some of the conditions under which the exception is thrown and the actions you can take to eliminate it include the following: - -**You are calling the method.** - -You are attempting to increase the length of a object beyond the size specified by its property. The following example illustrates the exception thrown by a call to the method when the example tries to insert a string that would cause the object's property to exceed its maximum capacity. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.outofmemoryexception/vb/failfast1.vb" id="Snippet2"::: + + Some of the conditions under which the exception is thrown and the actions you can take to eliminate it include the following: + +**You are calling the method.** + +You are attempting to increase the length of a object beyond the size specified by its property. The following example illustrates the exception thrown by a call to the method when the example tries to insert a string that would cause the object's property to exceed its maximum capacity. + :::code language="csharp" source="~/snippets/csharp/System/OutOfMemoryException/Overview/sb_example1.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/OutOfMemoryException/Overview/sb_example1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.outofmemoryexception/vb/sb_example1.vb" id="Snippet1"::: -You can do either of the following to address the error: - -- Replace the call to the constructor with a call any other constructor overload. The maximum capacity of your object will be set to its default value, which is . +You can do either of the following to address the error: + +- Replace the call to the constructor with a call any other constructor overload. The maximum capacity of your object will be set to its default value, which is . + +- Call the constructor with a `maxCapacity` value that is large enough to accommodate any expansions to the object. -- Call the constructor with a `maxCapacity` value that is large enough to accommodate any expansions to the object. - **Your app runs as a 32-bit process.** -32-bit processes can allocate a maximum of 2GB of virtual user-mode memory on 32-bit systems, and 4GB of virtual user-mode memory on 64-bit systems. This can make it more difficult for the common language runtime to allocate sufficient contiguous memory when a large allocation is needed. In contrast, 64-bit processes can allocate up to 8TB of virtual memory. To address this exception, recompile your app to target a 64-bit platform. For information on targeting specific platforms in Visual Studio, see [How to: Configure Projects to Target Platforms](/visualstudio/ide/how-to-configure-projects-to-target-platforms). - -**Your app is leaking unmanaged resources** +32-bit processes can allocate a maximum of 2GB of virtual user-mode memory on 32-bit systems, and 4GB of virtual user-mode memory on 64-bit systems. This can make it more difficult for the common language runtime to allocate sufficient contiguous memory when a large allocation is needed. In contrast, 64-bit processes can allocate up to 8TB of virtual memory. To address this exception, recompile your app to target a 64-bit platform. For information on targeting specific platforms in Visual Studio, see [How to: Configure Projects to Target Platforms](/visualstudio/ide/how-to-configure-projects-to-target-platforms). + +**Your app is leaking unmanaged resources** + +Although the garbage collector is able to free memory allocated to managed types, it does not manage memory allocated to unmanaged resources such as operating system handles (including handles to files, memory-mapped files, pipes, registry keys, and wait handles) and memory blocks allocated directly by Windows API calls or by calls to memory allocation functions such as `malloc`. Types that consume unmanaged resources implement the interface. -Although the garbage collector is able to free memory allocated to managed types, it does not manage memory allocated to unmanaged resources such as operating system handles (including handles to files, memory-mapped files, pipes, registry keys, and wait handles) and memory blocks allocated directly by Windows API calls or by calls to memory allocation functions such as `malloc`. Types that consume unmanaged resources implement the interface. +If you are consuming a type that uses unmanaged resources, you should be sure to call its method when you have finished using it. (Some types also implement a `Close` method that is identical in function to a `Dispose` method.) For more information, see the [Using Objects That Implement IDisposable](/dotnet/standard/garbage-collection/using-objects) topic. -If you are consuming a type that uses unmanaged resources, you should be sure to call its method when you have finished using it. (Some types also implement a `Close` method that is identical in function to a `Dispose` method.) For more information, see the [Using Objects That Implement IDisposable](/dotnet/standard/garbage-collection/using-objects) topic. +If you have created a type that uses unmanaged resources, make sure that you have implemented the Dispose pattern and, if necessary, supplied a finalizer. For more information, see [Implementing a Dispose method](/dotnet/standard/garbage-collection/implementing-dispose) and . -If you have created a type that uses unmanaged resources, make sure that you have implemented the Dispose pattern and, if necessary, supplied a finalizer. For more information, see [Implementing a Dispose method](/dotnet/standard/garbage-collection/implementing-dispose) and . - **You are attempting to create a large array in a 64-bit process** -By default, the common language runtime in .NET Framework does not allow single objects whose size exceeds 2GB. To override this default, you can use the [\](/dotnet/framework/configure-apps/file-schema/runtime/gcallowverylargeobjects-element) configuration file setting to enable arrays whose total size exceeds 2 GB. On .NET Core, support for arrays of greater than 2 GB is enabled by default. - +By default, the common language runtime in .NET Framework does not allow single objects whose size exceeds 2GB. To override this default, you can use the [\](/dotnet/framework/configure-apps/file-schema/runtime/gcallowverylargeobjects-element) configuration file setting to enable arrays whose total size exceeds 2 GB. On .NET Core, support for arrays of greater than 2 GB is enabled by default. + **You are working with very large sets of data (such as arrays, collections, or database data sets) in memory.** -When data structures or data sets that reside in memory become so large that the common language runtime is unable to allocate enough contiguous memory for them, an exception results. +When data structures or data sets that reside in memory become so large that the common language runtime is unable to allocate enough contiguous memory for them, an exception results. + +To prevent the exceptions, you must modify your application so that less data is resident in memory, or the data is divided into segments that require smaller memory allocations. For example: -To prevent the exceptions, you must modify your application so that less data is resident in memory, or the data is divided into segments that require smaller memory allocations. For example: +- If you are retrieving all of the data from a database and then filtering it in your app to minimize trips to the server, you should modify your queries to return only the subset of data that your app needs. When working with large tables, multiple queries are almost always more efficient than retrieving all of the data in a single table and then manipulating it. -- If you are retrieving all of the data from a database and then filtering it in your app to minimize trips to the server, you should modify your queries to return only the subset of data that your app needs. When working with large tables, multiple queries are almost always more efficient than retrieving all of the data in a single table and then manipulating it. +- If you are executing queries that users create dynamically, you should ensure that the number of records returned by the query is limited. -- If you are executing queries that users create dynamically, you should ensure that the number of records returned by the query is limited. +- If you are using large arrays or other collection objects whose size results in an exception, you should modify your application to work the data in subsets rather than to work with it all at once. -- If you are using large arrays or other collection objects whose size results in an exception, you should modify your application to work the data in subsets rather than to work with it all at once. - -The following example gets a array that consists of 200 million floating-point values and then calculates their mean. The output from the example shows that, because the example stores the entire array in memory before it calculates the mean, an is thrown. +The following example gets a array that consists of 200 million floating-point values and then calculates their mean. The output from the example shows that, because the example stores the entire array in memory before it calculates the mean, an is thrown. :::code language="csharp" source="~/snippets/csharp/System/OutOfMemoryException/Overview/data1.cs" id="Snippet3"::: :::code language="fsharp" source="~/snippets/fsharp/System/OutOfMemoryException/Overview/data1.fs" id="Snippet3"::: -:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.outofmemoryexception/vb/data1.vb" id="Snippet3"::: - -The following example eliminates the exception by processing the incoming data without storing the entire data set in memory, serializing the data to a file if necessary to permit further processing (these lines are commented out in the example, since in this case they produce a file whose size is greater than 1GB), and returning the calculated mean and the number of cases to the calling routine. +:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.outofmemoryexception/vb/data1.vb" id="Snippet3"::: + +The following example eliminates the exception by processing the incoming data without storing the entire data set in memory, serializing the data to a file if necessary to permit further processing (these lines are commented out in the example, since in this case they produce a file whose size is greater than 1GB), and returning the calculated mean and the number of cases to the calling routine. :::code language="csharp" source="~/snippets/csharp/System/OutOfMemoryException/Overview/data2.cs" id="Snippet4"::: :::code language="fsharp" source="~/snippets/fsharp/System/OutOfMemoryException/Overview/data2.fs" id="Snippet4"::: -:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.outofmemoryexception/vb/data2.vb" id="Snippet4"::: - -**You are repeatedly concatenating large strings.** +:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.outofmemoryexception/vb/data2.vb" id="Snippet4"::: + +**You are repeatedly concatenating large strings.** + +Because strings are immutable, each string concatenation operation creates a new string. The impact for small strings, or for a small number of concatenation operations, is negligible. But for large strings or a very large number of concatenation operations, string concatenation can lead to a large number of memory allocations and memory fragmentation, poor performance, and possibly exceptions. -Because strings are immutable, each string concatenation operation creates a new string. The impact for small strings, or for a small number of concatenation operations, is negligible. But for large strings or a very large number of concatenation operations, string concatenation can lead to a large number of memory allocations and memory fragmentation, poor performance, and possibly exceptions. +When concatenating large strings or performing a large number of concatenation operations, you should use the class instead of the class. When you have finished manipulating the string, convert the instance to a string by calling the method. -When concatenating large strings or performing a large number of concatenation operations, you should use the class instead of the class. When you have finished manipulating the string, convert the instance to a string by calling the method. - -**You pin a large number of objects in memory.** - -Pinning a large number of objects in memory for long periods can make it difficult for the garbage collector to allocate contiguous blocks of memory. If you've pinned a large number of objects in memory, for example by using the `fixed` statement in C# or by calling the method with a handle type of , you can do the following to address the exception. - -- Evaluate whether each object really needs to be pinned, +**You pin a large number of objects in memory.** -- Ensure that each object is unpinned as soon as possible. +Pinning a large number of objects in memory for long periods can make it difficult for the garbage collector to allocate contiguous blocks of memory. If you've pinned a large number of objects in memory, for example by using the `fixed` statement in C# or by calling the method with a handle type of , you can do the following to address the exception. -- Make sure that each call to the method to pin memory has a corresponding call to the method to unpin that memory. +- Evaluate whether each object really needs to be pinned, -The following Microsoft intermediate (MSIL) instructions throw an exception: - -- [box](xref:System.Reflection.Emit.OpCodes.Box) -- [newarr](xref:System.Reflection.Emit.OpCodes.Newarr) -- [newobj](xref:System.Reflection.Emit.OpCodes.Newobj) +- Ensure that each object is unpinned as soon as possible. + +- Make sure that each call to the method to pin memory has a corresponding call to the method to unpin that memory. + +The following Microsoft intermediate (MSIL) instructions throw an exception: + +- [box](xref:System.Reflection.Emit.OpCodes.Box) +- [newarr](xref:System.Reflection.Emit.OpCodes.Newarr) +- [newobj](xref:System.Reflection.Emit.OpCodes.Newobj) ]]> @@ -228,18 +228,18 @@ The following Microsoft intermediate (MSIL) instructions throw an Initializes a new instance of the class. - property of the new instance to a system-supplied message that describes the error, such as "There was not enough memory to continue the execution of the program." This message takes into account the current system culture. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||`null`.| -||The localized error message string.| - + property of the new instance to a system-supplied message that describes the error, such as "There was not enough memory to continue the execution of the program." This message takes into account the current system culture. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||`null`.| +||The localized error message string.| + ]]> @@ -286,18 +286,18 @@ The following Microsoft intermediate (MSIL) instructions throw an The message that describes the error. Initializes a new instance of the class with a specified error message. - . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The error message string.| - + . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The error message string.| + ]]> @@ -359,11 +359,11 @@ The following Microsoft intermediate (MSIL) instructions throw an The contextual information about the source or destination. Initializes a new instance of the class with serialized data. - XML and SOAP Serialization @@ -413,18 +413,18 @@ The following Microsoft intermediate (MSIL) instructions throw an The exception that is the cause of the current exception. If the parameter is not a null reference ( in Visual Basic), the current exception is raised in a block that handles the inner exception. Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception. - property. The property returns the same value that is passed into the constructor, or a null reference (`Nothing` in Visual Basic) if the property does not supply the inner exception value to the constructor. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||The inner exception reference.| -||The error message string.| - + property. The property returns the same value that is passed into the constructor, or a null reference (`Nothing` in Visual Basic) if the property does not supply the inner exception value to the constructor. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||The inner exception reference.| +||The error message string.| + ]]> diff --git a/xml/System/OverflowException.xml b/xml/System/OverflowException.xml index b471f1c300e..c3f55bfef3b 100644 --- a/xml/System/OverflowException.xml +++ b/xml/System/OverflowException.xml @@ -64,48 +64,48 @@ The exception that is thrown when an arithmetic, casting, or conversion operation in a checked context results in an overflow. - is thrown at run time under the following conditions: - -- An arithmetic operation produces a result that is outside the range of the data type returned by the operation. The following example illustrates the that is thrown by a multiplication operation that overflows the bounds of the type. - + is thrown at run time under the following conditions: + +- An arithmetic operation produces a result that is outside the range of the data type returned by the operation. The following example illustrates the that is thrown by a multiplication operation that overflows the bounds of the type. + :::code language="csharp" source="~/snippets/csharp/System/OverflowException/Overview/arithmetic1.cs" interactive="try-dotnet-method" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/OverflowException/Overview/arithmetic1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.overflowexception/vb/arithmetic1.vb" id="Snippet1"::: -- A casting or conversion operation attempts to perform a narrowing conversion, and the value of the source data type is outside the range of the target data type. The following example illustrates the that is thrown by the attempt to convert a large unsigned byte value to a signed byte value. - +- A casting or conversion operation attempts to perform a narrowing conversion, and the value of the source data type is outside the range of the target data type. The following example illustrates the that is thrown by the attempt to convert a large unsigned byte value to a signed byte value. + :::code language="csharp" source="~/snippets/csharp/System/OverflowException/Overview/arithmetic1.cs" interactive="try-dotnet-method" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/OverflowException/Overview/arithmetic1.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.overflowexception/vb/arithmetic1.vb" id="Snippet2"::: - In each case, the result of the operation is a value that is less than the `MinValue` property or greater than the `MaxValue` property of the data type that results from the operation. - - For the arithmetic, casting, or conversion operation to throw an , the operation must occur in a checked context. By default, arithmetic operations and overflows in Visual Basic are checked; in C# and F#, they are not. If the operation occurs in an unchecked context, the result is truncated by discarding any high-order bits that do not fit into the destination type. The following example illustrates such an unchecked conversion in C# or F#. It repeats the previous example in an unchecked context. - - :::code language="csharp" source="~/snippets/csharp/System/OverflowException/Overview/arithmetic1.cs" interactive="try-dotnet-method" id="Snippet3"::: - :::code language="fsharp" source="~/snippets/fsharp/System/OverflowException/Overview/arithmetic1.fs" id="Snippet3"::: - - The following Microsoft intermediate language (MSIL) instructions throw an : - -- `add.ovf.` *\* - -- `conv.ovf.` *\* - -- `conv.ovf.` *\* `.un` - -- `mul.ovf.` *\* - -- `sub.ovf.` *\* - -- `newarr` - - uses the HRESULT COR_E_OVERFLOW, which has the value 0x80131516. - - For a list of initial property values for an instance of , see the constructors. - + In each case, the result of the operation is a value that is less than the `MinValue` property or greater than the `MaxValue` property of the data type that results from the operation. + + For the arithmetic, casting, or conversion operation to throw an , the operation must occur in a checked context. By default, arithmetic operations and overflows in Visual Basic are checked; in C# and F#, they are not. If the operation occurs in an unchecked context, the result is truncated by discarding any high-order bits that do not fit into the destination type. The following example illustrates such an unchecked conversion in C# or F#. It repeats the previous example in an unchecked context. + + :::code language="csharp" source="~/snippets/csharp/System/OverflowException/Overview/arithmetic1.cs" interactive="try-dotnet-method" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/System/OverflowException/Overview/arithmetic1.fs" id="Snippet3"::: + + The following Microsoft intermediate language (MSIL) instructions throw an : + +- `add.ovf.` *\* + +- `conv.ovf.` *\* + +- `conv.ovf.` *\* `.un` + +- `mul.ovf.` *\* + +- `sub.ovf.` *\* + +- `newarr` + + uses the HRESULT COR_E_OVERFLOW, which has the value 0x80131516. + + For a list of initial property values for an instance of , see the constructors. + ]]> @@ -162,16 +162,16 @@ Initializes a new instance of the class. - . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The localized error message string.| - + . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The localized error message string.| + ]]> @@ -218,18 +218,18 @@ The message that describes the error. Initializes a new instance of the class with a specified error message. - . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The error message string.| - + . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The error message string.| + ]]> @@ -291,11 +291,11 @@ The contextual information about the source or destination. Initializes a new instance of the class with serialized data. - @@ -344,18 +344,18 @@ The exception that is the cause of the current exception. If the parameter is not a null reference ( in Visual Basic), the current exception is raised in a block that handles the inner exception. Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception. - property. The property returns the same value that is passed into the constructor, or a null reference (`Nothing` in Visual Basic) if the property does not supply the inner exception value to the constructor. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||The inner exception reference.| -||The error message string.| - + property. The property returns the same value that is passed into the constructor, or a null reference (`Nothing` in Visual Basic) if the property does not supply the inner exception value to the constructor. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||The inner exception reference.| +||The error message string.| + ]]> diff --git a/xml/System/ParamArrayAttribute.xml b/xml/System/ParamArrayAttribute.xml index 36eec8a7492..a67814ae3c0 100644 --- a/xml/System/ParamArrayAttribute.xml +++ b/xml/System/ParamArrayAttribute.xml @@ -55,39 +55,39 @@ Indicates that a method will allow a variable number of arguments in its invocation. This class cannot be inherited. - indicates that a method parameter is a parameter array. A parameter array allows the specification of an unknown number of arguments. A parameter array must be the last parameter in a formal parameter list, and it must be a single-dimension array. When the method is called, a parameter array permits arguments to a method to be specified in either of two ways: - -- As a single expression of a type that is implicitly convertible to the parameter array type. The parameter array functions as a value parameter. - -- As zero or more arguments, where each argument is an expression of a type that is implicitly convertible to the type of the parameter array element. - - The example in the next section illustrates both calling conventions. - + indicates that a method parameter is a parameter array. A parameter array allows the specification of an unknown number of arguments. A parameter array must be the last parameter in a formal parameter list, and it must be a single-dimension array. When the method is called, a parameter array permits arguments to a method to be specified in either of two ways: + +- As a single expression of a type that is implicitly convertible to the parameter array type. The parameter array functions as a value parameter. + +- As zero or more arguments, where each argument is an expression of a type that is implicitly convertible to the type of the parameter array element. + + The example in the next section illustrates both calling conventions. + > [!NOTE] -> Typically, the is not used directly in code. Instead, individual language keywords, such as `ParamArray` in Visual Basic and `params` in C#, are used as wrappers for the class. Some languages, such as C#, may even require the use of the language keyword and prohibit the use of . - - During overload resolution, when compilers that support parameter arrays encounter a method overload that does not exist but has one fewer parameter than an overload that includes a parameter array, they will replace the method with the overload that includes the parameter array. For example, a call to the `String.Split()` instance method (which does not exist in the class) is resolved as a call to the method. The compiler will also pass an empty array of the required type to the method. This means that the method must always be prepared to handle an array whose length is zero when it processes the elements in the parameter array. The example provides an illustration. - - For more information about using attributes, see [Attributes](/dotnet/standard/attributes/). - - - -## Examples - The following example defines a `Temperature` class that includes a `Display` method, which is intended to display one or more formatted temperature values. The method has a single parameter, `formats`, which is defined as a parameter array. - +> Typically, the is not used directly in code. Instead, individual language keywords, such as `ParamArray` in Visual Basic and `params` in C#, are used as wrappers for the class. Some languages, such as C#, may even require the use of the language keyword and prohibit the use of . + + During overload resolution, when compilers that support parameter arrays encounter a method overload that does not exist but has one fewer parameter than an overload that includes a parameter array, they will replace the method with the overload that includes the parameter array. For example, a call to the `String.Split()` instance method (which does not exist in the class) is resolved as a call to the method. The compiler will also pass an empty array of the required type to the method. This means that the method must always be prepared to handle an array whose length is zero when it processes the elements in the parameter array. The example provides an illustration. + + For more information about using attributes, see [Attributes](/dotnet/standard/attributes/). + + + +## Examples + The following example defines a `Temperature` class that includes a `Display` method, which is intended to display one or more formatted temperature values. The method has a single parameter, `formats`, which is defined as a parameter array. + :::code language="csharp" source="~/snippets/csharp/System/ParamArrayAttribute/Overview/Example.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/ParamArrayAttribute/Overview/Example.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.ParamArrayAttribute/vb/Example.vb" id="Snippet1"::: - - The following example illustrates three different calls to the `Temperature.Display` method. In the first, the method is passed an array of format strings. In the second, the method is passed four individual format strings as arguments. In the third, the method is called with no arguments. As the output from the example illustrates, the Visual Basic and C# compilers translate this into a call to the `Display` method with an empty string array. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.ParamArrayAttribute/vb/Example.vb" id="Snippet1"::: + + The following example illustrates three different calls to the `Temperature.Display` method. In the first, the method is passed an array of format strings. In the second, the method is passed four individual format strings as arguments. In the third, the method is called with no arguments. As the output from the example illustrates, the Visual Basic and C# compilers translate this into a call to the `Display` method with an empty string array. + :::code language="csharp" source="~/snippets/csharp/System/ParamArrayAttribute/Overview/Example.cs" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/ParamArrayAttribute/Overview/Example.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.ParamArrayAttribute/vb/Example.vb" id="Snippet2"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.ParamArrayAttribute/vb/Example.vb" id="Snippet2"::: + ]]> diff --git a/xml/System/PlatformID.xml b/xml/System/PlatformID.xml index e48d91f02b0..b6d13c4e60c 100644 --- a/xml/System/PlatformID.xml +++ b/xml/System/PlatformID.xml @@ -57,21 +57,21 @@ Identifies the operating system, or platform, supported by an assembly. - and properties to obtain the `PlatformID` enumeration for the currently executing operating system or development platform. Use the `PlatformID` enumeration to help determine whether the current operating system or development platform supports your application. - - You can use the underlying integer value of each `PlatformID` enumeration member as the `PlatformId` argument for the [SignTool.exe (Sign Tool)](/dotnet/framework/tools/signtool-exe) utility. - -## Examples + and properties to obtain the `PlatformID` enumeration for the currently executing operating system or development platform. Use the `PlatformID` enumeration to help determine whether the current operating system or development platform supports your application. + + You can use the underlying integer value of each `PlatformID` enumeration member as the `PlatformId` argument for the [SignTool.exe (Sign Tool)](/dotnet/framework/tools/signtool-exe) utility. + +## Examples The following example demonstrates using the `PlatformID` class to identify the currently executing operating system: - + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/platformID.class/CPP/pid.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/PlatformID/Overview/pid.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/PlatformID/Overview/pid.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/platformID.class/VB/pid.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/platformID.class/VB/pid.vb" id="Snippet1"::: + ]]> diff --git a/xml/System/PlatformNotSupportedException.xml b/xml/System/PlatformNotSupportedException.xml index 4a01005887b..c829cad8197 100644 --- a/xml/System/PlatformNotSupportedException.xml +++ b/xml/System/PlatformNotSupportedException.xml @@ -64,11 +64,11 @@ The exception that is thrown when a feature does not run on a particular platform. - @@ -125,16 +125,16 @@ Initializes a new instance of the class with default properties. - class is created by a call to this constructor, the following properties are initialized to the specified values: - -|Property|Value| -|--------------|-----------| -||`null`.| -||The empty string.| - + class is created by a call to this constructor, the following properties are initialized to the specified values: + +|Property|Value| +|--------------|-----------| +||`null`.| +||The empty string.| + ]]> @@ -181,16 +181,16 @@ The text message that explains the reason for the exception. Initializes a new instance of the class with a specified error message. - class is created by a call to this constructor, the following properties are initialized to the specified values: - -|Property|Value| -|--------------|-----------| -||`null`.| -||The error message string.| - + class is created by a call to this constructor, the following properties are initialized to the specified values: + +|Property|Value| +|--------------|-----------| +||`null`.| +||The error message string.| + ]]> @@ -298,18 +298,18 @@ The exception that is the cause of the current exception. If the parameter is not , the current exception is raised in a block that handles the inner exception. Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception. - property. The property returns the same value that is passed into the constructor, or `null` if the property does not supply the inner exception value to the constructor. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||The inner exception reference.| -||The error message string.| - + property. The property returns the same value that is passed into the constructor, or `null` if the property does not supply the inner exception value to the constructor. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||The inner exception reference.| +||The error message string.| + ]]> diff --git a/xml/System/Predicate`1.xml b/xml/System/Predicate`1.xml index 348e366960d..96838f4374b 100644 --- a/xml/System/Predicate`1.xml +++ b/xml/System/Predicate`1.xml @@ -69,32 +69,32 @@ if meets the criteria defined within the method represented by this delegate; otherwise, . - and classes to search for elements in the collection. - - Typically, the delegate is represented by a lambda expression. Because locally scoped variables are available to the lambda expression, it is easy to test for a condition that is not precisely known at compile time. This is simulated in the following example, which defines a `HockeyTeam` class that contains information about a National Hockey League team and the year in which it was founded. The example defines an array of integer values that represent years, and randomly assigns one element of the array to `foundedBeforeYear`, which is a variable that is locally scoped to the example's `Main` method. Because locally scoped variables are available to a lambda expression, the lambda expression passed to the method is able to return a `HockeyTeam` object for each team founded on or before that year. - + and classes to search for elements in the collection. + + Typically, the delegate is represented by a lambda expression. Because locally scoped variables are available to the lambda expression, it is easy to test for a condition that is not precisely known at compile time. This is simulated in the following example, which defines a `HockeyTeam` class that contains information about a National Hockey League team and the year in which it was founded. The example defines an array of integer values that represent years, and randomly assigns one element of the array to `foundedBeforeYear`, which is a variable that is locally scoped to the example's `Main` method. Because locally scoped variables are available to a lambda expression, the lambda expression passed to the method is able to return a `HockeyTeam` object for each team founded on or before that year. + :::code language="csharp" source="~/snippets/csharp/System/PredicateT/Overview/predicate1.cs" interactive="try-dotnet" id="Snippet3"::: :::code language="fsharp" source="~/snippets/fsharp/System/PredicateT/Overview/predicate1.fs" id="Snippet3"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Predicate`1/vb/predicate1.vb" id="Snippet3"::: - - - -## Examples - The following code example uses a delegate with the method to search an array of structures. The example explicitly defines a delegate named `predicate` and assigns it a method named `FindPoints` that returns `true` if the product of the and fields is greater than 100,000. Note that it is customary to use a lambda expression rather than to explicitly define a delegate of type , as the second example illustrates. - + + + +## Examples + The following code example uses a delegate with the method to search an array of structures. The example explicitly defines a delegate named `predicate` and assigns it a method named `FindPoints` that returns `true` if the product of the and fields is greater than 100,000. Note that it is customary to use a lambda expression rather than to explicitly define a delegate of type , as the second example illustrates. + :::code language="csharp" source="~/snippets/csharp/System/PredicateT/Overview/predicateex2.cs" interactive="try-dotnet" id="Snippet4"::: :::code language="fsharp" source="~/snippets/fsharp/System/PredicateT/Overview/predicateex2.fs" id="Snippet4"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Predicate`1/vb/predicateex2.vb" id="Snippet4"::: - - The following example is identical to the previous example, except that it uses a lambda expression to represent the delegate. Each element of the `points` array is passed to the lambda expression until the expression finds an element that meets the search criteria. In this case, the lambda expression returns `true` if the product of the X and Y fields is greater than 100,000. - + + The following example is identical to the previous example, except that it uses a lambda expression to represent the delegate. Each element of the `points` array is passed to the lambda expression until the expression finds an element that meets the search criteria. In this case, the lambda expression returns `true` if the product of the X and Y fields is greater than 100,000. + :::code language="csharp" source="~/snippets/csharp/System/PredicateT/Overview/predicateex1.cs" interactive="try-dotnet" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/PredicateT/Overview/predicateex1.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Predicate`1/vb/predicateex1.vb" id="Snippet2"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Predicate`1/vb/predicateex1.vb" id="Snippet2"::: + ]]> diff --git a/xml/System/Progress`1.xml b/xml/System/Progress`1.xml index 8e7f9124e08..551b670bc43 100644 --- a/xml/System/Progress`1.xml +++ b/xml/System/Progress`1.xml @@ -74,13 +74,13 @@ Specifies the type of the progress report value. Provides an that invokes callbacks for each reported progress value. - event are invoked through a instance captured when the instance is constructed. If there is no current at the time of construction, the callbacks will be invoked on the . - - For more information and a code example, see the article [Async in 4.5: Enabling Progress and Cancellation in Async APIs](https://devblogs.microsoft.com/dotnet/async-in-4-5-enabling-progress-and-cancellation-in-async-apis/) in the .NET Framework blog. - + event are invoked through a instance captured when the instance is constructed. If there is no current at the time of construction, the callbacks will be invoked on the . + + For more information and a code example, see the article [Async in 4.5: Enabling Progress and Cancellation in Async APIs](https://devblogs.microsoft.com/dotnet/async-in-4-5-enabling-progress-and-cancellation-in-async-apis/) in the .NET Framework blog. + ]]> @@ -275,11 +275,11 @@ Raised for each reported progress value. - captured when the instance was constructed. - + captured when the instance was constructed. + ]]> diff --git a/xml/System/Random.xml b/xml/System/Random.xml index 8cde888ebeb..741395689fc 100644 --- a/xml/System/Random.xml +++ b/xml/System/Random.xml @@ -70,307 +70,305 @@ Represents a pseudo-random number generator, which is an algorithm that produces a sequence of numbers that meet certain statistical requirements for randomness. - class is based on a modified version of Donald E. Knuth's subtractive random number generator algorithm. For more information, see D. E. Knuth. *The Art of Computer Programming, Volume 2: Seminumerical Algorithms*. Addison-Wesley, Reading, MA, third edition, 1997. - - To generate a cryptographically secure random number, such as one that's suitable for creating a random password, use the class or derive a class from . - - In this topic: - - [Instantiating the random number generator](#Instantiate) - [Avoiding multiple instantiations](#Multiple) - [The System.Random class and thread safety](#ThreadSafety) - [Generating different types of random numbers](#Functionality) - [Substituting your own algorithm](#Overriding) - [How do you use System.Random to…](#Operations) - [Retrieve the same sequence of random values](#Same) - [Retrieve unique sequences of random values](#Unique) - [Retrieve integers in a specified range](#Range) - [Retrieve integers with a specified number of digits](#Digits) - [Retrieve floating-point values in a specified range](#Floats) - [Generate random Boolean values](#Boolean) - [Generate random 64-bit integers](#Long) - [Retrieve bytes in a specified range](#Bytes) - [Retrieve an element from an array or collection at random](#Array) - [Retrieve a unique element from an array or collection](#UniqueArray) - - -## Instantiating the random number generator - You instantiate the random number generator by providing a seed value (a starting value for the pseudo-random number generation algorithm) to a class constructor. You can supply the seed value either explicitly or implicitly: - -- The constructor uses an explicit seed value that you supply. - -- The constructor uses the default seed value. This is the most common way of instantiating the random number generator. - + class is based on a modified version of Donald E. Knuth's subtractive random number generator algorithm. For more information, see D. E. Knuth. *The Art of Computer Programming, Volume 2: Seminumerical Algorithms*. Addison-Wesley, Reading, MA, third edition, 1997. + + To generate a cryptographically secure random number, such as one that's suitable for creating a random password, use the class or derive a class from . + + In this topic: + + [Instantiating the random number generator](#Instantiate) + [Avoiding multiple instantiations](#Multiple) + [The System.Random class and thread safety](#ThreadSafety) + [Generating different types of random numbers](#Functionality) + [Substituting your own algorithm](#Overriding) + [How do you use System.Random to…](#Operations) + [Retrieve the same sequence of random values](#Same) + [Retrieve unique sequences of random values](#Unique) + [Retrieve integers in a specified range](#Range) + [Retrieve integers with a specified number of digits](#Digits) + [Retrieve floating-point values in a specified range](#Floats) + [Generate random Boolean values](#Boolean) + [Generate random 64-bit integers](#Long) + [Retrieve bytes in a specified range](#Bytes) + [Retrieve an element from an array or collection at random](#Array) + [Retrieve a unique element from an array or collection](#UniqueArray) + + +## Instantiating the random number generator + You instantiate the random number generator by providing a seed value (a starting value for the pseudo-random number generation algorithm) to a class constructor. You can supply the seed value either explicitly or implicitly: + +- The constructor uses an explicit seed value that you supply. + +- The constructor uses the default seed value. This is the most common way of instantiating the random number generator. + In .NET Framework, the default seed value is time-dependent. In .NET Core, the default seed value is produced by the thread-static, pseudo-random number generator. - - If the same seed is used for separate objects, they will generate the same series of random numbers. This can be useful for creating a test suite that processes random values, or for replaying games that derive their data from random numbers. However, note that objects in processes running under different versions of the .NET Framework may return different series of random numbers even if they're instantiated with identical seed values. - - To produce different sequences of random numbers, you can make the seed value time-dependent, thereby producing a different series with each new instance of . The parameterized constructor can take an value based on the number of ticks in the current time, whereas the parameterless constructor uses the system clock to generate its seed value. However, on the .NET Framework only, because the clock has finite resolution, using the parameterless constructor to create different objects in close succession creates random number generators that produce identical sequences of random numbers. The following example illustrates how two objects that are instantiated in close succession in a .NET Framework application generate an identical series of random numbers. On most Windows systems, objects created within 15 milliseconds of one another are likely to have identical seed values. - + + If the same seed is used for separate objects, they will generate the same series of random numbers. This can be useful for creating a test suite that processes random values, or for replaying games that derive their data from random numbers. However, note that objects in processes running under different versions of the .NET Framework may return different series of random numbers even if they're instantiated with identical seed values. + + To produce different sequences of random numbers, you can make the seed value time-dependent, thereby producing a different series with each new instance of . The parameterized constructor can take an value based on the number of ticks in the current time, whereas the parameterless constructor uses the system clock to generate its seed value. However, on the .NET Framework only, because the clock has finite resolution, using the parameterless constructor to create different objects in close succession creates random number generators that produce identical sequences of random numbers. The following example illustrates how two objects that are instantiated in close succession in a .NET Framework application generate an identical series of random numbers. On most Windows systems, objects created within 15 milliseconds of one another are likely to have identical seed values. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Random/cpp/random1.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Random/Overview/Random1.cs" interactive="try-dotnet-method" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/Random1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Random/vb/Random1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Random/vb/Random1.vb" id="Snippet1"::: + To avoid this problem, create a single object instead of multiple objects. Note that the `Random` class in .NET Core does not have this limitation. - - -## Avoiding multiple instantiations - On the .NET Framework, initializing two random number generators in a tight loop or in rapid succession creates two random number generators that can produce identical sequences of random numbers. In most cases, this is not the developer's intent and can lead to performance issues, because instantiating and initializing a random number generator is a relatively expensive process. - - Both to improve performance and to avoid inadvertently creating separate random number generators that generate identical numeric sequences, we recommend that you create one object to generate many random numbers over time, instead of creating new objects to generate one random number. - - However, the class isn't thread safe. If you call methods from multiple threads, follow the guidelines discussed in the next section. - - -## The System.Random class and thread safety - Instead of instantiating individual objects, we recommend that you create a single instance to generate all the random numbers needed by your app. However, objects are not thread safe. If your app calls methods from multiple threads, you must use a synchronization object to ensure that only one thread can access the random number generator at a time. If you don't ensure that the object is accessed in a thread-safe way, calls to methods that return random numbers return 0. - - The following example uses the C# [lock Statement](/dotnet/csharp/language-reference/keywords/lock-statement), the F# [lock function](https://fsharp.github.io/fsharp-core-docs/reference/fsharp-core-operators.html#lock) and the Visual Basic [SyncLock statement](/dotnet/visual-basic/language-reference/statements/synclock-statement) to ensure that a single random number generator is accessed by 11 threads in a thread-safe manner. Each thread generates 2 million random numbers, counts the number of random numbers generated and calculates their sum, and then updates the totals for all threads when it finishes executing. - + + +## Avoiding multiple instantiations + On the .NET Framework, initializing two random number generators in a tight loop or in rapid succession creates two random number generators that can produce identical sequences of random numbers. In most cases, this is not the developer's intent and can lead to performance issues, because instantiating and initializing a random number generator is a relatively expensive process. + + Both to improve performance and to avoid inadvertently creating separate random number generators that generate identical numeric sequences, we recommend that you create one object to generate many random numbers over time, instead of creating new objects to generate one random number. + + However, the class isn't thread safe. If you call methods from multiple threads, follow the guidelines discussed in the next section. + + +## The System.Random class and thread safety + Instead of instantiating individual objects, we recommend that you create a single instance to generate all the random numbers needed by your app. However, objects are not thread safe. If your app calls methods from multiple threads, you must use a synchronization object to ensure that only one thread can access the random number generator at a time. If you don't ensure that the object is accessed in a thread-safe way, calls to methods that return random numbers return 0. + + The following example uses the C# [lock Statement](/dotnet/csharp/language-reference/keywords/lock-statement), the F# [lock function](https://fsharp.github.io/fsharp-core-docs/reference/fsharp-core-operators.html#lock) and the Visual Basic [SyncLock statement](/dotnet/visual-basic/language-reference/statements/synclock-statement) to ensure that a single random number generator is accessed by 11 threads in a thread-safe manner. Each thread generates 2 million random numbers, counts the number of random numbers generated and calculates their sum, and then updates the totals for all threads when it finishes executing. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Random/cpp/threadsafeex1.cpp" id="Snippet3"::: :::code language="csharp" source="~/snippets/csharp/System/Random/Overview/threadsafeex1.cs" id="Snippet3"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/threadsafeex1.fs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Random/vb/threadsafeex1.vb" id="Snippet3"::: - - The example ensures thread-safety in the following ways: - -- The attribute is used to define thread-local variables that track the total number of random numbers generated and their sum for each thread. - -- A lock (the `lock` statement in C#, the `lock` function in F# and the `SyncLock` statement in Visual Basic) protects access to the variables for the total count and sum of all random numbers generated on all threads. - -- A semaphore (the object) is used to ensure that the main thread blocks until all other threads complete execution. - -- The example checks whether the random number generator has become corrupted by determining whether two consecutive calls to random number generation methods return 0. If corruption is detected, the example uses the object to signal that all threads should be canceled. - -- Before generating each random number, each thread checks the state of the object. If cancellation is requested, the example calls the method to cancel the thread. - - The following example is identical to the first, except that it uses a object and a lambda expression instead of objects. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Random/vb/threadsafeex1.vb" id="Snippet3"::: + + The example ensures thread-safety in the following ways: + +- The attribute is used to define thread-local variables that track the total number of random numbers generated and their sum for each thread. + +- A lock (the `lock` statement in C#, the `lock` function in F# and the `SyncLock` statement in Visual Basic) protects access to the variables for the total count and sum of all random numbers generated on all threads. + +- A semaphore (the object) is used to ensure that the main thread blocks until all other threads complete execution. + +- The example checks whether the random number generator has become corrupted by determining whether two consecutive calls to random number generation methods return 0. If corruption is detected, the example uses the object to signal that all threads should be canceled. + +- Before generating each random number, each thread checks the state of the object. If cancellation is requested, the example calls the method to cancel the thread. + + The following example is identical to the first, except that it uses a object and a lambda expression instead of objects. + :::code language="csharp" source="~/snippets/csharp/System/Random/Overview/threadsafeex2.cs" id="Snippet4"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/threadsafeex2.fs" id="Snippet4"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Random/vb/threadsafeex2.vb" id="Snippet4"::: - - It differs from the first example in the following ways: - -- The variables to keep track of the number of random numbers generated and their sum in each task are local to the task, so there is no need to use the attribute. - -- The static method is used to ensure that the main thread doesn't complete before all tasks have finished. There is no need for the object. - -- The exception that results from task cancellation is surfaced in the method. In the previous example, it is handled by each thread. - - -## Generating different types of random numbers - The random number generator provides methods that let you generate the following kinds of random numbers: - -- A series of values. You determine the number of byte values by passing an array initialized to the number of elements you want the method to return to the method. The following example generates 20 bytes. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Random/vb/threadsafeex2.vb" id="Snippet4"::: + + It differs from the first example in the following ways: + +- The variables to keep track of the number of random numbers generated and their sum in each task are local to the task, so there is no need to use the attribute. + +- The static method is used to ensure that the main thread doesn't complete before all tasks have finished. There is no need for the object. + +- The exception that results from task cancellation is surfaced in the method. In the previous example, it is handled by each thread. + + +## Generating different types of random numbers + The random number generator provides methods that let you generate the following kinds of random numbers: + +- A series of values. You determine the number of byte values by passing an array initialized to the number of elements you want the method to return to the method. The following example generates 20 bytes. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Random/cpp/nextbytes1.cpp" id="Snippet5"::: :::code language="csharp" source="~/snippets/csharp/System/Random/Overview/nextbytes1.cs" interactive="try-dotnet-method" id="Snippet5"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/nextbytes1.fs" id="Snippet5"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Random/vb/nextbytes1.vb" id="Snippet5"::: - -- A single integer. You can choose whether you want an integer from 0 to a maximum value ( - 1) by calling the method, an integer between 0 and a specific value by calling the method, or an integer within a range of values by calling the method. In the parameterized overloads, the specified maximum value is exclusive; that is, the actual maximum number generated is one less than the specified value. - - The following example calls the method to generate 10 random numbers between -10 and 10. Note that the second argument to the method specifies the exclusive upper bound of the range of random values returned by the method. In other words, the largest integer that the method can return is one less than this value. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Random/vb/nextbytes1.vb" id="Snippet5"::: + +- A single integer. You can choose whether you want an integer from 0 to a maximum value ( - 1) by calling the method, an integer between 0 and a specific value by calling the method, or an integer within a range of values by calling the method. In the parameterized overloads, the specified maximum value is exclusive; that is, the actual maximum number generated is one less than the specified value. + + The following example calls the method to generate 10 random numbers between -10 and 10. Note that the second argument to the method specifies the exclusive upper bound of the range of random values returned by the method. In other words, the largest integer that the method can return is one less than this value. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Random/cpp/nextex1.cpp" id="Snippet6"::: :::code language="csharp" source="~/snippets/csharp/System/Random/Overview/nextex1.cs" interactive="try-dotnet-method" id="Snippet6"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/nextex1.fs" id="Snippet6"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Random/vb/nextex1.vb" id="Snippet6"::: - -- A single floating-point value from 0.0 to less than 1.0 by calling the method. The exclusive upper bound of the random number returned by the method is 1, so its actual upper bound is 0.99999999999999978. The following example generates 10 random floating-point numbers. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Random/vb/nextex1.vb" id="Snippet6"::: + +- A single floating-point value from 0.0 to less than 1.0 by calling the method. The exclusive upper bound of the random number returned by the method is 1, so its actual upper bound is 0.99999999999999978. The following example generates 10 random floating-point numbers. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Random/cpp/nextdoubleex1.cpp" id="Snippet7"::: :::code language="csharp" source="~/snippets/csharp/System/Random/Overview/nextdoubleex1.cs" interactive="try-dotnet-method" id="Snippet7"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/nextdoubleex1.fs" id="Snippet7"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Random/vb/nextdoubleex1.vb" id="Snippet7"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Random/vb/nextdoubleex1.vb" id="Snippet7"::: + > [!IMPORTANT] -> The method allows you to specify the range of the returned random number. However, the `maxValue` parameter, which specifies the upper range returned number, is an exclusive, not an inclusive, value. This means that the method call `Next(0, 100)` returns a value between 0 and 99, and not between 0 and 100. - - You can also use the class for such tasks as generating [random T:System.Boolean values](#Boolean), generating [random floating point values with a range other than 0 to 1](#Floats), generating [random 64-bit integers](#Long), and [randomly retrieving a unique element from an array or collection](#UniqueArray). For these and other common tasks, see the [How do you use System.Random to…](#Operations) section. - - -## Substituting your own algorithm - You can implement your own random number generator by inheriting from the class and supplying your random number generation algorithm. To supply your own algorithm, you must override the method, which implements the random number generation algorithm. You should also override the , , and methods to ensure that they call your overridden method. You don't have to override the and methods. - - For an example that derives from the class and modifies its default pseudo-random number generator, see the reference page. - - +> The method allows you to specify the range of the returned random number. However, the `maxValue` parameter, which specifies the upper range returned number, is an exclusive, not an inclusive, value. This means that the method call `Next(0, 100)` returns a value between 0 and 99, and not between 0 and 100. + + You can also use the class for such tasks as generating [random T:System.Boolean values](#Boolean), generating [random floating point values with a range other than 0 to 1](#Floats), generating [random 64-bit integers](#Long), and [randomly retrieving a unique element from an array or collection](#UniqueArray). For these and other common tasks, see the [How do you use System.Random to…](#Operations) section. + + +## Substituting your own algorithm + You can implement your own random number generator by inheriting from the class and supplying your random number generation algorithm. To supply your own algorithm, you must override the method, which implements the random number generation algorithm. You should also override the , , and methods to ensure that they call your overridden method. You don't have to override the and methods. + + For an example that derives from the class and modifies its default pseudo-random number generator, see the reference page. + + ## How do you use System.Random to... - The following sections discuss and provide sample code for some of the ways you might want to use random numbers in your app. - - -### Retrieve the same sequence of random values - Sometimes you want to generate the same sequence of random numbers in software test scenarios and in game playing. Testing with the same sequence of random numbers allows you to detect regressions and confirm bug fixes. Using the same sequence of random number in games allows you to replay previous games. - - You can generate the same sequence of random numbers by providing the same seed value to the constructor. The seed value provides a starting value for the pseudo-random number generation algorithm. The following example uses 100100 as an arbitrary seed value to instantiate the object, displays 20 random floating-point values, and persists the seed value. It then restores the seed value, instantiates a new random number generator, and displays the same 20 random floating-point values. Note that the example may produce different sequences of random numbers if run on different versions of the .NET Framework. - + The following sections discuss and provide sample code for some of the ways you might want to use random numbers in your app. + + +### Retrieve the same sequence of random values + Sometimes you want to generate the same sequence of random numbers in software test scenarios and in game playing. Testing with the same sequence of random numbers allows you to detect regressions and confirm bug fixes. Using the same sequence of random number in games allows you to replay previous games. + + You can generate the same sequence of random numbers by providing the same seed value to the constructor. The seed value provides a starting value for the pseudo-random number generation algorithm. The following example uses 100100 as an arbitrary seed value to instantiate the object, displays 20 random floating-point values, and persists the seed value. It then restores the seed value, instantiates a new random number generator, and displays the same 20 random floating-point values. Note that the example may produce different sequences of random numbers if run on different versions of the .NET Framework. + :::code language="csharp" source="~/snippets/csharp/System/Random/Overview/same1.cs" interactive="try-dotnet" id="Snippet12"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/same1.fs" id="Snippet12"::: :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Random/cpp/same1.cpp" id="Snippet12"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Random/vb/same1.vb" id="Snippet12"::: - - -### Retrieve unique sequences of random numbers - Providing different seed values to instances of the class causes each random number generator to produce a different sequence of values. You can provide a seed value either explicitly by calling the constructor, or implicitly by calling the constructor. Most developers call the parameterless constructor, which uses the system clock. The following example uses this approach to instantiate two instances. Each instance displays a series of 10 random integers. + + +### Retrieve unique sequences of random numbers + Providing different seed values to instances of the class causes each random number generator to produce a different sequence of values. You can provide a seed value either explicitly by calling the constructor, or implicitly by calling the constructor. Most developers call the parameterless constructor, which uses the system clock. The following example uses this approach to instantiate two instances. Each instance displays a series of 10 random integers. :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Random/cpp/unique.cpp" id="Snippet13"::: :::code language="csharp" source="~/snippets/csharp/System/Random/Overview/unique.cs" interactive="try-dotnet" id="Snippet13"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/unique.fs" id="Snippet13"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Random/vb/unique.vb" id="Snippet13"::: - However, because of its finite resolution, the system clock doesn't detect time differences that are less than approximately 15 milliseconds. Therefore, if your code calls the overload on the .NET Framework to instantiate two objects in succession, you might inadvertently be providing the objects with identical seed values. (The class in .NET Core does not have this limitation.) To see this in the previous example, comment out the method call, and compile and run the example again. - - To prevent this from happening, we recommend that you instantiate a single object rather than multiple ones. However, since isn't thread safe, you must use some synchronization device if you access a instance from multiple threads; for more information, see [The Random class and thread safety](#ThreadSafety) earlier in this topic. Alternately, you can use a delay mechanism, such as the method used in the previous example, to ensure that the instantiations occur more than 15 millisecond apart. - - -### Retrieve integers in a specified range - You can retrieve integers in a specified range by calling the method, which lets you specify both the lower and the upper bound of the numbers you'd like the random number generator to return. The upper bound is an exclusive, not an inclusive, value. That is, it isn't included in the range of values returned by the method. The following example uses this method to generate random integers between -10 and 10. Note that it specifies 11, which is one greater than the desired value, as the value of the `maxValue` argument in the method call. - + However, because of its finite resolution, the system clock doesn't detect time differences that are less than approximately 15 milliseconds. Therefore, if your code calls the overload on the .NET Framework to instantiate two objects in succession, you might inadvertently be providing the objects with identical seed values. (The class in .NET Core does not have this limitation.) To see this in the previous example, comment out the method call, and compile and run the example again. + + To prevent this from happening, we recommend that you instantiate a single object rather than multiple ones. However, since isn't thread safe, you must use some synchronization device if you access a instance from multiple threads; for more information, see [The Random class and thread safety](#ThreadSafety) earlier in this topic. Alternately, you can use a delay mechanism, such as the method used in the previous example, to ensure that the instantiations occur more than 15 millisecond apart. + + +### Retrieve integers in a specified range + You can retrieve integers in a specified range by calling the method, which lets you specify both the lower and the upper bound of the numbers you'd like the random number generator to return. The upper bound is an exclusive, not an inclusive, value. That is, it isn't included in the range of values returned by the method. The following example uses this method to generate random integers between -10 and 10. Note that it specifies 11, which is one greater than the desired value, as the value of the `maxValue` argument in the method call. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Random/cpp/range1.cpp" id="Snippet15"::: :::code language="csharp" source="~/snippets/csharp/System/Random/Overview/range1.cs" interactive="try-dotnet-method" id="Snippet15"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/range1.fs" id="Snippet15"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Random/vb/range1.vb" id="Snippet15"::: - - -### Retrieve integers with a specified number of digits - You can call the method to retrieve numbers with a specified number of digits. For example, to retrieve numbers with four digits (that is, numbers that range from 1000 to 9999), you call the method with a `minValue` value of 1000 and a `maxValue` value of 10000, as the following example shows. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Random/vb/range1.vb" id="Snippet15"::: + + +### Retrieve integers with a specified number of digits + You can call the method to retrieve numbers with a specified number of digits. For example, to retrieve numbers with four digits (that is, numbers that range from 1000 to 9999), you call the method with a `minValue` value of 1000 and a `maxValue` value of 10000, as the following example shows. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Random/cpp/range2.cpp" id="Snippet16"::: :::code language="csharp" source="~/snippets/csharp/System/Random/Overview/range2.cs" interactive="try-dotnet-method" id="Snippet16"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/range2.fs" id="Snippet16"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Random/vb/range2.vb" id="Snippet16"::: - - -### Retrieve floating-point values in a specified range - The method returns random floating-point values that range from 0 to less than 1. However, you'll often want to generate random values in some other range. - - If the interval between the minimum and maximum desired values is 1, you can add the difference between the desired starting interval and 0 to the number returned by the method. The following example does this to generate 10 random numbers between -1 and 0. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Random/vb/range2.vb" id="Snippet16"::: + + +### Retrieve floating-point values in a specified range + The method returns random floating-point values that range from 0 to less than 1. However, you'll often want to generate random values in some other range. + + If the interval between the minimum and maximum desired values is 1, you can add the difference between the desired starting interval and 0 to the number returned by the method. The following example does this to generate 10 random numbers between -1 and 0. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Random/cpp/doublerange2.cpp" id="Snippet17"::: :::code language="csharp" source="~/snippets/csharp/System/Random/Overview/doublerange2.cs" interactive="try-dotnet-method" id="Snippet17"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/doublerange2.fs" id="Snippet17"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Random/vb/doublerange2.vb" id="Snippet17"::: - - To generate random floating-point numbers whose lower bound is 0 but upper bound is greater than 1 (or, in the case of negative numbers, whose lower bound is less than -1 and upper bound is 0), multiply the random number by the non-zero bound. The following example does this to generate 20 million random floating-point numbers that range from 0 to . In also displays the distribution of the random values generated by the method. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Random/vb/doublerange2.vb" id="Snippet17"::: + + To generate random floating-point numbers whose lower bound is 0 but upper bound is greater than 1 (or, in the case of negative numbers, whose lower bound is less than -1 and upper bound is 0), multiply the random number by the non-zero bound. The following example does this to generate 20 million random floating-point numbers that range from 0 to . In also displays the distribution of the random values generated by the method. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Random/cpp/doublerange1.cpp" id="Snippet18"::: :::code language="csharp" source="~/snippets/csharp/System/Random/Overview/doublerange1.cs" interactive="try-dotnet-method" id="Snippet18"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/doublerange1.fs" id="Snippet18"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Random/vb/doublerange1.vb" id="Snippet18"::: - - To generate random floating-point numbers between two arbitrary values, like the method does for integers, use the following formula: - -```csharp -Random.NextDouble() * (maxValue - minValue) + minValue -``` - - The following example generates 1 million random numbers that range from 10.0 to 11.0, and displays their distribution. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Random/vb/doublerange1.vb" id="Snippet18"::: + + To generate random floating-point numbers between two arbitrary values, like the method does for integers, use the following formula: + +```csharp +Random.NextDouble() * (maxValue - minValue) + minValue +``` + + The following example generates 1 million random numbers that range from 10.0 to 11.0, and displays their distribution. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Random/cpp/doublerange3.cpp" id="Snippet19"::: :::code language="csharp" source="~/snippets/csharp/System/Random/Overview/doublerange3.cs" interactive="try-dotnet-method" id="Snippet19"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/doublerange3.fs" id="Snippet19"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Random/vb/doublerange3.vb" id="Snippet19"::: - - -### Generate random Boolean values - The class doesn't provide methods that generate values. However, you can define your own class or method to do that. The following example defines a class, `BooleanGenerator`, with a single method, `NextBoolean`. The `BooleanGenerator` class stores a object as a private variable. The `NextBoolean` method calls the method and passes the result to the method. Note that 2 is used as the argument to specify the upper bound of the random number. Since this is an exclusive value, the method call returns either 0 or 1. + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Random/vb/doublerange3.vb" id="Snippet19"::: + + +### Generate random Boolean values + The class doesn't provide methods that generate values. However, you can define your own class or method to do that. The following example defines a class, `BooleanGenerator`, with a single method, `NextBoolean`. The `BooleanGenerator` class stores a object as a private variable. The `NextBoolean` method calls the method and passes the result to the method. Note that 2 is used as the argument to specify the upper bound of the random number. Since this is an exclusive value, the method call returns either 0 or 1. :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Random/cpp/booleans1.cpp" id="Snippet8"::: :::code language="csharp" source="~/snippets/csharp/System/Random/Overview/booleans1.cs" interactive="try-dotnet" id="Snippet8"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/booleans1.fs" id="Snippet8"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Random/vb/booleans1.vb" id="Snippet8"::: - - Instead of creating a separate class to generate random values, the example could simply have defined a single method. In that case, however, the object should have been defined as a class-level variable to avoid instantiating a new instance in each method call. In Visual Basic, the Random instance can be defined as a [Static](/dotnet/visual-basic/language-reference/modifiers/static) variable in the `NextBoolean` method. The following example provides an implementation. - + + Instead of creating a separate class to generate random values, the example could simply have defined a single method. In that case, however, the object should have been defined as a class-level variable to avoid instantiating a new instance in each method call. In Visual Basic, the Random instance can be defined as a [Static](/dotnet/visual-basic/language-reference/modifiers/static) variable in the `NextBoolean` method. The following example provides an implementation. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Random/cpp/booleans2.cpp" id="Snippet20"::: :::code language="csharp" source="~/snippets/csharp/System/Random/Overview/booleans2.cs" interactive="try-dotnet-method" id="Snippet20"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/booleans2.fs" id="Snippet20"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Random/vb/booleans2.vb" id="Snippet20"::: - - -### Generate random 64-bit integers - The overloads of the method return 32-bit integers. However, in some cases, you might want to work with 64-bit integers. You can do this as follows: - -1. Call the method to retrieve a double-precision floating point value. - -2. Multiply that value by . - - The following example uses this technique to generate 20 million random long integers and categorizes them in 10 equal groups. It then evaluates the distribution of the random numbers by counting the number in each group from 0 to . As the output from the example shows, the numbers are distributed more or less equally through the range of a long integer. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Random/vb/booleans2.vb" id="Snippet20"::: + + +### Generate random 64-bit integers + The overloads of the method return 32-bit integers. However, in some cases, you might want to work with 64-bit integers. You can do this as follows: + +1. Call the method to retrieve a double-precision floating point value. + +2. Multiply that value by . + + The following example uses this technique to generate 20 million random long integers and categorizes them in 10 equal groups. It then evaluates the distribution of the random numbers by counting the number in each group from 0 to . As the output from the example shows, the numbers are distributed more or less equally through the range of a long integer. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Random/cpp/long1.cpp" id="Snippet14"::: :::code language="csharp" source="~/snippets/csharp/System/Random/Overview/long1.cs" interactive="try-dotnet-method" id="Snippet14"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/long1.fs" id="Snippet14"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Random/vb/long1.vb" id="Snippet14"::: - - An alternative technique that uses bit manipulation does not generate truly random numbers. This technique calls to generate two integers, left-shifts one by 32 bits, and ORs them together. This technique has two limitations: - -1. Because bit 31 is the sign bit, the value in bit 31 of the resulting long integer is always 0. This can be addressed by generating a random 0 or 1, left-shifting it 31 bits, and ORing it with the original random long integer. - -2. More seriously, because the probability that the value returned by will be 0, there will be few if any random numbers in the range 0x0-0x00000000FFFFFFFF. - - -### Retrieve bytes in a specified range - The overloads of the method allow you to specify the range of random numbers, but the method does not. The following example implements a `NextBytes` method that lets you specify the range of the returned bytes. It defines a `Random2` class that derives from and overloads its `NextBytes` method. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Random/vb/long1.vb" id="Snippet14"::: + + An alternative technique that uses bit manipulation does not generate truly random numbers. This technique calls to generate two integers, left-shifts one by 32 bits, and ORs them together. This technique has two limitations: + +1. Because bit 31 is the sign bit, the value in bit 31 of the resulting long integer is always 0. This can be addressed by generating a random 0 or 1, left-shifting it 31 bits, and ORing it with the original random long integer. + +2. More seriously, because the probability that the value returned by will be 0, there will be few if any random numbers in the range 0x0-0x00000000FFFFFFFF. + + +### Retrieve bytes in a specified range + The overloads of the method allow you to specify the range of random numbers, but the method does not. The following example implements a `NextBytes` method that lets you specify the range of the returned bytes. It defines a `Random2` class that derives from and overloads its `NextBytes` method. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Random/cpp/bytes1.cpp" id="Snippet9"::: :::code language="csharp" source="~/snippets/csharp/System/Random/Overview/bytes1.cs" interactive="try-dotnet" id="Snippet9"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/bytes1.fs" id="Snippet9"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Random/vb/bytes1.vb" id="Snippet9"::: - The `NextBytes(Byte[], Byte, Byte)` method wraps a call to the method and specifies the minimum value and one greater than the maximum value (in this case, 0 and 101) that we want returned in the byte array. Because we are sure that the integer values returned by the method are within the range of the data type, we can safely cast them (in C# and F#) or convert them (in Visual Basic) from integers to bytes. - - -### Retrieve an element from an array or collection at random - Random numbers often serve as indexes to retrieve values from arrays or collections. To retrieve a random index value, you can call the method, and use the lower bound of the array as the value of its `minValue` argument and one greater than the upper bound of the array as the value of its `maxValue` argument. For a zero-based array, this is equivalent to its property, or one greater than the value returned by the method. The following example randomly retrieves the name of a city in the United States from an array of cities. - + The `NextBytes(Byte[], Byte, Byte)` method wraps a call to the method and specifies the minimum value and one greater than the maximum value (in this case, 0 and 101) that we want returned in the byte array. Because we are sure that the integer values returned by the method are within the range of the data type, we can safely cast them (in C# and F#) or convert them (in Visual Basic) from integers to bytes. + + +### Retrieve an element from an array or collection at random + Random numbers often serve as indexes to retrieve values from arrays or collections. To retrieve a random index value, you can call the method, and use the lower bound of the array as the value of its `minValue` argument and one greater than the upper bound of the array as the value of its `maxValue` argument. For a zero-based array, this is equivalent to its property, or one greater than the value returned by the method. The following example randomly retrieves the name of a city in the United States from an array of cities. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Random/cpp/array1.cpp" id="Snippet10"::: :::code language="csharp" source="~/snippets/csharp/System/Random/Overview/array1.cs" interactive="try-dotnet-method" id="Snippet10"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/array1.fs" id="Snippet10"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Random/vb/array1.vb" id="Snippet10"::: - - -### Retrieve a unique element from an array or collection - A random number generator can always return duplicate values. As the range of numbers becomes smaller or the number of values generated becomes larger, the probability of duplicates grows. If random values must be unique, more numbers are generated to compensate for duplicates, resulting in increasingly poor performance. - - There are a number of techniques to handle this scenario. One common solution is to create an array or collection that contains the values to be retrieved, and a parallel array that contains random floating-point numbers. The second array is populated with random numbers at the time the first array is created, and the method is used to sort the first array by using the values in the parallel array. - - For example, if you're developing a Solitaire game, you want to ensure that each card is used only once. Instead of generating random numbers to retrieve a card and tracking whether that card has already been dealt, you can create a parallel array of random numbers that can be used to sort the deck. Once the deck is sorted, your app can maintain a pointer to indicate the index of the next card on the deck. - - The following example illustrates this approach. It defines a `Card` class that represents a playing card and a `Dealer` class that deals a deck of shuffled cards. The `Dealer` class constructor populates two arrays: a `deck` array that has class scope and that represents all the cards in the deck; and a local `order` array that has the same number of elements as the `deck` array and is populated with randomly generated values. The method is then called to sort the `deck` array based on the values in the `order` array. + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Random/vb/array1.vb" id="Snippet10"::: + + +### Retrieve a unique element from an array or collection + A random number generator can always return duplicate values. As the range of numbers becomes smaller or the number of values generated becomes larger, the probability of duplicates grows. If random values must be unique, more numbers are generated to compensate for duplicates, resulting in increasingly poor performance. + + There are a number of techniques to handle this scenario. One common solution is to create an array or collection that contains the values to be retrieved, and a parallel array that contains random floating-point numbers. The second array is populated with random numbers at the time the first array is created, and the method is used to sort the first array by using the values in the parallel array. + + For example, if you're developing a Solitaire game, you want to ensure that each card is used only once. Instead of generating random numbers to retrieve a card and tracking whether that card has already been dealt, you can create a parallel array of random numbers that can be used to sort the deck. Once the deck is sorted, your app can maintain a pointer to indicate the index of the next card on the deck. + + The following example illustrates this approach. It defines a `Card` class that represents a playing card and a `Dealer` class that deals a deck of shuffled cards. The `Dealer` class constructor populates two arrays: a `deck` array that has class scope and that represents all the cards in the deck; and a local `order` array that has the same number of elements as the `deck` array and is populated with randomly generated values. The method is then called to sort the `deck` array based on the values in the `order` array. :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Random/cpp/uniquearray1.cpp" id="Snippet11"::: :::code language="csharp" source="~/snippets/csharp/System/Random/Overview/uniquearray1.cs" interactive="try-dotnet" id="Snippet11"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/uniquearray1.fs" id="Snippet11"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Random/vb/uniquearray1.vb" id="Snippet11"::: - -## Examples - The following example creates a single random number generator and calls its , , and methods to generate sequences of random numbers within different ranges. - +## Examples + + The following example creates a single random number generator and calls its , , and methods to generate sequences of random numbers within different ranges. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Random/cpp/random2.cpp" id="Snippet2"::: :::code language="csharp" source="~/snippets/csharp/System/Random/Overview/Random2.cs" interactive="try-dotnet-method" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Random/fs/Random2.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Random/vb/Random2.vb" id="Snippet2"::: - - The following example generates a random integer that it uses as an index to retrieve a string value from an array. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Random/vb/Random2.vb" id="Snippet2"::: + + The following example generates a random integer that it uses as an index to retrieve a string value from an array. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Random.Next/CPP/next1.cpp" id="Snippet3"::: :::code language="csharp" source="~/snippets/csharp/System/Random/Overview/next1.cs" interactive="try-dotnet-method" id="Snippet3"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Random.Next/FS/next1.fs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Random.Next/VB/next1.vb" id="Snippet3"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Random.Next/VB/next1.vb" id="Snippet3"::: + ]]> - In the .NET Framework 1.0 and 1.1, a minimum implementation of a class derived from required overriding the method to define a new or modified algorithm for generating random numbers. The derived class could then rely on the base class implementation of the , , , , and methods to call the derived class implementation of the method. - - In the .NET Framework 2.0 and later, the behavior of the , , and methods have changed so that these methods do not necessarily call the derived class implementation of the method. As a result, classes derived from that target the .NET Framework 2.0 and later should also override these three methods. + In the .NET Framework 1.0 and 1.1, a minimum implementation of a class derived from required overriding the method to define a new or modified algorithm for generating random numbers. The derived class could then rely on the base class implementation of the , , , , and methods to call the derived class implementation of the method. In the .NET Framework 2.0 and later, the behavior of the , , and methods have changed so that these methods do not necessarily call the derived class implementation of the method. As a result, classes derived from that target the .NET Framework 2.0 and later should also override these three methods. The implementation of the random number generator in the class isn't guaranteed to remain the same across major versions of the .NET Framework. As a result, you shouldn't assume that the same seed will result in the same pseudo-random sequence in different versions of the .NET Framework. @@ -428,23 +426,23 @@ Random.NextDouble() * (maxValue - minValue) + minValue Initializes a new instance of the class using a default seed value. - objects that are created in close succession by a call to the parameterless constructor have identical default seed values and, therefore, produce identical sets of random numbers. You can avoid this problem by using a single object to generate all random numbers. You can also work around it by generating your own random seed value and passing it to the constructor. For more information, see the constructor. +In .NET Framework, the default seed value is derived from the system clock, which has finite resolution. As a result, different objects that are created in close succession by a call to the parameterless constructor have identical default seed values and, therefore, produce identical sets of random numbers. You can avoid this problem by using a single object to generate all random numbers. You can also work around it by generating your own random seed value and passing it to the constructor. For more information, see the constructor. In .NET Core, the default seed value is produced by the thread-static, pseudo-random number generator, so the previously described limitation does not apply. Different objects created in close succession produce different sets of random numbers in .NET Core. - - Call this constructor if you want your random number generator to generate a random sequence of numbers. To generate a fixed sequence of random numbers that will be the same for different random number generators, call the constructor with a fixed seed value. This constructor overload is frequently used when testing apps that use random numbers. - - Once you've instantiated the random number generator, you call individual methods, such as or , to generate random numbers. - - - + + Call this constructor if you want your random number generator to generate a random sequence of numbers. To generate a fixed sequence of random numbers that will be the same for different random number generators, call the constructor with a fixed seed value. This constructor overload is frequently used when testing apps that use random numbers. + + Once you've instantiated the random number generator, you call individual methods, such as or , to generate random numbers. + + + ## Examples -The following example uses the parameterless constructor to instantiate three objects and displays a sequence of five random integers for each. If it is run on .NET Framework, because the first two objects are created in close succession, they are instantiated using identical seed values based on the system clock and, therefore, they produce an identical sequence of random numbers. On the other hand, the parameterless constructor of the third object is called after a two-second delay caused by calling the method. Because this produces a different seed value for the third object, it produces a different sequence of random numbers. - +The following example uses the parameterless constructor to instantiate three objects and displays a sequence of five random integers for each. If it is run on .NET Framework, because the first two objects are created in close succession, they are instantiated using identical seed values based on the system clock and, therefore, they produce an identical sequence of random numbers. On the other hand, the parameterless constructor of the third object is called after a two-second delay caused by calling the method. Because this produces a different seed value for the third object, it produces a different sequence of random numbers. + :::code language="csharp" source="~/snippets/csharp/System/Random/.ctor/ctor1.cs" interactive="try-dotnet" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Random.Ctor/FS/ctor1.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Random.Ctor/VB/ctor1.vb" id="Snippet2"::: @@ -496,28 +494,28 @@ The following example uses the parameterless constructor to instantiate three A number used to calculate a starting value for the pseudo-random number sequence. If a negative number is specified, the absolute value of the number is used. Initializes a new instance of the class, using the specified seed value. - objects causes each instance to produce identical sequences of random numbers. This is often done when testing apps that rely on random number generators. - - If your application requires different random number sequences, invoke this constructor repeatedly with different seed values. One way to produce a unique seed value is to make it time-dependent. For example, derive the seed value from the system clock, as the overload does. However, the system clock might not have sufficient resolution to provide different invocations of this constructor with a different seed value. On the .NET Framework, this results in random number generators that generate identical sequences of pseudo-random numbers, as illustrated by the first two objects in the following example. To prevent this, apply an algorithm to differentiate the seed value in each invocation, or call the method to ensure that you provide each constructor with a different seed value. - + objects causes each instance to produce identical sequences of random numbers. This is often done when testing apps that rely on random number generators. + + If your application requires different random number sequences, invoke this constructor repeatedly with different seed values. One way to produce a unique seed value is to make it time-dependent. For example, derive the seed value from the system clock, as the overload does. However, the system clock might not have sufficient resolution to provide different invocations of this constructor with a different seed value. On the .NET Framework, this results in random number generators that generate identical sequences of pseudo-random numbers, as illustrated by the first two objects in the following example. To prevent this, apply an algorithm to differentiate the seed value in each invocation, or call the method to ensure that you provide each constructor with a different seed value. + :::code language="csharp" source="~/snippets/csharp/System/Random/.ctor/ctor4.cs" interactive="try-dotnet" id="Snippet4"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Random.Ctor/FS/ctor4.fs" id="Snippet4"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Random.Ctor/VB/ctor4.vb" id="Snippet4"::: - - Another option is to instantiate a single object that you use to generate all the random numbers in your application. This yields slightly better performance, since instantiating a random number generator is fairly expensive. - - - -## Examples - The following example creates objects with the class constructor that takes a seed parameter and generates a sequence of random integers and doubles. The example illustrates that the same sequence is generated when the object is created again with the constructor and seed parameter. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Random.Ctor/VB/ctor4.vb" id="Snippet4"::: + + Another option is to instantiate a single object that you use to generate all the random numbers in your application. This yields slightly better performance, since instantiating a random number generator is fairly expensive. + + + +## Examples + The following example creates objects with the class constructor that takes a seed parameter and generates a sequence of random integers and doubles. The example illustrates that the same sequence is generated when the object is created again with the constructor and seed parameter. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Random.Ctor/CPP/ctor.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Random/.ctor/ctor.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Random.Ctor/FS/ctor.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Random.Ctor/VB/ctor.vb" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Random.Ctor/VB/ctor.vb" id="Snippet1"::: ]]> @@ -758,27 +756,27 @@ The following example uses the parameterless constructor to instantiate three Returns a non-negative random integer. A 32-bit signed integer that is greater than or equal to 0 and less than Int32.MaxValue. - generates a random number whose value ranges from 0 to less than . To generate a random number whose value ranges from 0 to some other positive number, use the method overload. To generate a random number within a different range, use the method overload. - - - -## Examples - The following example makes repeated calls to the method to generate a specific number of random numbers requested by the user. The method is used to get customer input. - + generates a random number whose value ranges from 0 to less than . To generate a random number whose value ranges from 0 to some other positive number, use the method overload. To generate a random number within a different range, use the method overload. + + + +## Examples + The following example makes repeated calls to the method to generate a specific number of random numbers requested by the user. The method is used to get customer input. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Random.Next/CPP/next3.cpp" id="Snippet5"::: :::code language="csharp" source="~/snippets/csharp/System/Random/Overview/next3.cs" interactive="try-dotnet-method" id="Snippet5"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Random.Next/FS/next3.fs" id="Snippet5"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Random.Next/VB/next3.vb" id="Snippet5"::: - - The following example derives a class from to generate a sequence of random numbers whose distribution differs from the uniform distribution generated by the method of the base class. It overrides the method to provide the distribution of random numbers, and overrides the method to use series of random numbers. - + + The following example derives a class from to generate a sequence of random numbers whose distribution differs from the uniform distribution generated by the method of the base class. It overrides the method to provide the distribution of random numbers, and overrides the method to use series of random numbers. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Random.Sample/cpp/sampleex.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Random/Next/sample.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Random.Sample/VB/sample.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Random.Sample/VB/sample.vb" id="Snippet1"::: + ]]> @@ -834,28 +832,28 @@ The following example uses the parameterless constructor to instantiate three Returns a non-negative random integer that is less than the specified maximum. A 32-bit signed integer that is greater than or equal to 0, and less than ; that is, the range of return values ordinarily includes 0 but not . However, if equals 0, 0 is returned. - overload returns random integers that range from 0 to `maxValue` - 1. However, if `maxValue` is 0, the method returns 0. - - - -## Examples - The following example generates random integers with various overloads of the method. + overload returns random integers that range from 0 to `maxValue` - 1. However, if `maxValue` is 0, the method returns 0. + + + +## Examples + The following example generates random integers with various overloads of the method. :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Random.Next/CPP/next.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Random/Overview/next.cs" interactive="try-dotnet-method" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Random.Next/FS/next.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Random.Next/VB/next.vb" id="Snippet1"::: - - The following example generates a random integer that it uses as an index to retrieve a string value from an array. Because the highest index of the array is one less than its length, the value of the property is supplied as a the `maxValue` parameter. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Random.Next/VB/next.vb" id="Snippet1"::: + + The following example generates a random integer that it uses as an index to retrieve a string value from an array. Because the highest index of the array is one less than its length, the value of the property is supplied as a the `maxValue` parameter. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Random.Next/CPP/next1.cpp" id="Snippet3"::: :::code language="csharp" source="~/snippets/csharp/System/Random/Overview/next1.cs" interactive="try-dotnet-method" id="Snippet3"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Random.Next/FS/next1.fs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Random.Next/VB/next1.vb" id="Snippet3"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Random.Next/VB/next1.vb" id="Snippet3"::: + ]]> @@ -912,30 +910,30 @@ The following example uses the parameterless constructor to instantiate three Returns a random integer that is within a specified range. A 32-bit signed integer greater than or equal to and less than ; that is, the range of return values includes but not . If equals , is returned. - overload returns random integers that range from `minValue` to `maxValue` - 1. However, if `maxValue` equals `minValue`, the method returns `minValue`. - - Unlike the other overloads of the method, which return only non-negative values, this method can return a negative random integer. - - - -## Examples - The following example uses the method to generate random integers with three distinct ranges. Note that the exact output from the example depends on the system-supplied seed value passed to the class constructor. - + overload returns random integers that range from `minValue` to `maxValue` - 1. However, if `maxValue` equals `minValue`, the method returns `minValue`. + + Unlike the other overloads of the method, which return only non-negative values, this method can return a negative random integer. + + + +## Examples + The following example uses the method to generate random integers with three distinct ranges. Note that the exact output from the example depends on the system-supplied seed value passed to the class constructor. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Random.Next/CPP/next2.cpp" id="Snippet2"::: :::code language="csharp" source="~/snippets/csharp/System/Random/Overview/Next2.cs" interactive="try-dotnet-method" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Random.Next/FS/Next2.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Random.Next/VB/next2.vb" id="Snippet2"::: - - The following example generates a random integer that it uses as an index to retrieve a string value from an array. Because the highest index of the array is one less than its length, the value of the property is supplied as a the `maxValue` parameter. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Random.Next/VB/next2.vb" id="Snippet2"::: + + The following example generates a random integer that it uses as an index to retrieve a string value from an array. Because the highest index of the array is one less than its length, the value of the property is supplied as a the `maxValue` parameter. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Random.Next/CPP/next4.cpp" id="Snippet4"::: :::code language="csharp" source="~/snippets/csharp/System/Random/Overview/next4.cs" interactive="try-dotnet-method" id="Snippet4"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Random.Next/FS/next4.fs" id="Snippet4"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Random.Next/VB/next4.vb" id="Snippet4"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Random.Next/VB/next4.vb" id="Snippet4"::: + ]]> @@ -992,23 +990,23 @@ The following example uses the parameterless constructor to instantiate three The array to be filled with random numbers. Fills the elements of a specified array of bytes with random numbers. - . - - For example, to generate a cryptographically secured random number suitable for creating a random password, use a method such as . - - - + . + + For example, to generate a cryptographically secured random number suitable for creating a random password, use a method such as . + + + ## Examples - The following example demonstrates how to use the method to fill an array of bytes with random byte values. - + The following example demonstrates how to use the method to fill an array of bytes with random byte values. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_Classic/classic Random.NextBytes Example/CPP/source.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Random/NextBytes/source.cs" interactive="try-dotnet-method" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_Classic/classic Random.NextBytes Example/VB/source.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_Classic/classic Random.NextBytes Example/VB/source.vb" id="Snippet1"::: + ]]> @@ -1122,32 +1120,32 @@ Each element of the span of bytes is set to a random number greater than or equa Returns a random floating-point number that is greater than or equal to 0.0, and less than 1.0. A double-precision floating point number that is greater than or equal to 0.0, and less than 1.0. - class topic. - - This method is the public version of the protected method, . - - - -## Examples - - The following example uses the method to generate sequences of random doubles. - + class topic. + + This method is the public version of the protected method, . + + + +## Examples + + The following example uses the method to generate sequences of random doubles. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Random.Ctor/CPP/ctor.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Random/.ctor/ctor.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Random.Ctor/FS/ctor.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.Random.Ctor/VB/ctor.vb" id="Snippet1"::: - - The following example calls the method to generate 100 random numbers and displays their frequency distribution. - + + The following example calls the method to generate 100 random numbers and displays their frequency distribution. + :::code language="csharp" source="~/snippets/csharp/System/Random/NextDouble/nextdouble1.cs" interactive="try-dotnet-method" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.random.nextdouble/fs/nextdouble1.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.random.nextdouble/vb/nextdouble1.vb" id="Snippet2"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.random.nextdouble/vb/nextdouble1.vb" id="Snippet2"::: + ]]> @@ -1346,19 +1344,19 @@ Each element of the span of bytes is set to a random number greater than or equa Returns a random floating-point number between 0.0 and 1.0. A double-precision floating point number that is greater than or equal to 0.0, and less than 1.0. - class and override the method. - + class and override the method. + > [!IMPORTANT] -> The method is `protected`, which means that it is accessible only within the class and its derived classes. To generate a random number between 0 and 1 from a instance, call the method. - - - -## Examples - The following example derives a class from and overrides the method to generate a distribution of random numbers. This distribution is different than the uniform distribution generated by the method of the base class. - +> The method is `protected`, which means that it is accessible only within the class and its derived classes. To generate a random number between 0 and 1 from a instance, call the method. + + + +## Examples + The following example derives a class from and overrides the method to generate a distribution of random numbers. This distribution is different than the uniform distribution generated by the method of the base class. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.Random.Sample/cpp/sampleex.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/Random/Next/sample.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/VS_Snippets_CLR_System/system.Random.Sample/FS/sample.fs" id="Snippet1"::: @@ -1367,15 +1365,7 @@ Each element of the span of bytes is set to a random number greater than or equa ]]> - Starting with the .NET Framework version 2.0, if you derive a class from and override the method, the distribution provided by the derived class implementation of the method is not used in calls to the base class implementation of the following methods: - -- The method. - -- The method. - -- The method, if ( - ) is greater than Int32.MaxValue. - - Instead, the uniform distribution provided by the base class is used. This behavior improves the overall performance of the class. To modify this behavior to call the implementation of the method in the derived class, you must also override the behavior of these three members. The example provides an illustration. + Starting with the .NET Framework version 2.0, if you derive a class from and override the method, the distribution provided by the derived class implementation of the method is not used in calls to the base class implementation of the following methods: - The method. - The method. - The method, if ( - ) is greater than Int32.MaxValue. Instead, the uniform distribution provided by the base class is used. This behavior improves the overall performance of the class. To modify this behavior to call the implementation of the method in the derived class, you must also override the behavior of these three members. The example provides an illustration. @@ -1459,8 +1449,7 @@ Each element of the span of bytes is set to a random number greater than or equa The type of span. The span to shuffle. Performs an in-place shuffle of a span. - This method uses to choose values for shuffling. - This method is an O(n) operation. + This method uses to choose values for shuffling. This method is an O(n) operation. @@ -1504,8 +1493,7 @@ Each element of the span of bytes is set to a random number greater than or equa The type of array. The array to shuffle. Performs an in-place shuffle of an array. - This method uses to choose values for shuffling. - This method is an O(n) operation. + This method uses to choose values for shuffling. This method is an O(n) operation. is . diff --git a/xml/System/RankException.xml b/xml/System/RankException.xml index d622b3559df..1d663c1547d 100644 --- a/xml/System/RankException.xml +++ b/xml/System/RankException.xml @@ -70,13 +70,13 @@ The exception that is thrown when an array with the wrong number of dimensions is passed to a method. - uses the HRESULT COR_E_RANK, that has the value 0x80131517. - - For a list of initial property values for an instance of , see the constructors. - + uses the HRESULT COR_E_RANK, that has the value 0x80131517. + + For a list of initial property values for an instance of , see the constructors. + ]]> @@ -133,18 +133,18 @@ Initializes a new instance of the class. - property of the new instance to a system-supplied message that describes the error, such as "The two arrays must have the same number of dimensions." This message takes into account the current system culture. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The localized error message string.| - + property of the new instance to a system-supplied message that describes the error, such as "The two arrays must have the same number of dimensions." This message takes into account the current system culture. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The localized error message string.| + ]]> @@ -191,18 +191,18 @@ A that describes the error. Initializes a new instance of the class with a specified error message. - . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The error message string.| - + . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The error message string.| + ]]> @@ -264,11 +264,11 @@ The contextual information about the source or destination. Initializes a new instance of the class with serialized data. - XML and SOAP Serialization @@ -318,18 +318,18 @@ The exception that is the cause of the current exception. If the parameter is not a null reference ( in Visual Basic), the current exception is raised in a block that handles the inner exception. Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception. - property. The property returns the same value that is passed into the constructor, or a null reference (`Nothing` in Visual Basic) if the property does not supply the inner exception value to the constructor. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||The inner exception reference.| -||The error message string.| - + property. The property returns the same value that is passed into the constructor, or a null reference (`Nothing` in Visual Basic) if the property does not supply the inner exception value to the constructor. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||The inner exception reference.| +||The error message string.| + ]]> diff --git a/xml/System/ReadOnlySpan`1+Enumerator.xml b/xml/System/ReadOnlySpan`1+Enumerator.xml index 04d4f941ca2..a3c15da914d 100644 --- a/xml/System/ReadOnlySpan`1+Enumerator.xml +++ b/xml/System/ReadOnlySpan`1+Enumerator.xml @@ -66,13 +66,13 @@ ## Remarks -The C# [foreach](/dotnet/csharp/language-reference/keywords/foreach-in) of the C# language and the [For Each...Next](/dotnet/visual-basic/language-reference/statements/for-each-next-statement) construct in Visual Basic hides the complexity of enumerators. Instead of directly manipulating the enumerator, using `foreach` or `For Each...Next` is recommended. +The C# [foreach](/dotnet/csharp/language-reference/keywords/foreach-in) of the C# language and the [For Each...Next](/dotnet/visual-basic/language-reference/statements/for-each-next-statement) construct in Visual Basic hides the complexity of enumerators. Instead of directly manipulating the enumerator, using `foreach` or `For Each...Next` is recommended. Initially, the enumerator is positioned before the first element in the . At this position, is undefined. You must call to advance the enumerator to the first item in the before reading the value of . returns the same value until is called. sets to the next item in the . -If passes the end of the , returns `false`. When the enumerator is at this state, subsequent calls to also return `false` and is undefined. You cannot set to the first item in the again; you must create a new enumerator instance instead. +If passes the end of the , returns `false`. When the enumerator is at this state, subsequent calls to also return `false` and is undefined. You cannot set to the first item in the again; you must create a new enumerator instance instead. Though the is allocated on the stack, the underlying data on which the points to, may not be. Therefore, enumerating through a is intrinsically not a thread-safe procedure. To guarantee thread safety during enumeration, you must implement your own synchronization. @@ -124,11 +124,11 @@ Unlike some other enumerator structures in .NET, the must be called to advance the enumerator to the first element of the span before reading the value of `Current`. -- The last call to returned `false`, which indicates the end of the span. +- The last call to returned `false`, which indicates the end of the span. `Current` returns the same value until is called. sets `Current` to the next item in the span. @@ -170,7 +170,7 @@ Unlike some other enumerator structures in .NET, the and exceeds the number of elements in the array. - + and exceeds the number of elements in the array. @@ -551,8 +550,8 @@ This method returns `default` when `array` is `null`. Returns a read-only reference to an object of type T that can be used for pinning. - -This method is intended to support .NET compilers and is not intended to be called by user code. + + This method is intended to support .NET compilers and is not intended to be called by user code. A reference to the element of the span at index 0, or if the span is empty. Provides data for loader resolution events, such as the , , , and events. - contains information about the item to be resolved. - -- The property contains the name of the item to be resolved. - -- Beginning with the .NET Framework 4, the property contains the assembly that requested an assembly that can provide the named item. For more information, see the property. - + contains information about the item to be resolved. + +- The property contains the name of the item to be resolved. + +- Beginning with the .NET Framework 4, the property contains the assembly that requested an assembly that can provide the named item. For more information, see the property. + ]]> @@ -119,11 +119,11 @@ The name of an item to resolve. Initializes a new instance of the class, specifying the name of the item to resolve. - @@ -214,11 +214,11 @@ Gets the name of the item to resolve. The name of the item to resolve. - event, is the assembly name before policy is applied. - + event, is the assembly name before policy is applied. + ]]> @@ -269,21 +269,21 @@ Gets the assembly whose dependency is being resolved. The assembly that requested the item specified by the property. - property, because the item did not exist in that assembly, in any of its loaded dependencies, or in any dependencies the loader could find through probing. - - For example, suppose the current assembly uses the method to load assembly A from a directory outside the probing path, in order to use class CA. Suppose further that class CA uses class CB, in assembly B, and that assembly A has a compile-time reference to assembly B, also located outside the probing path. When the current assembly attempts to instantiate CA, the loader attempts to resolve the reference to assembly B. However, because assembly A was loaded by using the method, the loader cannot resolve the dependency. If there is a handler for the event, the event is raised, and the property of the resulting object contains assembly A, because assembly A is the assembly that is missing a dependency. - - The semantics of the property vary, depending on how the requesting assembly was loaded: - -- Load context: The value of the property might be `null`. The load context is load-order independent, and the identity of the requesting assembly is not necessarily meaningful. A non-null example occurs when the method is called and the specified type is not known to the requesting assembly or any of its dependencies. - -- Load-from context: The property can be used as a probing hint, but the event handler should not get more than one request for a given assembly name. - -- No context (that is, the requesting assembly was loaded by using the method, or as a byte stream, or in mixed mode): The handler can use the property to load different implementations of the same assembly based on the identity of the requesting assembly. - + property, because the item did not exist in that assembly, in any of its loaded dependencies, or in any dependencies the loader could find through probing. + + For example, suppose the current assembly uses the method to load assembly A from a directory outside the probing path, in order to use class CA. Suppose further that class CA uses class CB, in assembly B, and that assembly A has a compile-time reference to assembly B, also located outside the probing path. When the current assembly attempts to instantiate CA, the loader attempts to resolve the reference to assembly B. However, because assembly A was loaded by using the method, the loader cannot resolve the dependency. If there is a handler for the event, the event is raised, and the property of the resulting object contains assembly A, because assembly A is the assembly that is missing a dependency. + + The semantics of the property vary, depending on how the requesting assembly was loaded: + +- Load context: The value of the property might be `null`. The load context is load-order independent, and the identity of the requesting assembly is not necessarily meaningful. A non-null example occurs when the method is called and the specified type is not known to the requesting assembly or any of its dependencies. + +- Load-from context: The property can be used as a probing hint, but the event handler should not get more than one request for a given assembly name. + +- No context (that is, the requesting assembly was loaded by using the method, or as a byte stream, or in mixed mode): The handler can use the property to load different implementations of the same assembly based on the identity of the requesting assembly. + ]]> diff --git a/xml/System/ResolveEventHandler.xml b/xml/System/ResolveEventHandler.xml index 22c24d0dd24..50f61872ad6 100644 --- a/xml/System/ResolveEventHandler.xml +++ b/xml/System/ResolveEventHandler.xml @@ -75,16 +75,16 @@ Represents a method that handles the , , or event of an . The assembly that resolves the type, assembly, or resource; or if the assembly cannot be resolved. - to return the assembly that resolves the type, assembly, or resource, or to return null if the assembly is not recognized. For more information, see [Resolving Assembly Loads](/dotnet/standard/assembly/resolve-loads) and the , , and events. - + to return the assembly that resolves the type, assembly, or resource, or to return null if the assembly is not recognized. For more information, see [Resolving Assembly Loads](/dotnet/standard/assembly/resolve-loads) and the , , and events. + > [!IMPORTANT] -> Beginning with the .NET Framework 4, the event is raised for all assemblies, including resource assemblies. In earlier versions, the event was not raised for resource assemblies. If the operating system is localized, the handler might be called multiple times: once for each culture in the fallback chain. - - Every derived class of and has a constructor and an `Invoke` method. See the C++ code example in the description for the class. - +> Beginning with the .NET Framework 4, the event is raised for all assemblies, including resource assemblies. In earlier versions, the event was not raised for resource assemblies. If the operating system is localized, the handler might be called multiple times: once for each culture in the fallback chain. + + Every derived class of and has a constructor and an `Invoke` method. See the C++ code example in the description for the class. + ]]> diff --git a/xml/System/RuntimeArgumentHandle.xml b/xml/System/RuntimeArgumentHandle.xml index 7d0cf5e1511..39614c4bbaa 100644 --- a/xml/System/RuntimeArgumentHandle.xml +++ b/xml/System/RuntimeArgumentHandle.xml @@ -51,11 +51,11 @@ References a variable-length argument list. - and classes. It exists only to support C/C++ programming language functions that take a variable number of parameters. An instance of the structure is passed to the constructor. - + and classes. It exists only to support C/C++ programming language functions that take a variable number of parameters. An instance of the structure is passed to the constructor. + ]]> diff --git a/xml/System/RuntimeFieldHandle.xml b/xml/System/RuntimeFieldHandle.xml index 9baf6e149b3..623c4c5eaa9 100644 --- a/xml/System/RuntimeFieldHandle.xml +++ b/xml/System/RuntimeFieldHandle.xml @@ -72,11 +72,11 @@ Represents a field using an internal metadata token. - structure is a handle to the field represented by the instance. - + structure is a handle to the field represented by the instance. + ]]> @@ -363,13 +363,13 @@ (Reserved) The place to store and retrieve serialized data. Populates a with the data necessary to deserialize the field represented by the current instance. - method. - + method. + ]]> diff --git a/xml/System/RuntimeMethodHandle.xml b/xml/System/RuntimeMethodHandle.xml index 6347251e45e..2ca038d8913 100644 --- a/xml/System/RuntimeMethodHandle.xml +++ b/xml/System/RuntimeMethodHandle.xml @@ -290,12 +290,12 @@ Obtains a pointer to the method represented by this instance. A pointer to the method represented by this instance. - attribute, then the returned value is an unmanaged function pointer with the same calling convention as specified in the attribute. If the method this handle represents is static, then the returned value can be cast to a C# managed function pointer type with the same signature. For instance method handles, the value is not easily usable from user code and is meant exclusively for usage within the runtime. - - For methods that don't have the , use to get a function pointer that can be passed to native code. + + For methods that don't have the , use to get a function pointer that can be passed to native code. ]]> The caller does not have the necessary permission to perform this operation. @@ -413,13 +413,13 @@ (Reserved) The place to store and retrieve serialized data. Populates a with the data necessary to deserialize the field represented by this instance. - method. - + method. + ]]> diff --git a/xml/System/RuntimeTypeHandle.xml b/xml/System/RuntimeTypeHandle.xml index 250405b4a1e..4a30d086ebd 100644 --- a/xml/System/RuntimeTypeHandle.xml +++ b/xml/System/RuntimeTypeHandle.xml @@ -80,16 +80,16 @@ Represents a type using an internal metadata token. - from a type or from an object, and how to turn the handle back into a type. - + from a type or from an object, and how to turn the handle back into a type. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Type_GetTypeHandle/CPP/Type_GetTypeHandle.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/RuntimeTypeHandle/Overview/type_gettypehandle.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/RuntimeTypeHandle/Overview/type_gettypehandle.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Type_GetTypeHandle/VB/type_gettypehandle.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Type_GetTypeHandle/VB/type_gettypehandle.vb" id="Snippet1"::: + ]]> @@ -406,13 +406,13 @@ (Reserved) The location where serialized data will be stored and retrieved. Populates a with the data necessary to deserialize the type represented by the current instance. - method. - + method. + ]]> @@ -482,11 +482,11 @@ if is a structure and is equal to ; otherwise, . - causes an ambiguous overload resolution error when compiled. Use the method instead. - + causes an ambiguous overload resolution error when compiled. Use the method instead. + The equivalent method for this operator is .]]> @@ -539,11 +539,11 @@ if is a and is equal to ; otherwise, . - causes an ambiguous overload resolution error when compiled. Use the method instead. - + causes an ambiguous overload resolution error when compiled. Use the method instead. + The equivalent method for this operator is >.]]> @@ -609,11 +609,11 @@ if is a and is not equal to ; otherwise, . - causes an ambiguous overload resolution error when compiled. Use the method instead. - + causes an ambiguous overload resolution error when compiled. Use the method instead. + The equivalent method for this operator is .]]> @@ -666,11 +666,11 @@ if is a structure and is not equal to ; otherwise, . - causes an ambiguous overload resolution error when compiled. Use the method instead. - + causes an ambiguous overload resolution error when compiled. Use the method instead. + The equivalent method for this operator is .]]> diff --git a/xml/System/SByte.xml b/xml/System/SByte.xml index 1750742cb23..1a3432ccf41 100644 --- a/xml/System/SByte.xml +++ b/xml/System/SByte.xml @@ -412,25 +412,34 @@ An object to compare, or . Compares this instance to a specified object and returns an indication of their relative values. - A signed number indicating the relative values of this instance and . - - Return Value - - Description - - Less than zero - - This instance is less than . - - Zero - - This instance is equal to . - - Greater than zero - - This instance is greater than , or is . - - + A signed number indicating the relative values of this instance and . + + Return Value + + + Description + + + + + Less than zero + + + This instance is less than . + + + Zero + + + This instance is equal to . + + + Greater than zero + + + This instance is greater than , or is . + + An 8-bit signed integer to compare. Compares this instance to a specified 8-bit signed integer and returns an indication of their relative values. - A signed integer that indicates the relative order of this instance and . - - Return Value - - Description - - Less than zero - - This instance is less than . - - Zero - - This instance is equal to . - - Greater than zero - - This instance is greater than . - - + A signed integer that indicates the relative order of this instance and . + + Return Value + + + Description + + + + + Less than zero + + + This instance is less than . + + + Zero + + + This instance is equal to . + + + Greater than zero + + + This instance is greater than . + + this method matches the IEE represents a number less than SByte.MinValue or greater than SByte.MaxValue. - -or- +-or- - includes non-zero, fractional digits. + includes non-zero, fractional digits. is not a value. - -or- +-or- - is not a combination of and values. + is not a combination of and values. Parsing Numeric Strings in .NET @@ -2324,9 +2342,9 @@ For this method matches the IEE is not a value. - -or- +-or- - is not a combination of and . + is not a combination of and . is . @@ -2334,9 +2352,9 @@ For this method matches the IEE represents a number that is less than SByte.MinValue or greater than SByte.MaxValue. - -or- +-or- - includes non-zero, fractional digits. + includes non-zero, fractional digits. @@ -7002,9 +7020,9 @@ This member is an explicit interface member implementation. It can be used only is not a value. - -or- +-or- - is not a combination of and values. + is not a combination of and values. Parsing Numeric Strings in .NET diff --git a/xml/System/STAThreadAttribute.xml b/xml/System/STAThreadAttribute.xml index 47f4c522936..13e4ccc646c 100644 --- a/xml/System/STAThreadAttribute.xml +++ b/xml/System/STAThreadAttribute.xml @@ -55,36 +55,36 @@ Indicates that the COM threading model for an application is single-threaded apartment (STA). - or method before starting the thread. - + or method before starting the thread. + > [!NOTE] -> For an overview of COM threading models, see [Understanding and Using COM Threading Models](https://docs.microsoft.com/previous-versions/ms809971(v=msdn.10)). - - COM threading models only apply to applications that use COM interop. The COM threading model can be set to single-threaded apartment or multithreaded apartment. The application thread is only initialized for COM interop if the thread actually makes a call to a COM component. If COM interop is not used, then the thread is not initialized, and the attribute, if it is present, has no effect. - - Starting with the .NET Framework version 2.0, the default threading model for COM interop depends on the language in which you are developing your application, as the following table shows. - -|Language|COM apartment model| -|--------------|-------------------------| -|C#|Multithreaded apartment| -|C++|Multithreaded apartment| -|Visual Basic|Single-threaded apartment| - - To change these defaults, you use the attribute to set the threading model for the application, or call the or method before starting the thread to set the threading model for a particular thread. In C++, you can also use the [/CLRTHREADATTRIBUTE](/cpp/build/reference/clrthreadattribute-set-clr-thread-attribute) linker option to specify the apartment model. - - ASP.NET applications should set the `ASPCompat` attribute of the [@ Page](https://docs.microsoft.com/previous-versions/dotnet/netframework-4.0/ydy4x04a(v=vs.100)) directive to `true` to force the page to be serviced by the STA thread pool. - - Here are some of the cases in which you'll want to use the attribute to explicitly set the threading model to single-threaded apartment: - -- You're developing a Windows Forms app. Windows Forms apps must be single-threaded if they communicate with Windows system components such as the Clipboard or Windows common dialog boxes, or if they use system features such as drag-and-drop functionality. The Windows Forms Application template for C# automatically adds the attribute to C# projects. Because the single-threaded apartment model is the default for Visual Basic, there is no need for the attribute. - -- You're developing a C# app that calls a Visual Basic library, which, in turn, relies on COM interop. Because the single-threaded apartment model is the default for Visual Basic, you should change your app's threading model to single-threaded by using the attribute. - -- Your application makes calls to COM components that use the single-threaded apartment model. - +> For an overview of COM threading models, see [Understanding and Using COM Threading Models](https://docs.microsoft.com/previous-versions/ms809971(v=msdn.10)). + + COM threading models only apply to applications that use COM interop. The COM threading model can be set to single-threaded apartment or multithreaded apartment. The application thread is only initialized for COM interop if the thread actually makes a call to a COM component. If COM interop is not used, then the thread is not initialized, and the attribute, if it is present, has no effect. + + Starting with the .NET Framework version 2.0, the default threading model for COM interop depends on the language in which you are developing your application, as the following table shows. + +|Language|COM apartment model| +|--------------|-------------------------| +|C#|Multithreaded apartment| +|C++|Multithreaded apartment| +|Visual Basic|Single-threaded apartment| + + To change these defaults, you use the attribute to set the threading model for the application, or call the or method before starting the thread to set the threading model for a particular thread. In C++, you can also use the [/CLRTHREADATTRIBUTE](/cpp/build/reference/clrthreadattribute-set-clr-thread-attribute) linker option to specify the apartment model. + + ASP.NET applications should set the `ASPCompat` attribute of the [@ Page](https://docs.microsoft.com/previous-versions/dotnet/netframework-4.0/ydy4x04a(v=vs.100)) directive to `true` to force the page to be serviced by the STA thread pool. + + Here are some of the cases in which you'll want to use the attribute to explicitly set the threading model to single-threaded apartment: + +- You're developing a Windows Forms app. Windows Forms apps must be single-threaded if they communicate with Windows system components such as the Clipboard or Windows common dialog boxes, or if they use system features such as drag-and-drop functionality. The Windows Forms Application template for C# automatically adds the attribute to C# projects. Because the single-threaded apartment model is the default for Visual Basic, there is no need for the attribute. + +- You're developing a C# app that calls a Visual Basic library, which, in turn, relies on COM interop. Because the single-threaded apartment model is the default for Visual Basic, you should change your app's threading model to single-threaded by using the attribute. + +- Your application makes calls to COM components that use the single-threaded apartment model. + ]]> diff --git a/xml/System/SequencePosition.xml b/xml/System/SequencePosition.xml index 23edf9de114..c5a5f54622a 100644 --- a/xml/System/SequencePosition.xml +++ b/xml/System/SequencePosition.xml @@ -135,7 +135,7 @@ if is of type and is equal to the current instance; otherwise, . . @@ -182,7 +182,7 @@ Equality does not guarantee that the two instances point to the same location in if the two instances are equal; otherwise. . diff --git a/xml/System/SerializableAttribute.xml b/xml/System/SerializableAttribute.xml index c35e3f29f18..5c31f3d209a 100644 --- a/xml/System/SerializableAttribute.xml +++ b/xml/System/SerializableAttribute.xml @@ -66,30 +66,30 @@ Indicates that a class can be serialized using binary or XML serialization. This class cannot be inherited. - attribute to a type to indicate that instances of this type can be serialized using binary or XML serialization. The common language runtime throws if any type in the graph of objects being serialized does not have the attribute applied. - - Apply the attribute even if the class also implements the interface to control the binary serialization process. - - When you apply the attribute to a type, all private and public fields are serialized by default. You can control binary serialization more granularly by implementing the interface to override the serialization process. - - Or you can exclude fields from serialization by applying the attribute to the field. If a field of a binary-serializable type contains a pointer, a handle, or some other data structure that is specific to a particular environment, and cannot be meaningfully reconstituted in a different environment, then you might want to apply the attribute to that field. - + attribute to a type to indicate that instances of this type can be serialized using binary or XML serialization. The common language runtime throws if any type in the graph of objects being serialized does not have the attribute applied. + + Apply the attribute even if the class also implements the interface to control the binary serialization process. + + When you apply the attribute to a type, all private and public fields are serialized by default. You can control binary serialization more granularly by implementing the interface to override the serialization process. + + Or you can exclude fields from serialization by applying the attribute to the field. If a field of a binary-serializable type contains a pointer, a handle, or some other data structure that is specific to a particular environment, and cannot be meaningfully reconstituted in a different environment, then you might want to apply the attribute to that field. + For more information about using attributes, see [Attributes](/dotnet/standard/attributes/). For more information about binary serialization, see . > [!NOTE] > This attribute does not apply to JSON serialization using . - -## Examples - The following example demonstrates SOAP serialization of an object that's marked with the attribute. - + +## Examples + The following example demonstrates SOAP serialization of an object that's marked with the attribute. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_Remoting/SerializationAttributes/CPP/s.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/NonSerializedAttribute/Overview/s.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/NonSerializedAttribute/Overview/s.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_Remoting/SerializationAttributes/VB/s.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_Remoting/SerializationAttributes/VB/s.vb" id="Snippet1"::: + ]]> diff --git a/xml/System/Single.xml b/xml/System/Single.xml index 0480e0feac1..a6fd0c657d3 100644 --- a/xml/System/Single.xml +++ b/xml/System/Single.xml @@ -1283,23 +1283,34 @@ This computes `arctan(x) / π` in the interval `[-0.5, +0.5]`. An object to compare, or . Compares this instance to a specified object and returns an integer that indicates whether the value of this instance is less than, equal to, or greater than the value of the specified object. - A signed number indicating the relative values of this instance and . - - Return Value - - Description - - Less than zero - - This instance is less than , or this instance is not a number () and is a number. - - Zero - - This instance is equal to , or this instance and value are both not a number (), , or . - - Greater than zero - - This instance is greater than , OR this instance is a number and is not a number (), OR is . + A signed number indicating the relative values of this instance and . + + Return Value + + + Description + + + + + Less than zero + + + This instance is less than , or this instance is not a number () and is a number. + + + Zero + + + This instance is equal to , or this instance and value are both not a number (), , or . + + + Greater than zero + + + This instance is greater than , OR this instance is a number and is not a number (), OR is . + + A single-precision floating-point number to compare. Compares this instance to a specified single-precision floating-point number and returns an integer that indicates whether the value of this instance is less than, equal to, or greater than the value of the specified single-precision floating-point number. - A signed number indicating the relative values of this instance and . - - Return Value - - Description - - Less than zero - - This instance is less than , or this instance is not a number () and is a number. - - Zero - - This instance is equal to , or both this instance and are not a number (), , or . - - Greater than zero - - This instance is greater than , or this instance is a number and is not a number (). - - + A signed number indicating the relative values of this instance and . + + Return Value + + + Description + + + + + Less than zero + + + This instance is less than , or this instance is not a number () and is a number. + + + Zero + + + This instance is equal to , or both this instance and are not a number (), , or . + + + Greater than zero + + + This instance is greater than , or this instance is a number and is not a number (). + + - 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 a is defined and the argument is not typed as an , compilers may perform an implicit conversion and call the method. Otherwise, they call the method, which always returns if its argument is not a value. The following example illustrates the difference in behavior between the two method overloads. In the case of all primitive numeric types except for in Visual Basic and except for and in C#, 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 language="csharp" source="~/snippets/csharp/System/Single/Equals/equalsoverl.cs" interactive="try-dotnet" id="Snippet2"::: - :::code language="fsharp" source="~/snippets/fsharp/System/Single/Equals/equalsoverl.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.single.equals/vb/equalsoverl.vb" id="Snippet2"::: + 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 a is defined and the argument is not typed as an , compilers may perform an implicit conversion and call the method. Otherwise, they call the method, which always returns if its argument is not a value. The following example illustrates the difference in behavior between the two method overloads. In the case of all primitive numeric types except for in Visual Basic and except for and in C#, 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 language="csharp" source="~/snippets/csharp/System/Single/Equals/equalsoverl.cs" interactive="try-dotnet" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/Single/Equals/equalsoverl.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.single.equals/vb/equalsoverl.vb" id="Snippet2"::: @@ -2118,11 +2134,7 @@ This is known as Euler's number and is approximately 2.7182818284590452354. ]]> - 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 a is defined and the argument is not typed as an , compilers may perform an implicit conversion and call the method. Otherwise, they call the method, which always returns if its argument is not a value. The following example illustrates the difference in behavior between the two method overloads. In the case of all primitive numeric types except for in Visual Basic and except for and in C#, 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 language="csharp" source="~/snippets/csharp/System/Single/Equals/equalsoverl.cs" interactive="try-dotnet" id="Snippet2"::: - :::code language="fsharp" source="~/snippets/fsharp/System/Single/Equals/equalsoverl.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.single.equals/vb/equalsoverl.vb" id="Snippet2"::: + 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 a is defined and the argument is not typed as an , compilers may perform an implicit conversion and call the method. Otherwise, they call the method, which always returns if its argument is not a value. The following example illustrates the difference in behavior between the two method overloads. In the case of all primitive numeric types except for in Visual Basic and except for and in C#, 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 language="csharp" source="~/snippets/csharp/System/Single/Equals/equalsoverl.cs" interactive="try-dotnet" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/Single/Equals/equalsoverl.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.single.equals/vb/equalsoverl.vb" id="Snippet2"::: @@ -2197,7 +2209,9 @@ This is known as Euler's number and is approximately 2.7182818284590452354. The power to which 10 is raised. Computes 10 raised to a given power. - 10 + 10 + + To be added. @@ -2235,7 +2249,9 @@ This is known as Euler's number and is approximately 2.7182818284590452354. The power to which 10 is raised. Computes 10 raised to a given power and subtracts one. - 10 - 1 + 10 + + - 1 To be added. @@ -2273,7 +2289,9 @@ This is known as Euler's number and is approximately 2.7182818284590452354. The power to which 2 is raised. Computes 2 raised to a given power. - 2 + 2 + + To be added. @@ -2311,7 +2329,9 @@ This is known as Euler's number and is approximately 2.7182818284590452354. The power to which 2 is raised. Computes 2 raised to a given power and subtracts one. - 2 - 1 + 2 + + - 1 To be added. @@ -2349,7 +2369,9 @@ This is known as Euler's number and is approximately 2.7182818284590452354. The power to which E is raised. Computes E raised to a given power and subtracts one. - E - 1 + E + + - 1 To be added. @@ -4843,8 +4865,7 @@ If a separator is encountered in the `s` parameter during a parse operation, and is . does not represent a number in a valid format. - - .NET Framework and .NET Core 2.2 and earlier versions only: represents a number less than Single.MinValue or greater than Single.MaxValue. + .NET Framework and .NET Core 2.2 and earlier versions only: represents a number less than Single.MinValue or greater than Single.MaxValue. Parsing Numeric Strings in .NET @@ -5080,14 +5101,13 @@ If a separator is encountered in the `s` parameter during a parse operation, and is . is not a number in a valid format. - - .NET Framework and .NET Core 2.2 and earlier versions only: represents a number that is less than Single.MinValue or greater than Single.MaxValue. + .NET Framework and .NET Core 2.2 and earlier versions only: represents a number that is less than Single.MinValue or greater than Single.MaxValue. is not a value. - -or- +-or- - includes the value. + includes the value. Parsing Numeric Strings in .NET @@ -5211,8 +5231,7 @@ Some examples of `s` are "100", "-123,456,789", "123.45e+6", "+500", "5e2", "3.1 is . does not represent a number in a valid format. - - .NET Framework and .NET Core 2.2 and earlier versions only: represents a number less than Single.MinValue or greater than Single.MaxValue. + .NET Framework and .NET Core 2.2 and earlier versions only: represents a number less than Single.MinValue or greater than Single.MaxValue. Parsing Numeric Strings in .NET @@ -5307,7 +5326,7 @@ Some examples of `s` are "100", "-123,456,789", "123.45e+6", "+500", "5e2", "3.1 A character span that contains the number to convert. - A bitwise combination of enumeration values that indicate the style elements that can be present in . A typical value to specify is combined with . + A bitwise combination of enumeration values that indicate the style elements that can be present in . A typical value to specify is combined with . An object that supplies culture-specific formatting information about . Converts a character span that contains the string representation of a number in a specified style and culture-specific format to its single-precision floating-point number equivalent. A single-precision floating-point number that is equivalent to the numeric value or symbol specified in . @@ -5478,11 +5497,10 @@ If a separator is encountered in the `s` parameter during a parse operation, and is not a value. - -or- +-or- - is the value. - - .NET Framework and .NET Core 2.2 and earlier versions only: represents a number that is less than Single.MinValue or greater than Single.MaxValue. + is the value. + .NET Framework and .NET Core 2.2 and earlier versions only: represents a number that is less than Single.MinValue or greater than Single.MaxValue. Parsing Numeric Strings in .NET @@ -10290,9 +10308,9 @@ If `s` is out of range of the data type, the method throws is not a value. - -or- +-or- - is the value. + is the value. Parsing Numeric Strings in .NET diff --git a/xml/System/Span`1+Enumerator.xml b/xml/System/Span`1+Enumerator.xml index 665f5a6fea0..2ad910e229d 100644 --- a/xml/System/Span`1+Enumerator.xml +++ b/xml/System/Span`1+Enumerator.xml @@ -62,22 +62,22 @@ Provides an enumerator for the elements of a . - . At this position, is undefined. You must call to advance the enumerator to the first item in the before reading the value of . returns the same value until is called. sets to the next item in the . -If passes the end of the , returns `false`. When the enumerator is at this state, subsequent calls to also return `false` and is undefined. You cannot set to the first item in the again; you must create a new enumerator instance instead. +If passes the end of the , returns `false`. When the enumerator is at this state, subsequent calls to also return `false` and is undefined. You cannot set to the first item in the again; you must create a new enumerator instance instead. The enumerator does not have exclusive access to the . In addition, the underlying data on which the span is based can also be modified. Therefore, enumerating through a span is intrinsically not a thread-safe procedure. To guarantee thread safety during enumeration, you must implement your own synchronization. For example, the following code has a race condition. It does not ensure that the span will be enumerated before the `ClearContents` method executes. As a result, the underlying array is cleared during enumeration of the span: :::code language="csharp" source="~/snippets/csharp/System/Span.Enumerator/Program.cs"::: :::code language="fsharp" source="~/snippets/fsharp/System/Span.Enumerator/Program.fs"::: -If you synchronize access to the array before enumerating the span, as the revised version of the `EnumerateSpan` method does in the following example, the `ClearContents` method doesn't modify underlying span data during enumeration. Note that the example locks the underlying array on which the span is based. +If you synchronize access to the array before enumerating the span, as the revised version of the `EnumerateSpan` method does in the following example, the `ClearContents` method doesn't modify underlying span data during enumeration. Note that the example locks the underlying array on which the span is based. :::code language="csharp" source="~/snippets/csharp/System/Span.Enumerator/Program2.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Span.Enumerator/Program2.fs" id="Snippet1"::: @@ -86,8 +86,8 @@ Unlike some other enumerator structures in .NET, the or interface. This is because is a [ref struct](/dotnet/csharp/reference-semantics-with-value-types#ref-struct-type). -- Does not include a `Reset` method, which can set the enumerator to its initial position before the first element in the span. (The method must be implemented as part of the interface, but most implementors either throw an exception or provide no implementation.) - +- Does not include a `Reset` method, which can set the enumerator to its initial position before the first element in the span. (The method must be implemented as part of the interface, but most implementors either throw an exception or provide no implementation.) + ]]> @@ -120,15 +120,15 @@ Unlike some other enumerator structures in .NET, the Gets a reference to the item at the current position of the enumerator. The element in the at the current position of the enumerator. - must be called to advance the enumerator to the first element of the span before reading the value of `Current`. -- The last call to returned `false`, which indicates the end of the span. +- The last call to returned `false`, which indicates the end of the span. -`Current` returns the same value until is called. sets `Current` to the next item in the span. +`Current` returns the same value until is called. sets `Current` to the next item in the span. ]]> @@ -164,9 +164,9 @@ Unlike some other enumerator structures in .NET, the if the enumerator successfully advanced to the next item; if the end of the span has been passed. - The type of items in the . Provides a type-safe and memory-safe representation of a contiguous region of arbitrary memory. - ` is a [ref struct](/dotnet/csharp/language-reference/builtin-types/ref-struct) that is allocated on the stack rather than on the managed heap. Ref struct types have a number of restrictions to ensure that they cannot be promoted to the managed heap, including that they can't be boxed, they can't be assigned to variables of type , `dynamic` or to any interface type, they can't be fields in a reference type, and they can't be used across `await` and `yield` boundaries. In addition, calls to two methods, and , throw a . +`Span` is a [ref struct](/dotnet/csharp/language-reference/builtin-types/ref-struct) that is allocated on the stack rather than on the managed heap. Ref struct types have a number of restrictions to ensure that they cannot be promoted to the managed heap, including that they can't be boxed, they can't be assigned to variables of type , `dynamic` or to any interface type, they can't be fields in a reference type, and they can't be used across `await` and `yield` boundaries. In addition, calls to two methods, and , throw a . > [!IMPORTANT] > Because it is a stack-only type, `Span` is unsuitable for many scenarios that require storing references to buffers on the heap. This is true, for example, of routines that make asynchronous method calls. For such scenarios, you can use the complementary and types. @@ -93,7 +93,7 @@ A `Span` represents a contiguous region of arbitrary memory. A `Span` inst :::code language="csharp" source="~/snippets/csharp/System/Span/Overview/program.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Span/Overview/program.fs" id="Snippet1"::: - + The following example creates a `Span` from 100 bytes of native memory: :::code language="csharp" source="~/snippets/csharp/System/Span/Overview/program.cs" id="Snippet2"::: @@ -111,7 +111,7 @@ Because `Span` is an abstraction over an arbitrary block of memory, methods o ## Span\ and arrays -When it wraps an array, `Span` can wrap an entire array, as it did in the examples in the [Span\ and memory](#spant-and-memory) section. Because it supports slicing, `Span` can also point to any contiguous range within the array. +When it wraps an array, `Span` can wrap an entire array, as it did in the examples in the [Span\ and memory](#spant-and-memory) section. Because it supports slicing, `Span` can also point to any contiguous range within the array. The following example creates a slice of the middle five elements of a 10-element integer array. Note that the code doubles the values of each integer in the slice. As the output shows, the changes made by the span are reflected in the values of the array. @@ -205,7 +205,7 @@ This allocation and copy operation can be eliminated by using either `Span` o The array from which to create the object. Creates a new object over the entirety of a specified array. - `. @@ -255,11 +255,11 @@ If `array` is `null`, this constructor returns a `null` `Span`. A pointer to the starting address of a specified number of elements in memory. The number of elements to be included in the . - Creates a new object from a specified number of elements starting at a specified memory address. + Creates a new object from a specified number of elements starting at a specified memory address. - object, all subsequent uses are correct. + This constructor should be used with care, since it creates arbitrarily typed `T`s from a `void*`-typed block of memory, and `length` is not checked. However, if the constructor succeeds in creating a new object, all subsequent uses are correct. ]]> @@ -329,8 +329,7 @@ This method returns `default` when `array` is `null`. -or- - and exceeds the number of elements in the array. - + and exceeds the number of elements in the array. is a reference type, and is not an array of type . @@ -366,9 +365,9 @@ This method returns `default` when `array` is `null`. Clears the contents of this object. - object to their default values. It does not remove items from the . +The `Clear` method sets the items in the object to their default values. It does not remove items from the . ]]> @@ -415,7 +414,7 @@ The `Clear` method sets the items in the object to their The destination object. Copies the contents of this into a destination . - Calls to this method are not supported. Calls to this method are not supported. - method are not supported. Calls to the methods produce either of two results: - If `obj` is a , the method call generates compiler error CS1503: "cannot convert from 'System.Span' to 'object'." This is because is a [ref struct](/dotnet/csharp/language-reference/builtin-types/ref-struct) that cannot be boxed and therefore cannot be converted to an . -- If the type of `obj` is not a , the method call throws a . +- If the type of `obj` is not a , the method call throws a . To compare two objects for equality, use the comparison operator. @@ -600,7 +599,7 @@ To compare two objects for equality, use the Returns an enumerator for this . An enumerator for this span. - method directly, you can use the C# `foreach` statement and the Visual Basic `For Each`...`Next` construct to enumerate a . ]]> @@ -688,8 +687,8 @@ Instead of calling the method directly, Returns a reference to an object of type T that can be used for pinning. - -This method is intended to support .NET compilers and is not intended to be called by user code. + + This method is intended to support .NET compilers and is not intended to be called by user code. A reference to the element of the span at index 0, or if the span is empty. if the two objects are equal; otherwise, . - objects are equal if they have the same length and the corresponding elements of `left` and `right` point to the same memory. Note that the test for equality does *not* attempt to determine whether the contents are equal. @@ -1062,9 +1061,9 @@ Two objects are equal if they have the same length and th if the two objects are not equal; otherwise, . - objects are not equal if they have different lengths or if the corresponding elements of `left` and `right` do not point to the same memory. +Two objects are not equal if they have different lengths or if the corresponding elements of `left` and `right` do not point to the same memory. ]]> @@ -1182,7 +1181,7 @@ Two objects are not equal if they have different lengths Copies the contents of this span into a new array. An array containing the data in the current span. - does not exist. @@ -1222,7 +1221,7 @@ This method performs a heap allocation and therefore should be avoided if possib Returns the string representation of this object. The string representation of this object. - `, the `ToString` method returns a that contains the characters pointed to by the . Otherwise, it returns a with the name of the type and the number of elements that the contains. ]]> @@ -1272,7 +1271,7 @@ For a `Span`, the `ToString` method returns a that co if the copy operation succeeded; otherwise, . - The exception that is thrown when the execution stack exceeds the stack size. This class cannot be inherited. - intermediate language (IL) instruction throws `StackOverflowException`. For a list of initial property values for a `StackOverflowException` object, see the constructors. - + + `StackOverflowException` uses the HRESULT COR_E_STACKOVERFLOW, which has the value 0x800703E9. The intermediate language (IL) instruction throws `StackOverflowException`. For a list of initial property values for a `StackOverflowException` object, see the constructors. + Starting with the .NET Framework 2.0, you can't catch a `StackOverflowException` object with a `try`/`catch` block, and the corresponding process is terminated by default. Consequently, you should write your code to detect and prevent a stack overflow. For example, if your app depends on recursion, use a counter or a state condition to terminate the recursive loop. See the [Examples](#examples) section for an illustration of this technique. - + > [!NOTE] > Applying the attribute to a method that throws a `StackOverflowException` has no effect. You still cannot handle the exception from user code. @@ -77,7 +77,7 @@ See the [Examples](#examples) section for an illustration of this technique. ## Examples The following example uses a counter to ensure that the number of recursive calls to the `Execute` method do not exceed a maximum defined by the MAX_RECURSIVE_CALLS constant. - + :::code language="csharp" source="~/snippets/csharp/System/StackOverflowException/Overview/example1a.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/StackOverflowException/Overview/example1a.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.stackoverflowexception.class/vb/example1a.vb" id="Snippet1"::: @@ -131,16 +131,16 @@ See the [Examples](#examples) section for an illustration of this technique. Initializes a new instance of the class, setting the property of the new instance to a system-supplied message that describes the error, such as "The requested operation caused a stack overflow." This message takes into account the current system culture. - . - -|Property|Value| -|--------------|-----------| -||`null`.| -||The localized error message string.| - + . + +|Property|Value| +|--------------|-----------| +||`null`.| +||The localized error message string.| + ]]> @@ -183,16 +183,16 @@ See the [Examples](#examples) section for an illustration of this technique. A that describes the error. The content of message is intended to be understood by humans. The caller of this constructor is required to ensure that this string has been localized for the current system culture. Initializes a new instance of the class with a specified error message. - . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The error message string.| - + . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The error message string.| + ]]> @@ -237,18 +237,18 @@ See the [Examples](#examples) section for an illustration of this technique. The exception that is the cause of the current exception. If the parameter is not a null reference ( in Visual Basic), the current exception is raised in a block that handles the inner exception. Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception. - property. The property returns the same value that is passed into the constructor, or a null reference (`Nothing` in Visual Basic) if the property does not supply the inner exception value to the constructor. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||The inner exception reference.| -||The error message string.| - + property. The property returns the same value that is passed into the constructor, or a null reference (`Nothing` in Visual Basic) if the property does not supply the inner exception value to the constructor. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||The inner exception reference.| +||The error message string.| + ]]> diff --git a/xml/System/String.xml b/xml/System/String.xml index d842652ad49..8586e21ec54 100644 --- a/xml/System/String.xml +++ b/xml/System/String.xml @@ -123,511 +123,511 @@ Represents text as a sequence of UTF-16 code units. - object is a sequential collection of objects that represent a string; a object corresponds to a UTF-16 code unit. The value of the object is the content of the sequential collection of objects, and that value is immutable (that is, it is read-only). For more information about the immutability of strings, see the [Immutability and the StringBuilder class](#Immutability) section. The maximum size of a object in memory is 2-GB, or about 1 billion characters. - -For more information about Unicode, UTF-16, code units, code points, and the and types, see [Introduction to character encoding in .NET](/dotnet/standard/base-types/character-encoding-introduction). - - In this section: - - [Instantiate a String object](#Instantiation)\ - [Char objects and Unicode characters](#Characters)\ - [Strings and The Unicode Standard](#Unicode)\ - [Strings and embedded null characters](#EmbeddedNulls)\ - [Strings and indexes](#Indexes)\ - [Null strings and empty strings](#Nulls)\ - [Immutability and the StringBuilder class](#Immutability)\ - [Ordinal vs. culture-sensitive operations](#CultureSensitive)\ - [Normalization](#Normalization)\ - [String operations by category](#ByCategory) - - -## Instantiate a String object - You can instantiate a object in the following ways: - -- By assigning a string literal to a variable. This is the most commonly used method for creating a string. The following example uses assignment to create several strings. Note that in C# and F#, because the backslash (\\) is an escape character, literal backslashes in a string must be escaped or the entire string must be @-quoted. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.string.class.instantiate/cpp/string.instantiate1.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Overview/program.cs" interactive="try-dotnet-method" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Overview/program.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.class.instantiate/vb/instantiate1.vb" id="Snippet1"::: - -- By calling a class constructor. The following example instantiates strings by calling several class constructors. Note that some of the constructors include pointers to character arrays or signed byte arrays as parameters. Visual Basic does not support calls to these constructors. For detailed information about constructors, see the constructor summary. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.string.class.instantiate/cpp/string.instantiate2.cpp" id="Snippet2"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Overview/program.cs" id="Snippet2"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Overview/program.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.class.instantiate/vb/instantiate1.vb" id="Snippet2"::: - -- By using the string concatenation operator (+ in C# and F#, and & or + in Visual Basic) to create a single string from any combination of instances and string literals. The following example illustrates the use of the string concatenation operator. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.string.class.instantiate/cpp/string.instantiate3.cpp" id="Snippet3"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Overview/program.cs" interactive="try-dotnet-method" id="Snippet3"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Overview/program.fs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.class.instantiate/vb/instantiate1.vb" id="Snippet3"::: - -- By retrieving a property or calling a method that returns a string. The following example uses the methods of the class to extract a substring from a larger string. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.string.class.instantiate/cpp/string.instantiate3.cpp" id="Snippet4"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Overview/program.cs" interactive="try-dotnet-method" id="Snippet4"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Overview/program.fs" id="Snippet4"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.class.instantiate/vb/instantiate1.vb" id="Snippet4"::: - -- By calling a formatting method to convert a value or object to its string representation. The following example uses the [composite formatting](/dotnet/standard/base-types/composite-formatting) feature to embed the string representation of two objects into a string. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.string.class.instantiate/cpp/string.instantiate3.cpp" id="Snippet5"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Overview/program.cs" id="Snippet5"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Overview/program.fs" id="Snippet5"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.class.instantiate/vb/instantiate1.vb" id="Snippet5"::: - - -## Char objects and Unicode characters - Each character in a string is defined by a Unicode scalar value, also called a Unicode code point or the ordinal (numeric) value of the Unicode character. Each code point is encoded by using UTF-16 encoding, and the numeric value of each element of the encoding is represented by a object. - -> [!NOTE] -> Note that, because a instance consists of a sequential collection of UTF-16 code units, it is possible to create a object that is not a well-formed Unicode string. For example, it is possible to create a string that has a low surrogate without a corresponding high surrogate. Although some methods, such as the methods of encoding and decoding objects in the namespace, may performs checks to ensure that strings are well-formed, class members don't ensure that a string is well-formed. - - A single object usually represents a single code point; that is, the numeric value of the equals the code point. For example, the code point for the character "a" is U+0061. However, a code point might require more than one encoded element (more than one object). The Unicode standard defines two types of characters that correspond to multiple objects: graphemes, and Unicode supplementary code points that correspond to characters in the Unicode supplementary planes. - -- A grapheme is represented by a base character followed by one or more combining characters. For example, the character ä is represented by a object whose code point is U+0061 followed by a object whose code point is U+0308. This character can also be defined by a single object that has a code point of U+00E4. As the following example shows, a culture-sensitive comparison for equality indicates that these two representations are equal, although an ordinary ordinal comparison does not. However, if the two strings are normalized, an ordinal comparison also indicates that they are equal. (For more information on normalizing strings, see the [Normalization](#Normalization) section.) - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Class/cpp/string.char1.cpp" id="Snippet2"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Overview/grapheme1.cs" id="Snippet2"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Overview/grapheme1.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Class/vb/grapheme1.vb" id="Snippet2"::: - -- A Unicode supplementary code point (a surrogate pair) is represented by a object whose code point is a high surrogate followed by a object whose code point is a low surrogate. The code units of high surrogates range from U+D800 to U+DBFF. The code units of low surrogates range from U+DC00 to U+DFFF. Surrogate pairs are used to represent characters in the 16 Unicode supplementary planes. The following example creates a surrogate character and passes it to the method to determine whether it is a surrogate pair. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Class/cpp/string.char2.cpp" id="Snippet3"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Overview/surrogate1.cs" interactive="try-dotnet-method" id="Snippet3"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Overview/surrogate1.fs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Class/vb/surrogate1.vb" id="Snippet3"::: - - -## Strings and the Unicode Standard - Characters in a string are represented by UTF-16 encoded code units, which correspond to values. - - Each character in a string has an associated Unicode character category, which is represented in .NET by the enumeration. The category of a character or a surrogate pair can be determined by calling the method. - -[!INCLUDE[character-categories](~/includes/unicode-categories.md)] - - In addition, .NET supports string comparison and sorting based on the Unicode standard. .NET Framework 4 and previous versions maintain their own table of string data. This is also true of versions of .NET Framework starting with .NET Framework 4.5 running on Windows 7. Starting with .NET Framework 4.5 running on Windows 8 and later versions of the Windows operating system, the runtime delegates string comparison and sorting operations to the operating system. On .NET Core and .NET 5+, string comparison and sorting information is provided by [International Components for Unicode](https://icu.unicode.org/) libraries (except on Windows versions prior to Windows 10 May 2019 Update). The following table lists the versions of .NET and the versions of the Unicode Standard on which character comparison and sorting are based. - -|.NET version|Version of the Unicode Standard| -|----------------------------|-------------------------------------| -|.NET Framework 1.1|[The Unicode Standard, Version 4.0.0](https://www.unicode.org/versions/Unicode4.0.0/)| -|.NET Framework 2.0|[The Unicode Standard, Version 5.0.0](https://www.unicode.org/versions/Unicode5.0.0)| -|.NET Framework 3.5|[The Unicode Standard, Version 5.0.0](https://www.unicode.org/versions/Unicode5.0.0)| -|.NET Framework 4|[The Unicode Standard, Version 5.0.0](https://www.unicode.org/versions/Unicode5.0.0)| -|.NET Framework 4.5 and later on Windows 7|[The Unicode Standard, Version 5.0.0](https://www.unicode.org/versions/Unicode5.0.0)| -|.NET Framework 4.5 and later on Windows 8 and later Windows operating systems|[The Unicode Standard, Version 6.3.0](https://www.unicode.org/versions/Unicode6.3.0/)| -|.NET Core and .NET 5+|Depends on the version of the Unicode Standard supported by the underlying operating system.| - - -## Strings and embedded null characters - In .NET, a object can include embedded null characters, which count as a part of the string's length. However, in some languages such as C and C++, a null character indicates the end of a string; it is not considered a part of the string and is not counted as part of the string's length. This means that the following common assumptions that C and C++ programmers or libraries written in C or C++ might make about strings are not necessarily valid when applied to objects: - -- The value returned by the `strlen` or `wcslen` functions does not necessarily equal . - -- The string created by the `strcpy_s` or `wcscpy_s` functions is not necessarily identical to the string created by the method. - - You should ensure that native C and C++ code that instantiates objects, and code that is passed objects through platform invoke, don't assume that an embedded null character marks the end of the string. - - Embedded null characters in a string are also treated differently when a string is sorted (or compared) and when a string is searched. Null characters are ignored when performing culture-sensitive comparisons between two strings, including comparisons using the invariant culture. They are considered only for ordinal or case-insensitive ordinal comparisons. On the other hand, embedded null characters are always considered when searching a string with methods such as , , and . - - -## Strings and indexes - An index is the position of a object (not a Unicode character) in a . An index is a zero-based, nonnegative number that starts from the first position in the string, which is index position zero. A number of search methods, such as and , return the index of a character or substring in the string instance. - - The property lets you access individual objects by their index position in the string. Because the property is the default property (in Visual Basic) or the indexer (in C# and F#), you can access the individual objects in a string by using code such as the following. This code looks for white space or punctuation characters in a string to determine how many words the string contains. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Class/cpp/string.index1.cpp" id="Snippet4"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Overview/index11.cs" interactive="try-dotnet-method" id="Snippet4"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Overview/index11.fs" id="Snippet4"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Class/vb/index1.vb" id="Snippet4"::: - - Because the class implements the interface, you can also iterate through the objects in a string by using a `foreach` construct, as the following example shows. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Class/cpp/string.index2.cpp" id="Snippet5"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Overview/index2.cs" interactive="try-dotnet-method" id="Snippet5"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Overview/index2.fs" id="Snippet5"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Class/vb/index2.vb" id="Snippet5"::: - - Consecutive index values might not correspond to consecutive Unicode characters, because a Unicode character might be encoded as more than one object. In particular, a string may contain multi-character units of text that are formed by a base character followed by one or more combining characters or by surrogate pairs. To work with Unicode characters instead of objects, use the and classes, or the method and the struct. The following example illustrates the difference between code that works with objects and code that works with Unicode characters. It compares the number of characters or text elements in each word of a sentence. The string includes two sequences of a base character followed by a combining character. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Class/cpp/string.index3.cpp" id="Snippet6"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Overview/index3.cs" interactive="try-dotnet-method" id="Snippet6"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Overview/index3.fs" id="Snippet6"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Class/vb/index3.vb" id="Snippet6"::: - - This example works with text elements by using the method and the class to enumerate all the text elements in a string. You can also retrieve an array that contains the starting index of each text element by calling the method. - - For more information about working with units of text rather than individual values, see [Introduction to character encoding in .NET](/dotnet/standard/base-types/character-encoding-introduction). - - -## Null strings and empty strings - A string that has been declared but has not been assigned a value is `null`. Attempting to call methods on that string throws a . A null string is different from an empty string, which is a string whose value is "" or . In some cases, passing either a null string or an empty string as an argument in a method call throws an exception. For example, passing a null string to the method throws an , and passing an empty string throws a . In other cases, a method argument can be either a null string or an empty string. For example, if you are providing an implementation for a class, you want to equate both a null string and an empty string with the general ("G") format specifier. - - The class includes the following two convenience methods that enable you to test whether a string is `null` or empty: - -- , which indicates whether a string is either `null` or is equal to . This method eliminates the need to use code such as the following: - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.string.class.null/cpp/string.null.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Overview/nullorempty1.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Overview/nullorempty1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.class.null/vb/nullorempty1.vb" id="Snippet1"::: - -- , which indicates whether a string is `null`, equals , or consists exclusively of white-space characters. This method eliminates the need to use code such as the following: - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.string.class.null/cpp/string.null.cpp" id="Snippet2"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Overview/nullorempty1.cs" id="Snippet2"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Overview/nullorempty1.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.class.null/vb/nullorempty1.vb" id="Snippet2"::: - - The following example uses the method in the implementation of a custom `Temperature` class. The method supports the "G", "C", "F", and "K" format strings. If an empty format string or a format string whose value is `null` is passed to the method, its value is changed to the "G" format string. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.string.class.null/cpp/string.null.cpp" id="Snippet3"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Overview/nullorempty1.cs" id="Snippet3"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Overview/nullorempty1.fs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.class.null/vb/nullorempty1.vb" id="Snippet3"::: - - -## Immutability and the StringBuilder class - A object is called immutable (read-only), because its value cannot be modified after it has been created. Methods that appear to modify a object actually return a new object that contains the modification. - - Because strings are immutable, string manipulation routines that perform repeated additions or deletions to what appears to be a single string can exact a significant performance penalty. For example, the following code uses a random number generator to create a string with 1000 characters in the range 0x0001 to 0x052F. Although the code appears to use string concatenation to append a new character to the existing string named `str`, it actually creates a new object for each concatenation operation. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Class/cpp/string.stringbuilder1.cpp" id="Snippet15"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Overview/immutable.cs" id="Snippet15"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Overview/immutable.fs" id="Snippet15"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Class/vb/immutable.vb" id="Snippet15"::: - - You can use the class instead of the class for operations that make multiple changes to the value of a string. Unlike instances of the class, objects are mutable; when you concatenate, append, or delete substrings from a string, the operations are performed on a single string. When you have finished modifying the value of a object, you can call its method to convert it to a string. The following example replaces the used in the previous example to concatenate 1000 random characters in the range to 0x0001 to 0x052F with a object. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Class/cpp/string.stringbuilder2.cpp" id="Snippet16"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Overview/immutable1.cs" id="Snippet16"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Overview/immutable1.fs" id="Snippet16"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Class/vb/immutable1.vb" id="Snippet16"::: - - -## Ordinal vs. culture-sensitive operations - Members of the class perform either ordinal or culture-sensitive (linguistic) operations on a object. An ordinal operation acts on the numeric value of each object. A culture-sensitive operation acts on the value of the object, and takes culture-specific casing, sorting, formatting, and parsing rules into account. Culture-sensitive operations execute in the context of an explicitly declared culture or the implicit current culture. The two kinds of operations can produce very different results when they are performed on the same string. - -.NET also supports culture-insensitive linguistic string operations by using the invariant culture (), which is loosely based on the culture settings of the English language independent of region. Unlike other settings, the settings of the invariant culture are guaranteed to remain consistent on a single computer, from system to system, and across versions of .NET. The invariant culture can be seen as a kind of black box that ensures stability of string comparisons and ordering across all cultures. - -> [!IMPORTANT] -> If your application makes a security decision about a symbolic identifier such as a file name or named pipe, or about persisted data such as the text-based data in an XML file, the operation should use an ordinal comparison instead of a culture-sensitive comparison. This is because a culture-sensitive comparison can yield different results depending on the culture in effect, whereas an ordinal comparison depends solely on the binary value of the compared characters. - -> [!IMPORTANT] -> Most methods that perform string operations include an overload that has a parameter of type , which enables you to specify whether the method performs an ordinal or culture-sensitive operation. In general, you should call this overload to make the intent of your method call clear. For best practices and guidance for using ordinal and culture-sensitive operations on strings, see [Best Practices for Using Strings](/dotnet/standard/base-types/best-practices-strings). - - Operations for [casing](#casing), [parsing and formatting](#parsing), [comparison and sorting](#comparison), and [testing for equality](#equality) can be either ordinal or culture-sensitive. The following sections discuss each category of operation. - -> [!TIP] -> You should always call a method overload that makes the intent of your method call clear. For example, instead of calling the method to perform a culture-sensitive comparison of two strings by using the conventions of the current culture, you should call the method with a value of for the `comparisonType` argument. For more information, see [Best Practices for Using Strings](/dotnet/standard/base-types/best-practices-strings). - -You can download the sorting weight tables, a set of text files that contain information on the character weights used in sorting and comparison operations, from the following links: - -- Windows (.NET Framework and .NET Core): [Sorting Weight Tables](https://www.microsoft.com/download/details.aspx?id=10921) -- Windows 10 May 2019 Update or later (.NET 5+) and Linux and macOS (.NET Core and .NET 5+): [Default Unicode Collation Element Table](https://www.unicode.org/Public/UCA/latest/allkeys.txt) - - -### Casing - Casing rules determine how to change the capitalization of a Unicode character; for example, from lowercase to uppercase. Often, a casing operation is performed before a string comparison. For example, a string might be converted to uppercase so that it can be compared with another uppercase string. You can convert the characters in a string to lowercase by calling the or method, and you can convert them to uppercase by calling the or method. In addition, you can use the method to convert a string to title case. - -[!INCLUDE[platform-note](~/includes/c-and-posix-cultures.md)] - - Casing operations can be based on the rules of the current culture, a specified culture, or the invariant culture. Because case mappings can vary depending on the culture used, the result of casing operations can vary based on culture. The actual differences in casing are of three kinds: - -- Differences in the case mapping of LATIN CAPITAL LETTER I (U+0049), LATIN SMALL LETTER I (U+0069), LATIN CAPITAL LETTER I WITH DOT ABOVE (U+0130), and LATIN SMALL LETTER DOTLESS I (U+0131). In the tr-TR (Turkish (Turkey)) and az-Latn-AZ (Azerbaijan, Latin) cultures, and in the tr, az, and az-Latn neutral cultures, the lowercase equivalent of LATIN CAPITAL LETTER I is LATIN SMALL LETTER DOTLESS I, and the uppercase equivalent of LATIN SMALL LETTER I is LATIN CAPITAL LETTER I WITH DOT ABOVE. In all other cultures, including the invariant culture, LATIN SMALL LETTER I and LATIN CAPITAL LETTER I are lowercase and uppercase equivalents. - - The following example demonstrates how a string comparison designed to prevent file system access can fail if it relies on a culture-sensitive casing comparison. (The casing conventions of the invariant culture should have been used.) - - :::code language="csharp" source="~/snippets/csharp/System/String/Overview/case2.cs" id="Snippet17"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Overview/case2.fs" id="Snippet17"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Class/vb/case2.vb" id="Snippet17"::: - -- Differences in case mappings between the invariant culture and all other cultures. In these cases, using the casing rules of the invariant culture to change a character to uppercase or lowercase returns the same character. For all other cultures, it returns a different character. Some of the affected characters are listed in the following table. - - |Character|If changed to|Returns| - |---------------|-------------------|-------------| - |MICRON SIGN (U+00B5)|Uppercase|GREEK CAPITAL LETTER MU (U+-39C)| - |LATIN CAPITAL LETTER I WITH DOT ABOVE (U+0130)|Lowercase|LATIN SMALL LETTER I (U+0069)| - |LATIN SMALL LETTER DOTLESS I (U+0131)|Uppercase|LATIN CAPITAL LETTER I (U+0049)| - |LATIN SMALL LETTER LONG S (U+017F)|Uppercase|LATIN CAPITAL LETTER S (U+0053)| - |LATIN CAPITAL LETTER D WITH SMALL LETTER Z WITH CARON (U+01C5)|Lowercase|LATIN SMALL LETTER DZ WITH CARON (U+01C6)| - |COMBINING GREEK YPOGEGRAMMENI (U+0345)|Uppercase|GREEK CAPITAL LETTER IOTA (U+0399)| - -- Differences in case mappings of two-letter mixed-case pairs in the ASCII character range. In most cultures, a two-letter mixed-case pair is equal to the equivalent two-letter uppercase or lowercase pair. This is not true for the following two-letter pairs in the following cultures, because in each case they are compared to a digraph: - - - "lJ" and "nJ" in the hr-HR (Croatian (Croatia)) culture. - - - "cH" in the cs-CZ (Czech (Czech Republic)) and sk-SK (Slovak (Slovakia)) cultures. - - - "aA" in the da-DK (Danish (Denmark)) culture. - - - "cS", "dZ", "dZS", "nY", "sZ", "tY", and "zS" in the hu-HU (Hungarian (Hungary)) culture. - - - "cH" and "lL" in the es-ES_tradnl (Spanish (Spain, Traditional Sort)) culture. - - - "cH", "gI", "kH", "nG" "nH", "pH", "qU', "tH", and "tR" in the vi-VN (Vietnamese (Vietnam)) culture. - - However, it is unusual to encounter a situation in which a culture-sensitive comparison of these pairs creates problems, because these pairs are uncommon in fixed strings or identifiers. - - The following example illustrates some of the differences in casing rules between cultures when converting strings to uppercase. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Class/cpp/string.casing.cpp" id="Snippet7"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Overview/case1.cs" id="Snippet7"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Overview/case1.fs" id="Snippet7"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Class/vb/case1.vb" id="Snippet7"::: - - -### Parsing and formatting - Formatting and parsing are inverse operations. Formatting rules determine how to convert a value, such as a date and time or a number, to its string representation, whereas parsing rules determine how to convert a string representation to a value such as a date and time. Both formatting and parsing rules are dependent on cultural conventions. The following example illustrates the ambiguity that can arise when interpreting a culture-specific date string. Without knowing the conventions of the culture that was used to produce a date string, it is not possible to know whether 03/01/2011, 3/1/2011, and 01/03/2011 represent January 3, 2011 or March 1, 2011. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Class/cpp/string.format1.cpp" id="Snippet8"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Overview/format1.cs" id="Snippet8"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Overview/format1.fs" id="Snippet8"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Class/vb/format1.vb" id="Snippet8"::: - - Similarly, as the following example shows, a single string can produce different dates depending on the culture whose conventions are used in the parsing operation. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Class/cpp/string.parse1.cpp" id="Snippet9"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Overview/parse1.cs" id="Snippet9"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Overview/parse1.fs" id="Snippet9"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Class/vb/parse1.vb" id="Snippet9"::: - - -### String comparison and sorting - Conventions for comparing and sorting strings vary from culture to culture. For example, the sort order may be based on phonetics or on the visual representation of characters. In East Asian languages, characters are sorted by the stroke and radical of ideographs. Sorting also depends on the order languages and cultures use for the alphabet. For example, the Danish language has an "Æ" character that it sorts after "Z" in the alphabet. In addition, comparisons can be case-sensitive or case-insensitive, and casing rules might differ by culture. Ordinal comparison, on the other hand, uses the Unicode code points of individual characters in a string when comparing and sorting strings. - - Sort rules determine the alphabetic order of Unicode characters and how two strings compare to each other. For example, the method compares two strings based on the parameter. If the parameter value is , the method performs a linguistic comparison that uses the conventions of the current culture; if the parameter value is , the method performs an ordinal comparison. Consequently, as the following example shows, if the current culture is U.S. English, the first call to the method (using culture-sensitive comparison) considers "a" less than "A", but the second call to the same method (using ordinal comparison) considers "a" greater than "A". - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Class/cpp/string.compare1.cpp" id="Snippet10"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Overview/compare11.cs" id="Snippet10"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Overview/compare11.fs" id="Snippet10"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Class/vb/compare1.vb" id="Snippet10"::: - - .NET supports word, string, and ordinal sort rules: - -- A word sort performs a culture-sensitive comparison of strings in which certain nonalphanumeric Unicode characters might have special weights assigned to them. For example, the hyphen (-) might have a very small weight assigned to it so that "coop" and "co-op" appear next to each other in a sorted list. For a list of the methods that compare two strings using word sort rules, see the [String operations by category](#ByCategory) section. - -- A string sort also performs a culture-sensitive comparison. It is similar to a word sort, except that there are no special cases, and all nonalphanumeric symbols come before all alphanumeric Unicode characters. Two strings can be compared using string sort rules by calling the method overloads that have an `options` parameter that is supplied a value of . Note that this is the only method that .NET provides to compare two strings using string sort rules. - -- An ordinal sort compares strings based on the numeric value of each object in the string. An ordinal comparison is automatically case-sensitive because the lowercase and uppercase versions of a character have different code points. However, if case is not important, you can specify an ordinal comparison that ignores case. This is equivalent to converting the string to uppercase by using the invariant culture and then performing an ordinal comparison on the result. For a list of the methods that compare two strings using ordinal sort rules, see the [String operations by category](#ByCategory) section. - - A culture-sensitive comparison is any comparison that explicitly or implicitly uses a object, including the invariant culture that is specified by the property. The implicit culture is the current culture, which is specified by the and properties. There is considerable variation in the sort order of alphabetic characters (that is, characters for which the property returns `true`) across cultures. You can specify a culture-sensitive comparison that uses the conventions of a specific culture by supplying a object to a string comparison method such as . You can specify a culture-sensitive comparison that uses the conventions of the current culture by supplying , , or any member of the enumeration other than or to an appropriate overload of the method. A culture-sensitive comparison is generally appropriate for sorting whereas an ordinal comparison is not. An ordinal comparison is generally appropriate for determining whether two strings are equal (that is, for determining identity) whereas a culture-sensitive comparison is not. - - The following example illustrates the difference between culture-sensitive and ordinal comparison. The example evaluates three strings, "Apple", "Æble", and "AEble", using ordinal comparison and the conventions of the da-DK and en-US cultures (each of which is the default culture at the time the method is called). Because the Danish language treats the character "Æ" as an individual letter and sorts it after "Z" in the alphabet, the string "Æble" is greater than "Apple". However, "Æble" is not considered equivalent to "AEble", so "Æble" is also greater than "AEble". The en-US culture doesn't include the letter"Æ" but treats it as equivalent to "AE", which explains why "Æble" is less than "Apple" but equal to "AEble". Ordinal comparison, on the other hand, considers "Apple" to be less than "Æble", and "Æble" to be greater than "AEble". - - :::code language="csharp" source="~/snippets/csharp/System/String/Overview/compare4.cs" id="Snippet21"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Overview/compare4.fs" id="Snippet21"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Class/vb/compare4.vb" id="Snippet21"::: - - Use the following general guidelines to choose an appropriate sorting or string comparison method: - -- If you want the strings to be ordered based on the user's culture, you should order them based on the conventions of the current culture. If the user's culture changes, the order of sorted strings will also change accordingly. For example, a thesaurus application should always sort words based on the user's culture. - -- If you want the strings to be ordered based on the conventions of a specific culture, you should order them by supplying a object that represents that culture to a comparison method. For example, in an application designed to teach students a particular language, you want strings to be ordered based on the conventions of one of the cultures that speaks that language. - -- If you want the order of strings to remain unchanged across cultures, you should order them based on the conventions of the invariant culture or use an ordinal comparison. For example, you would use an ordinal sort to organize the names of files, processes, mutexes, or named pipes. - -- For a comparison that involves a security decision (such as whether a username is valid), you should always perform an ordinal test for equality by calling an overload of the method. - -> [!NOTE] -> The culture-sensitive sorting and casing rules used in string comparison depend on the version of the .NET. On .NET Core, string comparison depends on the version of the Unicode Standard supported by the underlying operating system. In .NET Framework 4.5 and later versions running on Windows 8 or later, sorting, casing, normalization, and Unicode character information conform to the Unicode 6.0 standard. On other Windows operating systems, they conform to the Unicode 5.0 standard. - - For more information about word, string, and ordinal sort rules, see the topic. For additional recommendations on when to use each rule, see [Best Practices for Using Strings](/dotnet/standard/base-types/best-practices-strings). - - Ordinarily, you don't call string comparison methods such as directly to determine the sort order of strings. Instead, comparison methods are called by sorting methods such as or . The following example performs four different sorting operations (word sort using the current culture, word sort using the invariant culture, ordinal sort, and string sort using the invariant culture) without explicitly calling a string comparison method, although they do specify the type of comparison to use. Note that each type of sort produces a unique ordering of strings in its array. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Class/cpp/string.compare2.cpp" id="Snippet12"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Overview/compare2.cs" id="Snippet12"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Overview/compare2.fs" id="Snippet12"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Class/vb/compare2.vb" id="Snippet12"::: - -> [!TIP] -> Internally, .NET uses sort keys to support culturally sensitive string comparison. Each character in a string is given several categories of sort weights, including alphabetic, case, and diacritic. A sort key, represented by the class, provides a repository of these weights for a particular string. If your app performs a large number of searching or sorting operations on the same set of strings, you can improve its performance by generating and storing sort keys for all the strings that it uses. When a sort or comparison operation is required, you use the sort keys instead of the strings. For more information, see the class. - - If you don't specify a string comparison convention, sorting methods such as perform a culture-sensitive, case-sensitive sort on strings. The following example illustrates how changing the current culture affects the order of sorted strings in an array. It creates an array of three strings. First, it sets the `System.Threading.Thread.CurrentThread.CurrentCulture` property to en-US and calls the method. The resulting sort order is based on sorting conventions for the English (United States) culture. Next, the example sets the `System.Threading.Thread.CurrentThread.CurrentCulture` property to da-DK and calls the method again. Notice how the resulting sort order differs from the en-US results because it uses the sorting conventions for Danish (Denmark). - - :::code language="csharp" source="~/snippets/csharp/System/String/Overview/sort1.cs" id="Snippet3"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Overview/sort1.fs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/conceptual.strings.comparing/vb/sort1.vb" id="Snippet3"::: - -> [!WARNING] -> If your primary purpose in comparing strings is to determine whether they are equal, you should call the method. Typically, you should use to perform an ordinal comparison. The method is intended primarily to sort strings. - - String search methods, such as and , also can perform culture-sensitive or ordinal string comparisons. The following example illustrates the differences between ordinal and culture-sensitive comparisons using the method. A culture-sensitive search in which the current culture is English (United States) considers the substring "oe" to match the ligature "œ". Because a soft hyphen (U+00AD) is a zero-width character, the search treats the soft hyphen as equivalent to and finds a match at the beginning of the string. An ordinal search, on the other hand, does not find a match in either case. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Class/cpp/string.compare3.cpp" id="Snippet13"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Overview/compare3.cs" id="Snippet13"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Overview/compare3.fs" id="Snippet13"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Class/vb/compare3.vb" id="Snippet13"::: - -### Search in strings - String search methods, such as and , also can perform culture-sensitive or ordinal string comparisons to determine whether a character or substring is found in a specified string. - - The search methods in the class that search for an individual character, such as the method, or one of a set of characters, such as the method, all perform an ordinal search. To perform a culture-sensitive search for a character, you must call a method such as or . Note that the results of searching for a character using ordinal and culture-sensitive comparison can be very different. For example, a search for a precomposed Unicode character such as the ligature "Æ" (U+00C6) might match any occurrence of its components in the correct sequence, such as "AE" (U+041U+0045), depending on the culture. The following example illustrates the difference between the and methods when searching for an individual character. The ligature "æ" (U+00E6) is found in the string "aerial" when using the conventions of the en-US culture, but not when using the conventions of the da-DK culture or when performing an ordinal comparison. - - :::code language="csharp" source="~/snippets/csharp/System/String/Overview/search1.cs" id="Snippet22"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Overview/search1.fs" id="Snippet22"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Class/vb/search1.vb" id="Snippet22"::: - - On the other hand, class methods that search for a string rather than a character perform a culture-sensitive search if search options are not explicitly specified by a parameter of type . The sole exception is , which performs an ordinal search. - - -### Testing for equality - -Use the method to determine the relationship of two strings in the sort order. Typically, this is a culture-sensitive operation. In contrast, call the method to test for equality. Because the test for equality usually compares user input with some known string, such as a valid user name, a password, or a file system path, it is typically an ordinal operation. - -> [!WARNING] -> It is possible to test for equality by calling the method and determining whether the return value is zero. However, this practice is not recommended. To determine whether two strings are equal, you should call one of the overloads of the method. The preferred overload to call is either the instance method or the static method, because both methods include a parameter that explicitly specifies the type of comparison. - - The following example illustrates the danger of performing a culture-sensitive comparison for equality when an ordinal one should be used instead. In this case, the intent of the code is to prohibit file system access from URLs that begin with "FILE://" or "file://" by performing a case-insensitive comparison of the beginning of a URL with the string "FILE://". However, if a culture-sensitive comparison is performed using the Turkish (Turkey) culture on a URL that begins with "file://", the comparison for equality fails, because the Turkish uppercase equivalent of the lowercase "i" is "İ" instead of "I". As a result, file system access is inadvertently permitted. On the other hand, if an ordinal comparison is performed, the comparison for equality succeeds, and file system access is denied. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Class/cpp/string.equals.cpp" id="Snippet11"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Overview/equality1.cs" id="Snippet11"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Overview/equality1.fs" id="Snippet11"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Class/vb/equality1.vb" id="Snippet11"::: - - -## Normalization - Some Unicode characters have multiple representations. For example, any of the following code points can represent the letter "ắ": - -- U+1EAF - -- U+0103 U+0301 - -- U+0061 U+0306 U+0301 - - Multiple representations for a single character complicate searching, sorting, matching, and other string operations. - - The Unicode standard defines a process called normalization that returns one binary representation of a Unicode character for any of its equivalent binary representations. Normalization can use several algorithms, called normalization forms, that follow different rules. .NET supports Unicode normalization forms C, D, KC, and KD. When strings have been normalized to the same normalization form, they can be compared by using ordinal comparison. - - An ordinal comparison is a binary comparison of the Unicode scalar value of corresponding objects in each string. The class includes a number of methods that can perform an ordinal comparison, including the following: - -- Any overload of the , , , , , and methods that includes a parameter. The method performs an ordinal comparison if you supply a value of or for this parameter. - -- The overloads of the method. - -- Methods that use ordinal comparison by default, such as , , and . - -- Methods that search for a value or for the elements in a array in a string instance. Such methods include and . - - You can determine whether a string is normalized to normalization form C by calling the method, or you can call the method to determine whether a string is normalized to a specified normalization form. You can also call the method to convert a string to normalization form C, or you can call the method to convert a string to a specified normalization form. For step-by-step information about normalizing and comparing strings, see the and methods. - - The following simple example illustrates string normalization. It defines the letter "ố" in three different ways in three different strings, and uses an ordinal comparison for equality to determine that each string differs from the other two strings. It then converts each string to the supported normalization forms, and again performs an ordinal comparison of each string in a specified normalization form. In each case, the second test for equality shows that the strings are equal. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Class/cpp/string.normalize.cpp" id="Snippet14"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Overview/normalize1.cs" id="Snippet14"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Overview/normalize1.fs" id="Snippet14"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Class/vb/normalize1.vb" id="Snippet14"::: - - For more information about normalization and normalization forms, see , as well as [Unicode Standard Annex #15: Unicode Normalization Forms](https://unicode.org/reports/tr15/) and the [Normalization FAQ](https://www.unicode.org/faq/normalization.html) on the unicode.org website. - - -## String operations by category - The class provides members for comparing strings, testing strings for equality, finding characters or substrings in a string, modifying a string, extracting substrings from a string, combining strings, formatting values, copying a string, and normalizing a string. - -### Compare strings - You can compare strings to determine their relative position in the sort order by using the following methods: - -- returns an integer that indicates the relationship of one string to a second string in the sort order. - -- returns an integer that indicates the relationship of one string to a second string based on a comparison of their code points. - -- returns an integer that indicates the relationship of the current string instance to a second string in the sort order. The method provides the and implementations for the class. - -### Test strings for equality - -You call the method to determine whether two strings are equal. The instance and the static overloads let you specify whether the comparison is culture-sensitive or ordinal, and whether case is considered or ignored. Most tests for equality are ordinal, and comparisons for equality that determine access to a system resource (such as a file system object) should always be ordinal. - -### Find characters in a string - -The class includes two kinds of search methods: - -- Methods that return a value to indicate whether a particular substring is present in a string instance. These include the , , and methods. - -- Methods that indicate the starting position of a substring in a string instance. These include the , , , and methods. - -> [!WARNING] -> If you want to search a string for a particular pattern rather than a specific substring, you should use regular expressions. For more information, see [.NET Regular Expressions](/dotnet/standard/base-types/regular-expressions). - -### Modify a string - -The class includes the following methods that appear to modify the value of a string: - -- inserts a string into the current instance. - -- inserts one or more occurrences of a specified character at the beginning of a string. - -- inserts one or more occurrences of a specified character at the end of a string. - -- deletes a substring from the current instance. - -- replaces a substring with another substring in the current instance. - -- and convert all the characters in a string to lowercase. - -- and convert all the characters in a string to uppercase. - -- removes all occurrences of a character from the beginning and end of a string. - -- removes all occurrences of a character from the end of a string. - -- removes all occurrences of a character from the beginning of a string. - -> [!IMPORTANT] -> All string modification methods return a new object. They don't modify the value of the current instance. - -### Extract substrings from a string - -The method separates a single string into multiple strings. Overloads of the method allow you to specify multiple delimiters, to limit the number of substrings that the method extracts, to trim white space from substrings, and to specify whether empty strings (which occur when delimiters are adjacent) are included among the returned strings. - -### Combine strings - -The following methods can be used for string concatenation: - -- combines one or more substrings into a single string. - -- concatenates one or more substrings into a single element and adds a separator between each substring. - -### Format values - -The method uses the composite formatting feature to replace one or more placeholders in a string with the string representation of some object or value. The method is often used to do the following: - -- To embed the string representation of a numeric value in a string. - -- To embed the string representation of a date and time value in a string. - -- To embed the string representation of an enumeration value in a string. - -- To embed the string representation of some object that supports the interface in a string. - -- To right-justify or left-justify a substring in a field within a larger string. - - For detailed information about formatting operations and examples, see the overload summary. - -### Copy a string - -You can call the following methods to make a copy of a string: - -- returns a reference to an existing object. - -- creates a copy of an existing string. - -- copies a portion of a string to a character array. - -### Normalize a string - -In Unicode, a single character can have multiple code points. Normalization converts these equivalent characters into the same binary representation. The method performs the normalization, and the method determines whether a string is normalized. - -For more information and an example, see the [Normalization](#Normalization) section earlier in this topic. - + object is a sequential collection of objects that represent a string; a object corresponds to a UTF-16 code unit. The value of the object is the content of the sequential collection of objects, and that value is immutable (that is, it is read-only). For more information about the immutability of strings, see the [Immutability and the StringBuilder class](#Immutability) section. The maximum size of a object in memory is 2-GB, or about 1 billion characters. + +For more information about Unicode, UTF-16, code units, code points, and the and types, see [Introduction to character encoding in .NET](/dotnet/standard/base-types/character-encoding-introduction). + + In this section: + + [Instantiate a String object](#Instantiation)\ + [Char objects and Unicode characters](#Characters)\ + [Strings and The Unicode Standard](#Unicode)\ + [Strings and embedded null characters](#EmbeddedNulls)\ + [Strings and indexes](#Indexes)\ + [Null strings and empty strings](#Nulls)\ + [Immutability and the StringBuilder class](#Immutability)\ + [Ordinal vs. culture-sensitive operations](#CultureSensitive)\ + [Normalization](#Normalization)\ + [String operations by category](#ByCategory) + + +## Instantiate a String object + You can instantiate a object in the following ways: + +- By assigning a string literal to a variable. This is the most commonly used method for creating a string. The following example uses assignment to create several strings. Note that in C# and F#, because the backslash (\\) is an escape character, literal backslashes in a string must be escaped or the entire string must be @-quoted. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.string.class.instantiate/cpp/string.instantiate1.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Overview/program.cs" interactive="try-dotnet-method" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Overview/program.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.class.instantiate/vb/instantiate1.vb" id="Snippet1"::: + +- By calling a class constructor. The following example instantiates strings by calling several class constructors. Note that some of the constructors include pointers to character arrays or signed byte arrays as parameters. Visual Basic does not support calls to these constructors. For detailed information about constructors, see the constructor summary. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.string.class.instantiate/cpp/string.instantiate2.cpp" id="Snippet2"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Overview/program.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Overview/program.fs" id="Snippet2"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.class.instantiate/vb/instantiate1.vb" id="Snippet2"::: + +- By using the string concatenation operator (+ in C# and F#, and & or + in Visual Basic) to create a single string from any combination of instances and string literals. The following example illustrates the use of the string concatenation operator. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.string.class.instantiate/cpp/string.instantiate3.cpp" id="Snippet3"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Overview/program.cs" interactive="try-dotnet-method" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Overview/program.fs" id="Snippet3"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.class.instantiate/vb/instantiate1.vb" id="Snippet3"::: + +- By retrieving a property or calling a method that returns a string. The following example uses the methods of the class to extract a substring from a larger string. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.string.class.instantiate/cpp/string.instantiate3.cpp" id="Snippet4"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Overview/program.cs" interactive="try-dotnet-method" id="Snippet4"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Overview/program.fs" id="Snippet4"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.class.instantiate/vb/instantiate1.vb" id="Snippet4"::: + +- By calling a formatting method to convert a value or object to its string representation. The following example uses the [composite formatting](/dotnet/standard/base-types/composite-formatting) feature to embed the string representation of two objects into a string. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.string.class.instantiate/cpp/string.instantiate3.cpp" id="Snippet5"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Overview/program.cs" id="Snippet5"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Overview/program.fs" id="Snippet5"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.class.instantiate/vb/instantiate1.vb" id="Snippet5"::: + + +## Char objects and Unicode characters + Each character in a string is defined by a Unicode scalar value, also called a Unicode code point or the ordinal (numeric) value of the Unicode character. Each code point is encoded by using UTF-16 encoding, and the numeric value of each element of the encoding is represented by a object. + +> [!NOTE] +> Note that, because a instance consists of a sequential collection of UTF-16 code units, it is possible to create a object that is not a well-formed Unicode string. For example, it is possible to create a string that has a low surrogate without a corresponding high surrogate. Although some methods, such as the methods of encoding and decoding objects in the namespace, may performs checks to ensure that strings are well-formed, class members don't ensure that a string is well-formed. + + A single object usually represents a single code point; that is, the numeric value of the equals the code point. For example, the code point for the character "a" is U+0061. However, a code point might require more than one encoded element (more than one object). The Unicode standard defines two types of characters that correspond to multiple objects: graphemes, and Unicode supplementary code points that correspond to characters in the Unicode supplementary planes. + +- A grapheme is represented by a base character followed by one or more combining characters. For example, the character ä is represented by a object whose code point is U+0061 followed by a object whose code point is U+0308. This character can also be defined by a single object that has a code point of U+00E4. As the following example shows, a culture-sensitive comparison for equality indicates that these two representations are equal, although an ordinary ordinal comparison does not. However, if the two strings are normalized, an ordinal comparison also indicates that they are equal. (For more information on normalizing strings, see the [Normalization](#Normalization) section.) + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Class/cpp/string.char1.cpp" id="Snippet2"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Overview/grapheme1.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Overview/grapheme1.fs" id="Snippet2"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Class/vb/grapheme1.vb" id="Snippet2"::: + +- A Unicode supplementary code point (a surrogate pair) is represented by a object whose code point is a high surrogate followed by a object whose code point is a low surrogate. The code units of high surrogates range from U+D800 to U+DBFF. The code units of low surrogates range from U+DC00 to U+DFFF. Surrogate pairs are used to represent characters in the 16 Unicode supplementary planes. The following example creates a surrogate character and passes it to the method to determine whether it is a surrogate pair. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Class/cpp/string.char2.cpp" id="Snippet3"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Overview/surrogate1.cs" interactive="try-dotnet-method" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Overview/surrogate1.fs" id="Snippet3"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Class/vb/surrogate1.vb" id="Snippet3"::: + + +## Strings and the Unicode Standard + Characters in a string are represented by UTF-16 encoded code units, which correspond to values. + + Each character in a string has an associated Unicode character category, which is represented in .NET by the enumeration. The category of a character or a surrogate pair can be determined by calling the method. + +[!INCLUDE[character-categories](~/includes/unicode-categories.md)] + + In addition, .NET supports string comparison and sorting based on the Unicode standard. .NET Framework 4 and previous versions maintain their own table of string data. This is also true of versions of .NET Framework starting with .NET Framework 4.5 running on Windows 7. Starting with .NET Framework 4.5 running on Windows 8 and later versions of the Windows operating system, the runtime delegates string comparison and sorting operations to the operating system. On .NET Core and .NET 5+, string comparison and sorting information is provided by [International Components for Unicode](https://icu.unicode.org/) libraries (except on Windows versions prior to Windows 10 May 2019 Update). The following table lists the versions of .NET and the versions of the Unicode Standard on which character comparison and sorting are based. + +|.NET version|Version of the Unicode Standard| +|----------------------------|-------------------------------------| +|.NET Framework 1.1|[The Unicode Standard, Version 4.0.0](https://www.unicode.org/versions/Unicode4.0.0/)| +|.NET Framework 2.0|[The Unicode Standard, Version 5.0.0](https://www.unicode.org/versions/Unicode5.0.0)| +|.NET Framework 3.5|[The Unicode Standard, Version 5.0.0](https://www.unicode.org/versions/Unicode5.0.0)| +|.NET Framework 4|[The Unicode Standard, Version 5.0.0](https://www.unicode.org/versions/Unicode5.0.0)| +|.NET Framework 4.5 and later on Windows 7|[The Unicode Standard, Version 5.0.0](https://www.unicode.org/versions/Unicode5.0.0)| +|.NET Framework 4.5 and later on Windows 8 and later Windows operating systems|[The Unicode Standard, Version 6.3.0](https://www.unicode.org/versions/Unicode6.3.0/)| +|.NET Core and .NET 5+|Depends on the version of the Unicode Standard supported by the underlying operating system.| + + +## Strings and embedded null characters + In .NET, a object can include embedded null characters, which count as a part of the string's length. However, in some languages such as C and C++, a null character indicates the end of a string; it is not considered a part of the string and is not counted as part of the string's length. This means that the following common assumptions that C and C++ programmers or libraries written in C or C++ might make about strings are not necessarily valid when applied to objects: + +- The value returned by the `strlen` or `wcslen` functions does not necessarily equal . + +- The string created by the `strcpy_s` or `wcscpy_s` functions is not necessarily identical to the string created by the method. + + You should ensure that native C and C++ code that instantiates objects, and code that is passed objects through platform invoke, don't assume that an embedded null character marks the end of the string. + + Embedded null characters in a string are also treated differently when a string is sorted (or compared) and when a string is searched. Null characters are ignored when performing culture-sensitive comparisons between two strings, including comparisons using the invariant culture. They are considered only for ordinal or case-insensitive ordinal comparisons. On the other hand, embedded null characters are always considered when searching a string with methods such as , , and . + + +## Strings and indexes + An index is the position of a object (not a Unicode character) in a . An index is a zero-based, nonnegative number that starts from the first position in the string, which is index position zero. A number of search methods, such as and , return the index of a character or substring in the string instance. + + The property lets you access individual objects by their index position in the string. Because the property is the default property (in Visual Basic) or the indexer (in C# and F#), you can access the individual objects in a string by using code such as the following. This code looks for white space or punctuation characters in a string to determine how many words the string contains. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Class/cpp/string.index1.cpp" id="Snippet4"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Overview/index11.cs" interactive="try-dotnet-method" id="Snippet4"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Overview/index11.fs" id="Snippet4"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Class/vb/index1.vb" id="Snippet4"::: + + Because the class implements the interface, you can also iterate through the objects in a string by using a `foreach` construct, as the following example shows. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Class/cpp/string.index2.cpp" id="Snippet5"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Overview/index2.cs" interactive="try-dotnet-method" id="Snippet5"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Overview/index2.fs" id="Snippet5"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Class/vb/index2.vb" id="Snippet5"::: + + Consecutive index values might not correspond to consecutive Unicode characters, because a Unicode character might be encoded as more than one object. In particular, a string may contain multi-character units of text that are formed by a base character followed by one or more combining characters or by surrogate pairs. To work with Unicode characters instead of objects, use the and classes, or the method and the struct. The following example illustrates the difference between code that works with objects and code that works with Unicode characters. It compares the number of characters or text elements in each word of a sentence. The string includes two sequences of a base character followed by a combining character. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Class/cpp/string.index3.cpp" id="Snippet6"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Overview/index3.cs" interactive="try-dotnet-method" id="Snippet6"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Overview/index3.fs" id="Snippet6"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Class/vb/index3.vb" id="Snippet6"::: + + This example works with text elements by using the method and the class to enumerate all the text elements in a string. You can also retrieve an array that contains the starting index of each text element by calling the method. + + For more information about working with units of text rather than individual values, see [Introduction to character encoding in .NET](/dotnet/standard/base-types/character-encoding-introduction). + + +## Null strings and empty strings + A string that has been declared but has not been assigned a value is `null`. Attempting to call methods on that string throws a . A null string is different from an empty string, which is a string whose value is "" or . In some cases, passing either a null string or an empty string as an argument in a method call throws an exception. For example, passing a null string to the method throws an , and passing an empty string throws a . In other cases, a method argument can be either a null string or an empty string. For example, if you are providing an implementation for a class, you want to equate both a null string and an empty string with the general ("G") format specifier. + + The class includes the following two convenience methods that enable you to test whether a string is `null` or empty: + +- , which indicates whether a string is either `null` or is equal to . This method eliminates the need to use code such as the following: + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.string.class.null/cpp/string.null.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Overview/nullorempty1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Overview/nullorempty1.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.class.null/vb/nullorempty1.vb" id="Snippet1"::: + +- , which indicates whether a string is `null`, equals , or consists exclusively of white-space characters. This method eliminates the need to use code such as the following: + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.string.class.null/cpp/string.null.cpp" id="Snippet2"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Overview/nullorempty1.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Overview/nullorempty1.fs" id="Snippet2"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.class.null/vb/nullorempty1.vb" id="Snippet2"::: + + The following example uses the method in the implementation of a custom `Temperature` class. The method supports the "G", "C", "F", and "K" format strings. If an empty format string or a format string whose value is `null` is passed to the method, its value is changed to the "G" format string. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.string.class.null/cpp/string.null.cpp" id="Snippet3"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Overview/nullorempty1.cs" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Overview/nullorempty1.fs" id="Snippet3"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.class.null/vb/nullorempty1.vb" id="Snippet3"::: + + +## Immutability and the StringBuilder class + A object is called immutable (read-only), because its value cannot be modified after it has been created. Methods that appear to modify a object actually return a new object that contains the modification. + + Because strings are immutable, string manipulation routines that perform repeated additions or deletions to what appears to be a single string can exact a significant performance penalty. For example, the following code uses a random number generator to create a string with 1000 characters in the range 0x0001 to 0x052F. Although the code appears to use string concatenation to append a new character to the existing string named `str`, it actually creates a new object for each concatenation operation. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Class/cpp/string.stringbuilder1.cpp" id="Snippet15"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Overview/immutable.cs" id="Snippet15"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Overview/immutable.fs" id="Snippet15"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Class/vb/immutable.vb" id="Snippet15"::: + + You can use the class instead of the class for operations that make multiple changes to the value of a string. Unlike instances of the class, objects are mutable; when you concatenate, append, or delete substrings from a string, the operations are performed on a single string. When you have finished modifying the value of a object, you can call its method to convert it to a string. The following example replaces the used in the previous example to concatenate 1000 random characters in the range to 0x0001 to 0x052F with a object. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Class/cpp/string.stringbuilder2.cpp" id="Snippet16"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Overview/immutable1.cs" id="Snippet16"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Overview/immutable1.fs" id="Snippet16"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Class/vb/immutable1.vb" id="Snippet16"::: + + +## Ordinal vs. culture-sensitive operations + Members of the class perform either ordinal or culture-sensitive (linguistic) operations on a object. An ordinal operation acts on the numeric value of each object. A culture-sensitive operation acts on the value of the object, and takes culture-specific casing, sorting, formatting, and parsing rules into account. Culture-sensitive operations execute in the context of an explicitly declared culture or the implicit current culture. The two kinds of operations can produce very different results when they are performed on the same string. + +.NET also supports culture-insensitive linguistic string operations by using the invariant culture (), which is loosely based on the culture settings of the English language independent of region. Unlike other settings, the settings of the invariant culture are guaranteed to remain consistent on a single computer, from system to system, and across versions of .NET. The invariant culture can be seen as a kind of black box that ensures stability of string comparisons and ordering across all cultures. + +> [!IMPORTANT] +> If your application makes a security decision about a symbolic identifier such as a file name or named pipe, or about persisted data such as the text-based data in an XML file, the operation should use an ordinal comparison instead of a culture-sensitive comparison. This is because a culture-sensitive comparison can yield different results depending on the culture in effect, whereas an ordinal comparison depends solely on the binary value of the compared characters. + +> [!IMPORTANT] +> Most methods that perform string operations include an overload that has a parameter of type , which enables you to specify whether the method performs an ordinal or culture-sensitive operation. In general, you should call this overload to make the intent of your method call clear. For best practices and guidance for using ordinal and culture-sensitive operations on strings, see [Best Practices for Using Strings](/dotnet/standard/base-types/best-practices-strings). + + Operations for [casing](#casing), [parsing and formatting](#parsing), [comparison and sorting](#comparison), and [testing for equality](#equality) can be either ordinal or culture-sensitive. The following sections discuss each category of operation. + +> [!TIP] +> You should always call a method overload that makes the intent of your method call clear. For example, instead of calling the method to perform a culture-sensitive comparison of two strings by using the conventions of the current culture, you should call the method with a value of for the `comparisonType` argument. For more information, see [Best Practices for Using Strings](/dotnet/standard/base-types/best-practices-strings). + +You can download the sorting weight tables, a set of text files that contain information on the character weights used in sorting and comparison operations, from the following links: + +- Windows (.NET Framework and .NET Core): [Sorting Weight Tables](https://www.microsoft.com/download/details.aspx?id=10921) +- Windows 10 May 2019 Update or later (.NET 5+) and Linux and macOS (.NET Core and .NET 5+): [Default Unicode Collation Element Table](https://www.unicode.org/Public/UCA/latest/allkeys.txt) + + +### Casing + Casing rules determine how to change the capitalization of a Unicode character; for example, from lowercase to uppercase. Often, a casing operation is performed before a string comparison. For example, a string might be converted to uppercase so that it can be compared with another uppercase string. You can convert the characters in a string to lowercase by calling the or method, and you can convert them to uppercase by calling the or method. In addition, you can use the method to convert a string to title case. + +[!INCLUDE[platform-note](~/includes/c-and-posix-cultures.md)] + + Casing operations can be based on the rules of the current culture, a specified culture, or the invariant culture. Because case mappings can vary depending on the culture used, the result of casing operations can vary based on culture. The actual differences in casing are of three kinds: + +- Differences in the case mapping of LATIN CAPITAL LETTER I (U+0049), LATIN SMALL LETTER I (U+0069), LATIN CAPITAL LETTER I WITH DOT ABOVE (U+0130), and LATIN SMALL LETTER DOTLESS I (U+0131). In the tr-TR (Turkish (Turkey)) and az-Latn-AZ (Azerbaijan, Latin) cultures, and in the tr, az, and az-Latn neutral cultures, the lowercase equivalent of LATIN CAPITAL LETTER I is LATIN SMALL LETTER DOTLESS I, and the uppercase equivalent of LATIN SMALL LETTER I is LATIN CAPITAL LETTER I WITH DOT ABOVE. In all other cultures, including the invariant culture, LATIN SMALL LETTER I and LATIN CAPITAL LETTER I are lowercase and uppercase equivalents. + + The following example demonstrates how a string comparison designed to prevent file system access can fail if it relies on a culture-sensitive casing comparison. (The casing conventions of the invariant culture should have been used.) + + :::code language="csharp" source="~/snippets/csharp/System/String/Overview/case2.cs" id="Snippet17"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Overview/case2.fs" id="Snippet17"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Class/vb/case2.vb" id="Snippet17"::: + +- Differences in case mappings between the invariant culture and all other cultures. In these cases, using the casing rules of the invariant culture to change a character to uppercase or lowercase returns the same character. For all other cultures, it returns a different character. Some of the affected characters are listed in the following table. + + |Character|If changed to|Returns| + |---------------|-------------------|-------------| + |MICRON SIGN (U+00B5)|Uppercase|GREEK CAPITAL LETTER MU (U+-39C)| + |LATIN CAPITAL LETTER I WITH DOT ABOVE (U+0130)|Lowercase|LATIN SMALL LETTER I (U+0069)| + |LATIN SMALL LETTER DOTLESS I (U+0131)|Uppercase|LATIN CAPITAL LETTER I (U+0049)| + |LATIN SMALL LETTER LONG S (U+017F)|Uppercase|LATIN CAPITAL LETTER S (U+0053)| + |LATIN CAPITAL LETTER D WITH SMALL LETTER Z WITH CARON (U+01C5)|Lowercase|LATIN SMALL LETTER DZ WITH CARON (U+01C6)| + |COMBINING GREEK YPOGEGRAMMENI (U+0345)|Uppercase|GREEK CAPITAL LETTER IOTA (U+0399)| + +- Differences in case mappings of two-letter mixed-case pairs in the ASCII character range. In most cultures, a two-letter mixed-case pair is equal to the equivalent two-letter uppercase or lowercase pair. This is not true for the following two-letter pairs in the following cultures, because in each case they are compared to a digraph: + + - "lJ" and "nJ" in the hr-HR (Croatian (Croatia)) culture. + + - "cH" in the cs-CZ (Czech (Czech Republic)) and sk-SK (Slovak (Slovakia)) cultures. + + - "aA" in the da-DK (Danish (Denmark)) culture. + + - "cS", "dZ", "dZS", "nY", "sZ", "tY", and "zS" in the hu-HU (Hungarian (Hungary)) culture. + + - "cH" and "lL" in the es-ES_tradnl (Spanish (Spain, Traditional Sort)) culture. + + - "cH", "gI", "kH", "nG" "nH", "pH", "qU', "tH", and "tR" in the vi-VN (Vietnamese (Vietnam)) culture. + + However, it is unusual to encounter a situation in which a culture-sensitive comparison of these pairs creates problems, because these pairs are uncommon in fixed strings or identifiers. + + The following example illustrates some of the differences in casing rules between cultures when converting strings to uppercase. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Class/cpp/string.casing.cpp" id="Snippet7"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Overview/case1.cs" id="Snippet7"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Overview/case1.fs" id="Snippet7"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Class/vb/case1.vb" id="Snippet7"::: + + +### Parsing and formatting + Formatting and parsing are inverse operations. Formatting rules determine how to convert a value, such as a date and time or a number, to its string representation, whereas parsing rules determine how to convert a string representation to a value such as a date and time. Both formatting and parsing rules are dependent on cultural conventions. The following example illustrates the ambiguity that can arise when interpreting a culture-specific date string. Without knowing the conventions of the culture that was used to produce a date string, it is not possible to know whether 03/01/2011, 3/1/2011, and 01/03/2011 represent January 3, 2011 or March 1, 2011. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Class/cpp/string.format1.cpp" id="Snippet8"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Overview/format1.cs" id="Snippet8"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Overview/format1.fs" id="Snippet8"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Class/vb/format1.vb" id="Snippet8"::: + + Similarly, as the following example shows, a single string can produce different dates depending on the culture whose conventions are used in the parsing operation. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Class/cpp/string.parse1.cpp" id="Snippet9"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Overview/parse1.cs" id="Snippet9"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Overview/parse1.fs" id="Snippet9"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Class/vb/parse1.vb" id="Snippet9"::: + + +### String comparison and sorting + Conventions for comparing and sorting strings vary from culture to culture. For example, the sort order may be based on phonetics or on the visual representation of characters. In East Asian languages, characters are sorted by the stroke and radical of ideographs. Sorting also depends on the order languages and cultures use for the alphabet. For example, the Danish language has an "Æ" character that it sorts after "Z" in the alphabet. In addition, comparisons can be case-sensitive or case-insensitive, and casing rules might differ by culture. Ordinal comparison, on the other hand, uses the Unicode code points of individual characters in a string when comparing and sorting strings. + + Sort rules determine the alphabetic order of Unicode characters and how two strings compare to each other. For example, the method compares two strings based on the parameter. If the parameter value is , the method performs a linguistic comparison that uses the conventions of the current culture; if the parameter value is , the method performs an ordinal comparison. Consequently, as the following example shows, if the current culture is U.S. English, the first call to the method (using culture-sensitive comparison) considers "a" less than "A", but the second call to the same method (using ordinal comparison) considers "a" greater than "A". + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Class/cpp/string.compare1.cpp" id="Snippet10"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Overview/compare11.cs" id="Snippet10"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Overview/compare11.fs" id="Snippet10"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Class/vb/compare1.vb" id="Snippet10"::: + + .NET supports word, string, and ordinal sort rules: + +- A word sort performs a culture-sensitive comparison of strings in which certain nonalphanumeric Unicode characters might have special weights assigned to them. For example, the hyphen (-) might have a very small weight assigned to it so that "coop" and "co-op" appear next to each other in a sorted list. For a list of the methods that compare two strings using word sort rules, see the [String operations by category](#ByCategory) section. + +- A string sort also performs a culture-sensitive comparison. It is similar to a word sort, except that there are no special cases, and all nonalphanumeric symbols come before all alphanumeric Unicode characters. Two strings can be compared using string sort rules by calling the method overloads that have an `options` parameter that is supplied a value of . Note that this is the only method that .NET provides to compare two strings using string sort rules. + +- An ordinal sort compares strings based on the numeric value of each object in the string. An ordinal comparison is automatically case-sensitive because the lowercase and uppercase versions of a character have different code points. However, if case is not important, you can specify an ordinal comparison that ignores case. This is equivalent to converting the string to uppercase by using the invariant culture and then performing an ordinal comparison on the result. For a list of the methods that compare two strings using ordinal sort rules, see the [String operations by category](#ByCategory) section. + + A culture-sensitive comparison is any comparison that explicitly or implicitly uses a object, including the invariant culture that is specified by the property. The implicit culture is the current culture, which is specified by the and properties. There is considerable variation in the sort order of alphabetic characters (that is, characters for which the property returns `true`) across cultures. You can specify a culture-sensitive comparison that uses the conventions of a specific culture by supplying a object to a string comparison method such as . You can specify a culture-sensitive comparison that uses the conventions of the current culture by supplying , , or any member of the enumeration other than or to an appropriate overload of the method. A culture-sensitive comparison is generally appropriate for sorting whereas an ordinal comparison is not. An ordinal comparison is generally appropriate for determining whether two strings are equal (that is, for determining identity) whereas a culture-sensitive comparison is not. + + The following example illustrates the difference between culture-sensitive and ordinal comparison. The example evaluates three strings, "Apple", "Æble", and "AEble", using ordinal comparison and the conventions of the da-DK and en-US cultures (each of which is the default culture at the time the method is called). Because the Danish language treats the character "Æ" as an individual letter and sorts it after "Z" in the alphabet, the string "Æble" is greater than "Apple". However, "Æble" is not considered equivalent to "AEble", so "Æble" is also greater than "AEble". The en-US culture doesn't include the letter"Æ" but treats it as equivalent to "AE", which explains why "Æble" is less than "Apple" but equal to "AEble". Ordinal comparison, on the other hand, considers "Apple" to be less than "Æble", and "Æble" to be greater than "AEble". + + :::code language="csharp" source="~/snippets/csharp/System/String/Overview/compare4.cs" id="Snippet21"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Overview/compare4.fs" id="Snippet21"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Class/vb/compare4.vb" id="Snippet21"::: + + Use the following general guidelines to choose an appropriate sorting or string comparison method: + +- If you want the strings to be ordered based on the user's culture, you should order them based on the conventions of the current culture. If the user's culture changes, the order of sorted strings will also change accordingly. For example, a thesaurus application should always sort words based on the user's culture. + +- If you want the strings to be ordered based on the conventions of a specific culture, you should order them by supplying a object that represents that culture to a comparison method. For example, in an application designed to teach students a particular language, you want strings to be ordered based on the conventions of one of the cultures that speaks that language. + +- If you want the order of strings to remain unchanged across cultures, you should order them based on the conventions of the invariant culture or use an ordinal comparison. For example, you would use an ordinal sort to organize the names of files, processes, mutexes, or named pipes. + +- For a comparison that involves a security decision (such as whether a username is valid), you should always perform an ordinal test for equality by calling an overload of the method. + +> [!NOTE] +> The culture-sensitive sorting and casing rules used in string comparison depend on the version of the .NET. On .NET Core, string comparison depends on the version of the Unicode Standard supported by the underlying operating system. In .NET Framework 4.5 and later versions running on Windows 8 or later, sorting, casing, normalization, and Unicode character information conform to the Unicode 6.0 standard. On other Windows operating systems, they conform to the Unicode 5.0 standard. + + For more information about word, string, and ordinal sort rules, see the topic. For additional recommendations on when to use each rule, see [Best Practices for Using Strings](/dotnet/standard/base-types/best-practices-strings). + + Ordinarily, you don't call string comparison methods such as directly to determine the sort order of strings. Instead, comparison methods are called by sorting methods such as or . The following example performs four different sorting operations (word sort using the current culture, word sort using the invariant culture, ordinal sort, and string sort using the invariant culture) without explicitly calling a string comparison method, although they do specify the type of comparison to use. Note that each type of sort produces a unique ordering of strings in its array. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Class/cpp/string.compare2.cpp" id="Snippet12"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Overview/compare2.cs" id="Snippet12"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Overview/compare2.fs" id="Snippet12"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Class/vb/compare2.vb" id="Snippet12"::: + +> [!TIP] +> Internally, .NET uses sort keys to support culturally sensitive string comparison. Each character in a string is given several categories of sort weights, including alphabetic, case, and diacritic. A sort key, represented by the class, provides a repository of these weights for a particular string. If your app performs a large number of searching or sorting operations on the same set of strings, you can improve its performance by generating and storing sort keys for all the strings that it uses. When a sort or comparison operation is required, you use the sort keys instead of the strings. For more information, see the class. + + If you don't specify a string comparison convention, sorting methods such as perform a culture-sensitive, case-sensitive sort on strings. The following example illustrates how changing the current culture affects the order of sorted strings in an array. It creates an array of three strings. First, it sets the `System.Threading.Thread.CurrentThread.CurrentCulture` property to en-US and calls the method. The resulting sort order is based on sorting conventions for the English (United States) culture. Next, the example sets the `System.Threading.Thread.CurrentThread.CurrentCulture` property to da-DK and calls the method again. Notice how the resulting sort order differs from the en-US results because it uses the sorting conventions for Danish (Denmark). + + :::code language="csharp" source="~/snippets/csharp/System/String/Overview/sort1.cs" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Overview/sort1.fs" id="Snippet3"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/conceptual.strings.comparing/vb/sort1.vb" id="Snippet3"::: + +> [!WARNING] +> If your primary purpose in comparing strings is to determine whether they are equal, you should call the method. Typically, you should use to perform an ordinal comparison. The method is intended primarily to sort strings. + + String search methods, such as and , also can perform culture-sensitive or ordinal string comparisons. The following example illustrates the differences between ordinal and culture-sensitive comparisons using the method. A culture-sensitive search in which the current culture is English (United States) considers the substring "oe" to match the ligature "œ". Because a soft hyphen (U+00AD) is a zero-width character, the search treats the soft hyphen as equivalent to and finds a match at the beginning of the string. An ordinal search, on the other hand, does not find a match in either case. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Class/cpp/string.compare3.cpp" id="Snippet13"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Overview/compare3.cs" id="Snippet13"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Overview/compare3.fs" id="Snippet13"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Class/vb/compare3.vb" id="Snippet13"::: + +### Search in strings + String search methods, such as and , also can perform culture-sensitive or ordinal string comparisons to determine whether a character or substring is found in a specified string. + + The search methods in the class that search for an individual character, such as the method, or one of a set of characters, such as the method, all perform an ordinal search. To perform a culture-sensitive search for a character, you must call a method such as or . Note that the results of searching for a character using ordinal and culture-sensitive comparison can be very different. For example, a search for a precomposed Unicode character such as the ligature "Æ" (U+00C6) might match any occurrence of its components in the correct sequence, such as "AE" (U+041U+0045), depending on the culture. The following example illustrates the difference between the and methods when searching for an individual character. The ligature "æ" (U+00E6) is found in the string "aerial" when using the conventions of the en-US culture, but not when using the conventions of the da-DK culture or when performing an ordinal comparison. + + :::code language="csharp" source="~/snippets/csharp/System/String/Overview/search1.cs" id="Snippet22"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Overview/search1.fs" id="Snippet22"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Class/vb/search1.vb" id="Snippet22"::: + + On the other hand, class methods that search for a string rather than a character perform a culture-sensitive search if search options are not explicitly specified by a parameter of type . The sole exception is , which performs an ordinal search. + + +### Testing for equality + +Use the method to determine the relationship of two strings in the sort order. Typically, this is a culture-sensitive operation. In contrast, call the method to test for equality. Because the test for equality usually compares user input with some known string, such as a valid user name, a password, or a file system path, it is typically an ordinal operation. + +> [!WARNING] +> It is possible to test for equality by calling the method and determining whether the return value is zero. However, this practice is not recommended. To determine whether two strings are equal, you should call one of the overloads of the method. The preferred overload to call is either the instance method or the static method, because both methods include a parameter that explicitly specifies the type of comparison. + + The following example illustrates the danger of performing a culture-sensitive comparison for equality when an ordinal one should be used instead. In this case, the intent of the code is to prohibit file system access from URLs that begin with "FILE://" or "file://" by performing a case-insensitive comparison of the beginning of a URL with the string "FILE://". However, if a culture-sensitive comparison is performed using the Turkish (Turkey) culture on a URL that begins with "file://", the comparison for equality fails, because the Turkish uppercase equivalent of the lowercase "i" is "İ" instead of "I". As a result, file system access is inadvertently permitted. On the other hand, if an ordinal comparison is performed, the comparison for equality succeeds, and file system access is denied. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Class/cpp/string.equals.cpp" id="Snippet11"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Overview/equality1.cs" id="Snippet11"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Overview/equality1.fs" id="Snippet11"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Class/vb/equality1.vb" id="Snippet11"::: + + +## Normalization + Some Unicode characters have multiple representations. For example, any of the following code points can represent the letter "ắ": + +- U+1EAF + +- U+0103 U+0301 + +- U+0061 U+0306 U+0301 + + Multiple representations for a single character complicate searching, sorting, matching, and other string operations. + + The Unicode standard defines a process called normalization that returns one binary representation of a Unicode character for any of its equivalent binary representations. Normalization can use several algorithms, called normalization forms, that follow different rules. .NET supports Unicode normalization forms C, D, KC, and KD. When strings have been normalized to the same normalization form, they can be compared by using ordinal comparison. + + An ordinal comparison is a binary comparison of the Unicode scalar value of corresponding objects in each string. The class includes a number of methods that can perform an ordinal comparison, including the following: + +- Any overload of the , , , , , and methods that includes a parameter. The method performs an ordinal comparison if you supply a value of or for this parameter. + +- The overloads of the method. + +- Methods that use ordinal comparison by default, such as , , and . + +- Methods that search for a value or for the elements in a array in a string instance. Such methods include and . + + You can determine whether a string is normalized to normalization form C by calling the method, or you can call the method to determine whether a string is normalized to a specified normalization form. You can also call the method to convert a string to normalization form C, or you can call the method to convert a string to a specified normalization form. For step-by-step information about normalizing and comparing strings, see the and methods. + + The following simple example illustrates string normalization. It defines the letter "ố" in three different ways in three different strings, and uses an ordinal comparison for equality to determine that each string differs from the other two strings. It then converts each string to the supported normalization forms, and again performs an ordinal comparison of each string in a specified normalization form. In each case, the second test for equality shows that the strings are equal. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Class/cpp/string.normalize.cpp" id="Snippet14"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Overview/normalize1.cs" id="Snippet14"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Overview/normalize1.fs" id="Snippet14"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Class/vb/normalize1.vb" id="Snippet14"::: + + For more information about normalization and normalization forms, see , as well as [Unicode Standard Annex #15: Unicode Normalization Forms](https://unicode.org/reports/tr15/) and the [Normalization FAQ](https://www.unicode.org/faq/normalization.html) on the unicode.org website. + + +## String operations by category + The class provides members for comparing strings, testing strings for equality, finding characters or substrings in a string, modifying a string, extracting substrings from a string, combining strings, formatting values, copying a string, and normalizing a string. + +### Compare strings + You can compare strings to determine their relative position in the sort order by using the following methods: + +- returns an integer that indicates the relationship of one string to a second string in the sort order. + +- returns an integer that indicates the relationship of one string to a second string based on a comparison of their code points. + +- returns an integer that indicates the relationship of the current string instance to a second string in the sort order. The method provides the and implementations for the class. + +### Test strings for equality + +You call the method to determine whether two strings are equal. The instance and the static overloads let you specify whether the comparison is culture-sensitive or ordinal, and whether case is considered or ignored. Most tests for equality are ordinal, and comparisons for equality that determine access to a system resource (such as a file system object) should always be ordinal. + +### Find characters in a string + +The class includes two kinds of search methods: + +- Methods that return a value to indicate whether a particular substring is present in a string instance. These include the , , and methods. + +- Methods that indicate the starting position of a substring in a string instance. These include the , , , and methods. + +> [!WARNING] +> If you want to search a string for a particular pattern rather than a specific substring, you should use regular expressions. For more information, see [.NET Regular Expressions](/dotnet/standard/base-types/regular-expressions). + +### Modify a string + +The class includes the following methods that appear to modify the value of a string: + +- inserts a string into the current instance. + +- inserts one or more occurrences of a specified character at the beginning of a string. + +- inserts one or more occurrences of a specified character at the end of a string. + +- deletes a substring from the current instance. + +- replaces a substring with another substring in the current instance. + +- and convert all the characters in a string to lowercase. + +- and convert all the characters in a string to uppercase. + +- removes all occurrences of a character from the beginning and end of a string. + +- removes all occurrences of a character from the end of a string. + +- removes all occurrences of a character from the beginning of a string. + +> [!IMPORTANT] +> All string modification methods return a new object. They don't modify the value of the current instance. + +### Extract substrings from a string + +The method separates a single string into multiple strings. Overloads of the method allow you to specify multiple delimiters, to limit the number of substrings that the method extracts, to trim white space from substrings, and to specify whether empty strings (which occur when delimiters are adjacent) are included among the returned strings. + +### Combine strings + +The following methods can be used for string concatenation: + +- combines one or more substrings into a single string. + +- concatenates one or more substrings into a single element and adds a separator between each substring. + +### Format values + +The method uses the composite formatting feature to replace one or more placeholders in a string with the string representation of some object or value. The method is often used to do the following: + +- To embed the string representation of a numeric value in a string. + +- To embed the string representation of a date and time value in a string. + +- To embed the string representation of an enumeration value in a string. + +- To embed the string representation of some object that supports the interface in a string. + +- To right-justify or left-justify a substring in a field within a larger string. + + For detailed information about formatting operations and examples, see the overload summary. + +### Copy a string + +You can call the following methods to make a copy of a string: + +- returns a reference to an existing object. + +- creates a copy of an existing string. + +- copies a portion of a string to a character array. + +### Normalize a string + +In Unicode, a single character can have multiple code points. Normalization converts these equivalent characters into the same binary representation. The method performs the normalization, and the method determines whether a string is normalized. + +For more information and an example, see the [Normalization](#Normalization) section earlier in this topic. + ]]> Sorting Weight Tables for Windows (.NET Framework and .NET Core only) @@ -654,225 +654,225 @@ For more information and an example, see the [Normalization](#Normalization) sec Initializes a new instance of the class. - -## Overloaded constructor syntax - -String constructors fall into two categories: those without pointer parameters, and those with pointer parameters. The constructors that use pointers are not CLS-compliant. In addition, Visual Basic does not support the use of pointers, and C# requires code that uses pointers to run in an unsafe context. For more information, see [unsafe](/dotnet/csharp/language-reference/keywords/unsafe). - -For additional guidance on choosing an overload, see [Which method do I call?](#Tasks). - - `String(Char[] value)`\ - Initializes the new instance to the value indicated by an array of Unicode characters. This constructor copies Unicode characters([example](#Ctor2_Example)). - - `String(Char[] value, Int32 startIndex, Int32 length)`\ - Initializes the new instance to the value indicated by an array of Unicode characters, a starting character position within that array, and a length ([example](#Ctor3_Example)). - - `String(Char c, Int32 count)`\ - Initializes the new instance to the value indicated by a specified Unicode character repeated a specified number of times ([example](#Ctor3_Example)). - - `String(char* value)`\ - **(Not CLS-compliant)** Initializes the new instance to the value indicated by a pointer to an array of Unicode characters that is terminated by a null character (U+0000 or '\0'). ([example](#Ctor4_Example)). - - Permission: , requires full trust for the immediate caller. This member cannot be used by partially trusted or transparent code. - - `String(char* value, Int32 startIndex, Int32 length)`\ - **(Not CLS-compliant)** Initializes the new instance to the value indicated by a pointer to an array of Unicode characters, a starting character position within that array, and a length. The constructor copies the Unicode characters from `value` starting at index `startIndex` and ending at index `startIndex` + `length` - 1 ([example](#Ctor5_Example)). - - Permission: , requires full trust for the immediate caller. This member cannot be used by partially trusted or transparent code. - - `String(SByte* value)`\ - **(Not CLS-compliant)** Initializes the new instance to the value indicated by a pointer to an array of 8-bit signed integers. The array is assumed to represent a string encoded using the current system code page (that is, the encoding specified by ). The constructor processes characters from `value` starting from the location specified by the pointer until a null character (0x00) is reached ([example](#Ctor6_Example)). - - Permission: , requires full trust for the immediate caller. This member cannot be used by partially trusted or transparent code. - - `String(SByte* value, Int32 startIndex, Int32 length)`\ - **(Not CLS-compliant)** Initializes the new instance to the value indicated by a pointer to an array of 8-bit signed integers, a starting position within that array, and a length. The array is assumed to represent a string encoded using the current system code page (that is, the encoding specified by ). The constructor processes characters from value starting at `startIndex` and ending at `startIndex` + `length` - 1 ([example](#Ctor6_Example)). - - Permission: , requires full trust for the immediate caller. This member cannot be used by partially trusted or transparent code. - - `String(SByte* value, Int32 startIndex, Int32 length, Encoding enc)`\ - **(Not CLS-compliant)** Initializes the new instance to the value indicated by a pointer to an array of 8-bit signed integers, a starting position within that array, a length, and an object. - - Permission: , requires full trust for the immediate caller. This member cannot be used by partially trusted or transparent code. - - -## Parameters - -Here is a complete list of parameters used by constructors that don't include a pointer parameter. For the parameters used by each overload, see the overload syntax above. - -|Parameter|Type|Description| -|---------------|----------|-----------------| -|`value`|[]|An array of Unicode characters.| -|`c`||A Unicode character.| -|`startIndex`||The starting position in `value` of the first character in the new string.

Default value: 0| -|`length`||The number of characters in `value` to include in the new string.

Default value: | -|`count`||The number of times the character `c` is repeated in the new string. If `count` is zero, the value of the new object is .| - - Here is a complete list of parameters used by constructors that include a pointer parameter. For the parameters used by each overload, see the overload syntax above. - -|Parameter|Type|Description| -|---------------|----------|-----------------| -|`value`|*

-or-

\*|A pointer to a null-terminated array of Unicode characters or an array of 8-bit signed integers. If `value` is `null` or an empty array, the value of the new string is .| -|`startIndex`||The index of the array element that defines the first character in the new string.

Default value: 0| -|`length`||The number of array elements to use to create the new string. If length is zero, the constructor creates a string whose value is .

Default value: | -|`enc`||An object that specifies how the `value` array is encoded.

Default value: , or the system's current ANSI code page| - - -## Exceptions - Here's a list of exceptions thrown by constructors that don't include pointer parameters. - -|Exception|Condition|Thrown by| -|---------------|---------------|---------------| -||`value` is `null`.|| -||`startIndex`,`length`, or `count` is less than zero.

-or-

The sum of `startIndex` and `length` is greater than the number of elements in `value`.

-or-

`count` is less than zero.|

| - - Here's a list of exceptions thrown by constructors that include pointer parameters. - -|Exception|Condition|Thrown by| -|---------------|---------------|---------------| -||`value` specifies an array that contains an invalid Unicode character.

-or-

`value` or `value` + `startIndex` specifies an address that is less than 64K.

-or-

A new instance could not be initialized from the `value` byte array because `value` does not use the default code page encoding.|All constructors with pointers.| -||`value` is null.|



| -||The current process does not have read access to all the addressed characters.

-or-

`startIndex` or `length` is less than zero, `value` + `startIndex` cause a pointer overflow, or the current process does not have read access to all the addressed characters.

-or-

The length of the new string is too large to allocate.|All constructors with pointers.| -||`value`, or `value` + `startIndex` + `length` - 1, specifies an invalid address.|



| - - -## Which method do I call? - -|To|Call or use| -|--------|-----------------| -|Create a string.|Assignment from a string literal or an existing string ([example](#Ctor1_Example))| -|Create a string from an entire character array.| ([example](#Ctor2_Example))| -|Create a string from a portion of a character array.| ([example](#Ctor3_Example))| -|Create a string that repeats the same character multiple times.| ([example](#Ctor3_Example))| -|Create a string from a pointer to a Unicode or wide character array.|| -|Create a string from a portion of a Unicode or wide character array by using its pointer.|| -|Create a string from a C++ `char` array.|,

-or-

| -|Create a string from ASCII characters.|| - - -## Create strings - -The most commonly used technique for creating strings programmatically is simple assignment, as illustrated in [this example](#Ctor1_Example). The class also includes four types of constructor overloads that let you create strings from the following values: - -- From a character array (an array of UTF-16-encoded characters). You can create a new object from the characters in the entire array or a portion of it. The constructor copies all the characters in the array to the new string. The constructor copies the characters from index `startIndex` to index `startIndex` + `length` - 1 to the new string. If `length` is zero, the value of the new string is . - - If your code repeatedly instantiates strings that have the same value, you can improve application performance by using an alternate means of creating strings. For more information, see [Handling repetitive strings](#Repetitive). - -- From a single character that is duplicated zero, one, or more times, by using the constructor. If `count` is zero, the value of the new string is . - -- From a pointer to a null-terminated character array, by using the or constructor. Either the entire array or a specified range can be used to initialize the string. The constructor copies a sequence of Unicode characters starting from the specified pointer or from the specified pointer plus `startIndex` and continuing to the end of the array or for `length` characters. If `value` is a null pointer or `length` is zero, the constructor creates a string whose value is . If the copy operation proceeds to the end of the array and the array is not null-terminated, the constructor behavior is system-dependent. Such a condition might cause an access violation. - - If the array contains any embedded null characters (U+0000 or '\0') and the overload is called, the string instance contains `length` characters including any embedded nulls. The following example shows what happens when a pointer to an array of 10 elements that includes two null characters is passed to the method. Because the address is the beginning of the array and all elements in the array are to be added to the string, the constructor instantiates a string with ten characters, including two embedded nulls. On the other hand, if the same array is passed to the constructor, the result is a four-character string that does not include the first null character. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.string.ctor/cpp/chptrctor_null.cpp" id="Snippet5"::: - :::code language="csharp" source="~/snippets/csharp/System/String/.ctor/chptrctor_null.cs" id="Snippet5"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/.ctor/chptrctor_null.fs" id="Snippet5"::: - - The array must contain Unicode characters. In C++, this means that the character array must be defined either as the managed [] type or the unmanaged`wchar_t`[] type. - - If the overload is called and the array is not null-terminated, or if the overload is called and `startIndex` + `length`-1 includes a range that is outside the memory allocated for the sequence of characters, the behavior of the constructor is system-dependent, and an access violation may occur. - -- From a pointer to a signed byte array. Either the entire array or a specified range can be used to initialize the string. The sequence of bytes can be interpreted by using the default code page encoding, or an encoding can be specified in the constructor call. If the constructor tries to instantiate a string from an entire array that is not null-terminated, or if the range of the array from `value` + `startIndex` to `value` + `startIndex` + `length` -1 is outside of the memory allocated for the array, the behavior of this constructor is system-dependent, and an access violation may occur. - - The three constructors that include a signed byte array as a parameter are designed primarily to convert a C++ `char` array to a string, as shown in this example: - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.string.ctor/cpp/sbyte_ctor1.cpp" id="Snippet4"::: - - If the array contains any null characters ('\0') or bytes whose value is 0 and the overload is called, the string instance contains `length` characters including any embedded nulls. The following example shows what happens when a pointer to an array of 10 elements that includes two null characters is passed to the method. Because the address is the beginning of the array and all elements in the array are to be added to the string, the constructor instantiates a string with ten characters, including two embedded nulls. On the other hand, if the same array is passed to the constructor, the result is a four-character string that does not include the first null character. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.string.ctor/cpp/ptrctor_null.cpp" id="Snippet6"::: - :::code language="csharp" source="~/snippets/csharp/System/String/.ctor/ptrctor_null.cs" id="Snippet6"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/.ctor/ptrctor_null.fs" id="Snippet6"::: - - Because the and constructors interpret `value` by using the default ANSI code page, calling these constructors with identical byte arrays may create strings that have different values on different systems. - - -## Handle repetitive strings - -Apps that parse or decode streams of text often use the constructor or the method to convert sequences of characters into a string. Repeatedly creating new strings with the same value instead of creating and reusing one string wastes memory. If you are likely to create the same string value repeatedly by calling the constructor, even if you don't know in advance what those identical string values may be, you can use a lookup table instead. - -For example, suppose you read and parse a stream of characters from a file that contains XML tags and attributes. When you parse the stream, you repeatedly encounter certain tokens (that is, sequences of characters that have a symbolic meaning). Tokens equivalent to the strings "0", "1", "true", and "false" are likely to occur frequently in an XML stream. - -Instead of converting each token into a new string, you can create a object to hold commonly occurring strings. The object improves performance, because it retrieves stored strings without allocating temporary memory. When you encounter a token, use the method to retrieve the token from the table. If the token exists, the method returns the corresponding string. If the token does not exist, use the method to insert the token into the table and to get the corresponding string. - - -## Example 1: Use string assignment - -The following example creates a new string by assigning it a string literal. It creates a second string by assigning the value of the first string to it. These are the two most common ways to instantiate a new object. - -:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.string.ctor/cpp/assignment.cpp" id="Snippet1"::: -:::code language="csharp" source="~/snippets/csharp/System/String/.ctor/ctor1.cs" interactive="try-dotnet" id="Snippet1"::: -:::code language="fsharp" source="~/snippets/fsharp/System/String/.ctor/ctor1.fs" id="Snippet1"::: -:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.ctor/vb/ctor1.vb" id="Snippet1"::: - - -## Example 2: Use a character array - -The following example demonstrates how to create a new object from a character array. - -:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/stringexample1/CPP/source.cpp" id="Snippet1"::: -:::code language="csharp" source="~/snippets/csharp/System/String/.ctor/source.cs" interactive="try-dotnet-method" id="Snippet1"::: -:::code language="fsharp" source="~/snippets/fsharp/System/String/.ctor/source.fs" id="Snippet1"::: -:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/stringexample1/VB/source.vb" id="Snippet1"::: - - -## Example 3: Use a portion of a character array and repeating a single character - -The following example demonstrates how to create a new object from a portion of a character array, and how to create a new object that contains multiple occurrences of a single character. - -:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/stringexample1/CPP/source.cpp" id="Snippet3"::: -:::code language="csharp" source="~/snippets/csharp/System/String/.ctor/source.cs" interactive="try-dotnet-method" id="Snippet3"::: -:::code language="fsharp" source="~/snippets/fsharp/System/String/.ctor/source.fs" id="Snippet3"::: -:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/stringexample1/VB/source.vb" id="Snippet3"::: - - -## Example 4: Use a pointer to a character array - -The following example demonstrates how to create a new object from a pointer to an array of characters. The C# example must be compiled by using the `/unsafe` compiler switch. - -:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.string.ctor/cpp/char1_ctor.cpp" id="Snippet2"::: -:::code language="csharp" source="~/snippets/csharp/System/String/.ctor/ctor2.cs" id="Snippet2"::: -:::code language="fsharp" source="~/snippets/fsharp/System/String/.ctor/ctor2.fs" id="Snippet2"::: - - -## Example 5: Instantiate a string from a pointer and a range of an array - -The following example examines the elements of a character array for either a period or an exclamation point. If one is found, it instantiates a string from the characters in the array that precede the punctuation symbol. If not, it instantiates a string with the entire contents of the array. The C# example must be compiled using the `/unsafe` compiler switch. - -:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.string.ctor/cpp/char2_ctor.cpp" id="Snippet3"::: -:::code language="csharp" source="~/snippets/csharp/System/String/.ctor/char2_ctor.cs" id="Snippet3"::: -:::code language="fsharp" source="~/snippets/fsharp/System/String/.ctor/char2_ctor.fs" id="Snippet3"::: - - -## Example 6: Instantiate a string from a pointer to a signed byte array - -The following example demonstrates how you can create an instance of the class with the constructor. - -:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/stringexample1/CPP/source.cpp" id="Snippet2"::: -:::code language="csharp" source="~/snippets/csharp/System/String/.ctor/source.cs" id="Snippet2"::: -:::code language="fsharp" source="~/snippets/fsharp/System/String/.ctor/source.fs" id="Snippet2"::: - + +## Overloaded constructor syntax + +String constructors fall into two categories: those without pointer parameters, and those with pointer parameters. The constructors that use pointers are not CLS-compliant. In addition, Visual Basic does not support the use of pointers, and C# requires code that uses pointers to run in an unsafe context. For more information, see [unsafe](/dotnet/csharp/language-reference/keywords/unsafe). + +For additional guidance on choosing an overload, see [Which method do I call?](#Tasks). + + `String(Char[] value)`\ + Initializes the new instance to the value indicated by an array of Unicode characters. This constructor copies Unicode characters([example](#Ctor2_Example)). + + `String(Char[] value, Int32 startIndex, Int32 length)`\ + Initializes the new instance to the value indicated by an array of Unicode characters, a starting character position within that array, and a length ([example](#Ctor3_Example)). + + `String(Char c, Int32 count)`\ + Initializes the new instance to the value indicated by a specified Unicode character repeated a specified number of times ([example](#Ctor3_Example)). + + `String(char* value)`\ + **(Not CLS-compliant)** Initializes the new instance to the value indicated by a pointer to an array of Unicode characters that is terminated by a null character (U+0000 or '\0'). ([example](#Ctor4_Example)). + + Permission: , requires full trust for the immediate caller. This member cannot be used by partially trusted or transparent code. + + `String(char* value, Int32 startIndex, Int32 length)`\ + **(Not CLS-compliant)** Initializes the new instance to the value indicated by a pointer to an array of Unicode characters, a starting character position within that array, and a length. The constructor copies the Unicode characters from `value` starting at index `startIndex` and ending at index `startIndex` + `length` - 1 ([example](#Ctor5_Example)). + + Permission: , requires full trust for the immediate caller. This member cannot be used by partially trusted or transparent code. + + `String(SByte* value)`\ + **(Not CLS-compliant)** Initializes the new instance to the value indicated by a pointer to an array of 8-bit signed integers. The array is assumed to represent a string encoded using the current system code page (that is, the encoding specified by ). The constructor processes characters from `value` starting from the location specified by the pointer until a null character (0x00) is reached ([example](#Ctor6_Example)). + + Permission: , requires full trust for the immediate caller. This member cannot be used by partially trusted or transparent code. + + `String(SByte* value, Int32 startIndex, Int32 length)`\ + **(Not CLS-compliant)** Initializes the new instance to the value indicated by a pointer to an array of 8-bit signed integers, a starting position within that array, and a length. The array is assumed to represent a string encoded using the current system code page (that is, the encoding specified by ). The constructor processes characters from value starting at `startIndex` and ending at `startIndex` + `length` - 1 ([example](#Ctor6_Example)). + + Permission: , requires full trust for the immediate caller. This member cannot be used by partially trusted or transparent code. + + `String(SByte* value, Int32 startIndex, Int32 length, Encoding enc)`\ + **(Not CLS-compliant)** Initializes the new instance to the value indicated by a pointer to an array of 8-bit signed integers, a starting position within that array, a length, and an object. + + Permission: , requires full trust for the immediate caller. This member cannot be used by partially trusted or transparent code. + + +## Parameters + +Here is a complete list of parameters used by constructors that don't include a pointer parameter. For the parameters used by each overload, see the overload syntax above. + +|Parameter|Type|Description| +|---------------|----------|-----------------| +|`value`|[]|An array of Unicode characters.| +|`c`||A Unicode character.| +|`startIndex`||The starting position in `value` of the first character in the new string.

Default value: 0| +|`length`||The number of characters in `value` to include in the new string.

Default value: | +|`count`||The number of times the character `c` is repeated in the new string. If `count` is zero, the value of the new object is .| + + Here is a complete list of parameters used by constructors that include a pointer parameter. For the parameters used by each overload, see the overload syntax above. + +|Parameter|Type|Description| +|---------------|----------|-----------------| +|`value`|*

-or-

\*|A pointer to a null-terminated array of Unicode characters or an array of 8-bit signed integers. If `value` is `null` or an empty array, the value of the new string is .| +|`startIndex`||The index of the array element that defines the first character in the new string.

Default value: 0| +|`length`||The number of array elements to use to create the new string. If length is zero, the constructor creates a string whose value is .

Default value: | +|`enc`||An object that specifies how the `value` array is encoded.

Default value: , or the system's current ANSI code page| + + +## Exceptions + Here's a list of exceptions thrown by constructors that don't include pointer parameters. + +|Exception|Condition|Thrown by| +|---------------|---------------|---------------| +||`value` is `null`.|| +||`startIndex`,`length`, or `count` is less than zero.

-or-

The sum of `startIndex` and `length` is greater than the number of elements in `value`.

-or-

`count` is less than zero.|

| + + Here's a list of exceptions thrown by constructors that include pointer parameters. + +|Exception|Condition|Thrown by| +|---------------|---------------|---------------| +||`value` specifies an array that contains an invalid Unicode character.

-or-

`value` or `value` + `startIndex` specifies an address that is less than 64K.

-or-

A new instance could not be initialized from the `value` byte array because `value` does not use the default code page encoding.|All constructors with pointers.| +||`value` is null.|



| +||The current process does not have read access to all the addressed characters.

-or-

`startIndex` or `length` is less than zero, `value` + `startIndex` cause a pointer overflow, or the current process does not have read access to all the addressed characters.

-or-

The length of the new string is too large to allocate.|All constructors with pointers.| +||`value`, or `value` + `startIndex` + `length` - 1, specifies an invalid address.|



| + + +## Which method do I call? + +|To|Call or use| +|--------|-----------------| +|Create a string.|Assignment from a string literal or an existing string ([example](#Ctor1_Example))| +|Create a string from an entire character array.| ([example](#Ctor2_Example))| +|Create a string from a portion of a character array.| ([example](#Ctor3_Example))| +|Create a string that repeats the same character multiple times.| ([example](#Ctor3_Example))| +|Create a string from a pointer to a Unicode or wide character array.|| +|Create a string from a portion of a Unicode or wide character array by using its pointer.|| +|Create a string from a C++ `char` array.|,

-or-

| +|Create a string from ASCII characters.|| + + +## Create strings + +The most commonly used technique for creating strings programmatically is simple assignment, as illustrated in [this example](#Ctor1_Example). The class also includes four types of constructor overloads that let you create strings from the following values: + +- From a character array (an array of UTF-16-encoded characters). You can create a new object from the characters in the entire array or a portion of it. The constructor copies all the characters in the array to the new string. The constructor copies the characters from index `startIndex` to index `startIndex` + `length` - 1 to the new string. If `length` is zero, the value of the new string is . + + If your code repeatedly instantiates strings that have the same value, you can improve application performance by using an alternate means of creating strings. For more information, see [Handling repetitive strings](#Repetitive). + +- From a single character that is duplicated zero, one, or more times, by using the constructor. If `count` is zero, the value of the new string is . + +- From a pointer to a null-terminated character array, by using the or constructor. Either the entire array or a specified range can be used to initialize the string. The constructor copies a sequence of Unicode characters starting from the specified pointer or from the specified pointer plus `startIndex` and continuing to the end of the array or for `length` characters. If `value` is a null pointer or `length` is zero, the constructor creates a string whose value is . If the copy operation proceeds to the end of the array and the array is not null-terminated, the constructor behavior is system-dependent. Such a condition might cause an access violation. + + If the array contains any embedded null characters (U+0000 or '\0') and the overload is called, the string instance contains `length` characters including any embedded nulls. The following example shows what happens when a pointer to an array of 10 elements that includes two null characters is passed to the method. Because the address is the beginning of the array and all elements in the array are to be added to the string, the constructor instantiates a string with ten characters, including two embedded nulls. On the other hand, if the same array is passed to the constructor, the result is a four-character string that does not include the first null character. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.string.ctor/cpp/chptrctor_null.cpp" id="Snippet5"::: + :::code language="csharp" source="~/snippets/csharp/System/String/.ctor/chptrctor_null.cs" id="Snippet5"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/.ctor/chptrctor_null.fs" id="Snippet5"::: + + The array must contain Unicode characters. In C++, this means that the character array must be defined either as the managed [] type or the unmanaged`wchar_t`[] type. + + If the overload is called and the array is not null-terminated, or if the overload is called and `startIndex` + `length`-1 includes a range that is outside the memory allocated for the sequence of characters, the behavior of the constructor is system-dependent, and an access violation may occur. + +- From a pointer to a signed byte array. Either the entire array or a specified range can be used to initialize the string. The sequence of bytes can be interpreted by using the default code page encoding, or an encoding can be specified in the constructor call. If the constructor tries to instantiate a string from an entire array that is not null-terminated, or if the range of the array from `value` + `startIndex` to `value` + `startIndex` + `length` -1 is outside of the memory allocated for the array, the behavior of this constructor is system-dependent, and an access violation may occur. + + The three constructors that include a signed byte array as a parameter are designed primarily to convert a C++ `char` array to a string, as shown in this example: + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.string.ctor/cpp/sbyte_ctor1.cpp" id="Snippet4"::: + + If the array contains any null characters ('\0') or bytes whose value is 0 and the overload is called, the string instance contains `length` characters including any embedded nulls. The following example shows what happens when a pointer to an array of 10 elements that includes two null characters is passed to the method. Because the address is the beginning of the array and all elements in the array are to be added to the string, the constructor instantiates a string with ten characters, including two embedded nulls. On the other hand, if the same array is passed to the constructor, the result is a four-character string that does not include the first null character. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.string.ctor/cpp/ptrctor_null.cpp" id="Snippet6"::: + :::code language="csharp" source="~/snippets/csharp/System/String/.ctor/ptrctor_null.cs" id="Snippet6"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/.ctor/ptrctor_null.fs" id="Snippet6"::: + + Because the and constructors interpret `value` by using the default ANSI code page, calling these constructors with identical byte arrays may create strings that have different values on different systems. + + +## Handle repetitive strings + +Apps that parse or decode streams of text often use the constructor or the method to convert sequences of characters into a string. Repeatedly creating new strings with the same value instead of creating and reusing one string wastes memory. If you are likely to create the same string value repeatedly by calling the constructor, even if you don't know in advance what those identical string values may be, you can use a lookup table instead. + +For example, suppose you read and parse a stream of characters from a file that contains XML tags and attributes. When you parse the stream, you repeatedly encounter certain tokens (that is, sequences of characters that have a symbolic meaning). Tokens equivalent to the strings "0", "1", "true", and "false" are likely to occur frequently in an XML stream. + +Instead of converting each token into a new string, you can create a object to hold commonly occurring strings. The object improves performance, because it retrieves stored strings without allocating temporary memory. When you encounter a token, use the method to retrieve the token from the table. If the token exists, the method returns the corresponding string. If the token does not exist, use the method to insert the token into the table and to get the corresponding string. + + +## Example 1: Use string assignment + +The following example creates a new string by assigning it a string literal. It creates a second string by assigning the value of the first string to it. These are the two most common ways to instantiate a new object. + +:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.string.ctor/cpp/assignment.cpp" id="Snippet1"::: +:::code language="csharp" source="~/snippets/csharp/System/String/.ctor/ctor1.cs" interactive="try-dotnet" id="Snippet1"::: +:::code language="fsharp" source="~/snippets/fsharp/System/String/.ctor/ctor1.fs" id="Snippet1"::: +:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.ctor/vb/ctor1.vb" id="Snippet1"::: + + +## Example 2: Use a character array + +The following example demonstrates how to create a new object from a character array. + +:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/stringexample1/CPP/source.cpp" id="Snippet1"::: +:::code language="csharp" source="~/snippets/csharp/System/String/.ctor/source.cs" interactive="try-dotnet-method" id="Snippet1"::: +:::code language="fsharp" source="~/snippets/fsharp/System/String/.ctor/source.fs" id="Snippet1"::: +:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/stringexample1/VB/source.vb" id="Snippet1"::: + + +## Example 3: Use a portion of a character array and repeating a single character + +The following example demonstrates how to create a new object from a portion of a character array, and how to create a new object that contains multiple occurrences of a single character. + +:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/stringexample1/CPP/source.cpp" id="Snippet3"::: +:::code language="csharp" source="~/snippets/csharp/System/String/.ctor/source.cs" interactive="try-dotnet-method" id="Snippet3"::: +:::code language="fsharp" source="~/snippets/fsharp/System/String/.ctor/source.fs" id="Snippet3"::: +:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/stringexample1/VB/source.vb" id="Snippet3"::: + + +## Example 4: Use a pointer to a character array + +The following example demonstrates how to create a new object from a pointer to an array of characters. The C# example must be compiled by using the `/unsafe` compiler switch. + +:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.string.ctor/cpp/char1_ctor.cpp" id="Snippet2"::: +:::code language="csharp" source="~/snippets/csharp/System/String/.ctor/ctor2.cs" id="Snippet2"::: +:::code language="fsharp" source="~/snippets/fsharp/System/String/.ctor/ctor2.fs" id="Snippet2"::: + + +## Example 5: Instantiate a string from a pointer and a range of an array + +The following example examines the elements of a character array for either a period or an exclamation point. If one is found, it instantiates a string from the characters in the array that precede the punctuation symbol. If not, it instantiates a string with the entire contents of the array. The C# example must be compiled using the `/unsafe` compiler switch. + +:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.string.ctor/cpp/char2_ctor.cpp" id="Snippet3"::: +:::code language="csharp" source="~/snippets/csharp/System/String/.ctor/char2_ctor.cs" id="Snippet3"::: +:::code language="fsharp" source="~/snippets/fsharp/System/String/.ctor/char2_ctor.fs" id="Snippet3"::: + + +## Example 6: Instantiate a string from a pointer to a signed byte array + +The following example demonstrates how you can create an instance of the class with the constructor. + +:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/stringexample1/CPP/source.cpp" id="Snippet2"::: +:::code language="csharp" source="~/snippets/csharp/System/String/.ctor/source.cs" id="Snippet2"::: +:::code language="fsharp" source="~/snippets/fsharp/System/String/.ctor/source.fs" id="Snippet2"::: + ]]>
@@ -931,13 +931,13 @@ The following example demonstrates how you can create an instance of the A pointer to a null-terminated array of Unicode characters. Initializes a new instance of the class to the value indicated by a specified pointer to an array of Unicode characters. - [!NOTE] -> For examples and comprehensive usage information about this and other `String` constructor overloads, see the constructor summary. - + [!NOTE] +> For examples and comprehensive usage information about this and other `String` constructor overloads, see the constructor summary. + ]]> The current process does not have read access to all the addressed characters. @@ -997,13 +997,13 @@ The following example demonstrates how you can create an instance of the An array of Unicode characters. Initializes a new instance of the class to the Unicode characters indicated in the specified character array. - [!NOTE] -> For examples and comprehensive usage information about this and other `String` constructor overloads, see the constructor summary. - + [!NOTE] +> For examples and comprehensive usage information about this and other `String` constructor overloads, see the constructor summary. + ]]>
@@ -1097,13 +1097,13 @@ The following example demonstrates how you can create an instance of the A pointer to a null-terminated array of 8-bit signed integers. The integers are interpreted using the current system code page encoding (that is, the encoding specified by ). Initializes a new instance of the class to the value indicated by a pointer to an array of 8-bit signed integers. - [!NOTE] -> For examples and comprehensive usage information about this and other `String` constructor overloads, see the constructor summary. - + [!NOTE] +> For examples and comprehensive usage information about this and other `String` constructor overloads, see the constructor summary. + ]]> @@ -1163,13 +1163,13 @@ The following example demonstrates how you can create an instance of the The number of times occurs. Initializes a new instance of the class to the value indicated by a specified Unicode character repeated a specified number of times. - [!NOTE] -> For examples and comprehensive usage information about this and other `String` constructor overloads, see the constructor summary. - + [!NOTE] +> For examples and comprehensive usage information about this and other `String` constructor overloads, see the constructor summary. + ]]> @@ -1234,13 +1234,13 @@ The following example demonstrates how you can create an instance of the The number of characters within to use. Initializes a new instance of the class to the value indicated by a specified pointer to an array of Unicode characters, a starting character position within that array, and a length. - [!NOTE] -> For examples and comprehensive usage information about this and other `String` constructor overloads, see the constructor summary. - + [!NOTE] +> For examples and comprehensive usage information about this and other `String` constructor overloads, see the constructor summary. + ]]> @@ -1300,23 +1300,23 @@ The following example demonstrates how you can create an instance of the The number of characters within to use. Initializes a new instance of the class to the value indicated by an array of Unicode characters, a starting character position within that array, and a length. - [!NOTE] -> For examples and comprehensive usage information about this and other `String` constructor overloads, see the constructor summary. - + [!NOTE] +> For examples and comprehensive usage information about this and other `String` constructor overloads, see the constructor summary. + ]]> is . - or is less than zero. - - -or- - - The sum of and is greater than the number of elements in . + or is less than zero. + +-or- + +The sum of and is greater than the number of elements in .
@@ -1373,32 +1373,32 @@ The following example demonstrates how you can create an instance of the The number of characters within to use. Initializes a new instance of the class to the value indicated by a specified pointer to an array of 8-bit signed integers, a starting position within that array, and a length. - [!NOTE] -> For examples and comprehensive usage information about this and other `String` constructor overloads, see the constructor summary. - + [!NOTE] +> For examples and comprehensive usage information about this and other `String` constructor overloads, see the constructor summary. + ]]> is . - or is less than zero. - - -or- - - The address specified by + is too large for the current platform; that is, the address calculation overflowed. - - -or- - - The length of the new string to initialize is too large to allocate. - The address specified by + is less than 64K. - - -or- - - A new instance of could not be initialized using , assuming is encoded in ANSI. + or is less than zero. + +-or- + +The address specified by + is too large for the current platform; that is, the address calculation overflowed. + +-or- + +The length of the new string to initialize is too large to allocate. + The address specified by + is less than 64K. + +-or- + +A new instance of could not be initialized using , assuming is encoded in ANSI. , , and collectively specify an invalid address. @@ -1466,32 +1466,32 @@ The following example demonstrates how you can create an instance of the An object that specifies how the array referenced by is encoded. If is , ANSI encoding is assumed. Initializes a new instance of the class to the value indicated by a specified pointer to an array of 8-bit signed integers, a starting position within that array, a length, and an object. - [!NOTE] -> For examples and comprehensive usage information about this and other `String` constructor overloads, see the constructor summary. - + [!NOTE] +> For examples and comprehensive usage information about this and other `String` constructor overloads, see the constructor summary. + ]]> is . - or is less than zero. - - -or- - - The address specified by + is too large for the current platform; that is, the address calculation overflowed. - - -or- - - The length of the new string to initialize is too large to allocate. - The address specified by + is less than 64K. - - -or- - - A new instance of could not be initialized using , assuming is encoded as specified by . + or is less than zero. + +-or- + +The address specified by + is too large for the current platform; that is, the address calculation overflowed. + +-or- + +The length of the new string to initialize is too large to allocate. + The address specified by + is less than 64K. + +-or- + +A new instance of could not be initialized using , assuming is encoded as specified by . , , and collectively specify an invalid address. @@ -1547,27 +1547,27 @@ The following example demonstrates how you can create an instance of the Gets the object at a specified position in the current object. The object at position . - object at the position specified by the `index` parameter. However, a Unicode character might be represented by more than one . Use the class to work with Unicode characters instead of objects. For more information, see the "Char Objects and Unicode Characters" section in the class overview. - - In C#, the property is an indexer. In Visual Basic, it is the default property of the class. Each object in the string can be accessed by using code such as the following. - - :::code language="csharp" source="~/snippets/csharp/System/String/Chars/chars1.cs" interactive="try-dotnet-method" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Chars/chars1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.chars/vb/chars1.vb" id="Snippet1"::: - -## Examples - The following example demonstrates how you can use this indexer in a routine to validate a string. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Uri_IsHexDigit/CPP/uri_ishexdigit.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Chars/uri_ishexdigit.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Chars/uri_ishexdigit.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Uri_IsHexDigit/VB/uri_ishexdigit.vb" id="Snippet1"::: - + object at the position specified by the `index` parameter. However, a Unicode character might be represented by more than one . Use the class to work with Unicode characters instead of objects. For more information, see the "Char Objects and Unicode Characters" section in the class overview. + + In C#, the property is an indexer. In Visual Basic, it is the default property of the class. Each object in the string can be accessed by using code such as the following. + + :::code language="csharp" source="~/snippets/csharp/System/String/Chars/chars1.cs" interactive="try-dotnet-method" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Chars/chars1.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.chars/vb/chars1.vb" id="Snippet1"::: + +## Examples + The following example demonstrates how you can use this indexer in a routine to validate a string. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/Uri_IsHexDigit/CPP/uri_ishexdigit.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Chars/uri_ishexdigit.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Chars/uri_ishexdigit.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/Uri_IsHexDigit/VB/uri_ishexdigit.vb" id="Snippet1"::: + ]]> @@ -1618,13 +1618,13 @@ The following example demonstrates how you can create an instance of the Returns a reference to this instance of . This instance of . - or method to create a separate object with the same value as this instance. - - Because the method simply returns the existing string instance, there is little reason to call it directly. - + or method to create a separate object with the same value as this instance. + + Because the method simply returns the existing string instance, there is little reason to call it directly. + ]]> @@ -1642,20 +1642,20 @@ The following example demonstrates how you can create an instance of the Compares two specified objects and returns an integer that indicates their relative position in the sort order. - method return a 32-bit signed integer indicating the lexical relationship between the two comparands. - -|Value|Condition| -|-----------|---------------| -|Less than zero|The first substring precedes the second substring in the sort order.| -|Zero|The substrings occur in the same position in the sort order, or `length` is zero.| -|Greater than zero|The first substring follows the second substring in the sort order.| - -> [!WARNING] -> Whenever possible, you should call an overload of the method that includes a parameter. For more information, see [Best Practices for Using Strings](/dotnet/standard/base-types/best-practices-strings). - + method return a 32-bit signed integer indicating the lexical relationship between the two comparands. + +|Value|Condition| +|-----------|---------------| +|Less than zero|The first substring precedes the second substring in the sort order.| +|Zero|The substrings occur in the same position in the sort order, or `length` is zero.| +|Greater than zero|The first substring follows the second substring in the sort order.| + +> [!WARNING] +> Whenever possible, you should call an overload of the method that includes a parameter. For more information, see [Best Practices for Using Strings](/dotnet/standard/base-types/best-practices-strings). + ]]> Best Practices for Using Strings in .NET @@ -1717,79 +1717,82 @@ The following example demonstrates how you can create an instance of the The first string to compare. The second string to compare. Compares two specified objects and returns an integer that indicates their relative position in the sort order. - A 32-bit signed integer that indicates the lexical relationship between the two comparands. - - Value - - Condition - - Less than zero - - precedes in the sort order. - - Zero - - occurs in the same position as in the sort order. - - Greater than zero - - follows in the sort order. - - + A 32-bit signed integer that indicates the lexical relationship between the two comparands. + + Value + + + Condition + + + + + Less than zero + + + precedes in the sort order. + + + Zero + + + occurs in the same position as in the sort order. + + + Greater than zero + + + follows in the sort order. + + - . - -> [!WARNING] -> When comparing strings, you should call the method, which requires that you explicitly specify the type of string comparison that the method uses. For more information, see [Best Practices for Using Strings](/dotnet/standard/base-types/best-practices-strings). - - One or both comparands can be `null`. By definition, any string, including the empty string (""), compares greater than a null reference; and two null references compare equal to each other. - - The comparison terminates when an inequality is discovered or both strings have been compared. However, if the two strings compare equal to the end of one string, and the other string has characters remaining, then the string with remaining characters is considered greater. The return value is the result of the last comparison performed. - - Unexpected results can occur when comparisons are affected by culture-specific casing rules. For example, in Turkish, the following example yields the wrong results because the file system in Turkish does not use linguistic casing rules for the letter "i" in "file". - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Compare/cpp/remarks.cpp" id="Snippet10"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Compare/remarks.cs" id="Snippet10"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Compare/remarks.fs" id="Snippet10"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Compare/vb/remarks.vb" id="Snippet10"::: - - Compare the path name to "file" using an ordinal comparison. The correct code to do this is as follows: - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Compare/cpp/remarks.cpp" id="Snippet11"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Compare/remarks.cs" id="Snippet11"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Compare/remarks.fs" id="Snippet11"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Compare/vb/remarks.vb" id="Snippet11"::: - -## Examples - The following example calls the method to compare three sets of strings. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Compare/cpp/compare02.cpp" id="Snippet18"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Compare/compare02.cs" interactive="try-dotnet-method" id="Snippet18"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Compare/compare02.fs" id="Snippet18"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Compare/vb/compare02.vb" id="Snippet18"::: - - In the following example, the `ReverseStringComparer` class demonstrates how you can evaluate two strings with the method. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/ArrayList/CPP/ArrayListSample.cpp" id="Snippet7"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Compare/ArrayListSample.cs" interactive="try-dotnet" id="Snippet7"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Compare/ArrayListSample.fs" id="Snippet7"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ArrayList/VB/ArrayListSample.vb" id="Snippet7"::: - + . + +> [!WARNING] +> When comparing strings, you should call the method, which requires that you explicitly specify the type of string comparison that the method uses. For more information, see [Best Practices for Using Strings](/dotnet/standard/base-types/best-practices-strings). + + One or both comparands can be `null`. By definition, any string, including the empty string (""), compares greater than a null reference; and two null references compare equal to each other. + + The comparison terminates when an inequality is discovered or both strings have been compared. However, if the two strings compare equal to the end of one string, and the other string has characters remaining, then the string with remaining characters is considered greater. The return value is the result of the last comparison performed. + + Unexpected results can occur when comparisons are affected by culture-specific casing rules. For example, in Turkish, the following example yields the wrong results because the file system in Turkish does not use linguistic casing rules for the letter "i" in "file". + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Compare/cpp/remarks.cpp" id="Snippet10"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Compare/remarks.cs" id="Snippet10"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Compare/remarks.fs" id="Snippet10"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Compare/vb/remarks.vb" id="Snippet10"::: + + Compare the path name to "file" using an ordinal comparison. The correct code to do this is as follows: + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Compare/cpp/remarks.cpp" id="Snippet11"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Compare/remarks.cs" id="Snippet11"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Compare/remarks.fs" id="Snippet11"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Compare/vb/remarks.vb" id="Snippet11"::: + +## Examples + The following example calls the method to compare three sets of strings. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Compare/cpp/compare02.cpp" id="Snippet18"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Compare/compare02.cs" interactive="try-dotnet-method" id="Snippet18"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Compare/compare02.fs" id="Snippet18"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Compare/vb/compare02.vb" id="Snippet18"::: + + In the following example, the `ReverseStringComparer` class demonstrates how you can evaluate two strings with the method. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/ArrayList/CPP/ArrayListSample.cpp" id="Snippet7"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Compare/ArrayListSample.cs" interactive="try-dotnet" id="Snippet7"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Compare/ArrayListSample.fs" id="Snippet7"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ArrayList/VB/ArrayListSample.vb" id="Snippet7"::: + ]]> - Character sets include ignorable characters. The method does not consider such characters when it performs a culture-sensitive comparison. For example, if the following code is run on the .NET Framework 4 or later, a culture-sensitive comparison of "animal" with "ani-mal" (using a soft hyphen, or U+00AD) indicates that the two strings are equivalent. - - :::code language="csharp" source="~/snippets/csharp/System/String/Compare/compare21.cs" id="Snippet21"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Compare/compare21.fs" id="Snippet21"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Compare/vb/compare21.vb" id="Snippet21"::: - - To recognize ignorable characters in a string comparison, call the method and supply a value of either or for the `comparisonType` parameter. + Character sets include ignorable characters. The method does not consider such characters when it performs a culture-sensitive comparison. For example, if the following code is run on the .NET Framework 4 or later, a culture-sensitive comparison of "animal" with "ani-mal" (using a soft hyphen, or U+00AD) indicates that the two strings are equivalent. :::code language="csharp" source="~/snippets/csharp/System/String/Compare/compare21.cs" id="Snippet21"::: :::code language="fsharp" source="~/snippets/fsharp/System/String/Compare/compare21.fs" id="Snippet21"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Compare/vb/compare21.vb" id="Snippet21"::: To recognize ignorable characters in a string comparison, call the method and supply a value of either or for the `comparisonType` parameter. @@ -1853,72 +1856,75 @@ The following example demonstrates how you can create an instance of the to ignore case during the comparison; otherwise, . Compares two specified objects, ignoring or honoring their case, and returns an integer that indicates their relative position in the sort order. - A 32-bit signed integer that indicates the lexical relationship between the two comparands. - - Value - - Condition - - Less than zero - - precedes in the sort order. - - Zero - - occurs in the same position as in the sort order. - - Greater than zero - - follows in the sort order. - - + A 32-bit signed integer that indicates the lexical relationship between the two comparands. + + Value + + + Condition + + + + + Less than zero + + + precedes in the sort order. + + + Zero + + + occurs in the same position as in the sort order. + + + Greater than zero + + + follows in the sort order. + + - . - -> [!WARNING] -> When comparing strings, you should call the method, which requires that you explicitly specify the type of string comparison that the method uses. For more information, see [Best Practices for Using Strings](/dotnet/standard/base-types/best-practices-strings). - - One or both comparands can be `null`. By definition, any string, including the empty string (""), compares greater than a null reference; and two null references compare equal to each other. - - The comparison terminates when an inequality is discovered or both strings have been compared. However, if the two strings compare equal to the end of one string, and the other string has characters remaining, then the string with remaining characters is considered greater. The return value is the result of the last comparison performed. - - Unexpected results can occur when comparisons are affected by culture-specific casing rules. For example, in Turkish, the following example yields the wrong results because the file system in Turkish does not use linguistic casing rules for the letter "i" in "file". - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Compare/cpp/remarks.cpp" id="Snippet12"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Compare/remarks.cs" id="Snippet12"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Compare/remarks.fs" id="Snippet12"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Compare/vb/remarks.vb" id="Snippet12"::: - - Compare the path name to "file" using an ordinal comparison. The correct code to do this is as follows: - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Compare/cpp/remarks.cpp" id="Snippet13"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Compare/remarks.cs" id="Snippet13"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Compare/remarks.fs" id="Snippet13"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Compare/vb/remarks.vb" id="Snippet13"::: - -## Examples - The following example demonstrates that the method is equivalent to using or when comparing strings. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Compare/cpp/compare02.cpp" id="Snippet18"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Compare/compare02.cs" interactive="try-dotnet-method" id="Snippet18"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Compare/compare02.fs" id="Snippet18"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Compare/vb/compare02.vb" id="Snippet18"::: - + . + +> [!WARNING] +> When comparing strings, you should call the method, which requires that you explicitly specify the type of string comparison that the method uses. For more information, see [Best Practices for Using Strings](/dotnet/standard/base-types/best-practices-strings). + + One or both comparands can be `null`. By definition, any string, including the empty string (""), compares greater than a null reference; and two null references compare equal to each other. + + The comparison terminates when an inequality is discovered or both strings have been compared. However, if the two strings compare equal to the end of one string, and the other string has characters remaining, then the string with remaining characters is considered greater. The return value is the result of the last comparison performed. + + Unexpected results can occur when comparisons are affected by culture-specific casing rules. For example, in Turkish, the following example yields the wrong results because the file system in Turkish does not use linguistic casing rules for the letter "i" in "file". + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Compare/cpp/remarks.cpp" id="Snippet12"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Compare/remarks.cs" id="Snippet12"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Compare/remarks.fs" id="Snippet12"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Compare/vb/remarks.vb" id="Snippet12"::: + + Compare the path name to "file" using an ordinal comparison. The correct code to do this is as follows: + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Compare/cpp/remarks.cpp" id="Snippet13"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Compare/remarks.cs" id="Snippet13"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Compare/remarks.fs" id="Snippet13"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Compare/vb/remarks.vb" id="Snippet13"::: + +## Examples + The following example demonstrates that the method is equivalent to using or when comparing strings. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Compare/cpp/compare02.cpp" id="Snippet18"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Compare/compare02.cs" interactive="try-dotnet-method" id="Snippet18"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Compare/compare02.fs" id="Snippet18"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Compare/vb/compare02.vb" id="Snippet18"::: + ]]> - Character sets include ignorable characters. The method does not consider such characters when it performs a culture-sensitive comparison. For example, if the following code is run on the .NET Framework 4 or later, a culture-sensitive, case-insensitive comparison of "animal" with "Ani-mal" (using a soft hyphen, or U+00AD) indicates that the two strings are equivalent. - - :::code language="csharp" source="~/snippets/csharp/System/String/Compare/compare22.cs" id="Snippet22"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Compare/compare22.fs" id="Snippet22"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Compare/vb/compare22.vb" id="Snippet22"::: - - To recognize ignorable characters in a string comparison, call the method and supply a value of either or for the parameter. + Character sets include ignorable characters. The method does not consider such characters when it performs a culture-sensitive comparison. For example, if the following code is run on the .NET Framework 4 or later, a culture-sensitive, case-insensitive comparison of "animal" with "Ani-mal" (using a soft hyphen, or U+00AD) indicates that the two strings are equivalent. :::code language="csharp" source="~/snippets/csharp/System/String/Compare/compare22.cs" id="Snippet22"::: :::code language="fsharp" source="~/snippets/fsharp/System/String/Compare/compare22.fs" id="Snippet22"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Compare/vb/compare22.vb" id="Snippet22"::: To recognize ignorable characters in a string comparison, call the method and supply a value of either or for the parameter. @@ -1983,57 +1989,66 @@ The following example demonstrates how you can create an instance of the The second string to compare. One of the enumeration values that specifies the rules to use in the comparison. Compares two specified objects using the specified rules, and returns an integer that indicates their relative position in the sort order. - A 32-bit signed integer that indicates the lexical relationship between the two comparands. - - Value - - Condition - - Less than zero - - precedes in the sort order. - - Zero - - is in the same position as in the sort order. - - Greater than zero - - follows in the sort order. - - + A 32-bit signed integer that indicates the lexical relationship between the two comparands. + + Value + + + Condition + + + + + Less than zero + + + precedes in the sort order. + + + Zero + + + is in the same position as in the sort order. + + + Greater than zero + + + follows in the sort order. + + - @@ -2106,69 +2121,72 @@ The following example demonstrates how you can create an instance of the to ignore case during the comparison; otherwise, . An object that supplies culture-specific comparison information. If is , the current culture is used. Compares two specified objects, ignoring or honoring their case, and using culture-specific information to influence the comparison, and returns an integer that indicates their relative position in the sort order. - A 32-bit signed integer that indicates the lexical relationship between the two comparands. - - Value - - Condition - - Less than zero - - precedes in the sort order. - - Zero - - occurs in the same position as in the sort order. - - Greater than zero - - follows in the sort order. - - + A 32-bit signed integer that indicates the lexical relationship between the two comparands. + + Value + + + Condition + + + + + Less than zero + + + precedes in the sort order. + + + Zero + + + occurs in the same position as in the sort order. + + + Greater than zero + + + follows in the sort order. + + - . - - One or both comparands can be `null`. By definition, any string, including the empty string (""), compares greater than a null reference; and two null references compare equal to each other. - - The comparison terminates when an inequality is discovered or both strings have been compared. However, if the two strings compare equal to the end of one string, and the other string has characters remaining, then the string with remaining characters is considered greater. The return value is the result of the last comparison performed. - - Unexpected results can occur when comparisons are affected by culture-specific casing rules. For example, in Turkish, the following example yields the wrong results because the file system in Turkish does not use linguistic casing rules for the letter "i" in "file". - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Compare/cpp/remarks.cpp" id="Snippet14"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Compare/remarks.cs" id="Snippet14"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Compare/remarks.fs" id="Snippet14"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Compare/vb/remarks.vb" id="Snippet14"::: - - Compare the path name to "file" using an ordinal comparison. The correct code to do this is as follows: - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Compare/cpp/remarks.cpp" id="Snippet15"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Compare/remarks.cs" id="Snippet15"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Compare/remarks.fs" id="Snippet15"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Compare/vb/remarks.vb" id="Snippet15"::: - -## Examples - The following example demonstrates how culture can affect a comparison. In Czech - Czech Republic culture, "ch" is a single character that is greater than "d". However, in English - United States culture, "ch" consists of two characters, and "c" is less than "d". - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.comp4/CPP/string.comp4.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Compare/string.comp4.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Compare/string.comp4.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.comp4/VB/string.comp4.vb" id="Snippet1"::: - + . + + One or both comparands can be `null`. By definition, any string, including the empty string (""), compares greater than a null reference; and two null references compare equal to each other. + + The comparison terminates when an inequality is discovered or both strings have been compared. However, if the two strings compare equal to the end of one string, and the other string has characters remaining, then the string with remaining characters is considered greater. The return value is the result of the last comparison performed. + + Unexpected results can occur when comparisons are affected by culture-specific casing rules. For example, in Turkish, the following example yields the wrong results because the file system in Turkish does not use linguistic casing rules for the letter "i" in "file". + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Compare/cpp/remarks.cpp" id="Snippet14"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Compare/remarks.cs" id="Snippet14"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Compare/remarks.fs" id="Snippet14"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Compare/vb/remarks.vb" id="Snippet14"::: + + Compare the path name to "file" using an ordinal comparison. The correct code to do this is as follows: + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Compare/cpp/remarks.cpp" id="Snippet15"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Compare/remarks.cs" id="Snippet15"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Compare/remarks.fs" id="Snippet15"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Compare/vb/remarks.vb" id="Snippet15"::: + +## Examples + The following example demonstrates how culture can affect a comparison. In Czech - Czech Republic culture, "ch" is a single character that is greater than "d". However, in English - United States culture, "ch" consists of two characters, and "c" is less than "d". + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.comp4/CPP/string.comp4.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Compare/string.comp4.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Compare/string.comp4.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.comp4/VB/string.comp4.vb" id="Snippet1"::: + ]]> - Character sets include ignorable characters. The method does not consider such characters when it performs a culture-sensitive comparison. For example, if the following code is run on the .NET Framework 4 or later, a case-insensitive comparison of "animal" with "Ani-mal" (using a soft hyphen, or U+00AD) using the invariant culture indicates that the two strings are equivalent. - - :::code language="csharp" source="~/snippets/csharp/System/String/Compare/compare23.cs" id="Snippet23"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Compare/compare23.fs" id="Snippet23"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Compare/vb/compare23.vb" id="Snippet23"::: - - To recognize ignorable characters in a string comparison, call the method and supply a value of either or for the parameter. + Character sets include ignorable characters. The method does not consider such characters when it performs a culture-sensitive comparison. For example, if the following code is run on the .NET Framework 4 or later, a case-insensitive comparison of "animal" with "Ani-mal" (using a soft hyphen, or U+00AD) using the invariant culture indicates that the two strings are equivalent. :::code language="csharp" source="~/snippets/csharp/System/String/Compare/compare23.cs" id="Snippet23"::: :::code language="fsharp" source="~/snippets/fsharp/System/String/Compare/compare23.fs" id="Snippet23"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Compare/vb/compare23.vb" id="Snippet23"::: To recognize ignorable characters in a string comparison, call the method and supply a value of either or for the parameter. @@ -2232,48 +2250,57 @@ The following example demonstrates how you can create an instance of the The culture that supplies culture-specific comparison information. If is , the current culture is used. Options to use when performing the comparison (such as ignoring case or symbols). Compares two specified objects using the specified comparison options and culture-specific information to influence the comparison, and returns an integer that indicates the relationship of the two strings to each other in the sort order. - A 32-bit signed integer that indicates the lexical relationship between and , as shown in the following table - - Value - - Condition - - Less than zero - - precedes in the sort order. - - Zero - - occurs in the same position as in the sort order. - - Greater than zero - - follows in the sort order. - - + A 32-bit signed integer that indicates the lexical relationship between and , as shown in the following table + + Value + + + Condition + + + + + Less than zero + + + precedes in the sort order. + + + Zero + + + occurs in the same position as in the sort order. + + + Greater than zero + + + follows in the sort order. + + - [!CAUTION] -> The method is designed primarily for use in sorting or alphabetizing operations. It should not be used when the primary purpose of the method call is to determine whether two strings are equivalent (that is, when the purpose of the method call is to test for a return value of zero). To determine whether two strings are equivalent, call the method. - - The comparison can be further specified by the `options` parameter, which consists of one or more members of the enumeration. However, because the purpose of this method is to conduct a culture-sensitive string comparison, the and values have no effect. - - Either or both comparands can be `null`. By definition, any string, including , compares greater than a null reference, and two null references compare equal to each other. - - The comparison terminates when an inequality is discovered or both strings have been compared. However, if the two strings compare equal to the end of one string, and the other string has characters remaining, the string with the remaining characters is considered greater. - -## Examples - The following example compares two strings in three different ways: Use linguistic comparison for the en-US culture; using linguistic case-sensitive comparison for the en-US culture; and using an ordinal comparison. It illustrates how the three methods of comparison produce three different results. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Compare/cpp/example.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Compare/Example.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Compare/Example.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Compare/vb/Example.vb" id="Snippet1"::: - + [!CAUTION] +> The method is designed primarily for use in sorting or alphabetizing operations. It should not be used when the primary purpose of the method call is to determine whether two strings are equivalent (that is, when the purpose of the method call is to test for a return value of zero). To determine whether two strings are equivalent, call the method. + + The comparison can be further specified by the `options` parameter, which consists of one or more members of the enumeration. However, because the purpose of this method is to conduct a culture-sensitive string comparison, the and values have no effect. + + Either or both comparands can be `null`. By definition, any string, including , compares greater than a null reference, and two null references compare equal to each other. + + The comparison terminates when an inequality is discovered or both strings have been compared. However, if the two strings compare equal to the end of one string, and the other string has characters remaining, the string with the remaining characters is considered greater. + +## Examples + The following example compares two strings in three different ways: Use linguistic comparison for the en-US culture; using linguistic case-sensitive comparison for the en-US culture; and using an ordinal comparison. It illustrates how the three methods of comparison produce three different results. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Compare/cpp/example.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Compare/Example.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Compare/Example.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Compare/vb/Example.vb" id="Snippet1"::: + ]]> @@ -2344,82 +2371,91 @@ The following example demonstrates how you can create an instance of the The position of the substring within . The maximum number of characters in the substrings to compare. Compares substrings of two specified objects and returns an integer that indicates their relative position in the sort order. - A 32-bit signed integer indicating the lexical relationship between the two comparands. - - Value - - Condition - - Less than zero - - The substring in precedes the substring in in the sort order. - - Zero - - The substrings occur in the same position in the sort order, or is zero. - - Greater than zero - - The substring in follows the substring in in the sort order. - - + A 32-bit signed integer indicating the lexical relationship between the two comparands. + + Value + + + Condition + + + + + Less than zero + + + The substring in precedes the substring in in the sort order. + + + Zero + + + The substrings occur in the same position in the sort order, or is zero. + + + Greater than zero + + + The substring in follows the substring in in the sort order. + + - . - -> [!WARNING] -> When comparing strings, you should call the method, which requires that you explicitly specify the type of string comparison that the method uses. For more information, see [Best Practices for Using Strings](/dotnet/standard/base-types/best-practices-strings). - - One or both comparands can be `null`. By definition, any string, including the empty string (""), compares greater than a null reference; and two null references compare equal to each other. - - The comparison terminates when an inequality is discovered or both substrings have been compared. However, if the two strings compare equal to the end of one string, and the other string has characters remaining, then the string with remaining characters is considered greater. The return value is the result of the last comparison performed. - - Unexpected results can occur when comparisons are affected by culture-specific casing rules. For example, in Turkish, the following example yields the wrong results because the file system in Turkish does not use linguistic casing rules for the letter "i" in "file". - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Compare/cpp/remarks.cpp" id="Snippet2"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Compare/remarks.cs" id="Snippet2"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Compare/remarks.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Compare/vb/remarks.vb" id="Snippet2"::: - - Compare the path name to "file" using an ordinal comparison. The correct code to do this is as follows: - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Compare/cpp/remarks.cpp" id="Snippet3"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Compare/remarks.cs" id="Snippet3"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Compare/remarks.fs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Compare/vb/remarks.vb" id="Snippet3"::: - -## Examples - The following example compares two substrings. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.compare3/CPP/comp3.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Compare/comp3.cs" interactive="try-dotnet-method" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Compare/comp3.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.compare3/VB/comp3.vb" id="Snippet1"::: - + . + +> [!WARNING] +> When comparing strings, you should call the method, which requires that you explicitly specify the type of string comparison that the method uses. For more information, see [Best Practices for Using Strings](/dotnet/standard/base-types/best-practices-strings). + + One or both comparands can be `null`. By definition, any string, including the empty string (""), compares greater than a null reference; and two null references compare equal to each other. + + The comparison terminates when an inequality is discovered or both substrings have been compared. However, if the two strings compare equal to the end of one string, and the other string has characters remaining, then the string with remaining characters is considered greater. The return value is the result of the last comparison performed. + + Unexpected results can occur when comparisons are affected by culture-specific casing rules. For example, in Turkish, the following example yields the wrong results because the file system in Turkish does not use linguistic casing rules for the letter "i" in "file". + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Compare/cpp/remarks.cpp" id="Snippet2"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Compare/remarks.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Compare/remarks.fs" id="Snippet2"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Compare/vb/remarks.vb" id="Snippet2"::: + + Compare the path name to "file" using an ordinal comparison. The correct code to do this is as follows: + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Compare/cpp/remarks.cpp" id="Snippet3"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Compare/remarks.cs" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Compare/remarks.fs" id="Snippet3"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Compare/vb/remarks.vb" id="Snippet3"::: + +## Examples + The following example compares two substrings. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.compare3/CPP/comp3.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Compare/comp3.cs" interactive="try-dotnet-method" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Compare/comp3.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.compare3/VB/comp3.vb" id="Snippet1"::: + ]]> - is greater than .. - - -or- - - is greater than .. - - -or- - - , , or is negative. - - -or- - - Either or is , and is greater than zero. + is greater than .. + +-or- + + is greater than .. + +-or- + +, , or is negative. + +-or- + +Either or is , and is greater than zero. Character sets include ignorable characters. The method does not consider these characters when it performs a linguistic or culture-sensitive comparison. To recognize ignorable characters in your comparison, call the method and supply a value of or for the parameter. @@ -2485,82 +2521,91 @@ The following example demonstrates how you can create an instance of the to ignore case during the comparison; otherwise, . Compares substrings of two specified objects, ignoring or honoring their case, and returns an integer that indicates their relative position in the sort order. - A 32-bit signed integer that indicates the lexical relationship between the two comparands. - - Value - - Condition - - Less than zero - - The substring in precedes the substring in in the sort order. - - Zero - - The substrings occur in the same position in the sort order, or is zero. - - Greater than zero - - The substring in follows the substring in in the sort order. - - + A 32-bit signed integer that indicates the lexical relationship between the two comparands. + + Value + + + Condition + + + + + Less than zero + + + The substring in precedes the substring in in the sort order. + + + Zero + + + The substrings occur in the same position in the sort order, or is zero. + + + Greater than zero + + + The substring in follows the substring in in the sort order. + + - . - -> [!WARNING] -> When comparing strings, you should call the method, which requires that you explicitly specify the type of string comparison that the method uses. For more information, see [Best Practices for Using Strings](/dotnet/standard/base-types/best-practices-strings). - - One or both comparands can be `null`. By definition, any string, including the empty string (""), compares greater than a null reference; and two null references compare equal to each other. - - The comparison terminates when an inequality is discovered or both substrings have been compared. However, if the two strings compare equal to the end of one string, and the other string has characters remaining, then the string with remaining characters is considered greater. The return value is the result of the last comparison performed. - - Unexpected results can occur when comparisons are affected by culture-specific casing rules. For example, in Turkish, the following example yields the wrong results because the file system in Turkish does not use linguistic casing rules for the letter "i" in "file". - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Compare/cpp/remarks.cpp" id="Snippet4"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Compare/remarks.cs" id="Snippet4"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Compare/remarks.fs" id="Snippet4"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Compare/vb/remarks.vb" id="Snippet4"::: - - The path name needs to be compared in an invariant manner. The correct code to do this is as follows. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Compare/cpp/remarks.cpp" id="Snippet5"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Compare/remarks.cs" id="Snippet5"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Compare/remarks.fs" id="Snippet5"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Compare/vb/remarks.vb" id="Snippet5"::: - -## Examples - The following example performs two comparisons of two substrings that only differ in case. The first comparison ignores case and the second comparison considers case. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.compare4/CPP/comp4.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Compare/comp4.cs" interactive="try-dotnet-method" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Compare/comp4.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.compare4/VB/comp4.vb" id="Snippet1"::: - + . + +> [!WARNING] +> When comparing strings, you should call the method, which requires that you explicitly specify the type of string comparison that the method uses. For more information, see [Best Practices for Using Strings](/dotnet/standard/base-types/best-practices-strings). + + One or both comparands can be `null`. By definition, any string, including the empty string (""), compares greater than a null reference; and two null references compare equal to each other. + + The comparison terminates when an inequality is discovered or both substrings have been compared. However, if the two strings compare equal to the end of one string, and the other string has characters remaining, then the string with remaining characters is considered greater. The return value is the result of the last comparison performed. + + Unexpected results can occur when comparisons are affected by culture-specific casing rules. For example, in Turkish, the following example yields the wrong results because the file system in Turkish does not use linguistic casing rules for the letter "i" in "file". + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Compare/cpp/remarks.cpp" id="Snippet4"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Compare/remarks.cs" id="Snippet4"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Compare/remarks.fs" id="Snippet4"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Compare/vb/remarks.vb" id="Snippet4"::: + + The path name needs to be compared in an invariant manner. The correct code to do this is as follows. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Compare/cpp/remarks.cpp" id="Snippet5"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Compare/remarks.cs" id="Snippet5"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Compare/remarks.fs" id="Snippet5"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Compare/vb/remarks.vb" id="Snippet5"::: + +## Examples + The following example performs two comparisons of two substrings that only differ in case. The first comparison ignores case and the second comparison considers case. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.compare4/CPP/comp4.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Compare/comp4.cs" interactive="try-dotnet-method" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Compare/comp4.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.compare4/VB/comp4.vb" id="Snippet1"::: + ]]> - is greater than .. - - -or- - - is greater than .. - - -or- - - , , or is negative. - - -or- - - Either or is , and is greater than zero. + is greater than .. + +-or- + + is greater than .. + +-or- + +, , or is negative. + +-or- + +Either or is , and is greater than zero. Character sets include ignorable characters. The method does not consider these characters when it performs a linguistic or culture-sensitive comparison. To recognize ignorable characters in your comparison, call the method and supply a value of or for the parameter. @@ -2632,77 +2677,86 @@ The following example demonstrates how you can create an instance of the The maximum number of characters in the substrings to compare. One of the enumeration values that specifies the rules to use in the comparison. Compares substrings of two specified objects using the specified rules, and returns an integer that indicates their relative position in the sort order. - A 32-bit signed integer that indicates the lexical relationship between the two comparands. - - Value - - Condition - - Less than zero - - The substring in precedes the substring in in the sort order. - - Zero - - The substrings occur in the same position in the sort order, or the parameter is zero. - - Greater than zero - - The substring in follows the substring in in the sort order. - - + A 32-bit signed integer that indicates the lexical relationship between the two comparands. + + Value + + + Condition + + + + + Less than zero + + + The substring in precedes the substring in in the sort order. + + + Zero + + + The substrings occur in the same position in the sort order, or the parameter is zero. + + + Greater than zero + + + The substring in follows the substring in in the sort order. + + - - is greater than .. - - -or- - - is greater than .. - - -or- - - , , or is negative. - - -or- - - Either or is , and is greater than zero. + is greater than .. + +-or- + + is greater than .. + +-or- + +, , or is negative. + +-or- + +Either or is , and is greater than zero. is not a value. @@ -2772,79 +2826,88 @@ The following example demonstrates how you can create an instance of the to ignore case during the comparison; otherwise, . An object that supplies culture-specific comparison information. If is , the current culture is used. Compares substrings of two specified objects, ignoring or honoring their case and using culture-specific information to influence the comparison, and returns an integer that indicates their relative position in the sort order. - An integer that indicates the lexical relationship between the two comparands. - - Value - - Condition - - Less than zero - - The substring in precedes the substring in in the sort order. - - Zero - - The substrings occur in the same position in the sort order, or is zero. - - Greater than zero - - The substring in follows the substring in in the sort order. - - + An integer that indicates the lexical relationship between the two comparands. + + Value + + + Condition + + + + + Less than zero + + + The substring in precedes the substring in in the sort order. + + + Zero + + + The substrings occur in the same position in the sort order, or is zero. + + + Greater than zero + + + The substring in follows the substring in in the sort order. + + - . - - One or both comparands can be `null`. By definition, any string, including the empty string (""), compares greater than a null reference; and two null references compare equal to each other. - - The comparison terminates when an inequality is discovered or both substrings have been compared. However, if the two strings compare equal to the end of one string, and the other string has characters remaining, then the string with remaining characters is considered greater. The return value is the result of the last comparison performed. - - Unexpected results can occur when comparisons are affected by culture-specific casing rules. For example, in Turkish, the following example yields the wrong results because the file system in Turkish does not use linguistic casing rules for the letter "i" in "file". - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Compare/cpp/remarks.cpp" id="Snippet6"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Compare/remarks.cs" id="Snippet6"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Compare/remarks.fs" id="Snippet6"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Compare/vb/remarks.vb" id="Snippet6"::: - - Compare the path name to "file" using an ordinal comparison. The correct code to do this is as follows: - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Compare/cpp/remarks.cpp" id="Snippet7"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Compare/remarks.cs" id="Snippet7"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Compare/remarks.fs" id="Snippet7"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Compare/vb/remarks.vb" id="Snippet7"::: - -## Examples - The following example compares two substrings using different cultures and ignoring the case of the substrings. The choice of culture affects how the letter "I" is compared. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.compare5/CPP/comp5.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Compare/comp5.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Compare/comp5.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.compare5/VB/comp5.vb" id="Snippet1"::: - + . + + One or both comparands can be `null`. By definition, any string, including the empty string (""), compares greater than a null reference; and two null references compare equal to each other. + + The comparison terminates when an inequality is discovered or both substrings have been compared. However, if the two strings compare equal to the end of one string, and the other string has characters remaining, then the string with remaining characters is considered greater. The return value is the result of the last comparison performed. + + Unexpected results can occur when comparisons are affected by culture-specific casing rules. For example, in Turkish, the following example yields the wrong results because the file system in Turkish does not use linguistic casing rules for the letter "i" in "file". + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Compare/cpp/remarks.cpp" id="Snippet6"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Compare/remarks.cs" id="Snippet6"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Compare/remarks.fs" id="Snippet6"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Compare/vb/remarks.vb" id="Snippet6"::: + + Compare the path name to "file" using an ordinal comparison. The correct code to do this is as follows: + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Compare/cpp/remarks.cpp" id="Snippet7"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Compare/remarks.cs" id="Snippet7"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Compare/remarks.fs" id="Snippet7"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Compare/vb/remarks.vb" id="Snippet7"::: + +## Examples + The following example compares two substrings using different cultures and ignoring the case of the substrings. The choice of culture affects how the letter "I" is compared. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.compare5/CPP/comp5.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Compare/comp5.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Compare/comp5.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.compare5/VB/comp5.vb" id="Snippet1"::: + ]]> - is greater than .. - - -or- - - is greater than .. - - -or- - - , , or is negative. - - -or- - - Either or is , and is greater than zero. + is greater than .. + +-or- + + is greater than .. + +-or- + +, , or is negative. + +-or- + +Either or is , and is greater than zero. Character sets include ignorable characters. The method does not consider these characters when it performs a linguistic or culture-sensitive comparison. To recognize ignorable characters in your comparison, call the method and supply a value of or for the parameter. @@ -2910,69 +2973,78 @@ The following example demonstrates how you can create an instance of the An object that supplies culture-specific comparison information. If is , the current culture is used. Options to use when performing the comparison (such as ignoring case or symbols). Compares substrings of two specified objects using the specified comparison options and culture-specific information to influence the comparison, and returns an integer that indicates the relationship of the two substrings to each other in the sort order. - An integer that indicates the lexical relationship between the two substrings, as shown in the following table. - - Value - - Condition - - Less than zero - - The substring in precedes the substring in in the sort order. - - Zero - - The substrings occur in the same position in the sort order, or is zero. - - Greater than zero - - The substring in follows the substring in in the sort order. - - + An integer that indicates the lexical relationship between the two substrings, as shown in the following table. + + Value + + + Condition + + + + + Less than zero + + + The substring in precedes the substring in in the sort order. + + + Zero + + + The substrings occur in the same position in the sort order, or is zero. + + + Greater than zero + + + The substring in follows the substring in in the sort order. + + - [!CAUTION] -> The method is designed primarily for use in sorting or alphabetizing operations. It should not be used when the primary purpose of the method call is to determine whether two substrings are equivalent (that is, when the purpose of the method call is to test for a return value of zero). To determine whether two strings are equivalent, call the method. - - One or both of `strA` and `strB` can be `null`. By definition, any string, including , compares greater than a null reference, and two null references compare equal to each other. - - The comparison can be further specified by the `options` parameter, which consists of one or more members of the enumeration. However, because the purpose of this method is to conduct a culture-sensitive string comparison, the and values have no effect. - - The comparison terminates when an inequality is discovered or both substrings have been compared. However, if the two strings compare equal to the end of one string, and the other string has characters remaining, the string with the remaining characters is considered greater. The return value is the result of the last comparison performed. - -## Examples - The following example uses the method to compare the last names of two people. It then lists them in alphabetical order. - - :::code language="csharp" source="~/snippets/csharp/System/String/Compare/Example1.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Compare/Example1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Compare5/vb/Example.vb" id="Snippet1"::: - + [!CAUTION] +> The method is designed primarily for use in sorting or alphabetizing operations. It should not be used when the primary purpose of the method call is to determine whether two substrings are equivalent (that is, when the purpose of the method call is to test for a return value of zero). To determine whether two strings are equivalent, call the method. + + One or both of `strA` and `strB` can be `null`. By definition, any string, including , compares greater than a null reference, and two null references compare equal to each other. + + The comparison can be further specified by the `options` parameter, which consists of one or more members of the enumeration. However, because the purpose of this method is to conduct a culture-sensitive string comparison, the and values have no effect. + + The comparison terminates when an inequality is discovered or both substrings have been compared. However, if the two strings compare equal to the end of one string, and the other string has characters remaining, the string with the remaining characters is considered greater. The return value is the result of the last comparison performed. + +## Examples + The following example uses the method to compare the last names of two people. It then lists them in alphabetical order. + + :::code language="csharp" source="~/snippets/csharp/System/String/Compare/Example1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Compare/Example1.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Compare5/vb/Example.vb" id="Snippet1"::: + ]]> is not a value. - is greater than . - - -or- - - is greater than . - - -or- - - , , or is negative. - - -or- - - Either or is , and is greater than zero. + is greater than . + +-or- + + is greater than . + +-or- + +, , or is negative. + +-or- + +Either or is , and is greater than zero. Character sets include ignorable characters. The method does not consider these characters when it performs a linguistic or culture-sensitive comparison. To recognize ignorable characters in your comparison, supply a value of or for the parameter. @@ -3048,41 +3120,50 @@ The following example demonstrates how you can create an instance of the The first string to compare. The second string to compare. Compares two specified objects by evaluating the numeric values of the corresponding objects in each string. - An integer that indicates the lexical relationship between the two comparands. - - Value - - Condition - - Less than zero - - is less than . - - Zero - - and are equal. - - Greater than zero - - is greater than . - - + An integer that indicates the lexical relationship between the two comparands. + + Value + + + Condition + + + + + Less than zero + + + is less than . + + + Zero + + + and are equal. + + + Greater than zero + + + is greater than . + + - . To perform a case-insensitive comparison using ordinal sort rules, call the method with the `comparisonType` argument set to . - - Because is a static method, `strA` and `strB` can be `null`. If both values are `null`, the method returns 0 (zero), which indicates that `strA` and `strB` are equal. If only one of the values is `null`, the method considers the non-null value to be greater. - -## Examples - The following example performs and ordinal comparison of two strings that only differ in case. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.compareordinal/CPP/comp0.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/CompareOrdinal/comp0.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/CompareOrdinal/comp0.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.compareordinal/VB/comp0.vb" id="Snippet1"::: - + . To perform a case-insensitive comparison using ordinal sort rules, call the method with the `comparisonType` argument set to . + + Because is a static method, `strA` and `strB` can be `null`. If both values are `null`, the method returns 0 (zero), which indicates that `strA` and `strB` are equal. If only one of the values is `null`, the method considers the non-null value to be greater. + +## Examples + The following example performs and ordinal comparison of two strings that only differ in case. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.compareordinal/CPP/comp0.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/CompareOrdinal/comp0.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/CompareOrdinal/comp0.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.compareordinal/VB/comp0.vb" id="Snippet1"::: + ]]> @@ -3156,57 +3237,66 @@ The following example demonstrates how you can create an instance of the The starting index of the substring in . The maximum number of characters in the substrings to compare. Compares substrings of two specified objects by evaluating the numeric values of the corresponding objects in each substring. - A 32-bit signed integer that indicates the lexical relationship between the two comparands. - - Value - - Condition - - Less than zero - - The substring in is less than the substring in . - - Zero - - The substrings are equal, or is zero. - - Greater than zero - - The substring in is greater than the substring in . - - + A 32-bit signed integer that indicates the lexical relationship between the two comparands. + + Value + + + Condition + + + + + Less than zero + + + The substring in is less than the substring in . + + + Zero + + + The substrings are equal, or is zero. + + + Greater than zero + + + The substring in is greater than the substring in . + + - . To perform a case-insensitive comparison using ordinal sort rules, call the method with the `comparisonType` argument set to . - - Because is a static method, `strA` and `strB` can be `null`. If both values are `null`, the method returns 0 (zero), which indicates that `strA` and `strB` are equal. If only one of the values is `null`, the method considers the non-null value to be greater. - -## Examples - This following example demonstrates that and use different sort orders. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/StringCompareOrdinal/CPP/stringcompareordinal.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/CompareOrdinal/stringcompareordinal.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/CompareOrdinal/stringcompareordinal.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/StringCompareOrdinal/VB/stringcompareordinal.vb" id="Snippet1"::: - + . To perform a case-insensitive comparison using ordinal sort rules, call the method with the `comparisonType` argument set to . + + Because is a static method, `strA` and `strB` can be `null`. If both values are `null`, the method returns 0 (zero), which indicates that `strA` and `strB` are equal. If only one of the values is `null`, the method considers the non-null value to be greater. + +## Examples + This following example demonstrates that and use different sort orders. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/StringCompareOrdinal/CPP/stringcompareordinal.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/CompareOrdinal/stringcompareordinal.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/CompareOrdinal/stringcompareordinal.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/StringCompareOrdinal/VB/stringcompareordinal.vb" id="Snippet1"::: + ]]> - is not and is greater than .. - - -or- - - is not and is greater than .. - - -or- - - , , or is negative. + is not and is greater than .. + +-or- + + is not and is greater than .. + +-or- + +, , or is negative. @@ -3221,11 +3311,11 @@ The following example demonstrates how you can create an instance of the Compares this instance with a specified object or and returns an integer that indicates whether this instance precedes, follows, or appears in the same position in the sort order as the specified object or . - method perform culture-sensitive and case-sensitive comparison. You cannot use this method to perform culture-insensitive or ordinal comparisons. For code clarity, we recommend that you avoid the method and call the method instead. - + method perform culture-sensitive and case-sensitive comparison. You cannot use this method to perform culture-insensitive or ordinal comparisons. For code clarity, we recommend that you avoid the method and call the method instead. + ]]> @@ -3283,62 +3373,65 @@ The following example demonstrates how you can create an instance of the An object that evaluates to a . Compares this instance with a specified and indicates whether this instance precedes, follows, or appears in the same position in the sort order as the specified . - A 32-bit signed integer that indicates whether this instance precedes, follows, or appears in the same position in the sort order as the parameter. - - Value - - Condition - - Less than zero - - This instance precedes . - - Zero - - This instance has the same position in the sort order as . - - Greater than zero - - This instance follows . - - -or- - - is . - - + A 32-bit signed integer that indicates whether this instance precedes, follows, or appears in the same position in the sort order as the parameter. + + Value + + + Condition + + + + + Less than zero + + + This instance precedes . + + + Zero + + + This instance has the same position in the sort order as . + + + Greater than zero + + + This instance follows . + +-or- + + is . + + - object. - -> [!CAUTION] -> The method was designed primarily for use in sorting or alphabetizing operations. It should not be used when the primary purpose of the method call is to determine whether two strings are equivalent. To determine whether two strings are equivalent, call the method. - - This method performs a word (case-sensitive and culture-sensitive) comparison using the current culture. For more information about word, string, and ordinal sorts, see . - - For more information about the behavior of this method, see the Remarks section of the method. - -## Examples - The following example uses the method with an . Because it attempts to compare a instance to a `TestClass` object, the method throws an . - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/ExToString/CPP/extostring.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/CompareTo/extostring.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/CompareTo/extostring.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ExToString/VB/extostring.vb" id="Snippet1"::: - + object. + +> [!CAUTION] +> The method was designed primarily for use in sorting or alphabetizing operations. It should not be used when the primary purpose of the method call is to determine whether two strings are equivalent. To determine whether two strings are equivalent, call the method. + + This method performs a word (case-sensitive and culture-sensitive) comparison using the current culture. For more information about word, string, and ordinal sorts, see . + + For more information about the behavior of this method, see the Remarks section of the method. + +## Examples + The following example uses the method with an . Because it attempts to compare a instance to a `TestClass` object, the method throws an . + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/ExToString/CPP/extostring.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/CompareTo/extostring.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/CompareTo/extostring.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ExToString/VB/extostring.vb" id="Snippet1"::: + ]]> is not a . - Character sets include ignorable characters. The method does not consider such characters when it performs a culture-sensitive comparison. For example, if the following code is run on the .NET Framework 4 or later, a comparison of "animal" with "ani-mal" (using a soft hyphen, or U+00AD) indicates that the two strings are equivalent. - - :::code language="csharp" source="~/snippets/csharp/System/String/CompareTo/compareto1.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/CompareTo/compareto1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.compareto/vb/compareto1.vb" id="Snippet1"::: - - To recognize ignorable characters in a string comparison, call the method. + Character sets include ignorable characters. The method does not consider such characters when it performs a culture-sensitive comparison. For example, if the following code is run on the .NET Framework 4 or later, a comparison of "animal" with "ani-mal" (using a soft hyphen, or U+00AD) indicates that the two strings are equivalent. :::code language="csharp" source="~/snippets/csharp/System/String/CompareTo/compareto1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/String/CompareTo/compareto1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.compareto/vb/compareto1.vb" id="Snippet1"::: To recognize ignorable characters in a string comparison, call the method. @@ -3404,67 +3497,70 @@ The following example demonstrates how you can create an instance of the The string to compare with this instance. Compares this instance with a specified object and indicates whether this instance precedes, follows, or appears in the same position in the sort order as the specified string. - A 32-bit signed integer that indicates whether this instance precedes, follows, or appears in the same position in the sort order as the parameter. - - Value - - Condition - - Less than zero - - This instance precedes . - - Zero - - This instance has the same position in the sort order as . - - Greater than zero - - This instance follows . - - -or- - - is . - - + A 32-bit signed integer that indicates whether this instance precedes, follows, or appears in the same position in the sort order as the parameter. + + Value + + + Condition + + + + + Less than zero + + + This instance precedes . + + + Zero + + + This instance has the same position in the sort order as . + + + Greater than zero + + + This instance follows . + +-or- + + is . + + - . - -> [!CAUTION] -> The method was designed primarily for use in sorting or alphabetizing operations. It should not be used when the primary purpose of the method call is to determine whether two strings are equivalent. To determine whether two strings are equivalent, call the method. - - For more information about the behavior of this method, see the Remarks section of the method. - - This method implements the interface and performs slightly better than the method, because it does not have to determine whether the `strB` argument is a mutable value type that must be boxed, and it does not have to cast its parameter from an to a . - -## Examples - The following example uses the method to compare the current string instance with another string. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/StringCompareTo/CPP/stringcompareto.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/CompareTo/stringcompareto.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/CompareTo/stringcompareto.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/StringCompareTo/VB/stringcompareto.vb" id="Snippet1"::: - - The following example demonstrates generic and non-generic versions of the CompareTo method for several value and reference types. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/T.CompareTo/CPP/cat.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/Boolean/CompareTo/cat.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/Boolean/CompareTo/cat.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/T.CompareTo/VB/cat.vb" id="Snippet1"::: - + . + +> [!CAUTION] +> The method was designed primarily for use in sorting or alphabetizing operations. It should not be used when the primary purpose of the method call is to determine whether two strings are equivalent. To determine whether two strings are equivalent, call the method. + + For more information about the behavior of this method, see the Remarks section of the method. + + This method implements the interface and performs slightly better than the method, because it does not have to determine whether the `strB` argument is a mutable value type that must be boxed, and it does not have to cast its parameter from an to a . + +## Examples + The following example uses the method to compare the current string instance with another string. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/StringCompareTo/CPP/stringcompareto.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/CompareTo/stringcompareto.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/CompareTo/stringcompareto.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/StringCompareTo/VB/stringcompareto.vb" id="Snippet1"::: + + The following example demonstrates generic and non-generic versions of the CompareTo method for several value and reference types. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/T.CompareTo/CPP/cat.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/Boolean/CompareTo/cat.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/Boolean/CompareTo/cat.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/T.CompareTo/VB/cat.vb" id="Snippet1"::: + ]]> - Character sets include ignorable characters. The method does not consider such characters when it performs a culture-sensitive comparison. For example, if the following code is run on the .NET Framework 4 or later, a comparison of "animal" with "ani-mal" (using a soft hyphen, or U+00AD) indicates that the two strings are equivalent. - - :::code language="csharp" source="~/snippets/csharp/System/String/CompareTo/compareto2.cs" id="Snippet2"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/CompareTo/compareto2.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.compareto/vb/compareto2.vb" id="Snippet2"::: - - To recognize ignorable characters in a string comparison, call the method. + Character sets include ignorable characters. The method does not consider such characters when it performs a culture-sensitive comparison. For example, if the following code is run on the .NET Framework 4 or later, a comparison of "animal" with "ani-mal" (using a soft hyphen, or U+00AD) indicates that the two strings are equivalent. :::code language="csharp" source="~/snippets/csharp/System/String/CompareTo/compareto2.cs" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/String/CompareTo/compareto2.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.compareto/vb/compareto2.vb" id="Snippet2"::: To recognize ignorable characters in a string comparison, call the method. @@ -3482,11 +3578,11 @@ The following example demonstrates how you can create an instance of the Concatenates one or more instances of , or the representations of the values of one or more instances of . - [!NOTE] -> You can also use your language's string concatenation operator, such as `+` in C# and F#, or `&` and `+` in Visual Basic, to concatenate strings. Both compilers translate the concatenation operator into a call to one of the overloads of `String.Concat`. - + [!NOTE] +> You can also use your language's string concatenation operator, such as `+` in C# and F#, or `&` and `+` in Visual Basic, to concatenate strings. Both compilers translate the concatenation operator into a call to one of the overloads of `String.Concat`. + ]]> @@ -3548,28 +3644,28 @@ The following example demonstrates how you can create an instance of the Concatenates the members of a constructed collection of type . The concatenated strings in , or if is an empty . - method. - - An string is used in place of any null element in `values`. - - If `values` is an empty `IEnumerable(Of String)`, the method returns . If `values` is `null`, the method throws an exception. - - is a convenience method that lets you concatenate each element in an `IEnumerable(Of String)` collection without first converting the elements to a string array. It is particularly useful with Language-Integrated Query (LINQ) query expressions. The following example passes a `List(Of String)` object that contains either the uppercase or lowercase letters of the alphabet to a lambda expression that selects letters that are equal to or greater than a particular letter (which, in the example, is "M"). The `IEnumerable(Of String)` collection that is returned by the method is passed to the method to display the result as a single string. - - :::code language="csharp" source="~/snippets/csharp/System/String/Concat/concat2.cs" interactive="try-dotnet" id="Snippet3"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Concat/concat2.fs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.concat/vb/concat2.vb" id="Snippet3"::: - -## Examples - The following example uses the Sieve of Eratosthenes algorithm to calculate the prime numbers that are less than or equal to 100. It assigns the result to a object of type , which it then passes to the method. - - :::code language="csharp" source="~/snippets/csharp/System/String/Concat/concat1.cs" interactive="try-dotnet" id="Snippet2"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Concat/concat1.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.concat/vb/concat1.vb" id="Snippet2"::: - + method. + + An string is used in place of any null element in `values`. + + If `values` is an empty `IEnumerable(Of String)`, the method returns . If `values` is `null`, the method throws an exception. + + is a convenience method that lets you concatenate each element in an `IEnumerable(Of String)` collection without first converting the elements to a string array. It is particularly useful with Language-Integrated Query (LINQ) query expressions. The following example passes a `List(Of String)` object that contains either the uppercase or lowercase letters of the alphabet to a lambda expression that selects letters that are equal to or greater than a particular letter (which, in the example, is "M"). The `IEnumerable(Of String)` collection that is returned by the method is passed to the method to display the result as a single string. + + :::code language="csharp" source="~/snippets/csharp/System/String/Concat/concat2.cs" interactive="try-dotnet" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Concat/concat2.fs" id="Snippet3"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.concat/vb/concat2.vb" id="Snippet3"::: + +## Examples + The following example uses the Sieve of Eratosthenes algorithm to calculate the prime numbers that are less than or equal to 100. It assigns the result to a object of type , which it then passes to the method. + + :::code language="csharp" source="~/snippets/csharp/System/String/Concat/concat1.cs" interactive="try-dotnet" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Concat/concat1.fs" id="Snippet2"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.concat/vb/concat1.vb" id="Snippet2"::: + ]]> @@ -3626,22 +3722,22 @@ The following example demonstrates how you can create an instance of the The object to represent, or . - Creates the string representation of a specified object. + Creates the string representation of a specified object. The string representation of the value of , or if is . - method represents `arg0` as a string by calling its parameterless `ToString` method. - -## Examples - The following example demonstrates the method. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.concat5/CPP/string.concat5.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Concat/string.concat5.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Concat/string.concat5.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.concat5/VB/string.concat5.vb" id="Snippet1"::: - + method represents `arg0` as a string by calling its parameterless `ToString` method. + +## Examples + The following example demonstrates the method. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.concat5/CPP/string.concat5.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Concat/string.concat5.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Concat/string.concat5.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.concat5/VB/string.concat5.vb" id="Snippet1"::: + ]]> @@ -3705,20 +3801,20 @@ The following example demonstrates how you can create an instance of the Concatenates the string representations of the elements in a specified array. The concatenated string representations of the values of the elements in . - is used in place of any null object in the array. - -## Examples - The following example demonstrates the use of the method with an array. - - :::code language="csharp" source="~/snippets/csharp/System/String/Concat/stringconcat1.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Concat/stringconcat1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/stringconcat1/VB/stringconcat1.vb" id="Snippet1"::: - + is used in place of any null object in the array. + +## Examples + The following example demonstrates the use of the method with an array. + + :::code language="csharp" source="~/snippets/csharp/System/String/Concat/stringconcat1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Concat/stringconcat1.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/stringconcat1/VB/stringconcat1.vb" id="Snippet1"::: + ]]> @@ -3794,21 +3890,21 @@ The following example demonstrates how you can create an instance of the Concatenates the elements of a specified array. The concatenated elements of . - string is used in place of any null object in the array. - -## Examples - The following example demonstrates the use of the method with a array. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/stringconcat3/CPP/stringconcat3.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Concat/stringconcat3.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Concat/stringconcat3.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/stringconcat3/VB/stringconcat3.vb" id="Snippet1"::: - + string is used in place of any null object in the array. + +## Examples + The following example demonstrates the use of the method with a array. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/stringconcat3/CPP/stringconcat3.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Concat/stringconcat3.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Concat/stringconcat3.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/stringconcat3/VB/stringconcat3.vb" id="Snippet1"::: + ]]> @@ -3871,23 +3967,23 @@ The following example demonstrates how you can create an instance of the Concatenates the string representations of two specified objects. The concatenated string representations of the values of and . - is used in place of any null argument. - - If either of the arguments is an array reference, the method concatenates a string representing that array, instead of its members (for example, "System.String[]"). - -## Examples - The following example demonstrates the method. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.concat5/CPP/string.concat5.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Concat/string.concat5.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Concat/string.concat5.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.concat5/VB/string.concat5.vb" id="Snippet1"::: - + is used in place of any null argument. + + If either of the arguments is an array reference, the method concatenates a string representing that array, instead of its members (for example, "System.String[]"). + +## Examples + The following example demonstrates the method. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.concat5/CPP/string.concat5.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Concat/string.concat5.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Concat/string.concat5.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.concat5/VB/string.concat5.vb" id="Snippet1"::: + ]]> @@ -3996,21 +4092,21 @@ The following example demonstrates how you can create an instance of the Concatenates two specified instances of . The concatenation of and . - string is used in place of any null argument. - -## Examples - The following example concatenates a person's first, middle, and last name. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/stringconcat4/CPP/stringconcat4.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Concat/stringconcat4.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Concat/stringconcat4.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/stringconcat4/VB/stringconcat4.vb" id="Snippet1"::: - + string is used in place of any null argument. + +## Examples + The following example concatenates a person's first, middle, and last name. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/stringconcat4/CPP/stringconcat4.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Concat/stringconcat4.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Concat/stringconcat4.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/stringconcat4/VB/stringconcat4.vb" id="Snippet1"::: + ]]> @@ -4072,21 +4168,21 @@ The following example demonstrates how you can create an instance of the Concatenates the string representations of three specified objects. The concatenated string representations of the values of , , and . - is used in place of any null argument. - -## Examples - The following example demonstrates the method. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.concat5/CPP/string.concat5.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Concat/string.concat5.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Concat/string.concat5.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.concat5/VB/string.concat5.vb" id="Snippet1"::: - + is used in place of any null argument. + +## Examples + The following example demonstrates the method. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.concat5/CPP/string.concat5.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Concat/string.concat5.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Concat/string.concat5.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.concat5/VB/string.concat5.vb" id="Snippet1"::: + ]]> @@ -4199,19 +4295,19 @@ The following example demonstrates how you can create an instance of the Concatenates three specified instances of . The concatenation of , , and . - method to concatenate three strings and displays the result. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.string.concat/cpp/Concat6.cpp" id="Snippet6"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Concat/Concat6.cs" interactive="try-dotnet" id="Snippet6"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Concat/Concat6.fs" id="Snippet6"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.concat/vb/Concat6.vb" id="Snippet6"::: - + method to concatenate three strings and displays the result. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.string.concat/cpp/Concat6.cpp" id="Snippet6"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Concat/Concat6.cs" interactive="try-dotnet" id="Snippet6"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Concat/Concat6.fs" id="Snippet6"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.concat/vb/Concat6.vb" id="Snippet6"::: + ]]> @@ -4266,27 +4362,27 @@ The following example demonstrates how you can create an instance of the Concatenates the string representations of four specified objects and any objects specified in an optional variable length parameter list. The concatenated string representation of each value in the parameter list. - [!NOTE] -> This API is not CLS-compliant. The CLS-compliant alternative is . The C# and Visual Basic compilers automatically resolve a call to this method as a call to . - - The method concatenates each object in the parameter list by calling its parameterless `ToString` method; it does not add any delimiters. - - is used in place of any null argument. - -> [!NOTE] -> The last parameter of the method is an optional comma-delimited list of one or more additional objects to concatenate. - -## Examples - The following example illustrates the use of the method to concatenate a list of variable parameters. In this case, the method is called with nine parameters. - - :::code language="csharp" source="~/snippets/csharp/System/String/Concat/concat4.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Concat/concat4.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.concat/vb/concat4.vb" id="Snippet1"::: - + [!NOTE] +> This API is not CLS-compliant. The CLS-compliant alternative is . The C# and Visual Basic compilers automatically resolve a call to this method as a call to . + + The method concatenates each object in the parameter list by calling its parameterless `ToString` method; it does not add any delimiters. + + is used in place of any null argument. + +> [!NOTE] +> The last parameter of the method is an optional comma-delimited list of one or more additional objects to concatenate. + +## Examples + The following example illustrates the use of the method to concatenate a list of variable parameters. In this case, the method is called with nine parameters. + + :::code language="csharp" source="~/snippets/csharp/System/String/Concat/concat4.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Concat/concat4.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.concat/vb/concat4.vb" id="Snippet1"::: + ]]> @@ -4404,18 +4500,18 @@ The following example demonstrates how you can create an instance of the Concatenates four specified instances of . The concatenation of , , , and . - method to reassemble the scrambled words. - - :::code language="csharp" source="~/snippets/csharp/System/String/Concat/concat4.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Concat/concat4.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.concat/vb/concat4.vb" id="Snippet1"::: - + method to reassemble the scrambled words. + + :::code language="csharp" source="~/snippets/csharp/System/String/Concat/concat4.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Concat/concat4.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.concat/vb/concat4.vb" id="Snippet1"::: + ]]> @@ -4481,22 +4577,22 @@ The following example demonstrates how you can create an instance of the Concatenates the members of an implementation. The concatenated members in . - string is used in place of any null argument. - - is a convenience method that lets you concatenate each element in an collection without first converting the elements to strings. It is particularly useful with Language-Integrated Query (LINQ) query expressions, as the example illustrates. The string representation of each object in the collection is derived by calling that object's `ToString` method. - -## Examples - The following example defines a very simple `Animal` class that contains the name of an animal and the order to which it belongs. It then defines a object to contain a number of `Animal` objects. The extension method is called to extract the `Animal` objects whose `Order` property equals "Rodent". The result is passed to the method and displayed to the console. - - :::code language="csharp" source="~/snippets/csharp/System/String/Concat/concat3.cs" interactive="try-dotnet" id="Snippet4"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Concat/concat3.fs" id="Snippet4"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.concat/vb/concat3.vb" id="Snippet4"::: - + string is used in place of any null argument. + + is a convenience method that lets you concatenate each element in an collection without first converting the elements to strings. It is particularly useful with Language-Integrated Query (LINQ) query expressions, as the example illustrates. The string representation of each object in the collection is derived by calling that object's `ToString` method. + +## Examples + The following example defines a very simple `Animal` class that contains the name of an animal and the order to which it belongs. It then defines a object to contain a number of `Animal` objects. The extension method is called to extract the `Animal` objects whose `Order` property equals "Rodent". The result is passed to the method and displayed to the console. + + :::code language="csharp" source="~/snippets/csharp/System/String/Concat/concat3.cs" interactive="try-dotnet" id="Snippet4"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Concat/concat3.fs" id="Snippet4"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.concat/vb/concat3.vb" id="Snippet4"::: + ]]> @@ -4539,10 +4635,10 @@ The following example demonstrates how you can create an instance of the if the parameter occurs within this string; otherwise, . - @@ -4598,34 +4694,34 @@ The following example demonstrates how you can create an instance of the if the parameter occurs within this string, or if is the empty string (""); otherwise, . - overload instead. - -- On .NET Framework: Create a custom method. The following example illustrates one such approach. It defines a extension method that includes a parameter and indicates whether a string contains a substring when using the specified form of string comparison. - - :::code language="csharp" source="~/snippets/csharp/System/String/Contains/ContainsExt1.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Contains/ContainsExt1.fs" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Contains/ContainsExt1.cs" id="Snippet2"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Contains/ContainsExt1.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.String.Contains/vb/ContainsExt1.vb" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.String.Contains/vb/ContainsExt1.vb" id="Snippet2"::: - - If you are interested in the position of the substring `value` in the current instance, you can call the method to get the starting position of its first occurrence, or you can call the method to get the starting position of its last occurrence. The example includes a call to the method if a substring is found in a string instance. - -## Examples - The following example determines whether the string "fox" is a substring of a familiar quotation. If "fox" is found in the string, it also displays its starting position. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.contains/CPP/cont.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Contains/cont.cs" interactive="try-dotnet-method" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Contains/cont.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.contains/VB/cont.vb" id="Snippet1"::: - + overload instead. + +- On .NET Framework: Create a custom method. The following example illustrates one such approach. It defines a extension method that includes a parameter and indicates whether a string contains a substring when using the specified form of string comparison. + + :::code language="csharp" source="~/snippets/csharp/System/String/Contains/ContainsExt1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Contains/ContainsExt1.fs" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Contains/ContainsExt1.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Contains/ContainsExt1.fs" id="Snippet2"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.String.Contains/vb/ContainsExt1.vb" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.String.Contains/vb/ContainsExt1.vb" id="Snippet2"::: + + If you are interested in the position of the substring `value` in the current instance, you can call the method to get the starting position of its first occurrence, or you can call the method to get the starting position of its last occurrence. The example includes a call to the method if a substring is found in a string instance. + +## Examples + The following example determines whether the string "fox" is a substring of a familiar quotation. If "fox" is found in the string, it also displays its starting position. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.contains/CPP/cont.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Contains/cont.cs" interactive="try-dotnet-method" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Contains/cont.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.contains/VB/cont.vb" id="Snippet1"::: + ]]> @@ -4769,36 +4865,36 @@ To perform a culture-sensitive or ordinal case-insensitive comparison: Creates a new instance of with the same value as a specified . A new string with the same value as . - object that has the same value as the original string but represents a different object reference. It differs from an assignment operation, which assigns an existing string reference to an additional object variable. - -> [!IMPORTANT] -> Starting with .NET Core 3.0, this method is obsolete. However, we do not recommend its use in any .NET implementation. In particular, because of changes in string interning in .NET Core 3.0, in some cases the `Copy` method will not create a new string but will simply return a reference to an existing interned string. - -Depending on Why you want to call the `Copy` method, there are a number of alternatives: - -- If you want a different string instance to use in an operation that modifies the string, use the original string instance. Because strings are immutable, the string operation creates a new string instance, and the original string remains unaffected. In this case, you should not assign the new string reference to the original string variable. The following example provides an illustration. - - :::code language="csharp" source="~/snippets/csharp/System/String/Copy/Program.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Copy/Program.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/api/system/string/copy/program.vb" id="Snippet1"::: - - In this case, calling the `Copy` method to create a new string before calling the method unnecessarily creates a new string instance. - -- If you want to create a mutable buffer with the same contents as the original string, call the or constructor. For example: - - :::code language="csharp" source="~/snippets/csharp/System/String/Copy/Program.cs" id="Snippet2"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Copy/Program.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/api/system/string/copy/program.vb" id="Snippet2"::: - -- If you want to create a mutable copy of the string so that you can use unsafe code to modify the string contents, use method. The following example uses the method to get a pointer to the location of an copied string in unmanaged memory, increments the Unicode code point of each character in the string by one, and copies the resulting string back to a managed string. - - :::code language="csharp" source="~/snippets/csharp/System/String/Copy/Program.cs" id="Snippet3"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Copy/Program.fs" id="Snippet3"::: - + object that has the same value as the original string but represents a different object reference. It differs from an assignment operation, which assigns an existing string reference to an additional object variable. + +> [!IMPORTANT] +> Starting with .NET Core 3.0, this method is obsolete. However, we do not recommend its use in any .NET implementation. In particular, because of changes in string interning in .NET Core 3.0, in some cases the `Copy` method will not create a new string but will simply return a reference to an existing interned string. + +Depending on Why you want to call the `Copy` method, there are a number of alternatives: + +- If you want a different string instance to use in an operation that modifies the string, use the original string instance. Because strings are immutable, the string operation creates a new string instance, and the original string remains unaffected. In this case, you should not assign the new string reference to the original string variable. The following example provides an illustration. + + :::code language="csharp" source="~/snippets/csharp/System/String/Copy/Program.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Copy/Program.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/api/system/string/copy/program.vb" id="Snippet1"::: + + In this case, calling the `Copy` method to create a new string before calling the method unnecessarily creates a new string instance. + +- If you want to create a mutable buffer with the same contents as the original string, call the or constructor. For example: + + :::code language="csharp" source="~/snippets/csharp/System/String/Copy/Program.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Copy/Program.fs" id="Snippet2"::: + :::code language="vb" source="~/snippets/visualbasic/api/system/string/copy/program.vb" id="Snippet2"::: + +- If you want to create a mutable copy of the string so that you can use unsafe code to modify the string contents, use method. The following example uses the method to get a pointer to the location of an copied string in unmanaged memory, increments the Unicode code point of each character in the string by one, and copies the resulting string back to a managed string. + + :::code language="csharp" source="~/snippets/csharp/System/String/Copy/Program.cs" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Copy/Program.fs" id="Snippet3"::: + ]]> @@ -4900,43 +4996,43 @@ Depending on Why you want to call the `Copy` method, there are a number of alter The number of characters in this instance to copy to . Copies a specified number of characters from a specified position in this instance to a specified position in an array of Unicode characters. - . - - `sourceIndex` and `destinationIndex` are zero-based. - -## Examples - The following example demonstrates the method. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/stringcopyto/CPP/stringcopyto.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/CopyTo/stringcopyto.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/CopyTo/stringcopyto.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/stringcopyto/VB/stringcopyto.vb" id="Snippet1"::: - + . + + `sourceIndex` and `destinationIndex` are zero-based. + +## Examples + The following example demonstrates the method. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/stringcopyto/CPP/stringcopyto.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/CopyTo/stringcopyto.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/CopyTo/stringcopyto.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/stringcopyto/VB/stringcopyto.vb" id="Snippet1"::: + ]]> is . - , , or is negative - - -or- - - does not identify a position in the current instance. - - -or- - - does not identify a valid index in the array. - - -or- - - is greater than the length of the substring from to the end of this instance - - -or- - - is greater than the length of the subarray from to the end of the array. + , , or is negative + +-or- + + does not identify a position in the current instance. + +-or- + + does not identify a valid index in the array. + +-or- + + is greater than the length of the substring from to the end of this instance + +-or- + + is greater than the length of the subarray from to the end of the array. @@ -5099,9 +5195,9 @@ Depending on Why you want to call the `Copy` method, there are a number of alter Creates a new string with a specific length and initializes it after creation by using the specified callback. The created string. - @@ -5146,13 +5242,13 @@ The initial content of the destination span passed to `action` is undefined. The Represents the empty string. This field is read-only. - , use the method. - + , use the method. + ]]> @@ -5205,12 +5301,12 @@ The initial content of the destination span passed to `action` is undefined. The if matches the end of this instance; otherwise, . - @@ -5261,27 +5357,27 @@ This method performs an ordinal (case-sensitive and culture-insensitive) compari if matches the end of this instance; otherwise, . - method to remove HTML end tags from the end of a line. Note that the `StripEndTags` method is called recursively to ensure that multiple HTML end tags at the end of the line are removed. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/stringendswith/CPP/stringendswith.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/EndsWith/stringendswith.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/EndsWith/stringendswith.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/stringendswith/VB/stringendswith.vb" id="Snippet1"::: - + method to remove HTML end tags from the end of a line. Note that the `StripEndTags` method is called recursively to ensure that multiple HTML end tags at the end of the line are removed. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/stringendswith/CPP/stringendswith.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/EndsWith/stringendswith.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/EndsWith/stringendswith.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/stringendswith/VB/stringendswith.vb" id="Snippet1"::: + ]]> @@ -5350,19 +5446,19 @@ This method performs an ordinal (case-sensitive and culture-insensitive) compari if the parameter matches the end of this string; otherwise, . - method compares the `value` parameter to the substring at the end of this string and returns a value that indicates whether they are equal. To be equal, `value` must be a reference to this same string, must be the empty string (""), or must match the end of this string. The type of comparison performed by the method depends on the value of the `comparisonType` parameter. - -## Examples - The following example determines whether a string ends with a particular substring. The results are affected by the choice of culture, whether case is ignored, and whether an ordinal comparison is performed. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.EndsWithCmp/cpp/ewcmp.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/EndsWith/ewcmp.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/EndsWith/ewcmp.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.EndsWithCmp/vb/ewcmp.vb" id="Snippet1"::: - + method compares the `value` parameter to the substring at the end of this string and returns a value that indicates whether they are equal. To be equal, `value` must be a reference to this same string, must be the empty string (""), or must match the end of this string. The type of comparison performed by the method depends on the value of the `comparisonType` parameter. + +## Examples + The following example determines whether a string ends with a particular substring. The results are affected by the choice of culture, whether case is ignored, and whether an ordinal comparison is performed. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.EndsWithCmp/cpp/ewcmp.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/EndsWith/ewcmp.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/EndsWith/ewcmp.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.EndsWithCmp/vb/ewcmp.vb" id="Snippet1"::: + ]]> @@ -5426,20 +5522,20 @@ This method performs an ordinal (case-sensitive and culture-insensitive) compari if the parameter matches the end of this string; otherwise, . - method is called several times using case sensitivity, case insensitivity, and different cultures that influence the results of the search. - - :::code language="csharp" source="~/snippets/csharp/System/String/EndsWith/ewci.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/EndsWith/ewci.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.EndsWithCI/vb/ewci.vb" id="Snippet1"::: - + method is called several times using case sensitivity, case insensitivity, and different cultures that influence the results of the search. + + :::code language="csharp" source="~/snippets/csharp/System/String/EndsWith/ewci.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/EndsWith/ewci.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.EndsWithCI/vb/ewci.vb" id="Snippet1"::: + ]]> @@ -5478,12 +5574,12 @@ This method performs an ordinal (case-sensitive and culture-insensitive) compari Returns an enumeration of from this string. A string rune enumerator. - . - + . + ]]> @@ -5563,21 +5659,21 @@ Invalid sequences are represented in the enumeration by The string to compare to this instance. Determines whether this instance and a specified object, which must also be a object, have the same value. - if is a and its value is the same as this instance; otherwise, . If is , the method returns . + if is a and its value is the same as this instance; otherwise, . If is , the method returns . - method. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.equals/CPP/equals.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Equals/equals.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Equals/equals.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.equals/VB/equals.vb" id="Snippet1"::: - + method. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.equals/CPP/equals.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Equals/equals.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Equals/equals.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.equals/VB/equals.vb" id="Snippet1"::: + ]]> @@ -5657,18 +5753,18 @@ Invalid sequences are represented in the enumeration by if the value of the parameter is the same as the value of this instance; otherwise, . If is , the method returns . - method. It compares the title-cased word "File" with an equivalent word, its lowercase equivalent, its uppercase equivalent, and a word that contains LATIN SMALL LETTER DOTLESS I (U+0131) instead of LATIN SMALL LETTER I (U+0069). Because the method performs an ordinal comparison, only the comparison with an identical word returns `true`. - - :::code language="csharp" source="~/snippets/csharp/System/String/Equals/equalsex1.cs" id="Snippet2"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Equals/equalsex1.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.equals/vb/equalsex1.vb" id="Snippet2"::: - + method. It compares the title-cased word "File" with an equivalent word, its lowercase equivalent, its uppercase equivalent, and a word that contains LATIN SMALL LETTER DOTLESS I (U+0131) instead of LATIN SMALL LETTER I (U+0069). Because the method performs an ordinal comparison, only the comparison with an identical word returns `true`. + + :::code language="csharp" source="~/snippets/csharp/System/String/Equals/equalsex1.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Equals/equalsex1.fs" id="Snippet2"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.equals/vb/equalsex1.vb" id="Snippet2"::: + ]]> @@ -5733,19 +5829,19 @@ Invalid sequences are represented in the enumeration by if the value of is the same as the value of ; otherwise, . If both and are , the method returns . - method. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.equals/CPP/equals.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Equals/equals.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Equals/equals.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.equals/VB/equals.vb" id="Snippet1"::: - + method. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.equals/CPP/equals.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Equals/equals.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Equals/equals.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.equals/VB/equals.vb" id="Snippet1"::: + ]]> @@ -5816,18 +5912,18 @@ Invalid sequences are represented in the enumeration by if the value of the parameter is the same as this string; otherwise, . - method to compare them by using each possible enumeration value. - - :::code language="csharp" source="~/snippets/csharp/System/String/Equals/eqcmp.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Equals/eqcmp.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.equals/vb/eqcmp.vb" id="Snippet1"::: - + method to compare them by using each possible enumeration value. + + :::code language="csharp" source="~/snippets/csharp/System/String/Equals/eqcmp.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Equals/eqcmp.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.equals/vb/eqcmp.vb" id="Snippet1"::: + ]]> @@ -5895,18 +5991,18 @@ Invalid sequences are represented in the enumeration by if the value of the parameter is equal to the value of the parameter; otherwise, . - enumeration. The comparisons use the conventions of the English (United States), Thai (Thailand) and Turkish (Turkey) cultures. Note that the strings "a" and "a-" are considered equivalent in the "th-TH" culture but not in the others, while "i" and "İ" are considered equivalent in the "tr-TR" culture when case is ignored but not in the other cultures. - - :::code language="csharp" source="~/snippets/csharp/System/String/Equals/equals_ex3.cs" interactive="try-dotnet" id="Snippet3"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Equals/equals_ex3.fs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.equals/vb/equals_ex3.vb" id="Snippet3"::: - + enumeration. The comparisons use the conventions of the English (United States), Thai (Thailand) and Turkish (Turkey) cultures. Note that the strings "a" and "a-" are considered equivalent in the "th-TH" culture but not in the others, while "i" and "İ" are considered equivalent in the "tr-TR" culture when case is ignored but not in the other cultures. + + :::code language="csharp" source="~/snippets/csharp/System/String/Equals/equals_ex3.cs" interactive="try-dotnet" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Equals/equals_ex3.fs" id="Snippet3"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.equals/vb/equals_ex3.vb" id="Snippet3"::: + ]]> @@ -5921,376 +6017,376 @@ Invalid sequences are represented in the enumeration by 4.1.0.0 - Converts the value of objects to strings based on the formats specified and inserts them into another string. - - If you are new to the `String.Format` method, see the [Get started with the String.Format method](#Starting) section for a quick overview. - - See the [Remarks](#remarks-top) section for general documentation for the `String.Format` method. + Converts the value of objects to strings based on the formats specified and inserts them into another string. + + If you are new to the `String.Format` method, see the [Get started with the String.Format method](#Starting) section for a quick overview. + + See the [Remarks](#remarks-top) section for general documentation for the `String.Format` method. - -## Remarks - -[!INCLUDE[interpolated-strings](~/includes/interpolated-strings.md)] - - In this section: - - [Get started with the String.Format method](#Starting)\ - [Which method do I call?](#FTaskList)\ - [The Format method in brief](#Format_Brief)\ - [The Format item](#FormatItem)\ - [How arguments are formatted](#HowFormatted)\ - [Format items that have the same index](#SameIndex)\ - [Formatting and culture](#Format_Culture)\ - [Custom formatting operations](#Format_Custom)\ - [String.Format Q & A](#QA) - - -## Get started with the String.Format method - Use if you need to insert the value of an object, variable, or expression into another string. For example, you can insert the value of a value into a string to display it to the user as a single string: - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Format/cpp/starting2.cpp" id="Snippet35"::: - :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/starting2.cs" interactive="try-dotnet-method" id="Snippet35"::: - :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/starting2.fs" id="Snippet35"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format/vb/starting2.vb" id="Snippet35"::: - - And you can control that value's formatting: - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Format/cpp/starting2.cpp" id="Snippet36"::: - :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/starting2.cs" id="Snippet36"::: - :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/starting2.fs" id="Snippet36"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format/vb/starting2.vb" id="Snippet36"::: - - Besides formatting, you can also control alignment and spacing. - - ### Insert a string - - starts with a format string, followed by one or more objects or expressions that will be converted to strings and inserted at a specified place in the format string. For example: - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Format/cpp/starting1.cpp" id="Snippet30"::: - :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/starting1.cs" interactive="try-dotnet-method" id="Snippet30"::: - :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/starting1.fs" id="Snippet30"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format/vb/starting1.vb" id="Snippet30"::: - - The `{0}` in the format string is a format item. `0` is the index of the object whose string value will be inserted at that position. (Indexes start at 0.) If the object to be inserted is not a string, its `ToString` method is called to convert it to one before inserting it in the result string. - - Here's another example that uses two format items and two objects in the object list: - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Format/cpp/starting1.cpp" id="Snippet31"::: - :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/starting1.cs" id="Snippet31"::: - :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/starting1.fs" id="Snippet31"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format/vb/starting1.vb" id="Snippet31"::: - - You can have as many format items and as many objects in the object list as you want, as long as the index of every format item has a matching object in the object list. You also don't have to worry about which overload you call; the compiler will select the appropriate one for you. - - ### Control formatting - You can follow the index in a format item with a format string to control how an object is formatted. For example, `{0:d}` applies the "d" format string to the first object in the object list. Here is an example with a single object and two format items: - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Format/cpp/starting1.cpp" id="Snippet32"::: - :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/starting1.cs" id="Snippet32"::: - :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/starting1.fs" id="Snippet32"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format/vb/starting1.vb" id="Snippet32"::: - - A number of types support format strings, including all numeric types (both [standard](/dotnet/standard/base-types/standard-numeric-format-strings) and [custom](/dotnet/standard/base-types/custom-numeric-format-strings) format strings), all dates and times (both [standard](/dotnet/standard/base-types/standard-date-and-time-format-strings) and [custom](/dotnet/standard/base-types/custom-date-and-time-format-strings) format strings) and time intervals (both [standard](/dotnet/standard/base-types/standard-timespan-format-strings) and [custom](/dotnet/standard/base-types/custom-timespan-format-strings) format strings), all enumeration types [enumeration types](/dotnet/standard/base-types/enumeration-format-strings), and [GUIDs](xref:System.Guid.ToString(System.String)). You can also add support for format strings to your own types. - - ### Control spacing - You can define the width of the string that is inserted into the result string by using syntax such as `{0,12}`, which inserts a 12-character string. In this case, the string representation of the first object is right-aligned in the 12-character field. (If the string representation of the first object is more than 12 characters in length, though, the preferred field width is ignored, and the entire string is inserted into the result string.) - - The following example defines a 6-character field to hold the string "Year" and some year strings, as well as an 15-character field to hold the string "Population" and some population data. Note that the characters are right-aligned in the field. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Format/cpp/starting1.cpp" id="Snippet33"::: - :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/starting3.cs" id="Snippet33"::: - :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/starting3.fs" id="Snippet33"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format/vb/starting1.vb" id="Snippet33"::: - - ### Control alignment - By default, strings are right-aligned within their field if you specify a field width. To left-align strings in a field, you preface the field width with a negative sign, such as `{0,-12}` to define a 12-character left-aligned field. - - The following example is similar to the previous one, except that it left-aligns both labels and data. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Format/cpp/starting1.cpp" id="Snippet34"::: - :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/starting1.cs" id="Snippet34"::: - :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/starting1.fs" id="Snippet34"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format/vb/starting1.vb" id="Snippet34"::: - - makes use of the composite formatting feature. For more information, see [Composite Formatting](/dotnet/standard/base-types/composite-formatting). - - -## Which method do I call? - -|To|Call| -|--------|----------| -|Format one or more objects by using the conventions of the current culture.|Except for the overloads that include a `provider` parameter, the remaining overloads include a parameter followed by one or more object parameters. Because of this, you don't have to determine which overload you intend to call. Your language compiler selects the appropriate overload from among the overloads that don't have a `provider` parameter, based on your argument list. For example, if your argument list has five arguments, the compiler calls the method.| -|Format one or more objects by using the conventions of a specific culture.|Each overload that begins with a `provider` parameter is followed by a parameter and one or more object parameters. Because of this, you don't have to determine which specific overload you intend to call. Your language compiler selects the appropriate overload from among the overloads that have a `provider` parameter, based on your argument list. For example, if your argument list has five arguments, the compiler calls the method.| -|Perform a custom formatting operation either with an implementation or an implementation.|Any of the four overloads with a `provider` parameter. The compiler selects the appropriate overload from among the overloads that have a `provider` parameter, based on your argument list.| - - -## The Format method in brief - - Each overload of the method uses the [composite formatting feature](/dotnet/standard/base-types/composite-formatting) to include zero-based indexed placeholders, called *format items*, in a composite format string. At run time, each format item is replaced with the string representation of the corresponding argument in a parameter list. If the value of the argument is `null`, the format item is replaced with . For example, the following call to the method includes a format string with three format items, {0}, {1}, and {2}, and an argument list with three items. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Format/cpp/formatoverload1.cpp" id="Snippet8"::: - :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/formatoverload1.cs" id="Snippet8"::: - :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/formatoverload1.fs" id="Snippet8"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format/vb/formatoverload1.vb" id="Snippet8"::: - - -## The format item - A format item has this syntax: - -``` -{index[,alignment][:formatString]} -``` - - Brackets denote optional elements. The opening and closing braces are required. (To include a literal opening or closing brace in the format string, see the [Escaping Braces](/dotnet/standard/base-types/composite-formatting#escaping-braces) section in the [Composite Formatting](/dotnet/standard/base-types/composite-formatting) article.) - - For example, a format item to format a currency value might appear like this: - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Format/cpp/formatsyntax1.cpp" id="Snippet12"::: - :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/formatsyntax1.cs" id="Snippet12"::: - :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/formatsyntax1.fs" id="Snippet12"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format/vb/formatsyntax1.vb" id="Snippet12"::: - - A format item has the following elements: - - *index*\ - The zero-based index of the argument whose string representation is to be included at this position in the string. If this argument is `null`, an empty string will be included at this position in the string. - - *alignment*\ - Optional. A signed integer that indicates the total length of the field into which the argument is inserted and whether it is right-aligned (a positive integer) or left-aligned (a negative integer). If you omit *alignment*, the string representation of the corresponding argument is inserted in a field with no leading or trailing spaces. - - If the value of *alignment* is less than the length of the argument to be inserted, *alignment* is ignored and the length of the string representation of the argument is used as the field width. - - *formatString*\ - Optional. A string that specifies the format of the corresponding argument's result string. If you omit *formatString*, the corresponding argument's parameterless `ToString` method is called to produce its string representation. If you specify *formatString*, the argument referenced by the format item must implement the interface. Types that support format strings include: - -- All integral and floating-point types. (See [Standard Numeric Format Strings](/dotnet/standard/base-types/standard-numeric-format-strings) and [Custom Numeric Format Strings](/dotnet/standard/base-types/custom-numeric-format-strings).) - -- and . (See [Standard Date and Time Format Strings](/dotnet/standard/base-types/standard-date-and-time-format-strings) and [Custom Date and Time Format Strings](/dotnet/standard/base-types/custom-date-and-time-format-strings).) - -- All enumeration types. (See [Enumeration Format Strings](/dotnet/standard/base-types/enumeration-format-strings).) - -- values. (See [Standard TimeSpan Format Strings](/dotnet/standard/base-types/standard-timespan-format-strings) and [Custom TimeSpan Format Strings](/dotnet/standard/base-types/custom-timespan-format-strings).) - -- GUIDs. (See the method.) - - However, note that any custom type can implement or extend an existing type's implementation. - - The following example uses the `alignment` and `formatString` arguments to produce formatted output. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Format/cpp/formatoverload2.cpp" id="Snippet9"::: - :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/formatoverload2.cs" interactive="try-dotnet-method" id="Snippet9"::: - :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/formatoverload2.fs" id="Snippet9"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format/vb/formatoverload2.vb" id="Snippet9"::: - - -## How arguments are formatted - Format items are processed sequentially from the beginning of the string. Each format item has an index that corresponds to an object in the method's argument list. The method retrieves the argument and derives its string representation as follows: - -- If the argument is `null`, the method inserts into the result string. You don't have to be concerned with handling a for null arguments. - -- If you call the overload and the `provider` object's implementation returns a non-null implementation, the argument is passed to its method. If the format item includes a *formatString* argument, it is passed as the first argument to the method. If the implementation is available and produces a non-null string, that string is returned as the string representation of the argument; otherwise, the next step executes. - -- If the argument implements the interface, its implementation is called. - -- The argument's parameterless `ToString` method, which either overrides or inherits from a base class implementation, is called. - - For an example that intercepts calls to the method and allows you to see what information the method passes to a formatting method for each format item in a composite format string, see [Example: An intercept provider and Roman numeral formatter](#Format7_Example). - - For more information, see the [Processing Order](/dotnet/standard/base-types/composite-formatting##processing-order) section in the [Composite Formatting](/dotnet/standard/base-types/composite-formatting) article. - - -## Format items that have the same index - The method throws a exception if the index of an index item is greater than or equal to the number of arguments in the argument list. However, `format` can include more format items than there are arguments, as long as multiple format items have the same index. In the call to the method in following example, the argument list has a single argument, but the format string includes two format items: one displays the decimal value of a number, and the other displays its hexadecimal value. - - :::code language="csharp" source="~/snippets/csharp/System/String/Format/Example1.cs" interactive="try-dotnet-method" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Format/Example1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format2/vb/Example1.vb" id="Snippet1"::: - - -## Format and culture - Generally, objects in the argument list are converted to their string representations by using the conventions of the current culture, which is returned by the property. You can control this behavior by calling one of the overloads of that includes a `provider` parameter. The `provider` parameter is an implementation that supplies custom and culture-specific formatting information that is used to moderate the formatting process. - - The interface has a single member, , which is responsible for returning the object that provides formatting information. .NET has three implementations that provide culture-specific formatting: - -- . Its method returns a culture-specific object for formatting numeric values and a culture-specific object for formatting date and time values. - -- , which is used for culture-specific formatting of date and time values. Its method returns itself. - -- , which is used for culture-specific formatting of numeric values. Its property returns itself. - - -## Custom formatting operations - You can also call the any of the overloads of the method that have a `provider` parameter of type to perform custom formatting operations. For example, you could format an integer as an identification number or as a telephone number. To perform custom formatting, your `provider` argument must implement both the and interfaces. When the method is passed an implementation as the `provider` argument, the method calls its implementation and requests an object of type . It then calls the returned object's method to format each format item in the composite string passed to it. - - For more information about providing custom formatting solutions, see [How to: Define and Use Custom Numeric Format Providers](/dotnet/standard/base-types/how-to-define-and-use-custom-numeric-format-providers) and . For an example that converts integers to formatted custom numbers, see [Example: A custom formatting operation](#Format6_Example). For an example that converts unsigned bytes to Roman numerals, see [Example: An intercept provider and Roman numeral formatter](#Format7_Example). - - -### Example: A custom formatting operation - This example defines a format provider that formats an integer value as a customer account number in the form x-xxxxx-xx. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Format/cpp/formatexample2.cpp" id="Snippet2"::: - :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/FormatExample2.cs" interactive="try-dotnet" id="Snippet2"::: - :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/FormatExample2.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format/vb/FormatExample2.vb" id="Snippet2"::: - - -### Example: An intercept provider and Roman numeral formatter - This example defines a custom format provider that implements the and interfaces to do two things: - -- It displays the parameters passed to its implementation. This enables us to see what parameters the method is passing to the custom formatting implementation for each object that it tries to format. This can be useful when you're debugging your application. - -- If the object to be formatted is an unsigned byte value that is to be formatted by using the "R" standard format string, the custom formatter formats the numeric value as a Roman numeral. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Format/cpp/interceptor2.cpp" id="Snippet11"::: - :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/interceptor2.cs" id="Snippet11"::: - :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/interceptor2.fs" id="Snippet11"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format/vb/interceptor2.vb" id="Snippet11"::: - - -## String.Format Q & A - -### Why do you recommend string interpolation over calls to the `String.Format` method? - -String interpolation is: - -- More flexible. It can be used in any string without requiring a call to a method that supports composite formatting. Otherwise, you have to call the method or another method that supports composite formatting, such as or . - -- More readable. Because the expression to insert into a string appears in the interpolated expression rather than in a argument list, interpolated strings are far easier to code and to read. Because of their greater readability, interpolated strings can replace not only calls to composite format methods, but they can also be used in string concatenation operations to produce more concise, clearer code. - -A comparison of the following two code examples illustrates the superiority of interpolated strings over string concatenation and calls to composite formatting methods. The use of multiple string concatenation operations in the following example produces verbose and hard-to-read code. - -:::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/qa-interpolated1.cs" id="SnippetQAInterpolated"::: -:::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/qa-interpolated1.fs" id="SnippetQAInterpolated"::: -:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format/vb/qa-interpolated1.vb"::: - -In contrast, the use of interpolated strings in the following example produce much clearer, more concise code than the string concatenation statement and the call to the method in the previous example. - -:::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/qa-interpolated2.cs" id="SnippetQAInterpolated2"::: -:::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/qa-interpolated2.fs" id="SnippetQAInterpolated2"::: -:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format/vb/qa-interpolated2.vb"::: - -### Where can I find a list of the predefined format strings that can be used with format items? - -- For all integral and floating-point types, see [Standard Numeric Format Strings](/dotnet/standard/base-types/standard-numeric-format-strings) and [Custom Numeric Format Strings](/dotnet/standard/base-types/custom-numeric-format-strings). - -- For date and time values, see [Standard Date and Time Format Strings](/dotnet/standard/base-types/standard-date-and-time-format-strings) and [Custom Date and Time Format Strings](/dotnet/standard/base-types/custom-date-and-time-format-strings). - -- For enumeration values, see [Enumeration Format Strings](/dotnet/standard/base-types/enumeration-format-strings). - -- For values, see [Standard TimeSpan Format Strings](/dotnet/standard/base-types/standard-timespan-format-strings) and [Custom TimeSpan Format Strings](/dotnet/standard/base-types/custom-timespan-format-strings). - -- For values, see the Remarks section of the reference page. - -### How do I control the alignment of the result strings that replace format items? - The general syntax of a format item is: - -``` -{index[,alignment][: formatString]} -``` - - where *alignment* is a signed integer that defines the field width. If this value is negative, text in the field is left-aligned. If it is positive, text is right-aligned. - -### How do I control the number of digits after the decimal separator? - All [standard numeric format strings](/dotnet/standard/base-types/standard-numeric-format-strings) except "D" (which is used with integers only), "G", "R", and "X" allow a precision specifier that defines the number of decimal digits in the result string. The following example uses standard numeric format strings to control the number of decimal digits in the result string. - - :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/qa26.cs" id="Snippet26"::: - :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/qa26.fs" id="Snippet26"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format/vb/qa26.vb" id="Snippet26"::: - - If you're using a [custom numeric format string](/dotnet/standard/base-types/custom-numeric-format-strings), use the "0" format specifier to control the number of decimal digits in the result string, as the following example shows. - - :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/qa27.cs" interactive="try-dotnet-method" id="Snippet27"::: - :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/qa27.fs" id="Snippet27"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format/vb/qa27.vb" id="Snippet27"::: - -### How do I control the number of integral digits? - By default, formatting operations only display non-zero integral digits. If you are formatting integers, you can use a precision specifier with the "D" and "X" standard format strings to control the number of digits. - - :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/qa29.cs" interactive="try-dotnet-method" id="Snippet29"::: - :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/qa29.fs" id="Snippet29"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format/vb/qa29.vb" id="Snippet29"::: - - You can pad an integer or floating-point number with leading zeros to produce a result string with a specified number of integral digits by using the "0" [custom numeric format specifier](/dotnet/standard/base-types/custom-numeric-format-strings), as the following example shows. - - :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/qa28.cs" interactive="try-dotnet-method" id="Snippet28"::: - :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/qa28.fs" id="Snippet28"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format/vb/qa28.vb" id="Snippet28"::: - -### How many items can I include in the format list? - There is no practical limit. The second parameter of the method is tagged with the attribute, which allows you to include either a delimited list or an object array as your format list. - - -### How do I include literal braces ("{" and "}") in the result string? - For example, how do you prevent the following method call from throwing a exception? - - :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/qa3.cs" id="Snippet23"::: - :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/qa3.fs" id="Snippet23"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format/vb/qa3.vb" id="Snippet23"::: - - A single opening or closing brace is always interpreted as the beginning or end of a format item. To be interpreted literally, it must be escaped. You escape a brace by adding another brace ("{{" and "}}" instead of "{" and "}"), as in the following method call: - - :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/qa3.cs" interactive="try-dotnet-method" id="Snippet24"::: - :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/qa3.fs" id="Snippet24"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format/vb/qa3.vb" id="Snippet24"::: - - However, even escaped braces are easily misinterpreted. We recommend that you include braces in the format list and use format items to insert them in the result string, as the following example shows. - - :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/qa3.cs" interactive="try-dotnet-method" id="Snippet25"::: - :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/qa3.fs" id="Snippet25"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format/vb/qa3.vb" id="Snippet25"::: - -### Why does my call to the String.Format method throw a FormatException? - The most common cause of the exception is that the index of a format item doesn't correspond to an object in the format list. Usually this indicates that you've misnumbered the indexes of format items or you've forgotten to include an object in the format list. Attempting to include an unescaped left or right brace character also throws a . Occasionally, the exception is the result of a typo; for example, a typical mistake is to mistype "[" (the left bracket) instead of "{" (the left brace). - -### If the Format(System.IFormatProvider,System.String,System.Object[]) method supports parameter arrays, why does my code throw an exception when I use an array? - For example, the following code throws a exception: - - :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/qa11.cs" id="Snippet21"::: - :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/qa11.fs" id="Snippet21"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format/vb/qa1.vb" id="Snippet21"::: - - This is a problem of compiler overload resolution. Because the compiler cannot convert an array of integers to an object array, it treats the integer array as a single argument, so it calls the method. The exception is thrown because there are four format items but only a single item in the format list. - - Because neither Visual Basic nor C# can convert an integer array to an object array, you have to perform the conversion yourself before calling the method. The following example provides one implementation. - - :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/qa21.cs" interactive="try-dotnet-method" id="Snippet22"::: - :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/qa21.fs" id="Snippet22"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format/vb/qa2.vb" id="Snippet22"::: - -## Examples - -Numerous examples that call the method are interspersed through the [Remarks](#remarks-top) section of this article. - -You can also download a complete set of `String.Format` examples, which are included a [.NET Core project for C#](https://docs.microsoft.com/samples/dotnet/samples/string-format/). - -The following are some of the examples included in the article: - -### Create a format string - -[Inserting a string](#insert-a-string)\ -[The format item](#the-format-item)\ -[Format items that have the same index](#format-items-that-have-the-same-index) - -### Control formatted output - -[Controlling formatting](#control-formatting)\ -[Controlling spacing](#control-spacing)\ -[Controlling alignment](#control-alignment)\ -[Controlling the number of integral digits](#how-do-i-control-the-number-of-integral-digits)\ -[Controlling the number of digits after the decimal separator](#how-do-i-control-the-number-of-digits-after-the-decimal-separator)\ -[Including literal braces in a result string](#braces) - -### Make format strings culture-sensitive - -[Culture-sensitive formatting](#culture-sensitive-formatting) - -### Customize the formatting operation - -[A custom formatting operation](#example-a-custom-formatting-operation)\ -[An intercept provider and Roman numeral formatter](#example-an-intercept-provider-and-roman-numeral-formatter) - + +## Remarks + +[!INCLUDE[interpolated-strings](~/includes/interpolated-strings.md)] + + In this section: + + [Get started with the String.Format method](#Starting)\ + [Which method do I call?](#FTaskList)\ + [The Format method in brief](#Format_Brief)\ + [The Format item](#FormatItem)\ + [How arguments are formatted](#HowFormatted)\ + [Format items that have the same index](#SameIndex)\ + [Formatting and culture](#Format_Culture)\ + [Custom formatting operations](#Format_Custom)\ + [String.Format Q & A](#QA) + + +## Get started with the String.Format method + Use if you need to insert the value of an object, variable, or expression into another string. For example, you can insert the value of a value into a string to display it to the user as a single string: + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Format/cpp/starting2.cpp" id="Snippet35"::: + :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/starting2.cs" interactive="try-dotnet-method" id="Snippet35"::: + :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/starting2.fs" id="Snippet35"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format/vb/starting2.vb" id="Snippet35"::: + + And you can control that value's formatting: + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Format/cpp/starting2.cpp" id="Snippet36"::: + :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/starting2.cs" id="Snippet36"::: + :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/starting2.fs" id="Snippet36"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format/vb/starting2.vb" id="Snippet36"::: + + Besides formatting, you can also control alignment and spacing. + + ### Insert a string + + starts with a format string, followed by one or more objects or expressions that will be converted to strings and inserted at a specified place in the format string. For example: + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Format/cpp/starting1.cpp" id="Snippet30"::: + :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/starting1.cs" interactive="try-dotnet-method" id="Snippet30"::: + :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/starting1.fs" id="Snippet30"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format/vb/starting1.vb" id="Snippet30"::: + + The `{0}` in the format string is a format item. `0` is the index of the object whose string value will be inserted at that position. (Indexes start at 0.) If the object to be inserted is not a string, its `ToString` method is called to convert it to one before inserting it in the result string. + + Here's another example that uses two format items and two objects in the object list: + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Format/cpp/starting1.cpp" id="Snippet31"::: + :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/starting1.cs" id="Snippet31"::: + :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/starting1.fs" id="Snippet31"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format/vb/starting1.vb" id="Snippet31"::: + + You can have as many format items and as many objects in the object list as you want, as long as the index of every format item has a matching object in the object list. You also don't have to worry about which overload you call; the compiler will select the appropriate one for you. + + ### Control formatting + You can follow the index in a format item with a format string to control how an object is formatted. For example, `{0:d}` applies the "d" format string to the first object in the object list. Here is an example with a single object and two format items: + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Format/cpp/starting1.cpp" id="Snippet32"::: + :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/starting1.cs" id="Snippet32"::: + :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/starting1.fs" id="Snippet32"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format/vb/starting1.vb" id="Snippet32"::: + + A number of types support format strings, including all numeric types (both [standard](/dotnet/standard/base-types/standard-numeric-format-strings) and [custom](/dotnet/standard/base-types/custom-numeric-format-strings) format strings), all dates and times (both [standard](/dotnet/standard/base-types/standard-date-and-time-format-strings) and [custom](/dotnet/standard/base-types/custom-date-and-time-format-strings) format strings) and time intervals (both [standard](/dotnet/standard/base-types/standard-timespan-format-strings) and [custom](/dotnet/standard/base-types/custom-timespan-format-strings) format strings), all enumeration types [enumeration types](/dotnet/standard/base-types/enumeration-format-strings), and [GUIDs](xref:System.Guid.ToString(System.String)). You can also add support for format strings to your own types. + + ### Control spacing + You can define the width of the string that is inserted into the result string by using syntax such as `{0,12}`, which inserts a 12-character string. In this case, the string representation of the first object is right-aligned in the 12-character field. (If the string representation of the first object is more than 12 characters in length, though, the preferred field width is ignored, and the entire string is inserted into the result string.) + + The following example defines a 6-character field to hold the string "Year" and some year strings, as well as an 15-character field to hold the string "Population" and some population data. Note that the characters are right-aligned in the field. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Format/cpp/starting1.cpp" id="Snippet33"::: + :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/starting3.cs" id="Snippet33"::: + :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/starting3.fs" id="Snippet33"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format/vb/starting1.vb" id="Snippet33"::: + + ### Control alignment + By default, strings are right-aligned within their field if you specify a field width. To left-align strings in a field, you preface the field width with a negative sign, such as `{0,-12}` to define a 12-character left-aligned field. + + The following example is similar to the previous one, except that it left-aligns both labels and data. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Format/cpp/starting1.cpp" id="Snippet34"::: + :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/starting1.cs" id="Snippet34"::: + :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/starting1.fs" id="Snippet34"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format/vb/starting1.vb" id="Snippet34"::: + + makes use of the composite formatting feature. For more information, see [Composite Formatting](/dotnet/standard/base-types/composite-formatting). + + +## Which method do I call? + +|To|Call| +|--------|----------| +|Format one or more objects by using the conventions of the current culture.|Except for the overloads that include a `provider` parameter, the remaining overloads include a parameter followed by one or more object parameters. Because of this, you don't have to determine which overload you intend to call. Your language compiler selects the appropriate overload from among the overloads that don't have a `provider` parameter, based on your argument list. For example, if your argument list has five arguments, the compiler calls the method.| +|Format one or more objects by using the conventions of a specific culture.|Each overload that begins with a `provider` parameter is followed by a parameter and one or more object parameters. Because of this, you don't have to determine which specific overload you intend to call. Your language compiler selects the appropriate overload from among the overloads that have a `provider` parameter, based on your argument list. For example, if your argument list has five arguments, the compiler calls the method.| +|Perform a custom formatting operation either with an implementation or an implementation.|Any of the four overloads with a `provider` parameter. The compiler selects the appropriate overload from among the overloads that have a `provider` parameter, based on your argument list.| + + +## The Format method in brief + + Each overload of the method uses the [composite formatting feature](/dotnet/standard/base-types/composite-formatting) to include zero-based indexed placeholders, called *format items*, in a composite format string. At run time, each format item is replaced with the string representation of the corresponding argument in a parameter list. If the value of the argument is `null`, the format item is replaced with . For example, the following call to the method includes a format string with three format items, {0}, {1}, and {2}, and an argument list with three items. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Format/cpp/formatoverload1.cpp" id="Snippet8"::: + :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/formatoverload1.cs" id="Snippet8"::: + :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/formatoverload1.fs" id="Snippet8"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format/vb/formatoverload1.vb" id="Snippet8"::: + + +## The format item + A format item has this syntax: + +``` +{index[,alignment][:formatString]} +``` + + Brackets denote optional elements. The opening and closing braces are required. (To include a literal opening or closing brace in the format string, see the [Escaping Braces](/dotnet/standard/base-types/composite-formatting#escaping-braces) section in the [Composite Formatting](/dotnet/standard/base-types/composite-formatting) article.) + + For example, a format item to format a currency value might appear like this: + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Format/cpp/formatsyntax1.cpp" id="Snippet12"::: + :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/formatsyntax1.cs" id="Snippet12"::: + :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/formatsyntax1.fs" id="Snippet12"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format/vb/formatsyntax1.vb" id="Snippet12"::: + + A format item has the following elements: + + *index*\ + The zero-based index of the argument whose string representation is to be included at this position in the string. If this argument is `null`, an empty string will be included at this position in the string. + + *alignment*\ + Optional. A signed integer that indicates the total length of the field into which the argument is inserted and whether it is right-aligned (a positive integer) or left-aligned (a negative integer). If you omit *alignment*, the string representation of the corresponding argument is inserted in a field with no leading or trailing spaces. + + If the value of *alignment* is less than the length of the argument to be inserted, *alignment* is ignored and the length of the string representation of the argument is used as the field width. + + *formatString*\ + Optional. A string that specifies the format of the corresponding argument's result string. If you omit *formatString*, the corresponding argument's parameterless `ToString` method is called to produce its string representation. If you specify *formatString*, the argument referenced by the format item must implement the interface. Types that support format strings include: + +- All integral and floating-point types. (See [Standard Numeric Format Strings](/dotnet/standard/base-types/standard-numeric-format-strings) and [Custom Numeric Format Strings](/dotnet/standard/base-types/custom-numeric-format-strings).) + +- and . (See [Standard Date and Time Format Strings](/dotnet/standard/base-types/standard-date-and-time-format-strings) and [Custom Date and Time Format Strings](/dotnet/standard/base-types/custom-date-and-time-format-strings).) + +- All enumeration types. (See [Enumeration Format Strings](/dotnet/standard/base-types/enumeration-format-strings).) + +- values. (See [Standard TimeSpan Format Strings](/dotnet/standard/base-types/standard-timespan-format-strings) and [Custom TimeSpan Format Strings](/dotnet/standard/base-types/custom-timespan-format-strings).) + +- GUIDs. (See the method.) + + However, note that any custom type can implement or extend an existing type's implementation. + + The following example uses the `alignment` and `formatString` arguments to produce formatted output. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Format/cpp/formatoverload2.cpp" id="Snippet9"::: + :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/formatoverload2.cs" interactive="try-dotnet-method" id="Snippet9"::: + :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/formatoverload2.fs" id="Snippet9"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format/vb/formatoverload2.vb" id="Snippet9"::: + + +## How arguments are formatted + Format items are processed sequentially from the beginning of the string. Each format item has an index that corresponds to an object in the method's argument list. The method retrieves the argument and derives its string representation as follows: + +- If the argument is `null`, the method inserts into the result string. You don't have to be concerned with handling a for null arguments. + +- If you call the overload and the `provider` object's implementation returns a non-null implementation, the argument is passed to its method. If the format item includes a *formatString* argument, it is passed as the first argument to the method. If the implementation is available and produces a non-null string, that string is returned as the string representation of the argument; otherwise, the next step executes. + +- If the argument implements the interface, its implementation is called. + +- The argument's parameterless `ToString` method, which either overrides or inherits from a base class implementation, is called. + + For an example that intercepts calls to the method and allows you to see what information the method passes to a formatting method for each format item in a composite format string, see [Example: An intercept provider and Roman numeral formatter](#Format7_Example). + + For more information, see the [Processing Order](/dotnet/standard/base-types/composite-formatting##processing-order) section in the [Composite Formatting](/dotnet/standard/base-types/composite-formatting) article. + + +## Format items that have the same index + The method throws a exception if the index of an index item is greater than or equal to the number of arguments in the argument list. However, `format` can include more format items than there are arguments, as long as multiple format items have the same index. In the call to the method in following example, the argument list has a single argument, but the format string includes two format items: one displays the decimal value of a number, and the other displays its hexadecimal value. + + :::code language="csharp" source="~/snippets/csharp/System/String/Format/Example1.cs" interactive="try-dotnet-method" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Format/Example1.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format2/vb/Example1.vb" id="Snippet1"::: + + +## Format and culture + Generally, objects in the argument list are converted to their string representations by using the conventions of the current culture, which is returned by the property. You can control this behavior by calling one of the overloads of that includes a `provider` parameter. The `provider` parameter is an implementation that supplies custom and culture-specific formatting information that is used to moderate the formatting process. + + The interface has a single member, , which is responsible for returning the object that provides formatting information. .NET has three implementations that provide culture-specific formatting: + +- . Its method returns a culture-specific object for formatting numeric values and a culture-specific object for formatting date and time values. + +- , which is used for culture-specific formatting of date and time values. Its method returns itself. + +- , which is used for culture-specific formatting of numeric values. Its property returns itself. + + +## Custom formatting operations + You can also call the any of the overloads of the method that have a `provider` parameter of type to perform custom formatting operations. For example, you could format an integer as an identification number or as a telephone number. To perform custom formatting, your `provider` argument must implement both the and interfaces. When the method is passed an implementation as the `provider` argument, the method calls its implementation and requests an object of type . It then calls the returned object's method to format each format item in the composite string passed to it. + + For more information about providing custom formatting solutions, see [How to: Define and Use Custom Numeric Format Providers](/dotnet/standard/base-types/how-to-define-and-use-custom-numeric-format-providers) and . For an example that converts integers to formatted custom numbers, see [Example: A custom formatting operation](#Format6_Example). For an example that converts unsigned bytes to Roman numerals, see [Example: An intercept provider and Roman numeral formatter](#Format7_Example). + + +### Example: A custom formatting operation + This example defines a format provider that formats an integer value as a customer account number in the form x-xxxxx-xx. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Format/cpp/formatexample2.cpp" id="Snippet2"::: + :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/FormatExample2.cs" interactive="try-dotnet" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/FormatExample2.fs" id="Snippet2"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format/vb/FormatExample2.vb" id="Snippet2"::: + + +### Example: An intercept provider and Roman numeral formatter + This example defines a custom format provider that implements the and interfaces to do two things: + +- It displays the parameters passed to its implementation. This enables us to see what parameters the method is passing to the custom formatting implementation for each object that it tries to format. This can be useful when you're debugging your application. + +- If the object to be formatted is an unsigned byte value that is to be formatted by using the "R" standard format string, the custom formatter formats the numeric value as a Roman numeral. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Format/cpp/interceptor2.cpp" id="Snippet11"::: + :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/interceptor2.cs" id="Snippet11"::: + :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/interceptor2.fs" id="Snippet11"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format/vb/interceptor2.vb" id="Snippet11"::: + + +## String.Format Q & A + +### Why do you recommend string interpolation over calls to the `String.Format` method? + +String interpolation is: + +- More flexible. It can be used in any string without requiring a call to a method that supports composite formatting. Otherwise, you have to call the method or another method that supports composite formatting, such as or . + +- More readable. Because the expression to insert into a string appears in the interpolated expression rather than in a argument list, interpolated strings are far easier to code and to read. Because of their greater readability, interpolated strings can replace not only calls to composite format methods, but they can also be used in string concatenation operations to produce more concise, clearer code. + +A comparison of the following two code examples illustrates the superiority of interpolated strings over string concatenation and calls to composite formatting methods. The use of multiple string concatenation operations in the following example produces verbose and hard-to-read code. + +:::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/qa-interpolated1.cs" id="SnippetQAInterpolated"::: +:::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/qa-interpolated1.fs" id="SnippetQAInterpolated"::: +:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format/vb/qa-interpolated1.vb"::: + +In contrast, the use of interpolated strings in the following example produce much clearer, more concise code than the string concatenation statement and the call to the method in the previous example. + +:::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/qa-interpolated2.cs" id="SnippetQAInterpolated2"::: +:::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/qa-interpolated2.fs" id="SnippetQAInterpolated2"::: +:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format/vb/qa-interpolated2.vb"::: + +### Where can I find a list of the predefined format strings that can be used with format items? + +- For all integral and floating-point types, see [Standard Numeric Format Strings](/dotnet/standard/base-types/standard-numeric-format-strings) and [Custom Numeric Format Strings](/dotnet/standard/base-types/custom-numeric-format-strings). + +- For date and time values, see [Standard Date and Time Format Strings](/dotnet/standard/base-types/standard-date-and-time-format-strings) and [Custom Date and Time Format Strings](/dotnet/standard/base-types/custom-date-and-time-format-strings). + +- For enumeration values, see [Enumeration Format Strings](/dotnet/standard/base-types/enumeration-format-strings). + +- For values, see [Standard TimeSpan Format Strings](/dotnet/standard/base-types/standard-timespan-format-strings) and [Custom TimeSpan Format Strings](/dotnet/standard/base-types/custom-timespan-format-strings). + +- For values, see the Remarks section of the reference page. + +### How do I control the alignment of the result strings that replace format items? + The general syntax of a format item is: + +``` +{index[,alignment][: formatString]} +``` + + where *alignment* is a signed integer that defines the field width. If this value is negative, text in the field is left-aligned. If it is positive, text is right-aligned. + +### How do I control the number of digits after the decimal separator? + All [standard numeric format strings](/dotnet/standard/base-types/standard-numeric-format-strings) except "D" (which is used with integers only), "G", "R", and "X" allow a precision specifier that defines the number of decimal digits in the result string. The following example uses standard numeric format strings to control the number of decimal digits in the result string. + + :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/qa26.cs" id="Snippet26"::: + :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/qa26.fs" id="Snippet26"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format/vb/qa26.vb" id="Snippet26"::: + + If you're using a [custom numeric format string](/dotnet/standard/base-types/custom-numeric-format-strings), use the "0" format specifier to control the number of decimal digits in the result string, as the following example shows. + + :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/qa27.cs" interactive="try-dotnet-method" id="Snippet27"::: + :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/qa27.fs" id="Snippet27"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format/vb/qa27.vb" id="Snippet27"::: + +### How do I control the number of integral digits? + By default, formatting operations only display non-zero integral digits. If you are formatting integers, you can use a precision specifier with the "D" and "X" standard format strings to control the number of digits. + + :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/qa29.cs" interactive="try-dotnet-method" id="Snippet29"::: + :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/qa29.fs" id="Snippet29"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format/vb/qa29.vb" id="Snippet29"::: + + You can pad an integer or floating-point number with leading zeros to produce a result string with a specified number of integral digits by using the "0" [custom numeric format specifier](/dotnet/standard/base-types/custom-numeric-format-strings), as the following example shows. + + :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/qa28.cs" interactive="try-dotnet-method" id="Snippet28"::: + :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/qa28.fs" id="Snippet28"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format/vb/qa28.vb" id="Snippet28"::: + +### How many items can I include in the format list? + There is no practical limit. The second parameter of the method is tagged with the attribute, which allows you to include either a delimited list or an object array as your format list. + + +### How do I include literal braces ("{" and "}") in the result string? + For example, how do you prevent the following method call from throwing a exception? + + :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/qa3.cs" id="Snippet23"::: + :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/qa3.fs" id="Snippet23"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format/vb/qa3.vb" id="Snippet23"::: + + A single opening or closing brace is always interpreted as the beginning or end of a format item. To be interpreted literally, it must be escaped. You escape a brace by adding another brace ("{{" and "}}" instead of "{" and "}"), as in the following method call: + + :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/qa3.cs" interactive="try-dotnet-method" id="Snippet24"::: + :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/qa3.fs" id="Snippet24"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format/vb/qa3.vb" id="Snippet24"::: + + However, even escaped braces are easily misinterpreted. We recommend that you include braces in the format list and use format items to insert them in the result string, as the following example shows. + + :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/qa3.cs" interactive="try-dotnet-method" id="Snippet25"::: + :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/qa3.fs" id="Snippet25"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format/vb/qa3.vb" id="Snippet25"::: + +### Why does my call to the String.Format method throw a FormatException? + The most common cause of the exception is that the index of a format item doesn't correspond to an object in the format list. Usually this indicates that you've misnumbered the indexes of format items or you've forgotten to include an object in the format list. Attempting to include an unescaped left or right brace character also throws a . Occasionally, the exception is the result of a typo; for example, a typical mistake is to mistype "[" (the left bracket) instead of "{" (the left brace). + +### If the Format(System.IFormatProvider,System.String,System.Object[]) method supports parameter arrays, why does my code throw an exception when I use an array? + For example, the following code throws a exception: + + :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/qa11.cs" id="Snippet21"::: + :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/qa11.fs" id="Snippet21"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format/vb/qa1.vb" id="Snippet21"::: + + This is a problem of compiler overload resolution. Because the compiler cannot convert an array of integers to an object array, it treats the integer array as a single argument, so it calls the method. The exception is thrown because there are four format items but only a single item in the format list. + + Because neither Visual Basic nor C# can convert an integer array to an object array, you have to perform the conversion yourself before calling the method. The following example provides one implementation. + + :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/qa21.cs" interactive="try-dotnet-method" id="Snippet22"::: + :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/qa21.fs" id="Snippet22"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format/vb/qa2.vb" id="Snippet22"::: + +## Examples + +Numerous examples that call the method are interspersed through the [Remarks](#remarks-top) section of this article. + +You can also download a complete set of `String.Format` examples, which are included a [.NET Core project for C#](https://docs.microsoft.com/samples/dotnet/samples/string-format/). + +The following are some of the examples included in the article: + +### Create a format string + +[Inserting a string](#insert-a-string)\ +[The format item](#the-format-item)\ +[Format items that have the same index](#format-items-that-have-the-same-index) + +### Control formatted output + +[Controlling formatting](#control-formatting)\ +[Controlling spacing](#control-spacing)\ +[Controlling alignment](#control-alignment)\ +[Controlling the number of integral digits](#how-do-i-control-the-number-of-integral-digits)\ +[Controlling the number of digits after the decimal separator](#how-do-i-control-the-number-of-digits-after-the-decimal-separator)\ +[Including literal braces in a result string](#braces) + +### Make format strings culture-sensitive + +[Culture-sensitive formatting](#culture-sensitive-formatting) + +### Customize the formatting operation + +[A custom formatting operation](#example-a-custom-formatting-operation)\ +[An intercept provider and Roman numeral formatter](#example-an-intercept-provider-and-roman-numeral-formatter) + ]]> Formatting Types in .NET @@ -6364,34 +6460,34 @@ The following are some of the examples included in the article: Replaces one or more format items in a string with the string representation of a specified object. A copy of in which any format items are replaced by the string representation of . - method to embed an individual's age in the middle of a string. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Format/cpp/format7.cpp" id="Snippet7"::: - :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/format7.cs" interactive="try-dotnet-method" id="Snippet7"::: - :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/format7.fs" id="Snippet7"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format/vb/format7.vb" id="Snippet7"::: - + method to embed an individual's age in the middle of a string. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Format/cpp/format7.cpp" id="Snippet7"::: + :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/format7.cs" interactive="try-dotnet-method" id="Snippet7"::: + :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/format7.fs" id="Snippet7"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format/vb/format7.vb" id="Snippet7"::: + ]]> is . - The format item in is invalid. - - -or- - - The index of a format item is not zero. + The format item in is invalid. + +-or- + +The index of a format item is not zero. Formatting Types in .NET Composite Formatting Standard Date and Time Format Strings @@ -6469,42 +6565,42 @@ This method uses the [composite formatting feature](/dotnet/standard/base-types/ Replaces the format item in a specified string with the string representation of a corresponding object in a specified array. A copy of in which the format items have been replaced by the string representation of the corresponding objects in . - attribute, you can pass the objects to the method as individual arguments or as an array. - -[!INCLUDE[simple-string-format](~/includes/simple-string-format.md)] - -## Example: Format more than three arguments - - This example creates a string that contains data on the high and low temperature on a particular date. The composite format string has five format items in the C# example and six in the Visual Basic example. Two of the format items define the width of their corresponding value's string representation, and the first format item also includes a standard date and time format string. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Format/cpp/format5.cpp" id="Snippet5"::: - :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/format5.cs" id="Snippet5"::: - :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/format5.fs" id="Snippet5"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format/vb/format5.vb" id="Snippet5"::: - - You can also pass the objects to be formatted as an array rather than as an argument list. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Format/cpp/format_paramarray1.cpp" id="Snippet10"::: - :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/format_paramarray1.cs" interactive="try-dotnet" id="Snippet10"::: - :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/format_paramarray1.fs" id="Snippet10"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format/vb/format_paramarray1.vb" id="Snippet10"::: - + attribute, you can pass the objects to the method as individual arguments or as an array. + +[!INCLUDE[simple-string-format](~/includes/simple-string-format.md)] + +## Example: Format more than three arguments + + This example creates a string that contains data on the high and low temperature on a particular date. The composite format string has five format items in the C# example and six in the Visual Basic example. Two of the format items define the width of their corresponding value's string representation, and the first format item also includes a standard date and time format string. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Format/cpp/format5.cpp" id="Snippet5"::: + :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/format5.cs" id="Snippet5"::: + :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/format5.fs" id="Snippet5"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format/vb/format5.vb" id="Snippet5"::: + + You can also pass the objects to be formatted as an array rather than as an argument list. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Format/cpp/format_paramarray1.cpp" id="Snippet10"::: + :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/format_paramarray1.cs" interactive="try-dotnet" id="Snippet10"::: + :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/format_paramarray1.fs" id="Snippet10"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format/vb/format_paramarray1.vb" id="Snippet10"::: + ]]> or is . - is invalid. - - -or- - - The index of a format item is less than zero, or greater than or equal to the length of the array. + is invalid. + +-or- + +The index of a format item is less than zero, or greater than or equal to the length of the array. Formatting Types in .NET Composite Formatting Standard Date and Time Format Strings @@ -6583,26 +6679,26 @@ This method uses the [composite formatting feature](/dotnet/standard/base-types/ Replaces the format item or items in a specified string with the string representation of the corresponding object. A parameter supplies culture-specific formatting information. A copy of in which the format item or items have been replaced by the string representation of . - is . - is invalid. - - -or- - - The index of a format item is not zero. + is invalid. + +-or- + +The index of a format item is not zero. @@ -6686,36 +6782,36 @@ This method uses the [composite formatting feature](/dotnet/standard/base-types/ Replaces the format items in a string with the string representations of corresponding objects in a specified array. A parameter supplies culture-specific formatting information. A copy of in which the format items have been replaced by the string representation of the corresponding objects in . - argument to its string representation by calling its **ToString(IFormatProvider)** method or, if the object's corresponding format item includes a format string, by calling its **ToString(String,IFormatProvider)** method. If these methods don't exist, it calls the object's parameterless **ToString** method. - -[!INCLUDE[provider-string-format](~/includes/provider-string-format.md)] - - - -### Example: Culture-sensitive formatting - - This example uses the method to display the string representation of some date and time values and numeric values by using several different cultures. - - :::code language="csharp" source="~/snippets/csharp/System/String/Format/Example2.cs" interactive="try-dotnet-method" id="Snippet2"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Format/Example2.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format2/vb/Example2.vb" id="Snippet2"::: - + argument to its string representation by calling its **ToString(IFormatProvider)** method or, if the object's corresponding format item includes a format string, by calling its **ToString(String,IFormatProvider)** method. If these methods don't exist, it calls the object's parameterless **ToString** method. + +[!INCLUDE[provider-string-format](~/includes/provider-string-format.md)] + + + +### Example: Culture-sensitive formatting + + This example uses the method to display the string representation of some date and time values and numeric values by using several different cultures. + + :::code language="csharp" source="~/snippets/csharp/System/String/Format/Example2.cs" interactive="try-dotnet-method" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Format/Example2.fs" id="Snippet2"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format2/vb/Example2.vb" id="Snippet2"::: + ]]> or is . - is invalid. - - -or- - - The index of a format item is less than zero, or greater than or equal to the length of the array. + is invalid. + +-or- + +The index of a format item is less than zero, or greater than or equal to the length of the array. @@ -6908,35 +7004,35 @@ This method uses the [composite formatting feature](/dotnet/standard/base-types/ Replaces the format items in a string with the string representation of two specified objects. A copy of in which format items are replaced by the string representations of and . - method to display time and temperature data stored in a generic object. Note that the format string has three format items, although there are only two objects to format. This is because the first object in the list (a date and time value) is used by two format items: The first format item displays the time, and the second displays the date. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Format/cpp/formatexample4.cpp" id="Snippet6"::: - :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/formatexample4.cs" id="Snippet6"::: - :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/formatexample4.fs" id="Snippet6"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format/vb/formatexample4.vb" id="Snippet6"::: - + method to display time and temperature data stored in a generic object. Note that the format string has three format items, although there are only two objects to format. This is because the first object in the list (a date and time value) is used by two format items: The first format item displays the time, and the second displays the date. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Format/cpp/formatexample4.cpp" id="Snippet6"::: + :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/formatexample4.cs" id="Snippet6"::: + :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/formatexample4.fs" id="Snippet6"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format/vb/formatexample4.vb" id="Snippet6"::: + ]]> is . - is invalid. - - -or- - - The index of a format item is not zero or one. + is invalid. + +-or- + +The index of a format item is not zero or one. Formatting Types in .NET Composite Formatting Standard Date and Time Format Strings @@ -7013,26 +7109,26 @@ This method uses the [composite formatting feature](/dotnet/standard/base-types/ Replaces the format items in a string with the string representation of two specified objects. A parameter supplies culture-specific formatting information. A copy of in which format items are replaced by the string representations of and . - argument to its string representation by calling its **ToString(IFormatProvider)** method or, if the object's corresponding format item includes a format string, by calling its **ToString(String,IFormatProvider)** method. If these methods don't exist, it calls the object's parameterless **ToString** method. - -[!INCLUDE[provider-string-format](~/includes/provider-string-format.md)] - + argument to its string representation by calling its **ToString(IFormatProvider)** method or, if the object's corresponding format item includes a format string, by calling its **ToString(String,IFormatProvider)** method. If these methods don't exist, it calls the object's parameterless **ToString** method. + +[!INCLUDE[provider-string-format](~/includes/provider-string-format.md)] + ]]> is . - is invalid. - - -or- - - The index of a format item is not zero or one. + is invalid. + +-or- + +The index of a format item is not zero or one. @@ -7102,35 +7198,35 @@ This method uses the [composite formatting feature](/dotnet/standard/base-types/ Replaces the format items in a string with the string representation of three specified objects. A copy of in which the format items have been replaced by the string representations of , , and . - method to create a string that illustrates the result of a Boolean `And` operation with two integer values. Note that the format string includes six format items, but the method has only three items in its parameter list, because each item is formatted in two different ways. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Format/cpp/format4.cpp" id="Snippet4"::: - :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/format4.cs" interactive="try-dotnet-method" id="Snippet4"::: - :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/format4.fs" id="Snippet4"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format/vb/format4.vb" id="Snippet4"::: - + method to create a string that illustrates the result of a Boolean `And` operation with two integer values. Note that the format string includes six format items, but the method has only three items in its parameter list, because each item is formatted in two different ways. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Format/cpp/format4.cpp" id="Snippet4"::: + :::code language="csharp" source="~/snippets/csharp/System/FormatException/Overview/format4.cs" interactive="try-dotnet-method" id="Snippet4"::: + :::code language="fsharp" source="~/snippets/fsharp/System/FormatException/Overview/format4.fs" id="Snippet4"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Format/vb/format4.vb" id="Snippet4"::: + ]]> is . - is invalid. - - -or- - - The index of a format item is less than zero, or greater than two. + is invalid. + +-or- + +The index of a format item is less than zero, or greater than two. Formatting Types in .NET Composite Formatting @@ -7202,26 +7298,26 @@ This method uses the [composite formatting feature](/dotnet/standard/base-types/ Replaces the format items in a string with the string representation of three specified objects. An parameter supplies culture-specific formatting information. A copy of in which the format items have been replaced by the string representations of , , and . - argument to its string representation by calling its **ToString(IFormatProvider)** method or, if the object's corresponding format item includes a format string, by calling its **ToString(String,IFormatProvider)** method. If these methods don't exist, it calls the object's parameterless **ToString** method. - -[!INCLUDE[provider-string-format](~/includes/provider-string-format.md)] - + argument to its string representation by calling its **ToString(IFormatProvider)** method or, if the object's corresponding format item includes a format string, by calling its **ToString(String,IFormatProvider)** method. If these methods don't exist, it calls the object's parameterless **ToString** method. + +[!INCLUDE[provider-string-format](~/includes/provider-string-format.md)] + ]]> is . - is invalid. - - -or- - - The index of a format item is less than zero, or greater than two. + is invalid. + +-or- + +The index of a format item is less than zero, or greater than two. @@ -7463,23 +7559,23 @@ This method uses the [composite formatting feature](/dotnet/standard/base-types/ Retrieves an object that can iterate through the individual characters in this string. An enumerator object. - [!TIP] -> Rather than calling the method to retrieve a object that you then use to enumerate a string, you should instead use your language's iteration construct (in C#, in F#, in C++/CLR, and in Visual Basic). [foreach](/dotnet/csharp/language-reference/keywords/foreach-in) in C#, [for..in](/dotnet/fsharp/language-reference/loops-for-in-expression) in F#, [for each](/cpp/dotnet/for-each-in) in C++/CLR, and [For Each](/dotnet/visual-basic/language-reference/statements/for-each-next-statement) in Visual Basic). - - This method enables you to iterate the individual characters in a string. For example, the Visual Basic `For Each`, the F# `for..in` expression, and C# `foreach` statements invoke this method to return a object that can provide read-only access to the characters in this string instance. - -## Examples - The following example iterates the characters in several strings and displays information about their individual characters. It uses the language iteration construct rather than a call to the method. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.GetEnumerator/CPP/getenumerator.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/GetEnumerator/getenumerator.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/GetEnumerator/getenumerator.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.GetEnumerator/VB/getenumerator.vb" id="Snippet1"::: - + [!TIP] +> Rather than calling the method to retrieve a object that you then use to enumerate a string, you should instead use your language's iteration construct (in C#, in F#, in C++/CLR, and in Visual Basic). [foreach](/dotnet/csharp/language-reference/keywords/foreach-in) in C#, [for..in](/dotnet/fsharp/language-reference/loops-for-in-expression) in F#, [for each](/cpp/dotnet/for-each-in) in C++/CLR, and [For Each](/dotnet/visual-basic/language-reference/statements/for-each-next-statement) in Visual Basic). + + This method enables you to iterate the individual characters in a string. For example, the Visual Basic `For Each`, the F# `for..in` expression, and C# `foreach` statements invoke this method to return a object that can provide read-only access to the characters in this string instance. + +## Examples + The following example iterates the characters in several strings and displays information about their individual characters. It uses the language iteration construct rather than a call to the method. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.GetEnumerator/CPP/getenumerator.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/GetEnumerator/getenumerator.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/GetEnumerator/getenumerator.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.GetEnumerator/VB/getenumerator.vb" id="Snippet1"::: + ]]> @@ -7539,66 +7635,66 @@ This method uses the [composite formatting feature](/dotnet/standard/base-types/ Returns the hash code for this string. A 32-bit signed integer hash code. - is dependent on its implementation, which might change from one version of the common language runtime to another. A reason why this might happen is to improve the performance of . - -> [!IMPORTANT] -> If two string objects are equal, the method returns identical values. However, there is not a unique hash code value for each unique string value. Different strings can return the same hash code. -> -> The hash code itself is not guaranteed to be stable. Hash codes for identical strings can differ across .NET implementations, across .NET versions, and across .NET platforms (such as 32-bit and 64-bit) for a single version of .NET. In some cases, they can even differ by application domain. This implies that two subsequent runs of the same program may return different hash codes. -> -> As a result, hash codes should never be used outside of the application domain in which they were created, they should never be used as key fields in a collection, and they should never be persisted. -> -> Finally, don't use the hash code instead of a value returned by a cryptographic hashing function if you need a cryptographically strong hash. For cryptographic hashes, use a class derived from the or class. -> -> For more information about hash codes, see . - - In .NET Framework desktop apps, you can use the [\ element](/dotnet/framework/configure-apps/file-schema/runtime/userandomizedstringhashalgorithm-element) to generate unique hash codes on a per-application domain basis. This can reduce the number of collisions and improve the overall performance of insertions and lookups that use hash tables. The following example shows how to use the [\ element](/dotnet/framework/configure-apps/file-schema/runtime/userandomizedstringhashalgorithm-element). It defines a `DisplayString` class that includes a private string constant, `s`, whose value is "This is a string." It also includes a `ShowStringHashCode` method that displays the string value and its hash code along with the name of the application domain in which the method is executing. - - :::code language="csharp" source="~/snippets/csharp/System/String/GetHashCode/perdomain.cs" id="Snippet2"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/GetHashCode/perdomain.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.GetHashCode/VB/perdomain.vb" id="Snippet2"::: - - When you run the example without supplying a configuration file, it displays output similar to the following. Note that the hash codes for the string are identical in the two application domains. - -``` -String 'This is a string.' in domain 'PerDomain.exe': 941BCEAC -String 'This is a string.' in domain 'NewDomain': 941BCEAC -``` - - However, if you add the following configuration file to the example's directory and then run the example, the hash codes for the same string will differ by application domain. - -```xml - - - - - - -``` - - When the configuration file is present, the example displays the following output: - -``` -String 'This is a string.' in domain 'PerDomain.exe': 5435776D -String 'This is a string.' in domain 'NewDomain': 75CC8236 -``` - -> [!IMPORTANT] -> Hash codes are used to insert and retrieve keyed objects from hash tables efficiently. However, hash codes don't uniquely identify strings. Identical strings have equal hash codes, but the common language runtime can also assign the same hash code to different strings. In addition, hash codes can vary by version of .NET, by platform within a single version, and by application domain. Because of this, you should not serialize or persist hash code values, nor should you use them as keys in a hash table or dictionary. - - For additional information about the use of hash codes and the `GetHashCode` method, see . - -## Examples - The following example demonstrates the method using various input strings. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.GetHashCode/CPP/gethashcode.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/GetHashCode/gethashcode.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/GetHashCode/gethashcode.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.GetHashCode/VB/gethashcode.vb" id="Snippet1"::: - + is dependent on its implementation, which might change from one version of the common language runtime to another. A reason why this might happen is to improve the performance of . + +> [!IMPORTANT] +> If two string objects are equal, the method returns identical values. However, there is not a unique hash code value for each unique string value. Different strings can return the same hash code. +> +> The hash code itself is not guaranteed to be stable. Hash codes for identical strings can differ across .NET implementations, across .NET versions, and across .NET platforms (such as 32-bit and 64-bit) for a single version of .NET. In some cases, they can even differ by application domain. This implies that two subsequent runs of the same program may return different hash codes. +> +> As a result, hash codes should never be used outside of the application domain in which they were created, they should never be used as key fields in a collection, and they should never be persisted. +> +> Finally, don't use the hash code instead of a value returned by a cryptographic hashing function if you need a cryptographically strong hash. For cryptographic hashes, use a class derived from the or class. +> +> For more information about hash codes, see . + + In .NET Framework desktop apps, you can use the [\ element](/dotnet/framework/configure-apps/file-schema/runtime/userandomizedstringhashalgorithm-element) to generate unique hash codes on a per-application domain basis. This can reduce the number of collisions and improve the overall performance of insertions and lookups that use hash tables. The following example shows how to use the [\ element](/dotnet/framework/configure-apps/file-schema/runtime/userandomizedstringhashalgorithm-element). It defines a `DisplayString` class that includes a private string constant, `s`, whose value is "This is a string." It also includes a `ShowStringHashCode` method that displays the string value and its hash code along with the name of the application domain in which the method is executing. + + :::code language="csharp" source="~/snippets/csharp/System/String/GetHashCode/perdomain.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/GetHashCode/perdomain.fs" id="Snippet2"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.GetHashCode/VB/perdomain.vb" id="Snippet2"::: + + When you run the example without supplying a configuration file, it displays output similar to the following. Note that the hash codes for the string are identical in the two application domains. + +``` +String 'This is a string.' in domain 'PerDomain.exe': 941BCEAC +String 'This is a string.' in domain 'NewDomain': 941BCEAC +``` + + However, if you add the following configuration file to the example's directory and then run the example, the hash codes for the same string will differ by application domain. + +```xml + + + + + + +``` + + When the configuration file is present, the example displays the following output: + +``` +String 'This is a string.' in domain 'PerDomain.exe': 5435776D +String 'This is a string.' in domain 'NewDomain': 75CC8236 +``` + +> [!IMPORTANT] +> Hash codes are used to insert and retrieve keyed objects from hash tables efficiently. However, hash codes don't uniquely identify strings. Identical strings have equal hash codes, but the common language runtime can also assign the same hash code to different strings. In addition, hash codes can vary by version of .NET, by platform within a single version, and by application domain. Because of this, you should not serialize or persist hash code values, nor should you use them as keys in a hash table or dictionary. + + For additional information about the use of hash codes and the `GetHashCode` method, see . + +## Examples + The following example demonstrates the method using various input strings. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.GetHashCode/CPP/gethashcode.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/GetHashCode/gethashcode.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/GetHashCode/gethashcode.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.GetHashCode/VB/gethashcode.vb" id="Snippet1"::: + ]]> @@ -7772,17 +7868,17 @@ String 'This is a string.' in domain 'NewDomain': 75CC8236 - Returns a reference to the element of the string at index zero. - -This method is intended to support .NET compilers and is not intended to be called by user code. + Returns a reference to the element of the string at index zero. + + This method is intended to support .NET compilers and is not intended to be called by user code. A reference to the first character in the string, or a reference to the string's null terminator if the string is empty. - in memory. It is required to support the use of a within a fixed statement. - + in memory. It is required to support the use of a within a fixed statement. + ]]> The string is null. @@ -7835,16 +7931,16 @@ The `GetPinnableReference` method returns a character that can be used for pinni Returns the for the class. The enumerated constant, . - enumerated constant for the type. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.gettypecode/CPP/gtc.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/GetTypeCode/gtc.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/GetTypeCode/gtc.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.gettypecode/VB/gtc.vb" id="Snippet1"::: - + enumerated constant for the type. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.gettypecode/CPP/gtc.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/GetTypeCode/gtc.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/GetTypeCode/gtc.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.gettypecode/VB/gtc.vb" id="Snippet1"::: + ]]> @@ -7913,21 +8009,21 @@ The `GetPinnableReference` method returns a character that can be used for pinni Reports the zero-based index of the first occurrence of the specified Unicode character in this string. The zero-based index position of if that character is found, or -1 if it is not. - method, where a Unicode scalar value representing a precomposed character, such as the ligature "Æ" (U+00C6), might be considered equivalent to any occurrence of the character's components in the correct sequence, such as "AE" (U+0041, U+0045), depending on the culture. - -## Examples - The following example demonstrates how you can search a for a character using the method. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.IndexOf/CPP/indexof_c.cpp" id="Snippet5"::: - :::code language="csharp" source="~/snippets/csharp/System/String/IndexOf/indexof_c.cs" interactive="try-dotnet-method" id="Snippet5"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/IndexOf/indexof_c.fs" id="Snippet5"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.IndexOf/VB/indexof_c.vb" id="Snippet5"::: - + method, where a Unicode scalar value representing a precomposed character, such as the ligature "Æ" (U+00C6), might be considered equivalent to any occurrence of the character's components in the correct sequence, such as "AE" (U+0041, U+0045), depending on the culture. + +## Examples + The following example demonstrates how you can search a for a character using the method. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.IndexOf/CPP/indexof_c.cpp" id="Snippet5"::: + :::code language="csharp" source="~/snippets/csharp/System/String/IndexOf/indexof_c.cs" interactive="try-dotnet-method" id="Snippet5"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/IndexOf/indexof_c.fs" id="Snippet5"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.IndexOf/VB/indexof_c.vb" id="Snippet5"::: + ]]> @@ -7981,34 +8077,34 @@ The `GetPinnableReference` method returns a character that can be used for pinni Reports the zero-based index of the first occurrence of the specified string in this instance. The zero-based index position of if that string is found, or -1 if it is not. If is , the return value is 0. - method always returns 0 (zero) to indicate that the match is found at the beginning of the current instance. In the following example, the method is used to find three substrings (a soft hyphen (U+00AD), a soft hyphen followed by "n", and a soft hyphen followed by "m") in two strings. Only one of the strings contains a soft hyphen. If the example is run on the .NET Framework 4 or later, in each case, because the soft hyphen is an ignorable character, the result is the same as if the soft hyphen had not been included in `value`. When searching for a soft hyphen only, the method returns 0 (zero) to indicate that it has found a match at the beginning of the string. - - :::code language="csharp" source="~/snippets/csharp/System/String/IndexOf/ignorable21.cs" id="Snippet21"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/IndexOf/ignorable21.fs" id="Snippet21"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.IndexOf/VB/ignorable21.vb" id="Snippet21"::: - -## Examples - The following example searches for the "n" in "animal". Because string indexes begin at zero rather than one, the method indicates that the "n" is at position 1. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.IndexOf/CPP/simple1.cpp" id="Snippet12"::: - :::code language="csharp" source="~/snippets/csharp/System/String/IndexOf/simple1.cs" interactive="try-dotnet-method" id="Snippet12"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/IndexOf/simple1.fs" id="Snippet12"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.IndexOf/VB/simple1.vb" id="Snippet12"::: - - The following example uses the method to determine the starting position of an animal name in a sentence. It then uses this position to insert an adjective that describes the animal into the sentence. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/stringinsert/CPP/stringinsert.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/IndexOf/stringinsert.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/IndexOf/stringinsert.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/stringinsert/VB/stringinsert.vb" id="Snippet1"::: - + method always returns 0 (zero) to indicate that the match is found at the beginning of the current instance. In the following example, the method is used to find three substrings (a soft hyphen (U+00AD), a soft hyphen followed by "n", and a soft hyphen followed by "m") in two strings. Only one of the strings contains a soft hyphen. If the example is run on the .NET Framework 4 or later, in each case, because the soft hyphen is an ignorable character, the result is the same as if the soft hyphen had not been included in `value`. When searching for a soft hyphen only, the method returns 0 (zero) to indicate that it has found a match at the beginning of the string. + + :::code language="csharp" source="~/snippets/csharp/System/String/IndexOf/ignorable21.cs" id="Snippet21"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/IndexOf/ignorable21.fs" id="Snippet21"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.IndexOf/VB/ignorable21.vb" id="Snippet21"::: + +## Examples + The following example searches for the "n" in "animal". Because string indexes begin at zero rather than one, the method indicates that the "n" is at position 1. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.IndexOf/CPP/simple1.cpp" id="Snippet12"::: + :::code language="csharp" source="~/snippets/csharp/System/String/IndexOf/simple1.cs" interactive="try-dotnet-method" id="Snippet12"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/IndexOf/simple1.fs" id="Snippet12"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.IndexOf/VB/simple1.vb" id="Snippet12"::: + + The following example uses the method to determine the starting position of an animal name in a sentence. It then uses this position to insert an adjective that describes the animal into the sentence. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/stringinsert/CPP/stringinsert.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/IndexOf/stringinsert.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/IndexOf/stringinsert.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/stringinsert/VB/stringinsert.vb" id="Snippet1"::: + ]]> @@ -8076,23 +8172,23 @@ The `GetPinnableReference` method returns a character that can be used for pinni Reports the zero-based index of the first occurrence of the specified Unicode character in this string. The search starts at a specified character position. The zero-based index position of from the start of the string if that character is found, or -1 if it is not. - method, where a Unicode scalar value representing a precomposed character, such as the ligature "Æ" (U+00C6), might be considered equivalent to any occurrence of the character's components in the correct sequence, such as "AE" (U+0041, U+0045), depending on the culture. - -## Examples - The following example demonstrates the method. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.indexof1/CPP/ixof1.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/IndexOf/ixof1.cs" interactive="try-dotnet-method" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/IndexOf/ixof1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.indexof1/VB/ixof1.vb" id="Snippet1"::: - + method, where a Unicode scalar value representing a precomposed character, such as the ligature "Æ" (U+00C6), might be considered equivalent to any occurrence of the character's components in the correct sequence, such as "AE" (U+0041, U+0045), depending on the culture. + +## Examples + The following example demonstrates the method. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.indexof1/CPP/ixof1.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/IndexOf/ixof1.cs" interactive="try-dotnet-method" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/IndexOf/ixof1.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.indexof1/VB/ixof1.vb" id="Snippet1"::: + ]]> @@ -8141,14 +8237,14 @@ The `GetPinnableReference` method returns a character that can be used for pinni Reports the zero-based index of the first occurrence of the specified Unicode character in this string. A parameter specifies the type of search to use for the specified character. The zero-based index of if that character is found, or -1 if it is not. - enumeration member that specifies whether the search for the `value` argument uses the current or invariant culture, is case-sensitive or case-insensitive, or uses word or ordinal comparison rules. - + enumeration member that specifies whether the search for the `value` argument uses the current or invariant culture, is case-sensitive or case-insensitive, or uses word or ordinal comparison rules. + ]]> @@ -8202,27 +8298,27 @@ The `comparisonType` parameter is a enumeration m Reports the zero-based index of the first occurrence of the specified string in this instance. The search starts at a specified character position. The zero-based index position of from the start of the current instance if that string is found, or -1 if it is not. If is , the return value is . - method always returns `startIndex`, which is the character position at which the search begins. In the following example, the method is used to find the position of a soft hyphen (U+00AD) followed by an "m" in two strings. Only one of the strings contains the required substring. If the example is run on the .NET Framework 4 or later, in both cases, because the soft hyphen is an ignorable character, the method returns the index of "m" in the string. Note that in the case of the first string, which includes the soft hyphen followed by an "m", the method fails to return the index of the soft hyphen but instead returns the index of the "m". - - :::code language="csharp" source="~/snippets/csharp/System/String/IndexOf/ignorable22.cs" id="Snippet22"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/IndexOf/ignorable22.fs" id="Snippet22"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.IndexOf/VB/ignorable22.vb" id="Snippet22"::: - -## Examples - The following example searches for all occurrences of a specified string within a target string. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/stringindexof4/CPP/stringindexof4.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/IndexOf/stringindexof4.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/IndexOf/stringindexof4.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/stringindexof4/VB/stringindexof4.vb" id="Snippet1"::: - + method always returns `startIndex`, which is the character position at which the search begins. In the following example, the method is used to find the position of a soft hyphen (U+00AD) followed by an "m" in two strings. Only one of the strings contains the required substring. If the example is run on the .NET Framework 4 or later, in both cases, because the soft hyphen is an ignorable character, the method returns the index of "m" in the string. Note that in the case of the first string, which includes the soft hyphen followed by an "m", the method fails to return the index of the soft hyphen but instead returns the index of the "m". + + :::code language="csharp" source="~/snippets/csharp/System/String/IndexOf/ignorable22.cs" id="Snippet22"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/IndexOf/ignorable22.fs" id="Snippet22"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.IndexOf/VB/ignorable22.vb" id="Snippet22"::: + +## Examples + The following example searches for all occurrences of a specified string within a target string. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/stringindexof4/CPP/stringindexof4.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/IndexOf/stringindexof4.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/IndexOf/stringindexof4.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/stringindexof4/VB/stringindexof4.vb" id="Snippet1"::: + ]]> @@ -8295,20 +8391,20 @@ The `comparisonType` parameter is a enumeration m Reports the zero-based index of the first occurrence of the specified string in the current object. A parameter specifies the type of search to use for the specified string. The index position of the parameter if that string is found, or -1 if it is not. If is , the return value is 0. - method that find the first occurrence of a string within another string using different values of the enumeration. - - :::code language="csharp" source="~/snippets/csharp/System/String/IndexOf/iocmp.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/IndexOf/iocmp.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.IndexOfCmp/vb/iocmp.vb" id="Snippet1"::: - + method that find the first occurrence of a string within another string using different values of the enumeration. + + :::code language="csharp" source="~/snippets/csharp/System/String/IndexOf/iocmp.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/IndexOf/iocmp.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.IndexOfCmp/vb/iocmp.vb" id="Snippet1"::: + ]]> @@ -8316,13 +8412,7 @@ The `comparisonType` parameter is a enumeration m is not a valid value. - Character sets include ignorable characters, which are characters that are not considered when performing a linguistic or culture-sensitive comparison. In a culture-sensitive search (that is, if is not or ), if contains an ignorable character, the result is equivalent to searching with that character removed. If consists only of one or more ignorable characters, the method always returns 0 (zero) to indicate that the match is found at the beginning of the current instance. - - In the following example, the method is used to find three substrings (a soft hyphen (U+00AD), a soft hyphen followed by "n", and a soft hyphen followed by "m") in two strings. Only one of the strings contains a soft hyphen. If the example is run on the .NET Framework 4 or later, because the soft hyphen is an ignorable character, a culture-sensitive search returns the same value that it would return if the soft hyphen were not included in the search string. An ordinal search, however, successfully finds the soft hyphen in one string and reports that it is absent from the second string. - - :::code language="csharp" source="~/snippets/csharp/System/String/IndexOf/ignorable26.cs" id="Snippet26"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/IndexOf/ignorable26.fs" id="Snippet26"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.IndexOf/VB/ignorable26.vb" id="Snippet26"::: + Character sets include ignorable characters, which are characters that are not considered when performing a linguistic or culture-sensitive comparison. In a culture-sensitive search (that is, if is not or ), if contains an ignorable character, the result is equivalent to searching with that character removed. If consists only of one or more ignorable characters, the method always returns 0 (zero) to indicate that the match is found at the beginning of the current instance. In the following example, the method is used to find three substrings (a soft hyphen (U+00AD), a soft hyphen followed by "n", and a soft hyphen followed by "m") in two strings. Only one of the strings contains a soft hyphen. If the example is run on the .NET Framework 4 or later, because the soft hyphen is an ignorable character, a culture-sensitive search returns the same value that it would return if the soft hyphen were not included in the search string. An ordinal search, however, successfully finds the soft hyphen in one string and reports that it is absent from the second string. :::code language="csharp" source="~/snippets/csharp/System/String/IndexOf/ignorable26.cs" id="Snippet26"::: :::code language="fsharp" source="~/snippets/fsharp/System/String/IndexOf/ignorable26.fs" id="Snippet26"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.IndexOf/VB/ignorable26.vb" id="Snippet26"::: @@ -8381,35 +8471,35 @@ The `comparisonType` parameter is a enumeration m Reports the zero-based index of the first occurrence of the specified character in this instance. The search starts at a specified character position and examines a specified number of character positions. The zero-based index position of from the start of the string if that character is found, or -1 if it is not. - method, where a Unicode scalar value representing a precomposed character, such as the ligature "Æ" (U+00C6), might be considered equivalent to any occurrence of the character's components in the correct sequence, such as "AE" (U+0041, U+0045), depending on the culture. - -## Examples - The following example demonstrates the method. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.IndexOf/CPP/indexofcii.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/IndexOf/indexofcii.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/IndexOf/indexofcii.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.IndexOf/VB/indexofcii.vb" id="Snippet1"::: - + method, where a Unicode scalar value representing a precomposed character, such as the ligature "Æ" (U+00C6), might be considered equivalent to any occurrence of the character's components in the correct sequence, such as "AE" (U+0041, U+0045), depending on the culture. + +## Examples + The following example demonstrates the method. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.IndexOf/CPP/indexofcii.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/IndexOf/indexofcii.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/IndexOf/indexofcii.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.IndexOf/VB/indexofcii.vb" id="Snippet1"::: + ]]> - or is negative. - - -or- - - is greater than the length of this string. - - -or- - - is greater than the length of this string minus . + or is negative. + +-or- + + is greater than the length of this string. + +-or- + + is greater than the length of this string minus . @@ -8466,41 +8556,41 @@ The `comparisonType` parameter is a enumeration m Reports the zero-based index of the first occurrence of the specified string in this instance. The search starts at a specified character position and examines a specified number of character positions. The zero-based index position of from the start of the current instance if that string is found, or -1 if it is not. If is , the return value is . - method always returns `startIndex`, which is the character position at which the search begins. In the following example, the method is used to find the position of a soft hyphen (U+00AD) followed by an "m" starting in the third through sixth character positions in two strings. Only one of the strings contains the required substring. If the example is run on the .NET Framework 4 or later, in both cases, because the soft hyphen is an ignorable character, the method returns the index of "m" in the string when it performs a culture-sensitive comparison. Note that in the case of the first string, which includes the soft hyphen followed by an "m", the method fails to return the index of the soft hyphen but instead returns the index of the "m". - - :::code language="csharp" source="~/snippets/csharp/System/String/IndexOf/ignorable23.cs" id="Snippet23"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/IndexOf/ignorable23.fs" id="Snippet23"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.IndexOf/VB/ignorable23.vb" id="Snippet23"::: - -## Examples - The following example finds the index of all occurrences of the string "he" within a substring of another string. Note that the number of characters to be searched must be recalculated for each search iteration. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.indexof8/CPP/ixof8.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/IndexOf/ixof8.cs" interactive="try-dotnet-method" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/IndexOf/ixof8.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.indexof8/VB/ixof8.vb" id="Snippet1"::: - + method always returns `startIndex`, which is the character position at which the search begins. In the following example, the method is used to find the position of a soft hyphen (U+00AD) followed by an "m" starting in the third through sixth character positions in two strings. Only one of the strings contains the required substring. If the example is run on the .NET Framework 4 or later, in both cases, because the soft hyphen is an ignorable character, the method returns the index of "m" in the string when it performs a culture-sensitive comparison. Note that in the case of the first string, which includes the soft hyphen followed by an "m", the method fails to return the index of the soft hyphen but instead returns the index of the "m". + + :::code language="csharp" source="~/snippets/csharp/System/String/IndexOf/ignorable23.cs" id="Snippet23"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/IndexOf/ignorable23.fs" id="Snippet23"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.IndexOf/VB/ignorable23.vb" id="Snippet23"::: + +## Examples + The following example finds the index of all occurrences of the string "he" within a substring of another string. Note that the number of characters to be searched must be recalculated for each search iteration. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.indexof8/CPP/ixof8.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/IndexOf/ixof8.cs" interactive="try-dotnet-method" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/IndexOf/ixof8.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.indexof8/VB/ixof8.vb" id="Snippet1"::: + ]]> is . - or is negative. - - -or- - - is greater than the length of this string. - - -or- - - is greater than the length of this string minus . + or is negative. + +-or- + + is greater than the length of this string. + +-or- + + is greater than the length of this string minus . As explained in [Best Practices for Using Strings](/dotnet/standard/base-types/best-practices-strings), we recommend that you avoid calling string comparison methods that substitute default values and instead call methods that require parameters to be explicitly specified. To use the comparison rules of the current culture to perform this operation, signal your intention explicitly by calling the method overload with a value of for its `comparisonType` parameter. If you don't need linguistic-aware comparison, consider using . @@ -8565,20 +8655,20 @@ The `comparisonType` parameter is a enumeration m Reports the zero-based index of the first occurrence of the specified string in the current object. Parameters specify the starting search position in the current string and the type of search to use for the specified string. The zero-based index position of the parameter from the start of the current instance if that string is found, or -1 if it is not. If is , the return value is . - method that find the first occurrence of a string within another string using different values of the enumeration. - - :::code language="csharp" source="~/snippets/csharp/System/String/IndexOf/iocmp.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/IndexOf/iocmp.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.IndexOfCmp/vb/iocmp.vb" id="Snippet1"::: - + method that find the first occurrence of a string within another string using different values of the enumeration. + + :::code language="csharp" source="~/snippets/csharp/System/String/IndexOf/iocmp.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/IndexOf/iocmp.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.IndexOfCmp/vb/iocmp.vb" id="Snippet1"::: + ]]> @@ -8588,13 +8678,7 @@ The `comparisonType` parameter is a enumeration m is not a valid value. - Character sets include ignorable characters, which are characters that are not considered when performing a linguistic or culture-sensitive comparison. In a culture-sensitive search (that is, if is not or ), if contains an ignorable character, the result is equivalent to searching with that character removed. If consists only of one or more ignorable characters, the method always returns , which is the character position at which the search begins. - - In the following example, the method is used to find the position of a soft hyphen (U+00AD) followed by an "m" starting with the third character position in two strings. Only one of the strings contains the required substring. If the example is run on the .NET Framework 4 or later, in both cases, because the soft hyphen is an ignorable character, the method returns the index of "m" in the string when it performs a culture-sensitive comparison. Note that in the case of the first string, which includes the soft hyphen followed by an "m", the method fails to return the index of the soft hyphen but instead returns the index of the "m". The method returns the index of the soft hyphen in the first string only when it performs an ordinal comparison. - - :::code language="csharp" source="~/snippets/csharp/System/String/IndexOf/ignorable25.cs" id="Snippet25"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/IndexOf/ignorable25.fs" id="Snippet25"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.IndexOf/VB/ignorable25.vb" id="Snippet25"::: + Character sets include ignorable characters, which are characters that are not considered when performing a linguistic or culture-sensitive comparison. In a culture-sensitive search (that is, if is not or ), if contains an ignorable character, the result is equivalent to searching with that character removed. If consists only of one or more ignorable characters, the method always returns , which is the character position at which the search begins. In the following example, the method is used to find the position of a soft hyphen (U+00AD) followed by an "m" starting with the third character position in two strings. Only one of the strings contains the required substring. If the example is run on the .NET Framework 4 or later, in both cases, because the soft hyphen is an ignorable character, the method returns the index of "m" in the string when it performs a culture-sensitive comparison. Note that in the case of the first string, which includes the soft hyphen followed by an "m", the method fails to return the index of the soft hyphen but instead returns the index of the "m". The method returns the index of the soft hyphen in the first string only when it performs an ordinal comparison. :::code language="csharp" source="~/snippets/csharp/System/String/IndexOf/ignorable25.cs" id="Snippet25"::: :::code language="fsharp" source="~/snippets/fsharp/System/String/IndexOf/ignorable25.fs" id="Snippet25"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.IndexOf/VB/ignorable25.vb" id="Snippet25"::: @@ -8654,46 +8738,40 @@ The `comparisonType` parameter is a enumeration m Reports the zero-based index of the first occurrence of the specified string in the current object. Parameters specify the starting search position in the current string, the number of characters in the current string to search, and the type of search to use for the specified string. The zero-based index position of the parameter from the start of the current instance if that string is found, or -1 if it is not. If is , the return value is . - method that find the first occurrence of a string within another string using different values of the enumeration. - - :::code language="csharp" source="~/snippets/csharp/System/String/IndexOf/iocmp.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/IndexOf/iocmp.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.IndexOfCmp/vb/iocmp.vb" id="Snippet1"::: - + method that find the first occurrence of a string within another string using different values of the enumeration. + + :::code language="csharp" source="~/snippets/csharp/System/String/IndexOf/iocmp.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/IndexOf/iocmp.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.IndexOfCmp/vb/iocmp.vb" id="Snippet1"::: + ]]> is . - or is negative. - - -or- - - is greater than the length of this instance. - - -or- - - is greater than the length of this string minus . + or is negative. + +-or- + + is greater than the length of this instance. + +-or- + + is greater than the length of this string minus . is not a valid value. - Character sets include ignorable characters, which are characters that are not considered when performing a linguistic or culture-sensitive comparison. In a culture-sensitive search (that is, if is not or ), if contains an ignorable character, the result is equivalent to searching with that character removed. If consists only of one or more ignorable characters, the method always returns , which is the character position at which the search begins. - - In the following example, the method is used to find the position of a soft hyphen (U+00AD) followed by an "m" starting in the third through sixth character positions in two strings. Only one of the strings contains the required substring. If the example is run on the .NET Framework 4 or later, in both cases, because the soft hyphen is an ignorable character, the method returns the index of "m" in the string when it performs a culture-sensitive comparison. When it performs an ordinal comparison, however, it finds the substring only in the first string. Note that in the case of the first string, which includes the soft hyphen followed by an "m", the method fails to return the index of the soft hyphen but instead returns the index of the "m" when it performs a culture-sensitive comparison. The method returns the index of the soft hyphen in the first string only when it performs an ordinal comparison. - - :::code language="csharp" source="~/snippets/csharp/System/String/IndexOf/ignorable24.cs" id="Snippet24"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/IndexOf/ignorable24.fs" id="Snippet24"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.IndexOf/VB/ignorable24.vb" id="Snippet24"::: + Character sets include ignorable characters, which are characters that are not considered when performing a linguistic or culture-sensitive comparison. In a culture-sensitive search (that is, if is not or ), if contains an ignorable character, the result is equivalent to searching with that character removed. If consists only of one or more ignorable characters, the method always returns , which is the character position at which the search begins. In the following example, the method is used to find the position of a soft hyphen (U+00AD) followed by an "m" starting in the third through sixth character positions in two strings. Only one of the strings contains the required substring. If the example is run on the .NET Framework 4 or later, in both cases, because the soft hyphen is an ignorable character, the method returns the index of "m" in the string when it performs a culture-sensitive comparison. When it performs an ordinal comparison, however, it finds the substring only in the first string. Note that in the case of the first string, which includes the soft hyphen followed by an "m", the method fails to return the index of the soft hyphen but instead returns the index of the "m" when it performs a culture-sensitive comparison. The method returns the index of the soft hyphen in the first string only when it performs an ordinal comparison. :::code language="csharp" source="~/snippets/csharp/System/String/IndexOf/ignorable24.cs" id="Snippet24"::: :::code language="fsharp" source="~/snippets/fsharp/System/String/IndexOf/ignorable24.fs" id="Snippet24"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.IndexOf/VB/ignorable24.vb" id="Snippet24"::: @@ -8761,22 +8839,22 @@ The `comparisonType` parameter is a enumeration m Reports the zero-based index of the first occurrence in this instance of any character in a specified array of Unicode characters. The zero-based index position of the first occurrence in this instance where any character in was found; -1 if no character in was found. - method, where a Unicode scalar value representing a precomposed character, such as the ligature "Æ" (U+00C6), might be considered equivalent to any occurrence of the character's components in the correct sequence, such as "AE" (U+0041, U+0045), depending on the culture. - -## Examples - The following example finds the first vowel in a string. - - :::code language="csharp" source="~/snippets/csharp/System/String/IndexOfAny/IndexOfAny1.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/IndexOfAny/IndexOfAny1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.String.IndexOfAny/vb/IndexOfAny1.vb" id="Snippet1"::: - + method, where a Unicode scalar value representing a precomposed character, such as the ligature "Æ" (U+00C6), might be considered equivalent to any occurrence of the character's components in the correct sequence, such as "AE" (U+0041, U+0045), depending on the culture. + +## Examples + The following example finds the first vowel in a string. + + :::code language="csharp" source="~/snippets/csharp/System/String/IndexOfAny/IndexOfAny1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/IndexOfAny/IndexOfAny1.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.String.IndexOfAny/vb/IndexOfAny1.vb" id="Snippet1"::: + ]]> @@ -8839,35 +8917,35 @@ The `comparisonType` parameter is a enumeration m Reports the zero-based index of the first occurrence in this instance of any character in a specified array of Unicode characters. The search starts at a specified character position. The zero-based index position of the first occurrence in this instance where any character in was found; -1 if no character in was found. - method, where a Unicode scalar value representing a precomposed character, such as the ligature "Æ" (U+00C6), might be considered equivalent to any occurrence of the character's components in the correct sequence, such as "AE" (U+0041, U+0045), depending on the culture. - -## Examples - The following example finds the index of the occurrence of any character of the string "is" within a substring of another string. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.indexofany2/CPP/ixany2.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/IndexOfAny/ixany2.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/IndexOfAny/ixany2.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.indexofany2/VB/ixany2.vb" id="Snippet1"::: - + method, where a Unicode scalar value representing a precomposed character, such as the ligature "Æ" (U+00C6), might be considered equivalent to any occurrence of the character's components in the correct sequence, such as "AE" (U+0041, U+0045), depending on the culture. + +## Examples + The following example finds the index of the occurrence of any character of the string "is" within a substring of another string. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.indexofany2/CPP/ixany2.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/IndexOfAny/ixany2.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/IndexOfAny/ixany2.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.indexofany2/VB/ixany2.vb" id="Snippet1"::: + ]]> is . - is negative. - - -or- - - is greater than the number of characters in this instance. + is negative. + +-or- + + is greater than the number of characters in this instance. @@ -8931,35 +9009,35 @@ The `comparisonType` parameter is a enumeration m Reports the zero-based index of the first occurrence in this instance of any character in a specified array of Unicode characters. The search starts at a specified character position and examines a specified number of character positions. The zero-based index position of the first occurrence in this instance where any character in was found; -1 if no character in was found. - method, where a Unicode scalar value representing a precomposed character, such as the ligature "Æ" (U+00C6), might be considered equivalent to any occurrence of the character's components in the correct sequence, such as "AE" (U+0041, U+0045), depending on the culture. - -## Examples - The following example finds the index of the occurrence of any character of the string "aid" within a substring of another string. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.indexofany3/CPP/ixany3.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/IndexOfAny/ixany3.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/IndexOfAny/ixany3.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.indexofany3/VB/ixany3.vb" id="Snippet1"::: - + method, where a Unicode scalar value representing a precomposed character, such as the ligature "Æ" (U+00C6), might be considered equivalent to any occurrence of the character's components in the correct sequence, such as "AE" (U+0041, U+0045), depending on the culture. + +## Examples + The following example finds the index of the occurrence of any character of the string "aid" within a substring of another string. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.indexofany3/CPP/ixany3.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/IndexOfAny/ixany3.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/IndexOfAny/ixany3.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.indexofany3/VB/ixany3.vb" id="Snippet1"::: + ]]> is . - or is negative. - - -or- - - + is greater than the number of characters in this instance. + or is negative. + +-or- + + + is greater than the number of characters in this instance. @@ -9021,30 +9099,30 @@ The `comparisonType` parameter is a enumeration m Returns a new string in which a specified string is inserted at a specified index position in this instance. A new string that is equivalent to this instance, but with inserted at position . - [!NOTE] -> This method does not modify the value of the current instance. Instead, it returns a new string in which `value` is inserted into the current instance. - - For example, the return value of `"abc".Insert(2, "XYZ")` is "abXYZc". - -## Examples - The following example inserts a space character in the fourth character position (the character at index 3) of a string. - - :::code language="csharp" source="~/snippets/csharp/System/String/Insert/Insert1.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Insert/Insert1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.String.Insert/vb/Insert1.vb" id="Snippet1"::: - - The following console application prompts the users to enter one or more adjectives to describe two animals. It then calls the method to insert the text entered by the user into a string. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/stringinsert/CPP/stringinsert.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/IndexOf/stringinsert.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/IndexOf/stringinsert.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/stringinsert/VB/stringinsert.vb" id="Snippet1"::: - + [!NOTE] +> This method does not modify the value of the current instance. Instead, it returns a new string in which `value` is inserted into the current instance. + + For example, the return value of `"abc".Insert(2, "XYZ")` is "abXYZc". + +## Examples + The following example inserts a space character in the fourth character position (the character at index 3) of a string. + + :::code language="csharp" source="~/snippets/csharp/System/String/Insert/Insert1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Insert/Insert1.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.String.Insert/vb/Insert1.vb" id="Snippet1"::: + + The following console application prompts the users to enter one or more adjectives to describe two animals. It then calls the method to insert the text entered by the user into a string. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/stringinsert/CPP/stringinsert.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/IndexOf/stringinsert.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/IndexOf/stringinsert.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/stringinsert/VB/stringinsert.vb" id="Snippet1"::: + ]]> @@ -9114,46 +9192,46 @@ The `comparisonType` parameter is a enumeration m Retrieves the system's reference to the specified . The system's reference to , if it is interned; otherwise, a new reference to a string with the value of . - method uses the intern pool to search for a string equal to the value of `str`. If such a string exists, its reference in the intern pool is returned. If the string does not exist, a reference to `str` is added to the intern pool, then that reference is returned. - - In the following example, the string s1, which has a value of "MyTest", is already interned because it is a literal in the program. The class generates a new string object that has the same value as s1. A reference to that string is assigned to s2. The method searches for a string that has the same value as s2. Because such a string exists, the method returns the same reference that is assigned to s1. That reference is then assigned to s3. References s1 and s2 compare unequal because they refer to different objects; references s1 and s3 compare equal because they refer to the same string. - - :::code language="csharp" source="~/snippets/csharp/System/String/Intern/Intern1.cs" interactive="try-dotnet-method" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Intern/Intern1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Intern/vb/Intern1.vb" id="Snippet1"::: - - Compare this method to the method. - -## Version considerations - - In the .NET Framework 3.5 Service Pack 1, the method reverts to its behavior in .NET Framework 1.0 and 1.1 with regard to interning the empty string. In the following example, the variable `str1` is assigned a reference to , and the variable `str2` is assigned the reference to that is returned by calling the method after converting a object whose value is to a string. Then the references contained in `str1` and `str2` are compared for equality. - - :::code language="csharp" source="~/snippets/csharp/System/String/Intern/Intern2.cs" interactive="try-dotnet-method" id="Snippet2"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Intern/Intern2.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Intern/vb/Intern2.vb" id="Snippet2"::: - - In the .NET Framework 2.0 Service Pack 1 and .NET Framework 3.0, `str1` and `str2` are not equal. In all other versions, `str1` and `str2` are equal. - -## Performance Considerations - If you are trying to reduce the total amount of memory your application allocates, keep in mind that interning a string has two unwanted side effects. First, the memory allocated for interned objects is not likely to be released until the common language runtime (CLR) terminates. The reason is that the CLR's reference to the interned object can persist after your application, or even your application domain, terminates. Second, to intern a string, you must first create the string. The memory used by the object must still be allocated, even though the memory will eventually be garbage collected. - -The enumeration member marks an assembly as not requiring string-literal interning. You can apply to an assembly using the attribute. Also, when you use [Ngen.exe (Native Image Generator)](/dotnet/framework/tools/ngen-exe-native-image-generator) to compile an assembly in advance of run time, strings are not interned across modules. - -## Examples - The following example uses three strings that are equal in value to determine whether a newly created string and an interned string are equal. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.intern/CPP/string_intern.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Intern/string_intern.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Intern/string_intern.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.intern/VB/string_intern.vb" id="Snippet1"::: - + method uses the intern pool to search for a string equal to the value of `str`. If such a string exists, its reference in the intern pool is returned. If the string does not exist, a reference to `str` is added to the intern pool, then that reference is returned. + + In the following example, the string s1, which has a value of "MyTest", is already interned because it is a literal in the program. The class generates a new string object that has the same value as s1. A reference to that string is assigned to s2. The method searches for a string that has the same value as s2. Because such a string exists, the method returns the same reference that is assigned to s1. That reference is then assigned to s3. References s1 and s2 compare unequal because they refer to different objects; references s1 and s3 compare equal because they refer to the same string. + + :::code language="csharp" source="~/snippets/csharp/System/String/Intern/Intern1.cs" interactive="try-dotnet-method" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Intern/Intern1.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Intern/vb/Intern1.vb" id="Snippet1"::: + + Compare this method to the method. + +## Version considerations + + In the .NET Framework 3.5 Service Pack 1, the method reverts to its behavior in .NET Framework 1.0 and 1.1 with regard to interning the empty string. In the following example, the variable `str1` is assigned a reference to , and the variable `str2` is assigned the reference to that is returned by calling the method after converting a object whose value is to a string. Then the references contained in `str1` and `str2` are compared for equality. + + :::code language="csharp" source="~/snippets/csharp/System/String/Intern/Intern2.cs" interactive="try-dotnet-method" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Intern/Intern2.fs" id="Snippet2"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Intern/vb/Intern2.vb" id="Snippet2"::: + + In the .NET Framework 2.0 Service Pack 1 and .NET Framework 3.0, `str1` and `str2` are not equal. In all other versions, `str1` and `str2` are equal. + +## Performance Considerations + If you are trying to reduce the total amount of memory your application allocates, keep in mind that interning a string has two unwanted side effects. First, the memory allocated for interned objects is not likely to be released until the common language runtime (CLR) terminates. The reason is that the CLR's reference to the interned object can persist after your application, or even your application domain, terminates. Second, to intern a string, you must first create the string. The memory used by the object must still be allocated, even though the memory will eventually be garbage collected. + +The enumeration member marks an assembly as not requiring string-literal interning. You can apply to an assembly using the attribute. Also, when you use [Ngen.exe (Native Image Generator)](/dotnet/framework/tools/ngen-exe-native-image-generator) to compile an assembly in advance of run time, strings are not interned across modules. + +## Examples + The following example uses three strings that are equal in value to determine whether a newly created string and an interned string are equal. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.intern/CPP/string_intern.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Intern/string_intern.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Intern/string_intern.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.intern/VB/string_intern.vb" id="Snippet1"::: + ]]> @@ -9209,34 +9287,34 @@ The Retrieves a reference to a specified . A reference to if it is in the common language runtime intern pool; otherwise, . - you add programmatically by calling the method. - - The intern pool conserves string storage. If you assign a literal string constant to several variables, each variable is set to reference the same constant in the intern pool instead of referencing several different instances of that have identical values. - - This method looks up `str` in the intern pool. If `str` has already been interned, a reference to that instance is returned; otherwise, `null` is returned. - - Compare this method to the method. - - This method does not return a Boolean value. If you call the method because you want a Boolean value that indicates whether a particular string is interned, you can use code such as the following. - - :::code language="csharp" source="~/snippets/csharp/System/String/IsInterned/isinternedex1.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/IsInterned/isinternedex1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.isinterned/vb/isinternedex1.vb" id="Snippet1"::: - -> [!NOTE] -> You can override the use of the intern pool when you use [Ngen.exe (Native Image Generator)](/dotnet/framework/tools/ngen-exe-native-image-generator) to install an assembly to the native image cache on a local computer. For more information, see Performance Considerations in the Remarks section for the property. - -## Examples - The following example demonstrates that literal strings are interned automatically by the compiler. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.isinterned/CPP/isin.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/IsInterned/isin.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/IsInterned/isin.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.isinterned/VB/isin.vb" id="Snippet1"::: - + you add programmatically by calling the method. + + The intern pool conserves string storage. If you assign a literal string constant to several variables, each variable is set to reference the same constant in the intern pool instead of referencing several different instances of that have identical values. + + This method looks up `str` in the intern pool. If `str` has already been interned, a reference to that instance is returned; otherwise, `null` is returned. + + Compare this method to the method. + + This method does not return a Boolean value. If you call the method because you want a Boolean value that indicates whether a particular string is interned, you can use code such as the following. + + :::code language="csharp" source="~/snippets/csharp/System/String/IsInterned/isinternedex1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/IsInterned/isinternedex1.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.isinterned/vb/isinternedex1.vb" id="Snippet1"::: + +> [!NOTE] +> You can override the use of the intern pool when you use [Ngen.exe (Native Image Generator)](/dotnet/framework/tools/ngen-exe-native-image-generator) to install an assembly to the native image cache on a local computer. For more information, see Performance Considerations in the Remarks section for the property. + +## Examples + The following example demonstrates that literal strings are interned automatically by the compiler. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.isinterned/CPP/isin.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/IsInterned/isin.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/IsInterned/isin.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.isinterned/VB/isin.vb" id="Snippet1"::: + ]]> @@ -9253,16 +9331,16 @@ The Indicates whether this string is in a particular Unicode normalization form. - @@ -9305,15 +9383,15 @@ The if this string is in normalization form C; otherwise, . - . - + . + ]]> The current instance contains invalid Unicode characters. @@ -9370,15 +9448,15 @@ The if this string is in the normalization form specified by the parameter; otherwise, . - . - + . + ]]> The current instance contains invalid Unicode characters. @@ -9451,44 +9529,44 @@ The if the parameter is or an empty string (""); otherwise, . - is a convenience method that enables you to simultaneously test whether a is `null` or its value is . It is equivalent to the following code: - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.string.isnullorempty/cpp/isnullorempty1.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/IsNullOrEmpty/isnullorempty1.cs" interactive="try-dotnet-method" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.isnullorempty/vb/isnullorempty1.vb" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/IsNullOrEmpty/isnullorempty1.fs" id="Snippet1"::: - - You can use the method to test whether a string is `null`, its value is , or it consists only of white-space characters. - -## What is a null string? - -A string is `null` if it has not been assigned a value (in C++ and Visual Basic) or if it has explicitly been assigned a value of `null`. Although the [composite formatting](/dotnet/standard/base-types/composite-formatting) feature can gracefully handle a null string, as the following example shows, attempting to call one if its members throws a . - -:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.string.isnullorempty/cpp/NullString1.cpp" id="Snippet2"::: -:::code language="csharp" source="~/snippets/csharp/System/String/IsNullOrEmpty/NullString1.cs" interactive="try-dotnet-method" id="Snippet2"::: -:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.isnullorempty/vb/NullString1.vb" id="Snippet2"::: -:::code language="fsharp" source="~/snippets/fsharp/System/String/IsNullOrEmpty/NullString1.fs" id="Snippet2"::: - -## What is an empty string? - -A string is empty if it is explicitly assigned an empty string ("") or . An empty string has a of 0. The following example creates an empty string and displays its value and its length. - -:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.string.isnullorempty/cpp/NullString1.cpp" id="Snippet3"::: -:::code language="csharp" source="~/snippets/csharp/System/String/IsNullOrEmpty/NullString1.cs" interactive="try-dotnet-method" id="Snippet3"::: -:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.isnullorempty/vb/NullString1.vb" id="Snippet3"::: -:::code language="fsharp" source="~/snippets/fsharp/System/String/IsNullOrEmpty/NullString2.fs" id="Snippet3"::: - -## Examples - The following example examines three strings and determines whether each string has a value, is an empty string, or is `null`. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.isNullOrEmpty/CPP/inoe.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/IsNullOrEmpty/inoe.cs" interactive="try-dotnet-method" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.isNullOrEmpty/VB/inoe.vb" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/IsNullOrEmpty/inoe.fs" id="Snippet1"::: - + is a convenience method that enables you to simultaneously test whether a is `null` or its value is . It is equivalent to the following code: + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.string.isnullorempty/cpp/isnullorempty1.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/IsNullOrEmpty/isnullorempty1.cs" interactive="try-dotnet-method" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.isnullorempty/vb/isnullorempty1.vb" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/IsNullOrEmpty/isnullorempty1.fs" id="Snippet1"::: + + You can use the method to test whether a string is `null`, its value is , or it consists only of white-space characters. + +## What is a null string? + +A string is `null` if it has not been assigned a value (in C++ and Visual Basic) or if it has explicitly been assigned a value of `null`. Although the [composite formatting](/dotnet/standard/base-types/composite-formatting) feature can gracefully handle a null string, as the following example shows, attempting to call one if its members throws a . + +:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.string.isnullorempty/cpp/NullString1.cpp" id="Snippet2"::: +:::code language="csharp" source="~/snippets/csharp/System/String/IsNullOrEmpty/NullString1.cs" interactive="try-dotnet-method" id="Snippet2"::: +:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.isnullorempty/vb/NullString1.vb" id="Snippet2"::: +:::code language="fsharp" source="~/snippets/fsharp/System/String/IsNullOrEmpty/NullString1.fs" id="Snippet2"::: + +## What is an empty string? + +A string is empty if it is explicitly assigned an empty string ("") or . An empty string has a of 0. The following example creates an empty string and displays its value and its length. + +:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.string.isnullorempty/cpp/NullString1.cpp" id="Snippet3"::: +:::code language="csharp" source="~/snippets/csharp/System/String/IsNullOrEmpty/NullString1.cs" interactive="try-dotnet-method" id="Snippet3"::: +:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.isnullorempty/vb/NullString1.vb" id="Snippet3"::: +:::code language="fsharp" source="~/snippets/fsharp/System/String/IsNullOrEmpty/NullString2.fs" id="Snippet3"::: + +## Examples + The following example examines three strings and determines whether each string has a value, is an empty string, or is `null`. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.isNullOrEmpty/CPP/inoe.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/IsNullOrEmpty/inoe.cs" interactive="try-dotnet-method" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.isNullOrEmpty/VB/inoe.vb" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/IsNullOrEmpty/inoe.fs" id="Snippet1"::: + ]]> @@ -9552,24 +9630,24 @@ A string is empty if it is explicitly assigned an empty string ("") or if the parameter is or , or if consists exclusively of white-space characters. - is a convenience method that is similar to the following code, except that it offers superior performance: - - :::code language="csharp" source="~/snippets/csharp/System/String/IsNullOrWhiteSpace/isnullorwhitespace.cs" id="Snippet2"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/IsNullOrWhiteSpace/isnullorwhitespace.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.isnullorwhitespace/vb/isnullorwhitespace.vb" id="Snippet2"::: - - White-space characters are defined by the Unicode standard. The method interprets any character that returns a value of `true` when it is passed to the method as a white-space character. - -## Examples - The following example creates a string array, and then passes each element of the array to the method. - - :::code language="csharp" source="~/snippets/csharp/System/String/IsNullOrWhiteSpace/isnullorwhitespace1.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/IsNullOrWhiteSpace/isnullorwhitespace1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.isnullorwhitespace/vb/isnullorwhitespace1.vb" id="Snippet1"::: - + is a convenience method that is similar to the following code, except that it offers superior performance: + + :::code language="csharp" source="~/snippets/csharp/System/String/IsNullOrWhiteSpace/isnullorwhitespace.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/IsNullOrWhiteSpace/isnullorwhitespace.fs" id="Snippet2"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.isnullorwhitespace/vb/isnullorwhitespace.vb" id="Snippet2"::: + + White-space characters are defined by the Unicode standard. The method interprets any character that returns a value of `true` when it is passed to the method as a white-space character. + +## Examples + The following example creates a string array, and then passes each element of the array to the method. + + :::code language="csharp" source="~/snippets/csharp/System/String/IsNullOrWhiteSpace/isnullorwhitespace1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/IsNullOrWhiteSpace/isnullorwhitespace1.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.isnullorwhitespace/vb/isnullorwhitespace1.vb" id="Snippet1"::: + ]]> @@ -9633,10 +9711,10 @@ A string is empty if it is explicitly assigned an empty string ("") or The character to use as a separator. is included in the returned string only if has more than one element. An array of objects whose string representations will be concatenated. Concatenates the string representations of an array of objects, using the specified separator between each member. - A string that consists of the elements of delimited by the character. - --or- - + A string that consists of the elements of delimited by the character. + +-or- + if has zero elements. To be added. @@ -9692,10 +9770,10 @@ A string is empty if it is explicitly assigned an empty string ("") or The character to use as a separator. is included in the returned string only if has more than one element. An array of strings to concatenate. Concatenates an array of strings, using the specified separator between each member. - A string that consists of the elements of delimited by the character. - --or- - + A string that consists of the elements of delimited by the character. + +-or- + if has zero elements. To be added. @@ -9767,30 +9845,30 @@ A string is empty if it is explicitly assigned an empty string ("") or The string to use as a separator. is included in the returned string only if has more than one element. A collection that contains the strings to concatenate. Concatenates the members of a constructed collection of type , using the specified separator between each member. - A string that consists of the elements of delimited by the string. - --or- - + A string that consists of the elements of delimited by the string. + +-or- + if has zero elements. - ) is used instead. If any member of `values` is `null`, an empty string is used instead. - - is a convenience method that lets you concatenate each element in an `IEnumerable(Of String)` collection without first converting the elements to a string array. It is particularly useful with Language-Integrated Query (LINQ) query expressions. The following example passes a `List(Of String)` object that contains either the uppercase or lowercase letters of the alphabet to a lambda expression that selects letters that are equal to or greater than a particular letter (which, in the example, is "M"). The `IEnumerable(Of String)` collection returned by the method is passed to the method to display the result as a single string. - - :::code language="csharp" source="~/snippets/csharp/System/String/Join/join4.cs" interactive="try-dotnet" id="Snippet4"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Join/join4.fs" id="Snippet4"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.join/vb/join4.vb" id="Snippet4"::: - -## Examples - The following example uses the Sieve of Eratosthenes algorithm to calculate the prime numbers that are less than or equal to 100. It assigns the result to a object of type , which it then passes to the method. - - :::code language="csharp" source="~/snippets/csharp/System/String/Join/join3.cs" interactive="try-dotnet" id="Snippet3"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Join/join3.fs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.join/vb/join3.vb" id="Snippet3"::: - + ) is used instead. If any member of `values` is `null`, an empty string is used instead. + + is a convenience method that lets you concatenate each element in an `IEnumerable(Of String)` collection without first converting the elements to a string array. It is particularly useful with Language-Integrated Query (LINQ) query expressions. The following example passes a `List(Of String)` object that contains either the uppercase or lowercase letters of the alphabet to a lambda expression that selects letters that are equal to or greater than a particular letter (which, in the example, is "M"). The `IEnumerable(Of String)` collection returned by the method is passed to the method to display the result as a single string. + + :::code language="csharp" source="~/snippets/csharp/System/String/Join/join4.cs" interactive="try-dotnet" id="Snippet4"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Join/join4.fs" id="Snippet4"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.join/vb/join4.vb" id="Snippet4"::: + +## Examples + The following example uses the Sieve of Eratosthenes algorithm to calculate the prime numbers that are less than or equal to 100. It assigns the result to a object of type , which it then passes to the method. + + :::code language="csharp" source="~/snippets/csharp/System/String/Join/join3.cs" interactive="try-dotnet" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Join/join3.fs" id="Snippet3"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.join/vb/join3.vb" id="Snippet3"::: + ]]> @@ -9867,41 +9945,37 @@ A string is empty if it is explicitly assigned an empty string ("") or The string to use as a separator. is included in the returned string only if has more than one element. An array that contains the elements to concatenate. Concatenates the elements of an object array, using the specified separator between each element. - A string that consists of the elements of delimited by the string. - --or- - - if has zero elements. - --or- - + A string that consists of the elements of delimited by the string. + +-or- + + if has zero elements. + +-or- + .NET Framework only: if the first element of is . - ) is used instead. See the Notes for Callers section if the first element of `values` is `null`. - - is a convenience method that lets you concatenate each element in an object array without explicitly converting its elements to strings. The string representation of each object in the array is derived by calling that object's `ToString` method. - -## Examples - The following example uses the Sieve of Eratosthenes algorithm to calculate the prime numbers that are less than or equal to 100. It assigns the result to a integer array, which it then passes to the method. - - :::code language="csharp" source="~/snippets/csharp/System/String/Join/join1.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Join/join1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.join/vb/join1.vb" id="Snippet1"::: - + ) is used instead. See the Notes for Callers section if the first element of `values` is `null`. + + is a convenience method that lets you concatenate each element in an object array without explicitly converting its elements to strings. The string representation of each object in the array is derived by calling that object's `ToString` method. + +## Examples + The following example uses the Sieve of Eratosthenes algorithm to calculate the prime numbers that are less than or equal to 100. It assigns the result to a integer array, which it then passes to the method. + + :::code language="csharp" source="~/snippets/csharp/System/String/Join/join1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Join/join1.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.join/vb/join1.vb" id="Snippet1"::: + ]]> is . The length of the resulting string overflows the maximum allowed length (Int32.MaxValue). - .NET Framework only: If the first element of is , the method does not concatenate the elements in but instead returns . A number of workarounds for this issue are available. The easiest is to assign a value of to the first element of the array, as the following example shows. - - :::code language="csharp" source="~/snippets/csharp/System/String/Join/joinfix1.cs" interactive="try-dotnet-method" id="Snippet6"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Join/joinfix1.fs" id="Snippet6"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.join/vb/joinfix1.vb" id="Snippet6"::: + .NET Framework only: If the first element of is , the method does not concatenate the elements in but instead returns . A number of workarounds for this issue are available. The easiest is to assign a value of to the first element of the array, as the following example shows. :::code language="csharp" source="~/snippets/csharp/System/String/Join/joinfix1.cs" interactive="try-dotnet-method" id="Snippet6"::: :::code language="fsharp" source="~/snippets/fsharp/System/String/Join/joinfix1.fs" id="Snippet6"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.join/vb/joinfix1.vb" id="Snippet6"::: @@ -9973,27 +10047,27 @@ A string is empty if it is explicitly assigned an empty string ("") or The string to use as a separator. is included in the returned string only if has more than one element. An array that contains the elements to concatenate. Concatenates all the elements of a string array, using the specified separator between each element. - A string that consists of the elements in delimited by the string. - --or- - + A string that consists of the elements in delimited by the string. + +-or- + if has zero elements. - ) is used instead. If any element in `value` is `null`, an empty string is used instead. - -## Examples - The following example demonstrates the method. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/stringjoin/CPP/stringjoin.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Join/stringjoin.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Join/stringjoin.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/stringjoin/VB/stringjoin.vb" id="Snippet1"::: - + ) is used instead. If any element in `value` is `null`, an empty string is used instead. + +## Examples + The following example demonstrates the method. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/stringjoin/CPP/stringjoin.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Join/stringjoin.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Join/stringjoin.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/stringjoin/VB/stringjoin.vb" id="Snippet1"::: + ]]> @@ -10050,20 +10124,20 @@ A string is empty if it is explicitly assigned an empty string ("") or The first item in to concatenate. The number of elements from to concatenate, starting with the element in the position. Concatenates an array of strings, using the specified separator between each member, starting with the element in located at the position, and concatenating up to elements. - A string that consists of elements of starting at delimited by the character. - --or- - + A string that consists of elements of starting at delimited by the character. + +-or- + if is zero. To be added. is . - or are negative. - --or- - - is greater than the length of - . + or are negative. + +-or- + + is greater than the length of - . The length of the resulting string overflows the maximum allowed length (Int32.MaxValue). @@ -10137,36 +10211,36 @@ A string is empty if it is explicitly assigned an empty string ("") or The first element in to use. The number of elements of to use. Concatenates the specified elements of a string array, using the specified separator between each element. - A string that consists of elements of starting at delimited by the character. - - -or- - - if is zero. + A string that consists of elements of starting at delimited by the character. + +-or- + + if is zero. - ) is used instead. If any element in `value` is `null`, an empty string is used instead. - -## Examples - The following example concatenates two elements from an array of names of fruit. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.join2/CPP/join2.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Join/join2.cs" interactive="try-dotnet-method" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Join/join2.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.join2/VB/join2.vb" id="Snippet1"::: - + ) is used instead. If any element in `value` is `null`, an empty string is used instead. + +## Examples + The following example concatenates two elements from an array of names of fruit. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.join2/CPP/join2.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Join/join2.cs" interactive="try-dotnet-method" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Join/join2.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.join2/VB/join2.vb" id="Snippet1"::: + ]]> is . - or is less than 0. - --or- - + or is less than 0. + +-or- + plus is greater than the number of elements in . Out of memory. @@ -10219,10 +10293,10 @@ A string is empty if it is explicitly assigned an empty string ("") or The character to use as a separator. is included in the returned string only if has more than one element. A collection that contains the objects to concatenate. Concatenates the members of a collection, using the specified separator between each member. - A string that consists of the members of delimited by the character. - --or- - + A string that consists of the members of delimited by the character. + +-or- + if has no elements. To be added. @@ -10298,32 +10372,32 @@ A string is empty if it is explicitly assigned an empty string ("") or The string to use as a separator. is included in the returned string only if has more than one element. A collection that contains the objects to concatenate. Concatenates the members of a collection, using the specified separator between each member. - A string that consists of the elements of delimited by the string. - --or- - + A string that consists of the elements of delimited by the string. + +-or- + if has no elements. - ) is used instead. If any member of `values` is `null`, an empty string is used instead. - - is a convenience method that lets you concatenate each member of an collection without first converting them to strings. The string representation of each object in the collection is derived by calling that object's `ToString` method. - - This method is particular useful with Language-Integrated Query (LINQ) query expressions. For example, the following code defines a very simple `Animal` class that contains the name of an animal and the order to which it belongs. It then defines a object that contains a number of `Animal` objects. The extension method is called to extract the `Animal` objects whose `Order` property equals "Rodent". The result is passed to the method. - - :::code language="csharp" source="~/snippets/csharp/System/String/Join/join5.cs" interactive="try-dotnet" id="Snippet5"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Join/join5.fs" id="Snippet5"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.join/vb/join5.vb" id="Snippet5"::: - -## Examples - The following example uses the Sieve of Eratosthenes algorithm to calculate the prime numbers that are less than or equal to 100. It assigns the result to a object of type integer, which it then passes to the method. - - :::code language="csharp" source="~/snippets/csharp/System/String/Join/join6.cs" interactive="try-dotnet" id="Snippet2"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Join/join6.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.join/vb/join2.vb" id="Snippet2"::: - + ) is used instead. If any member of `values` is `null`, an empty string is used instead. + + is a convenience method that lets you concatenate each member of an collection without first converting them to strings. The string representation of each object in the collection is derived by calling that object's `ToString` method. + + This method is particular useful with Language-Integrated Query (LINQ) query expressions. For example, the following code defines a very simple `Animal` class that contains the name of an animal and the order to which it belongs. It then defines a object that contains a number of `Animal` objects. The extension method is called to extract the `Animal` objects whose `Order` property equals "Rodent". The result is passed to the method. + + :::code language="csharp" source="~/snippets/csharp/System/String/Join/join5.cs" interactive="try-dotnet" id="Snippet5"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Join/join5.fs" id="Snippet5"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.join/vb/join5.vb" id="Snippet5"::: + +## Examples + The following example uses the Sieve of Eratosthenes algorithm to calculate the prime numbers that are less than or equal to 100. It assigns the result to a object of type integer, which it then passes to the method. + + :::code language="csharp" source="~/snippets/csharp/System/String/Join/join6.cs" interactive="try-dotnet" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Join/join6.fs" id="Snippet2"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.join/vb/join2.vb" id="Snippet2"::: + ]]> @@ -10396,22 +10470,22 @@ A string is empty if it is explicitly assigned an empty string ("") or Reports the zero-based index position of the last occurrence of a specified Unicode character within this instance. The zero-based index position of if that character is found, or -1 if it is not. - - 1. - - This method begins searching at the last character position of this instance and proceeds backward toward the beginning until either `value` is found or the first character position has been examined. The search is case-sensitive. - - This method performs an ordinal (culture-insensitive) search, where a character is considered equivalent to another character only if their Unicode scalar values are the same. To perform a culture-sensitive search, use the method, where a Unicode scalar value representing a precomposed character, such as the ligature "Æ" (U+00C6), might be considered equivalent to any occurrence of the character's components in the correct sequence, such as "AE" (U+0041, U+0045), depending on the culture. - -## Examples - The following example defines an `ExtractFilename` method that uses the method to find the last directory separator character in a string and to extract the string's file name. If the file exists, the method returns the file name without its path. - - :::code language="csharp" source="~/snippets/csharp/System/String/LastIndexOf/LastIndexOf_Example.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/LastIndexOf/LastIndexOf_Example.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.LastIndexOf/vb/LastIndexOf_Example.vb" id="Snippet1"::: - + - 1. + + This method begins searching at the last character position of this instance and proceeds backward toward the beginning until either `value` is found or the first character position has been examined. The search is case-sensitive. + + This method performs an ordinal (culture-insensitive) search, where a character is considered equivalent to another character only if their Unicode scalar values are the same. To perform a culture-sensitive search, use the method, where a Unicode scalar value representing a precomposed character, such as the ligature "Æ" (U+00C6), might be considered equivalent to any occurrence of the character's components in the correct sequence, such as "AE" (U+0041, U+0045), depending on the culture. + +## Examples + The following example defines an `ExtractFilename` method that uses the method to find the last directory separator character in a string and to extract the string's file name. If the file exists, the method returns the file name without its path. + + :::code language="csharp" source="~/snippets/csharp/System/String/LastIndexOf/LastIndexOf_Example.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/LastIndexOf/LastIndexOf_Example.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.LastIndexOf/vb/LastIndexOf_Example.vb" id="Snippet1"::: + ]]> @@ -10471,31 +10545,31 @@ A string is empty if it is explicitly assigned an empty string ("") or Reports the zero-based index position of the last occurrence of a specified string within this instance. The zero-based starting index position of if that string is found, or -1 if it is not. - - 1. - -The search begins at the last character position of this instance and proceeds backward toward the beginning until either `value` is found or the first character position has been examined. - -This method performs a word (case-sensitive and culture-sensitive) search using the current culture. - -Character sets include ignorable characters, which are characters that are not considered when performing a linguistic or culture-sensitive comparison. In a culture-sensitive search, if `value` contains an ignorable character, the result is equivalent to searching with that character removed. - -In the following example, the method is used to find two substrings (a soft hyphen followed by "n" and a soft hyphen followed by "m") in two strings. Only one of the strings contains a soft hyphen. If the example is run on .NET Framework 4 or later, in each case, because the soft hyphen is an ignorable character, the result is the same as if the soft hyphen had not been included in `value`. - - :::code language="csharp" source="~/snippets/csharp/System/String/LastIndexOf/lastindexof21.cs" id="Snippet21"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/LastIndexOf/lastindexof21.fs" id="Snippet21"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.LastIndexOf/vb/lastindexof21.vb" id="Snippet21"::: - -## Examples - The following example removes opening and closing HTML tags from a string if the tags begin and end the string. If a string ends with a closing bracket character (">"), the example uses the method to locate the start of the end tag. - - :::code language="csharp" source="~/snippets/csharp/System/String/LastIndexOf/lastindexof_example2.cs" id="Snippet2"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/LastIndexOf/lastindexof_example2.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.LastIndexOf/vb/lastindexof_example2.vb" id="Snippet2"::: - + - 1. + +The search begins at the last character position of this instance and proceeds backward toward the beginning until either `value` is found or the first character position has been examined. + +This method performs a word (case-sensitive and culture-sensitive) search using the current culture. + +Character sets include ignorable characters, which are characters that are not considered when performing a linguistic or culture-sensitive comparison. In a culture-sensitive search, if `value` contains an ignorable character, the result is equivalent to searching with that character removed. + +In the following example, the method is used to find two substrings (a soft hyphen followed by "n" and a soft hyphen followed by "m") in two strings. Only one of the strings contains a soft hyphen. If the example is run on .NET Framework 4 or later, in each case, because the soft hyphen is an ignorable character, the result is the same as if the soft hyphen had not been included in `value`. + + :::code language="csharp" source="~/snippets/csharp/System/String/LastIndexOf/lastindexof21.cs" id="Snippet21"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/LastIndexOf/lastindexof21.fs" id="Snippet21"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.LastIndexOf/vb/lastindexof21.vb" id="Snippet21"::: + +## Examples + The following example removes opening and closing HTML tags from a string if the tags begin and end the string. If a string ends with a closing bracket character (">"), the example uses the method to locate the start of the end tag. + + :::code language="csharp" source="~/snippets/csharp/System/String/LastIndexOf/lastindexof_example2.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/LastIndexOf/lastindexof_example2.fs" id="Snippet2"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.LastIndexOf/vb/lastindexof_example2.vb" id="Snippet2"::: + ]]> @@ -10556,21 +10630,21 @@ In the following example, the Reports the zero-based index position of the last occurrence of a specified Unicode character within this instance. The search starts at a specified character position and proceeds backward toward the beginning of the string. The zero-based index position of if that character is found, or -1 if it is not found or if the current instance equals . - - 1. This method begins searching at the `startIndex` character position of this instance and proceeds backward toward the beginning of the current instance until either `value` is found or the first character position has been examined. For example, if `startIndex` is - 1, the method searches every character from the last character in the string to the beginning. The search is case-sensitive. - - This method performs an ordinal (culture-insensitive) search, where a character is considered equivalent to another character only if their Unicode scalar values are the same. To perform a culture-sensitive search, use the method, where a Unicode scalar value representing a precomposed character, such as the ligature "Æ" (U+00C6), might be considered equivalent to any occurrence of the character's components in the correct sequence, such as "AE" (U+0041, U+0045), depending on the culture. - -## Examples - The following example finds the index of all occurrences of a character in a string, working from the end of the string to the start of the string. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.lastindexof1/CPP/lastixof1.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/LastIndexOf/lastixof1.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/LastIndexOf/lastixof1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.lastindexof1/VB/lastixof1.vb" id="Snippet1"::: - + - 1. This method begins searching at the `startIndex` character position of this instance and proceeds backward toward the beginning of the current instance until either `value` is found or the first character position has been examined. For example, if `startIndex` is - 1, the method searches every character from the last character in the string to the beginning. The search is case-sensitive. + + This method performs an ordinal (culture-insensitive) search, where a character is considered equivalent to another character only if their Unicode scalar values are the same. To perform a culture-sensitive search, use the method, where a Unicode scalar value representing a precomposed character, such as the ligature "Æ" (U+00C6), might be considered equivalent to any occurrence of the character's components in the correct sequence, such as "AE" (U+0041, U+0045), depending on the culture. + +## Examples + The following example finds the index of all occurrences of a character in a string, working from the end of the string to the start of the string. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.lastindexof1/CPP/lastixof1.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/LastIndexOf/lastixof1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/LastIndexOf/lastixof1.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.lastindexof1/VB/lastixof1.vb" id="Snippet1"::: + ]]> The current instance does not equal , and is less than zero or greater than or equal to the length of this instance. @@ -10628,38 +10702,38 @@ In the following example, the Reports the zero-based index position of the last occurrence of a specified string within this instance. The search starts at a specified character position and proceeds backward toward the beginning of the string. The zero-based starting index position of if that string is found, or -1 if it is not found or if the current instance equals . - - 1. - - The search begins at the `startIndex` character position of this instance and proceeds backward toward the beginning until either `value` is found or the first character position has been examined. For example, if `startIndex` is - 1, the method searches every character from the last character in the string to the beginning. - - This method performs a word (case-sensitive and culture-sensitive) search using the current culture. - - Character sets include ignorable characters, which are characters that are not considered when performing a linguistic or culture-sensitive comparison. In a culture-sensitive search, if `value` contains an ignorable character, the result is equivalent to searching with that character removed. In the following example, the method is used to find a substring that includes a soft hyphen (U+00AD) and that precedes or includes the final "m" in a string. If the example is run on .NET Framework 4 or later, because the soft hyphen in the search string is ignored, calling the method to find a substring that consists of the soft hyphen and "m" returns the position of the "m" in the string, whereas calling it to find a substring that consists of the soft hyphen and "n" returns the position of the "n". - - :::code language="csharp" source="~/snippets/csharp/System/String/LastIndexOf/lastindexof22.cs" id="Snippet22"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/LastIndexOf/lastindexof22.fs" id="Snippet22"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.LastIndexOf/vb/lastindexof22.vb" id="Snippet22"::: - -## Examples - The following example finds the index of all occurrences of a string in target string, working from the end of the target string to the start of the target string. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.LastIndexOf7/CPP/lastixof7.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/LastIndexOf/lastixof7.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/LastIndexOf/lastixof7.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.LastIndexOf7/VB/lastixof7.vb" id="Snippet1"::: - + - 1. + + The search begins at the `startIndex` character position of this instance and proceeds backward toward the beginning until either `value` is found or the first character position has been examined. For example, if `startIndex` is - 1, the method searches every character from the last character in the string to the beginning. + + This method performs a word (case-sensitive and culture-sensitive) search using the current culture. + + Character sets include ignorable characters, which are characters that are not considered when performing a linguistic or culture-sensitive comparison. In a culture-sensitive search, if `value` contains an ignorable character, the result is equivalent to searching with that character removed. In the following example, the method is used to find a substring that includes a soft hyphen (U+00AD) and that precedes or includes the final "m" in a string. If the example is run on .NET Framework 4 or later, because the soft hyphen in the search string is ignored, calling the method to find a substring that consists of the soft hyphen and "m" returns the position of the "m" in the string, whereas calling it to find a substring that consists of the soft hyphen and "n" returns the position of the "n". + + :::code language="csharp" source="~/snippets/csharp/System/String/LastIndexOf/lastindexof22.cs" id="Snippet22"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/LastIndexOf/lastindexof22.fs" id="Snippet22"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.LastIndexOf/vb/lastindexof22.vb" id="Snippet22"::: + +## Examples + The following example finds the index of all occurrences of a string in target string, working from the end of the target string to the start of the target string. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.LastIndexOf7/CPP/lastixof7.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/LastIndexOf/lastixof7.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/LastIndexOf/lastixof7.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.LastIndexOf7/VB/lastixof7.vb" id="Snippet1"::: + ]]> is . - The current instance does not equal , and is less than zero or greater than the length of the current instance. - - -or- - - The current instance equals , and is less than -1 or greater than zero. + The current instance does not equal , and is less than zero or greater than the length of the current instance. + +-or- + +The current instance equals , and is less than -1 or greater than zero. As explained in [Best Practices for Using Strings](/dotnet/standard/base-types/best-practices-strings), we recommend that you avoid calling string comparison methods that substitute default values and instead call methods that require parameters to be explicitly specified. To find the index of a substring that precedes a particular character position by using the comparison rules of the current culture, signal your intention explicitly by calling the method overload with a value of for its parameter. If you don't need linguistic-aware comparison, consider using . @@ -10725,27 +10799,27 @@ In the following example, the Reports the zero-based index of the last occurrence of a specified string within the current object. A parameter specifies the type of search to use for the specified string. The zero-based starting index position of the parameter if that string is found, or -1 if it is not. - - 1. - -The `comparisonType` parameter specifies to search for the `value` parameter using: - -- The current or invariant culture. -- A case-sensitive or case-insensitive search. -- Word or ordinal comparison rules. - -The search begins at the last character position of this instance and proceeds backward toward the beginning until either `value` is found or the first character position has been examined. - -## Examples - The following example demonstrates three overloads of the method that find the last occurrence of a string within another string using different values of the enumeration. - - :::code language="csharp" source="~/snippets/csharp/System/String/LastIndexOf/liocmp.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/LastIndexOf/liocmp.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.LastIndexOfCmp/vb/liocmp.vb" id="Snippet1"::: - + - 1. + +The `comparisonType` parameter specifies to search for the `value` parameter using: + +- The current or invariant culture. +- A case-sensitive or case-insensitive search. +- Word or ordinal comparison rules. + +The search begins at the last character position of this instance and proceeds backward toward the beginning until either `value` is found or the first character position has been examined. + +## Examples + The following example demonstrates three overloads of the method that find the last occurrence of a string within another string using different values of the enumeration. + + :::code language="csharp" source="~/snippets/csharp/System/String/LastIndexOf/liocmp.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/LastIndexOf/liocmp.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.LastIndexOfCmp/vb/liocmp.vb" id="Snippet1"::: + ]]> @@ -10753,13 +10827,7 @@ The search begins at the last character position of this instance and proceeds b is not a valid value. - Character sets include ignorable characters, which are characters that are not considered when performing a linguistic or culture-sensitive comparison. In a culture-sensitive search (that is, if is not or ), if contains an ignorable character, the result is equivalent to searching with that character removed. - - In the following example, the method is used to find two substrings (a soft hyphen followed by "n", and a soft hyphen followed by "m") in two strings. Only one of the strings contains a soft hyphen. If the example is run on .NET Framework 4 or later, because the soft hyphen is an ignorable character, a culture-sensitive search returns the same value that it would return if the soft hyphen were not included in the search string. An ordinal search, however, successfully finds the soft hyphen in one string and reports that it is absent from the second string. - - :::code language="csharp" source="~/snippets/csharp/System/String/LastIndexOf/lastindexof26.cs" id="Snippet26"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/LastIndexOf/lastindexof26.fs" id="Snippet26"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.LastIndexOf/vb/lastindexof26.vb" id="Snippet26"::: + Character sets include ignorable characters, which are characters that are not considered when performing a linguistic or culture-sensitive comparison. In a culture-sensitive search (that is, if is not or ), if contains an ignorable character, the result is equivalent to searching with that character removed. In the following example, the method is used to find two substrings (a soft hyphen followed by "n", and a soft hyphen followed by "m") in two strings. Only one of the strings contains a soft hyphen. If the example is run on .NET Framework 4 or later, because the soft hyphen is an ignorable character, a culture-sensitive search returns the same value that it would return if the soft hyphen were not included in the search string. An ordinal search, however, successfully finds the soft hyphen in one string and reports that it is absent from the second string. :::code language="csharp" source="~/snippets/csharp/System/String/LastIndexOf/lastindexof26.cs" id="Snippet26"::: :::code language="fsharp" source="~/snippets/fsharp/System/String/LastIndexOf/lastindexof26.fs" id="Snippet26"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.LastIndexOf/vb/lastindexof26.vb" id="Snippet26"::: @@ -10818,30 +10886,30 @@ The search begins at the last character position of this instance and proceeds b Reports the zero-based index position of the last occurrence of the specified Unicode character in a substring within this instance. The search starts at a specified character position and proceeds backward toward the beginning of the string for a specified number of character positions. The zero-based index position of if that character is found, or -1 if it is not found or if the current instance equals . - - 1. - - This method begins searching at the `startIndex` character position and proceeds backward toward the beginning of this instance until either `value` is found or `count` character positions have been examined. For example, if `startIndex` is - 1, the method searches backward `count` characters from the last character in the string. The search is case-sensitive. - - This method performs an ordinal (culture-insensitive) search, where a character is considered equivalent to another character only if their Unicode scalar value are the same. To perform a culture-sensitive search, use the method, where a Unicode scalar value representing a precomposed character, such as the ligature "Æ" (U+00C6), might be considered equivalent to any occurrence of the character's components in the correct sequence, such as "AE" (U+0041, U+0045), depending on the culture. - -## Examples - The following example finds the index of all occurrences of a character in a substring, working from the end of the substring to the start of the substring. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.lastindexof2/CPP/lastixof2.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/LastIndexOf/lastixof2.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/LastIndexOf/lastixof2.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.lastindexof2/VB/lastixof2.vb" id="Snippet1"::: - + - 1. + + This method begins searching at the `startIndex` character position and proceeds backward toward the beginning of this instance until either `value` is found or `count` character positions have been examined. For example, if `startIndex` is - 1, the method searches backward `count` characters from the last character in the string. The search is case-sensitive. + + This method performs an ordinal (culture-insensitive) search, where a character is considered equivalent to another character only if their Unicode scalar value are the same. To perform a culture-sensitive search, use the method, where a Unicode scalar value representing a precomposed character, such as the ligature "Æ" (U+00C6), might be considered equivalent to any occurrence of the character's components in the correct sequence, such as "AE" (U+0041, U+0045), depending on the culture. + +## Examples + The following example finds the index of all occurrences of a character in a substring, working from the end of the substring to the start of the substring. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.lastindexof2/CPP/lastixof2.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/LastIndexOf/lastixof2.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/LastIndexOf/lastixof2.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.lastindexof2/VB/lastixof2.vb" id="Snippet1"::: + ]]> - The current instance does not equal , and is less than zero or greater than or equal to the length of this instance. - - -or- - - The current instance does not equal , and - + 1 is less than zero. + The current instance does not equal , and is less than zero or greater than or equal to the length of this instance. + +-or- + +The current instance does not equal , and - + 1 is less than zero. @@ -10898,57 +10966,57 @@ The search begins at the last character position of this instance and proceeds b Reports the zero-based index position of the last occurrence of a specified string within this instance. The search starts at a specified character position and proceeds backward toward the beginning of the string for a specified number of character positions. The zero-based starting index position of if that string is found, or -1 if it is not found or if the current instance equals . - - 1. - - The search begins at the `startIndex` character position of this instance and proceeds backward toward the beginning until either `value` is found or `count` character positions have been examined. For example, if `startIndex` is - 1, the method searches backward `count` characters from the last character in the string. - - This method performs a word (case-sensitive and culture-sensitive) search using the current culture. - - Character sets include ignorable characters, which are characters that are not considered when performing a linguistic or culture-sensitive comparison. In a culture-sensitive search, if `value` contains an ignorable character, the result is equivalent to searching with that character removed. - -In the following example, the method is used to find the position of a soft hyphen (U+00AD) followed by an "m" or "n" in two strings. Only one of the strings contains a soft hyphen. In the case of the string that includes the soft hyphen followed by an "m", `LastIndexOf` returns the index of the "m" when searching for the soft hyphen followed by "m". - - :::code language="csharp" source="~/snippets/csharp/System/String/LastIndexOf/lastindexof23.cs" id="Snippet23"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/LastIndexOf/lastindexof23.fs" id="Snippet23"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.LastIndexOf/vb/lastindexof23.vb" id="Snippet23"::: - -## Examples - The following example finds the index of all occurrences of a string in substring, working from the end of the substring to the start of the substring. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.LastIndexOf8/CPP/lastixof8.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/LastIndexOf/lastixof8.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/LastIndexOf/lastixof8.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.LastIndexOf8/VB/lastixof8.vb" id="Snippet1"::: - + - 1. + + The search begins at the `startIndex` character position of this instance and proceeds backward toward the beginning until either `value` is found or `count` character positions have been examined. For example, if `startIndex` is - 1, the method searches backward `count` characters from the last character in the string. + + This method performs a word (case-sensitive and culture-sensitive) search using the current culture. + + Character sets include ignorable characters, which are characters that are not considered when performing a linguistic or culture-sensitive comparison. In a culture-sensitive search, if `value` contains an ignorable character, the result is equivalent to searching with that character removed. + +In the following example, the method is used to find the position of a soft hyphen (U+00AD) followed by an "m" or "n" in two strings. Only one of the strings contains a soft hyphen. In the case of the string that includes the soft hyphen followed by an "m", `LastIndexOf` returns the index of the "m" when searching for the soft hyphen followed by "m". + + :::code language="csharp" source="~/snippets/csharp/System/String/LastIndexOf/lastindexof23.cs" id="Snippet23"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/LastIndexOf/lastindexof23.fs" id="Snippet23"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.LastIndexOf/vb/lastindexof23.vb" id="Snippet23"::: + +## Examples + The following example finds the index of all occurrences of a string in substring, working from the end of the substring to the start of the substring. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.LastIndexOf8/CPP/lastixof8.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/LastIndexOf/lastixof8.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/LastIndexOf/lastixof8.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.LastIndexOf8/VB/lastixof8.vb" id="Snippet1"::: + ]]> is . - is negative. - - -or- - - The current instance does not equal , and is negative. - - -or- - - The current instance does not equal , and is greater than the length of this instance. - - -or- - - The current instance does not equal , and - + 1 specifies a position that is not within this instance. - - -or- - - The current instance equals and is less than -1 or greater than zero. - - -or- - - The current instance equals and is greater than 1. + is negative. + +-or- + +The current instance does not equal , and is negative. + +-or- + +The current instance does not equal , and is greater than the length of this instance. + +-or- + +The current instance does not equal , and - + 1 specifies a position that is not within this instance. + +-or- + +The current instance equals and is less than -1 or greater than zero. + +-or- + +The current instance equals and is greater than 1. As explained in [Best Practices for Using Strings](/dotnet/standard/base-types/best-practices-strings), we recommend that you avoid calling string comparison methods that substitute default values and instead call methods that require parameters to be explicitly specified. To perform this operation by using the comparison rules of the current culture, signal your intention explicitly by calling the method overload with a value of for its parameter. If you don't need linguistic-aware comparison, consider using . @@ -11006,41 +11074,35 @@ In the following example, the method is used Reports the zero-based index of the last occurrence of a specified string within the current object. The search starts at a specified character position and proceeds backward toward the beginning of the string. A parameter specifies the type of comparison to perform when searching for the specified string. The zero-based starting index position of the parameter if that string is found, or -1 if it is not found or if the current instance equals . - - 1. - - The search begins at the `startIndex` character position and proceeds backward until either `value` is found or the first character position has been examined. For example, if `startIndex` is - 1, the method searches every character from the last character in the string to the beginning. - - The `comparisonType` parameter specifies to search for the `value` parameter using the current or invariant culture, using a case-sensitive or case-insensitive search, and using word or ordinal comparison rules. - -## Examples - The following example demonstrates three overloads of the method that find the last occurrence of a string within another string using different values of the enumeration. - - :::code language="csharp" source="~/snippets/csharp/System/String/LastIndexOf/liocmp.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/LastIndexOf/liocmp.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.LastIndexOfCmp/vb/liocmp.vb" id="Snippet1"::: - + - 1. + + The search begins at the `startIndex` character position and proceeds backward until either `value` is found or the first character position has been examined. For example, if `startIndex` is - 1, the method searches every character from the last character in the string to the beginning. + + The `comparisonType` parameter specifies to search for the `value` parameter using the current or invariant culture, using a case-sensitive or case-insensitive search, and using word or ordinal comparison rules. + +## Examples + The following example demonstrates three overloads of the method that find the last occurrence of a string within another string using different values of the enumeration. + + :::code language="csharp" source="~/snippets/csharp/System/String/LastIndexOf/liocmp.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/LastIndexOf/liocmp.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.LastIndexOfCmp/vb/liocmp.vb" id="Snippet1"::: + ]]> is . - The current instance does not equal , and is less than zero or greater than the length of the current instance. - - -or- - - The current instance equals , and is less than -1 or greater than zero. + The current instance does not equal , and is less than zero or greater than the length of the current instance. + +-or- + +The current instance equals , and is less than -1 or greater than zero. is not a valid value. - Character sets include ignorable characters, which are characters that are not considered when performing a linguistic or culture-sensitive comparison. In a culture-sensitive search (that is, if is not or ), if contains an ignorable character, the result is equivalent to searching with that character removed. - - In the following example, the method is used to find the position of a soft hyphen (U+00AD) followed by an "m", starting with the final "m" in two strings. Only one of the strings contains the required substring. If the example is run on .NET Framework 4 or later, in both cases, because the soft hyphen is an ignorable character, the method returns the index of "m" in the string when it performs a culture-sensitive comparison. Note that in the case of the first string, which includes the soft hyphen followed by an "m", the method returns the index of the "m" and not the index of the soft hyphen. The method returns the index of the soft hyphen in the first string only when it performs an ordinal comparison. - - :::code language="csharp" source="~/snippets/csharp/System/String/LastIndexOf/lastindexof25.cs" id="Snippet25"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/LastIndexOf/lastindexof25.fs" id="Snippet25"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.LastIndexOf/vb/lastindexof25.vb" id="Snippet25"::: + Character sets include ignorable characters, which are characters that are not considered when performing a linguistic or culture-sensitive comparison. In a culture-sensitive search (that is, if is not or ), if contains an ignorable character, the result is equivalent to searching with that character removed. In the following example, the method is used to find the position of a soft hyphen (U+00AD) followed by an "m", starting with the final "m" in two strings. Only one of the strings contains the required substring. If the example is run on .NET Framework 4 or later, in both cases, because the soft hyphen is an ignorable character, the method returns the index of "m" in the string when it performs a culture-sensitive comparison. Note that in the case of the first string, which includes the soft hyphen followed by an "m", the method returns the index of the "m" and not the index of the soft hyphen. The method returns the index of the soft hyphen in the first string only when it performs an ordinal comparison. :::code language="csharp" source="~/snippets/csharp/System/String/LastIndexOf/lastindexof25.cs" id="Snippet25"::: :::code language="fsharp" source="~/snippets/fsharp/System/String/LastIndexOf/lastindexof25.fs" id="Snippet25"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.LastIndexOf/vb/lastindexof25.vb" id="Snippet25"::: @@ -11100,62 +11162,56 @@ In the following example, the method is used Reports the zero-based index position of the last occurrence of a specified string within this instance. The search starts at a specified character position and proceeds backward toward the beginning of the string for the specified number of character positions. A parameter specifies the type of comparison to perform when searching for the specified string. The zero-based starting index position of the parameter if that string is found, or -1 if it is not found or if the current instance equals . - - 1. - - The search begins at the `startIndex` character position and proceeds backward until either `value` is found or `count` character positions have been examined. For example, if `startIndex` is - 1, the method searches backward `count` characters from the last character in the string. - - The `comparisonType` parameter specifies to search for the `value` parameter using: - -- The current or invariant culture. -- A case-sensitive or case-insensitive search. -- Word or ordinal comparison rules. - -## Examples - The following example demonstrates three overloads of the method that find the last occurrence of a string within another string using different values of the enumeration. - - :::code language="csharp" source="~/snippets/csharp/System/String/LastIndexOf/liocmp.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/LastIndexOf/liocmp.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.LastIndexOfCmp/vb/liocmp.vb" id="Snippet1"::: - + - 1. + + The search begins at the `startIndex` character position and proceeds backward until either `value` is found or `count` character positions have been examined. For example, if `startIndex` is - 1, the method searches backward `count` characters from the last character in the string. + + The `comparisonType` parameter specifies to search for the `value` parameter using: + +- The current or invariant culture. +- A case-sensitive or case-insensitive search. +- Word or ordinal comparison rules. + +## Examples + The following example demonstrates three overloads of the method that find the last occurrence of a string within another string using different values of the enumeration. + + :::code language="csharp" source="~/snippets/csharp/System/String/LastIndexOf/liocmp.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/LastIndexOf/liocmp.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.LastIndexOfCmp/vb/liocmp.vb" id="Snippet1"::: + ]]> is . - is negative. - - -or- - - The current instance does not equal , and is negative. - - -or- - - The current instance does not equal , and is greater than the length of this instance. - - -or- - - The current instance does not equal , and + 1 - specifies a position that is not within this instance. - - -or- - - The current instance equals and is less than -1 or greater than zero. - - -or- - - The current instance equals and is greater than 1. + is negative. + +-or- + +The current instance does not equal , and is negative. + +-or- + +The current instance does not equal , and is greater than the length of this instance. + +-or- + +The current instance does not equal , and + 1 - specifies a position that is not within this instance. + +-or- + +The current instance equals and is less than -1 or greater than zero. + +-or- + +The current instance equals and is greater than 1. is not a valid value. - Character sets include ignorable characters, which are characters that are not considered when performing a linguistic or culture-sensitive comparison. In a culture-sensitive search (that is, if is not or ), if contains an ignorable character, the result is equivalent to searching with that character removed. - - In the following example, the method is used to find the position of a soft hyphen (U+00AD) followed by an "m" in all but the first character position before the final "m" in two strings. Only one of the strings contains the required substring. If the example is run on .NET Framework 4 or later, in both cases, because the soft hyphen is an ignorable character, the method returns the index of "m" in the string when it performs a culture-sensitive comparison. When it performs an ordinal comparison, however, it finds the substring only in the first string. Note that in the case of the first string, which includes the soft hyphen followed by an "m", the method returns the index of the "m" when it performs a culture-sensitive comparison. The method returns the index of the soft hyphen in the first string only when it performs an ordinal comparison. - - :::code language="csharp" source="~/snippets/csharp/System/String/LastIndexOf/lastindexof24.cs" id="Snippet24"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/LastIndexOf/lastindexof24.fs" id="Snippet24"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.LastIndexOf/vb/lastindexof24.vb" id="Snippet24"::: + Character sets include ignorable characters, which are characters that are not considered when performing a linguistic or culture-sensitive comparison. In a culture-sensitive search (that is, if is not or ), if contains an ignorable character, the result is equivalent to searching with that character removed. In the following example, the method is used to find the position of a soft hyphen (U+00AD) followed by an "m" in all but the first character position before the final "m" in two strings. Only one of the strings contains the required substring. If the example is run on .NET Framework 4 or later, in both cases, because the soft hyphen is an ignorable character, the method returns the index of "m" in the string when it performs a culture-sensitive comparison. When it performs an ordinal comparison, however, it finds the substring only in the first string. Note that in the case of the first string, which includes the soft hyphen followed by an "m", the method returns the index of the "m" when it performs a culture-sensitive comparison. The method returns the index of the soft hyphen in the first string only when it performs an ordinal comparison. :::code language="csharp" source="~/snippets/csharp/System/String/LastIndexOf/lastindexof24.cs" id="Snippet24"::: :::code language="fsharp" source="~/snippets/fsharp/System/String/LastIndexOf/lastindexof24.fs" id="Snippet24"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.LastIndexOf/vb/lastindexof24.vb" id="Snippet24"::: @@ -11217,23 +11273,23 @@ In the following example, the method is used Reports the zero-based index position of the last occurrence in this instance of one or more characters specified in a Unicode array. The index position of the last occurrence in this instance where any character in was found; -1 if no character in was found. - method, where a Unicode scalar value representing a precomposed character, such as the ligature "Æ" (U+00C6), might be considered equivalent to any occurrence of the character's components in the correct sequence, such as "AE" (U+0041, U+0045), depending on the culture. - -## Examples - The following example finds the index of the last occurrence of any character in the string "is" within another string. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.LastIndexOfAny1/CPP/lastixany1.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/LastIndexOfAny/lastixany1.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/LastIndexOfAny/lastixany1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.LastIndexOfAny1/VB/lastixany1.vb" id="Snippet1"::: - + method, where a Unicode scalar value representing a precomposed character, such as the ligature "Æ" (U+00C6), might be considered equivalent to any occurrence of the character's components in the correct sequence, such as "AE" (U+0041, U+0045), depending on the culture. + +## Examples + The following example finds the index of the last occurrence of any character in the string "is" within another string. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.LastIndexOfAny1/CPP/lastixany1.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/LastIndexOfAny/lastixany1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/LastIndexOfAny/lastixany1.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.LastIndexOfAny1/VB/lastixany1.vb" id="Snippet1"::: + ]]> @@ -11293,23 +11349,23 @@ In the following example, the method is used Reports the zero-based index position of the last occurrence in this instance of one or more characters specified in a Unicode array. The search starts at a specified character position and proceeds backward toward the beginning of the string. The index position of the last occurrence in this instance where any character in was found; -1 if no character in was found or if the current instance equals . - method, where a Unicode scalar value representing a precomposed character, such as the ligature "Æ" (U+00C6), might be considered equivalent to any occurrence of the character's components in the correct sequence, such as "AE" (U+0041, U+0045), depending on the culture. - -## Examples - The following example finds the index of the last occurrence of any character in the string "is" within a substring of another string. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.LastIndexOfAny2/CPP/lastixany2.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/LastIndexOfAny/lastixany2.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/LastIndexOfAny/lastixany2.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.LastIndexOfAny2/VB/lastixany2.vb" id="Snippet1"::: - + method, where a Unicode scalar value representing a precomposed character, such as the ligature "Æ" (U+00C6), might be considered equivalent to any occurrence of the character's components in the correct sequence, such as "AE" (U+0041, U+0045), depending on the culture. + +## Examples + The following example finds the index of the last occurrence of any character in the string "is" within a substring of another string. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.LastIndexOfAny2/CPP/lastixany2.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/LastIndexOfAny/lastixany2.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/LastIndexOfAny/lastixany2.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.LastIndexOfAny2/VB/lastixany2.vb" id="Snippet1"::: + ]]> @@ -11378,32 +11434,32 @@ In the following example, the method is used Reports the zero-based index position of the last occurrence in this instance of one or more characters specified in a Unicode array. The search starts at a specified character position and proceeds backward toward the beginning of the string for a specified number of character positions. The index position of the last occurrence in this instance where any character in was found; -1 if no character in was found or if the current instance equals . - method, where a Unicode scalar value representing a precomposed character, such as the ligature "Æ" (U+00C6), might be considered equivalent to any occurrence of the character's components in the correct sequence, such as "AE" (U+0041, U+0045), depending on the culture. - -## Examples - The following example finds the index of the last occurrence of any character in the string "aid" within a substring of another string. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.LastIndexOfAny3/CPP/lastixany3.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/LastIndexOfAny/lastixany3.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/LastIndexOfAny/lastixany3.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.LastIndexOfAny3/VB/lastixany3.vb" id="Snippet1"::: - + method, where a Unicode scalar value representing a precomposed character, such as the ligature "Æ" (U+00C6), might be considered equivalent to any occurrence of the character's components in the correct sequence, such as "AE" (U+0041, U+0045), depending on the culture. + +## Examples + The following example finds the index of the last occurrence of any character in the string "aid" within a substring of another string. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.LastIndexOfAny3/CPP/lastixany3.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/LastIndexOfAny/lastixany3.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/LastIndexOfAny/lastixany3.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.LastIndexOfAny3/VB/lastixany3.vb" id="Snippet1"::: + ]]> is . - The current instance does not equal , and or is negative. - - -or- - - The current instance does not equal , and minus + 1 is less than zero. + The current instance does not equal , and or is negative. + +-or- + +The current instance does not equal , and minus + 1 is less than zero. @@ -11459,26 +11515,26 @@ In the following example, the method is used Gets the number of characters in the current object. The number of characters in the current string. - property returns the number of objects in this instance, not the number of Unicode characters. The reason is that a Unicode character might be represented by more than one . Use the class to work with each Unicode character instead of each . - - In some languages, such as C and C++, a null character indicates the end of a string. In .NET, a null character can be embedded in a string. When a string includes one or more null characters, they are included in the length of the total string. For example, in the following string, the substrings "abc" and "def" are separated by a null character. The property returns 7, which indicates that it includes the six alphabetic characters as well as the null character. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Class/cpp/system.string.class.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Overview/System.String.Class.cs" interactive="try-dotnet-method" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Overview/System.String.Class.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Class/vb/System.String.Class.vb" id="Snippet1"::: - -## Examples - The following example demonstrates the property. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.length/CPP/length.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Length/length.cs" interactive="try-dotnet-method" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Length/length.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.length/VB/length.vb" id="Snippet1"::: - + property returns the number of objects in this instance, not the number of Unicode characters. The reason is that a Unicode character might be represented by more than one . Use the class to work with each Unicode character instead of each . + + In some languages, such as C and C++, a null character indicates the end of a string. In .NET, a null character can be embedded in a string. When a string includes one or more null characters, they are included in the length of the total string. For example, in the following string, the substrings "abc" and "def" are separated by a null character. The property returns 7, which indicates that it includes the six alphabetic characters as well as the null character. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Class/cpp/system.string.class.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Overview/System.String.Class.cs" interactive="try-dotnet-method" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Overview/System.String.Class.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Class/vb/System.String.Class.vb" id="Snippet1"::: + +## Examples + The following example demonstrates the property. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.length/CPP/length.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Length/length.cs" interactive="try-dotnet-method" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Length/length.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.length/VB/length.vb" id="Snippet1"::: + ]]> @@ -11493,16 +11549,16 @@ In the following example, the method is used Returns a new string whose binary representation is in a particular Unicode normalization form. - @@ -11544,33 +11600,33 @@ In the following example, the method is used Returns a new string whose textual value is the same as this string, but whose binary representation is in Unicode normalization form C. A new, normalized string whose textual value is the same as this string, but whose binary representation is in normalization form C. - method to normalize the strings to normalization form C. - -3. To compare two strings, call a method that supports ordinal string comparison, such as the method, and supply a value of or as the argument. To sort an array of normalized strings, pass a `comparer` value of or to an appropriate overload of . - -4. Emit the strings in the sorted output based on the order indicated by the previous step. - - For a description of supported Unicode normalization forms, see . - + method to normalize the strings to normalization form C. + +3. To compare two strings, call a method that supports ordinal string comparison, such as the method, and supply a value of or as the argument. To sort an array of normalized strings, pass a `comparer` value of or to an appropriate overload of . + +4. Emit the strings in the sorted output based on the order indicated by the previous step. + + For a description of supported Unicode normalization forms, see . + ]]> The current instance contains invalid Unicode characters. @@ -11626,25 +11682,25 @@ In the following example, the method is used Returns a new string whose textual value is the same as this string, but whose binary representation is in the specified Unicode normalization form. A new string whose textual value is the same as this string, but whose binary representation is in the normalization form specified by the parameter. - method to normalize the strings to a specified normalization form. - -3. To compare two strings, call a method that supports ordinal string comparison, such as the method, and supply a value of or as the argument. To sort an array of normalized strings, pass a `comparer` value of or to an appropriate overload of . - -4. Emit the strings in the sorted output based on the order indicated by the previous step. - - For a description of supported Unicode normalization forms, see . - + method to normalize the strings to a specified normalization form. + +3. To compare two strings, call a method that supports ordinal string comparison, such as the method, and supply a value of or as the argument. To sort an array of normalized strings, pass a `comparer` value of or to an appropriate overload of . + +4. Emit the strings in the sorted output based on the order indicated by the previous step. + + For a description of supported Unicode normalization forms, see . + ]]> The current instance contains invalid Unicode characters. @@ -11713,21 +11769,21 @@ In the following example, the method is used if the value of is the same as the value of ; otherwise, . - method defines the operation of the equality operator for the class. It enables code such as that shown in the Example section. The operator, in turn, calls the static method, which performs an ordinal (case-sensitive and culture-insensitive) comparison. - -> [!NOTE] -> The Visual Basic compiler does not resolve the equality operator as a call to the method. Instead, the equality operator wraps a call to the method. - -## Examples - The following example demonstrates the equality operator. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Equality/CPP/equalityop.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/op_Equality/equalityop.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/op_Equality/equalityop.fs" id="Snippet1"::: - + method defines the operation of the equality operator for the class. It enables code such as that shown in the Example section. The operator, in turn, calls the static method, which performs an ordinal (case-sensitive and culture-insensitive) comparison. + +> [!NOTE] +> The Visual Basic compiler does not resolve the equality operator as a call to the method. Instead, the equality operator wraps a call to the method. + +## Examples + The following example demonstrates the equality operator. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Equality/CPP/equalityop.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/op_Equality/equalityop.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/op_Equality/equalityop.fs" id="Snippet1"::: + ]]> @@ -11842,23 +11898,23 @@ In the following example, the method is used if the value of is different from the value of ; otherwise, . - method defines the operation of the inequality operator for the class. It enables code such as that shown in the Examples section. - - The operator in turn calls the static method, which performs an ordinal (case-sensitive and culture-insensitive) comparison. - -> [!NOTE] -> The Visual Basic compiler does not resolve the inequality operator as a call to the method. Instead, the inequality operator wraps a call to the method. - -## Examples - The following example demonstrates the inequality operator. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Inequality/CPP/inequalityop.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/op_Inequality/inequalityop.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/op_Inequality/inequalityop.fs" id="Snippet1"::: - + method defines the operation of the inequality operator for the class. It enables code such as that shown in the Examples section. + + The operator in turn calls the static method, which performs an ordinal (case-sensitive and culture-insensitive) comparison. + +> [!NOTE] +> The Visual Basic compiler does not resolve the inequality operator as a call to the method. Instead, the inequality operator wraps a call to the method. + +## Examples + The following example demonstrates the inequality operator. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Inequality/CPP/inequalityop.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/op_Inequality/inequalityop.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/op_Inequality/inequalityop.fs" id="Snippet1"::: + ]]> @@ -11921,24 +11977,24 @@ In the following example, the method is used Returns a new string that right-aligns the characters in this instance by padding them with spaces on the left, for a specified total length. A new string that is equivalent to this instance, but right-aligned and padded on the left with as many spaces as needed to create a length of . However, if is less than the length of this instance, the method returns a reference to the existing instance. If is equal to the length of this instance, the method returns a new string that is identical to this instance. - method pads the beginning of the returned string. This means that, when used with right-to-left languages, it pads the right portion of the string. - -> [!NOTE] -> If the method pads the current instance with white-space characters, this method does not modify the value of the current instance. Instead, it returns a new string that is padded with leading white space so that its total length is `totalWidth` characters. - -## Examples - The following example demonstrates the method. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_Classic/classic String.PadLeft Example/CPP/source.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/PadLeft/source.cs" interactive="try-dotnet-method" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/PadLeft/source.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_Classic/classic String.PadLeft Example/VB/source.vb" id="Snippet1"::: - + method pads the beginning of the returned string. This means that, when used with right-to-left languages, it pads the right portion of the string. + +> [!NOTE] +> If the method pads the current instance with white-space characters, this method does not modify the value of the current instance. Instead, it returns a new string that is padded with leading white space so that its total length is `totalWidth` characters. + +## Examples + The following example demonstrates the method. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_Classic/classic String.PadLeft Example/CPP/source.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/PadLeft/source.cs" interactive="try-dotnet-method" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/PadLeft/source.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_Classic/classic String.PadLeft Example/VB/source.vb" id="Snippet1"::: + ]]> @@ -11995,22 +12051,22 @@ In the following example, the method is used Returns a new string that right-aligns the characters in this instance by padding them on the left with a specified Unicode character, for a specified total length. A new string that is equivalent to this instance, but right-aligned and padded on the left with as many characters as needed to create a length of . However, if is less than the length of this instance, the method returns a reference to the existing instance. If is equal to the length of this instance, the method returns a new string that is identical to this instance. - method pads the beginning of the returned string. This means that, when used with right-to-left languages, it pads the right portion of the string. - -> [!NOTE] -> If the method pads the current instance with white-space characters, this method does not modify the value of the current instance. Instead, it returns a new string that is padded with leading `paddingChar` characters so that its total length is `totalWidth` characters. - -## Examples - The following example demonstrates the method. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_Classic/classic String.PadLeft1 Example/CPP/source.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/PadLeft/source1.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/PadLeft/source1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_Classic/classic String.PadLeft1 Example/VB/source.vb" id="Snippet1"::: - + method pads the beginning of the returned string. This means that, when used with right-to-left languages, it pads the right portion of the string. + +> [!NOTE] +> If the method pads the current instance with white-space characters, this method does not modify the value of the current instance. Instead, it returns a new string that is padded with leading `paddingChar` characters so that its total length is `totalWidth` characters. + +## Examples + The following example demonstrates the method. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_Classic/classic String.PadLeft1 Example/CPP/source.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/PadLeft/source1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/PadLeft/source1.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_Classic/classic String.PadLeft1 Example/VB/source.vb" id="Snippet1"::: + ]]> @@ -12079,24 +12135,24 @@ In the following example, the method is used Returns a new string that left-aligns the characters in this string by padding them with spaces on the right, for a specified total length. A new string that is equivalent to this instance, but left-aligned and padded on the right with as many spaces as needed to create a length of . However, if is less than the length of this instance, the method returns a reference to the existing instance. If is equal to the length of this instance, the method returns a new string that is identical to this instance. - method pads the end of the returned string. This means that, when used with right-to-left languages, it pads the left portion of the string. - -> [!NOTE] -> If the method pads the current instance with white-space characters, this method does not modify the value of the current instance. Instead, it returns a new string that is padded with trailing white space so that its total length is `totalWidth` characters. - -## Examples - The following example demonstrates the method. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_Classic/classic String.PadRight Example/CPP/source.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/PadRight/source.cs" interactive="try-dotnet-method" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/PadRight/source.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_Classic/classic String.PadRight Example/VB/source.vb" id="Snippet1"::: - + method pads the end of the returned string. This means that, when used with right-to-left languages, it pads the left portion of the string. + +> [!NOTE] +> If the method pads the current instance with white-space characters, this method does not modify the value of the current instance. Instead, it returns a new string that is padded with trailing white space so that its total length is `totalWidth` characters. + +## Examples + The following example demonstrates the method. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_Classic/classic String.PadRight Example/CPP/source.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/PadRight/source.cs" interactive="try-dotnet-method" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/PadRight/source.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_Classic/classic String.PadRight Example/VB/source.vb" id="Snippet1"::: + ]]> @@ -12153,22 +12209,22 @@ In the following example, the method is used Returns a new string that left-aligns the characters in this string by padding them on the right with a specified Unicode character, for a specified total length. A new string that is equivalent to this instance, but left-aligned and padded on the right with as many characters as needed to create a length of . However, if is less than the length of this instance, the method returns a reference to the existing instance. If is equal to the length of this instance, the method returns a new string that is identical to this instance. - method pads the end of the returned string. This means that, when used with right-to-left languages, it pads the left portion of the string. - -> [!NOTE] -> If the method pads the current instance with white-space characters, this method does not modify the value of the current instance. Instead, it returns a new string that is padded with trailing `paddingChar` characters so that its total length is `totalWidth` characters. - -## Examples - The following example demonstrates the method. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_Classic/classic String.PadRight1 Example/CPP/source.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/PadRight/source1.cs" interactive="try-dotnet-method" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/PadRight/source1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_Classic/classic String.PadRight1 Example/VB/source.vb" id="Snippet1"::: - + method pads the end of the returned string. This means that, when used with right-to-left languages, it pads the left portion of the string. + +> [!NOTE] +> If the method pads the current instance with white-space characters, this method does not modify the value of the current instance. Instead, it returns a new string that is padded with trailing `paddingChar` characters so that its total length is `totalWidth` characters. + +## Examples + The following example demonstrates the method. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_Classic/classic String.PadRight1 Example/CPP/source.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/PadRight/source1.cs" interactive="try-dotnet-method" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/PadRight/source1.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_Classic/classic String.PadRight1 Example/VB/source.vb" id="Snippet1"::: + ]]> @@ -12236,30 +12292,30 @@ In the following example, the method is used Returns a new string in which all the characters in the current instance, beginning at a specified position and continuing through the last position, have been deleted. A new string that is equivalent to this string except for the removed characters. - [!NOTE] -> This method does not modify the value of the current instance. Instead, it returns a new string in which all characters from position `startIndex` to the end of the original string have been removed. - -## Examples - The following example demonstrates the method. The next-to-last case removes all text starting from the specified index through the end of the string. The last case removes three characters starting from the specified index. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.remove/CPP/r.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Remove/r.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Remove/r.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.remove/VB/r.vb" id="Snippet1"::: - + [!NOTE] +> This method does not modify the value of the current instance. Instead, it returns a new string in which all characters from position `startIndex` to the end of the original string have been removed. + +## Examples + The following example demonstrates the method. The next-to-last case removes all text starting from the specified index through the end of the string. The last case removes three characters starting from the specified index. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.remove/CPP/r.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Remove/r.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Remove/r.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.remove/VB/r.vb" id="Snippet1"::: + ]]> - is less than zero. - - -or- - - specifies a position that is not within this string. + is less than zero. + +-or- + + specifies a position that is not within this string. @@ -12323,29 +12379,29 @@ In the following example, the method is used Returns a new string in which a specified number of characters in the current instance beginning at a specified position have been deleted. A new string that is equivalent to this instance except for the removed characters. - [!NOTE] -> This method does not modify the value of the current instance. Instead, it returns a new string in which the number of characters specified by the `count` parameter have been removed. The characters are removed at the position specified by `startIndex`. - -## Examples - The following example demonstrates how you can remove the middle name from a complete name. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/stringremove/CPP/stringremove.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Remove/stringremove.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Remove/stringremove.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/stringremove/VB/stringremove.vb" id="Snippet1"::: - + [!NOTE] +> This method does not modify the value of the current instance. Instead, it returns a new string in which the number of characters specified by the `count` parameter have been removed. The characters are removed at the position specified by `startIndex`. + +## Examples + The following example demonstrates how you can remove the middle name from a complete name. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/stringremove/CPP/stringremove.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Remove/stringremove.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Remove/stringremove.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/stringremove/VB/stringremove.vb" id="Snippet1"::: + ]]> - Either or is less than zero. - - -or- - - plus specify a position outside this instance. + Either or is less than zero. + +-or- + + plus specify a position outside this instance. @@ -12422,28 +12478,28 @@ In the following example, the method is used Returns a new string in which all occurrences of a specified Unicode character in this instance are replaced with another specified Unicode character. A string that is equivalent to this instance except that all instances of are replaced with . If is not found in the current instance, the method returns the current instance unchanged. - [!NOTE] -> This method does not modify the value of the current instance. Instead, it returns a new string in which all occurrences of `oldChar` are replaced by `newChar`. - - Because this method returns the modified string, you can chain together successive calls to the method to perform multiple replacements on the original string. Method calls are executed from left to right. The following example provides an illustration. - - :::code language="csharp" source="~/snippets/csharp/System/String/Replace/replace2.cs" interactive="try-dotnet-method" id="Snippet2"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Replace/replace2.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.replace/vb/replace2.vb" id="Snippet2"::: - -## Examples - The following example creates a comma separated value list by substituting commas for the blanks between a series of numbers. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.replace1/CPP/string.replace1.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Replace/string.replace1.cs" interactive="try-dotnet-method" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Replace/string.replace1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.replace1/VB/string.replace1.vb" id="Snippet1"::: - + [!NOTE] +> This method does not modify the value of the current instance. Instead, it returns a new string in which all occurrences of `oldChar` are replaced by `newChar`. + + Because this method returns the modified string, you can chain together successive calls to the method to perform multiple replacements on the original string. Method calls are executed from left to right. The following example provides an illustration. + + :::code language="csharp" source="~/snippets/csharp/System/String/Replace/replace2.cs" interactive="try-dotnet-method" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Replace/replace2.fs" id="Snippet2"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.replace/vb/replace2.vb" id="Snippet2"::: + +## Examples + The following example creates a comma separated value list by substituting commas for the blanks between a series of numbers. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.replace1/CPP/string.replace1.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Replace/string.replace1.cs" interactive="try-dotnet-method" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Replace/string.replace1.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.replace1/VB/string.replace1.vb" id="Snippet1"::: + ]]> @@ -12521,30 +12577,30 @@ In the following example, the method is used Returns a new string in which all occurrences of a specified string in the current instance are replaced with another specified string. A string that is equivalent to the current string except that all instances of are replaced with . If is not found in the current instance, the method returns the current instance unchanged. - [!NOTE] -> This method does not modify the value of the current instance. Instead, it returns a new string in which all occurrences of `oldValue` are replaced by `newValue`. - - This method performs an ordinal (case-sensitive and culture-insensitive) search to find `oldValue`. - - Because this method returns the modified string, you can chain together successive calls to the method to perform multiple replacements on the original string. Method calls are executed from left to right. The following example provides an illustration. - - :::code language="csharp" source="~/snippets/csharp/System/String/Replace/replace1.cs" interactive="try-dotnet-method" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Replace/replace1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.replace/vb/replace1.vb" id="Snippet1"::: - -## Examples - The following example demonstrates how you can use the method to correct a spelling error. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/stringreplace/CPP/stringreplace.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Replace/stringreplace.cs" interactive="try-dotnet-method" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Replace/stringreplace.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/stringreplace/VB/stringreplace.vb" id="Snippet1"::: - + [!NOTE] +> This method does not modify the value of the current instance. Instead, it returns a new string in which all occurrences of `oldValue` are replaced by `newValue`. + + This method performs an ordinal (case-sensitive and culture-insensitive) search to find `oldValue`. + + Because this method returns the modified string, you can chain together successive calls to the method to perform multiple replacements on the original string. Method calls are executed from left to right. The following example provides an illustration. + + :::code language="csharp" source="~/snippets/csharp/System/String/Replace/replace1.cs" interactive="try-dotnet-method" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Replace/replace1.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.replace/vb/replace1.vb" id="Snippet1"::: + +## Examples + The following example demonstrates how you can use the method to correct a spelling error. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/stringreplace/CPP/stringreplace.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Replace/stringreplace.cs" interactive="try-dotnet-method" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Replace/stringreplace.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/stringreplace/VB/stringreplace.vb" id="Snippet1"::: + ]]> @@ -12608,22 +12664,22 @@ In the following example, the method is used Returns a new string in which all occurrences of a specified string in the current instance are replaced with another specified string, using the provided comparison type. A string that is equivalent to the current string except that all instances of are replaced with . If is not found in the current instance, the method returns the current instance unchanged. - [!NOTE] -> This method does not modify the value of the current instance. Instead, it returns a new string in which all occurrences of `oldValue` are replaced by `newValue`. - -This method performs a search to find `oldValue` using the culture and case sensitivity described by `comparisonType`. - -Because this method returns the modified string, you can chain together successive calls to the method to perform multiple replacements on the original string. Method calls are executed from left to right. The following example provides an illustration. - -:::code language="csharp" source="~/snippets/csharp/System/String/Replace/replace1.cs" id="Snippet1"::: -:::code language="fsharp" source="~/snippets/fsharp/System/String/Replace/replace1.fs" id="Snippet1"::: -:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.replace/vb/replace1.vb" id="Snippet1"::: - + [!NOTE] +> This method does not modify the value of the current instance. Instead, it returns a new string in which all occurrences of `oldValue` are replaced by `newValue`. + +This method performs a search to find `oldValue` using the culture and case sensitivity described by `comparisonType`. + +Because this method returns the modified string, you can chain together successive calls to the method to perform multiple replacements on the original string. Method calls are executed from left to right. The following example provides an illustration. + +:::code language="csharp" source="~/snippets/csharp/System/String/Replace/replace1.cs" id="Snippet1"::: +:::code language="fsharp" source="~/snippets/fsharp/System/String/Replace/replace1.fs" id="Snippet1"::: +:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.replace/vb/replace1.vb" id="Snippet1"::: + ]]> @@ -12690,22 +12746,22 @@ Because this method returns the modified string, you can chain together successi Returns a new string in which all occurrences of a specified string in the current instance are replaced with another specified string, using the provided culture and case sensitivity. A string that is equivalent to the current string except that all instances of are replaced with . If is not found in the current instance, the method returns the current instance unchanged. - [!NOTE] -> This method does not modify the value of the current instance. Instead, it returns a new string in which all occurrences of `oldValue` are replaced by `newValue`. - -This method performs a search to find `oldValue` using the provided `culture` and `ignoreCase` case sensitivity. - -Because this method returns the modified string, you can chain together successive calls to the method to perform multiple replacements on the original string. Method calls are executed from left to right. The following example provides an illustration. - -:::code language="csharp" source="~/snippets/csharp/System/String/Replace/replace1.cs" id="Snippet1"::: -:::code language="fsharp" source="~/snippets/fsharp/System/String/Replace/replace1.fs" id="Snippet1"::: -:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.replace/vb/replace1.vb" id="Snippet1"::: - + [!NOTE] +> This method does not modify the value of the current instance. Instead, it returns a new string in which all occurrences of `oldValue` are replaced by `newValue`. + +This method performs a search to find `oldValue` using the provided `culture` and `ignoreCase` case sensitivity. + +Because this method returns the modified string, you can chain together successive calls to the method to perform multiple replacements on the original string. Method calls are executed from left to right. The following example provides an illustration. + +:::code language="csharp" source="~/snippets/csharp/System/String/Replace/replace1.cs" id="Snippet1"::: +:::code language="fsharp" source="~/snippets/fsharp/System/String/Replace/replace1.fs" id="Snippet1"::: +:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.replace/vb/replace1.vb" id="Snippet1"::: + ]]> @@ -12742,18 +12798,18 @@ Because this method returns the modified string, you can chain together successi Replaces all newline sequences in the current string with . A string whose contents match the current string, but with all newline sequences replaced with . - , passing as the replacementText parameter. - - This method is guaranteed O(n) complexity, where n is the length of the input string. - + , passing as the replacementText parameter. + + This method is guaranteed O(n) complexity, where n is the length of the input string. + ]]> @@ -12789,18 +12845,18 @@ Because this method returns the modified string, you can chain together successi Replaces all newline sequences in the current string with . A string whose contents match the current string, but with all newline sequences replaced with . - , all newline sequences within the string will be removed. - - It is not recommended that protocol parsers utilize this API. Protocol specifications often mandate specific newline sequences. For example, HTTP/1.1 (RFC 8615) mandates that the request line, status line, and headers lines end with CRLF. Since this API operates over a wide range of newline sequences, a protocol parser utilizing this API could exhibit behaviors unintended by the protocol's authors. - - The list of recognized newline sequences is CR (U+000D), LF (U+000A), CRLF (U+000D U+000A), NEL (U+0085), LS (U+2028), FF (U+000C), and PS (U+2029). This list is given by the Unicode Standard, Sec. 5.8, Recommendation R4 and Table 5-2. - - This method is guaranteed O(n * r) complexity, where n is the length of the input string, and where r is the length of `replacementText`. - + , all newline sequences within the string will be removed. + + It is not recommended that protocol parsers utilize this API. Protocol specifications often mandate specific newline sequences. For example, HTTP/1.1 (RFC 8615) mandates that the request line, status line, and headers lines end with CRLF. Since this API operates over a wide range of newline sequences, a protocol parser utilizing this API could exhibit behaviors unintended by the protocol's authors. + + The list of recognized newline sequences is CR (U+000D), LF (U+000A), CRLF (U+000D U+000A), NEL (U+0085), LS (U+2028), FF (U+000C), and PS (U+2029). This list is given by the Unicode Standard, Sec. 5.8, Recommendation R4 and Table 5-2. + + This method is guaranteed O(n * r) complexity, where n is the length of the input string, and where r is the length of `replacementText`. + ]]> @@ -12816,41 +12872,41 @@ Because this method returns the modified string, you can chain together successi Returns a string array that contains the substrings in this instance that are delimited by elements of a specified string or Unicode character array. - is used to break a delimited string into substrings. You can use either a character array or a string array to specify zero or more delimiting characters or strings. If no delimiting characters are specified, the string is split at white-space characters. - -Overloads of the method allow you to limit the number of substrings returned by the method (the method), to specify whether to include empty strings and/or trim substrings in the result (the and methods), or to do both (the and methods). - -> [!TIP] -> The method is not always the best way to break a delimited string into substrings. If you don't want to extract all of the substrings of a delimited string, or if you want to parse a string based on a pattern instead of a set of delimiter characters, consider using regular expressions, or combine one of the search methods that returns the index of a character with the method. For more information, see [Extract substrings from a string](/dotnet/standard/base-types/divide-up-strings). - -## Example - -The following examples show three different overloads of `String.Split()`. The first example calls the overload and passes in a single delimiter. - -:::code language="csharp" source="~/snippets/csharp/System/String/Split/intro.cs" interactive="try-dotnet-method" id="Snippet1"::: -:::code language="fsharp" source="~/snippets/fsharp/System/String/Split/intro.fs" id="Snippet1"::: -:::code language="vb" source="~/snippets/visualbasic/system/string.split/intro.vb" id="Snippet1"::: - -As you can see, the period characters (`.`) are included in two of the substrings. If you want to exclude the period characters, you can add the period character as an additional delimiting character. The next example shows how to do this. - -:::code language="csharp" source="~/snippets/csharp/System/String/Split/intro.cs" interactive="try-dotnet-method" id="Snippet2"::: -:::code language="fsharp" source="~/snippets/fsharp/System/String/Split/intro.fs" id="Snippet2"::: -:::code language="vb" source="~/snippets/visualbasic/system/string.split/intro.vb" id="Snippet2"::: - -The periods are gone from the substrings, but now two extra empty substrings have been included. These empty substring represent the substring between a word and the period that follows it. To omit empty substrings from the resulting array, you can call the - overload and specify - for the `options` parameter. - -:::code language="csharp" source="~/snippets/csharp/System/String/Split/intro.cs" interactive="try-dotnet-method" id="Snippet3"::: -:::code language="fsharp" source="~/snippets/fsharp/System/String/Split/intro.fs" id="Snippet3"::: -:::code language="vb" source="~/snippets/visualbasic/system/string.split/intro.vb" id="Snippet3"::: - -The sections for the individual overloads of `String.Split()` contain further examples. - + is used to break a delimited string into substrings. You can use either a character array or a string array to specify zero or more delimiting characters or strings. If no delimiting characters are specified, the string is split at white-space characters. + +Overloads of the method allow you to limit the number of substrings returned by the method (the method), to specify whether to include empty strings and/or trim substrings in the result (the and methods), or to do both (the and methods). + +> [!TIP] +> The method is not always the best way to break a delimited string into substrings. If you don't want to extract all of the substrings of a delimited string, or if you want to parse a string based on a pattern instead of a set of delimiter characters, consider using regular expressions, or combine one of the search methods that returns the index of a character with the method. For more information, see [Extract substrings from a string](/dotnet/standard/base-types/divide-up-strings). + +## Example + +The following examples show three different overloads of `String.Split()`. The first example calls the overload and passes in a single delimiter. + +:::code language="csharp" source="~/snippets/csharp/System/String/Split/intro.cs" interactive="try-dotnet-method" id="Snippet1"::: +:::code language="fsharp" source="~/snippets/fsharp/System/String/Split/intro.fs" id="Snippet1"::: +:::code language="vb" source="~/snippets/visualbasic/system/string.split/intro.vb" id="Snippet1"::: + +As you can see, the period characters (`.`) are included in two of the substrings. If you want to exclude the period characters, you can add the period character as an additional delimiting character. The next example shows how to do this. + +:::code language="csharp" source="~/snippets/csharp/System/String/Split/intro.cs" interactive="try-dotnet-method" id="Snippet2"::: +:::code language="fsharp" source="~/snippets/fsharp/System/String/Split/intro.fs" id="Snippet2"::: +:::code language="vb" source="~/snippets/visualbasic/system/string.split/intro.vb" id="Snippet2"::: + +The periods are gone from the substrings, but now two extra empty substrings have been included. These empty substring represent the substring between a word and the period that follows it. To omit empty substrings from the resulting array, you can call the + overload and specify + for the `options` parameter. + +:::code language="csharp" source="~/snippets/csharp/System/String/Split/intro.cs" interactive="try-dotnet-method" id="Snippet3"::: +:::code language="fsharp" source="~/snippets/fsharp/System/String/Split/intro.fs" id="Snippet3"::: +:::code language="vb" source="~/snippets/visualbasic/system/string.split/intro.vb" id="Snippet3"::: + +The sections for the individual overloads of `String.Split()` contain further examples. + ]]> @@ -12912,71 +12968,71 @@ The sections for the individual overloads of `String.Split()` contain further ex Splits a string into substrings based on specified delimiting characters. An array whose elements contain the substrings from this instance that are delimited by one or more characters in . For more information, see the Remarks section. - method to separate it into substrings. - -Delimiter characters are not included in the elements of the returned array. For example, if the separator array includes the character "-" and the value of the current string instance is "aa-bb-cc", the method returns an array that contains three elements: "aa", "bb", and "cc". - -If this instance does not contain any of the characters in `separator`, the returned array consists of a single element that contains this instance. - -Each element of `separator` defines a separate delimiter character. If two delimiters are adjacent, or a delimiter is found at the beginning or end of this instance, the corresponding element in the returned array contains . - -The following table shows some examples. - -| Language | String value | Separator | Returned array | -|--------------|--------------------------|------------------------|--------------------------------| -| C# | "42, 12, 19" | new Char[] {',', ' '} | {"42", "", "12", "", "19"} | -| Visual Basic | "42, 12, 19" | Char() = {","c, " "c}) | {"42", "", "12", "", "19"} | -| C# | "42..12..19." | new Char[] {'.'} | {"42", "", "12", "", "19", ""} | -| Visual Basic | "42..12..19." | Char() = {"."c} | {"42", "", "12", "", "19", ""} | -| C# | "Banana" | new Char[] {'.'} | {"Banana"} | -| Visual Basic | "Banana" | Char() = {"."c} | {"Banana"} | -| C# | "Darb\nSmarba" | new Char[] {} | {"Darb", "Smarba"} | -| Visual Basic | "Darb" & vbLf & "Smarba" | Char() = {} | {"Darb", "Smarba"} | -| C# | "Darb\nSmarba" | null | {"Darb", "Smarba"} | -| Visual Basic | "Darb" & vbLf & "Smarba" | Nothing | {"Darb", "Smarba"} | - -### The separator array - -Each element of separator defines a separate delimiter that consists of a single character. - -If the `separator` argument is `null` or contains no characters, the method treats white-space characters as the delimiters. White-space characters are defined by the Unicode standard, and the method returns `true` if a white-space character is passed to it. - -### String.Split(Char[]) and compiler overload resolution - -Although the single parameter for this overload of is a character array, you can call it with a single character, as the following example shows. - -:::code language="csharp" source="~/snippets/csharp/System/String/Split/compiler-resolution.cs" interactive="try-dotnet-method" id="Snippet1"::: -:::code language="fsharp" source="~/snippets/fsharp/System/String/Split/compiler-resolution.fs" id="Snippet1"::: -:::code language="vb" source="~/snippets/visualbasic/system/string.split/compiler-resolution.vb" id="Snippet12"::: - -Because the `separator` parameter is decorated with the attribute, compilers will interpret a single character as a single-element character array. This is not the case for other overloads that include a `separator` parameter; you must explicitly pass these overloads a character array as the `separator` argument. - -### Comparison details - -The method extracts the substrings in this string that are delimited by one or more of the characters in the `separator` array, and returns those substrings as elements of an array. - -The method looks for delimiters by performing comparisons using case-sensitive ordinal sort rules. For more information about word, string, and ordinal sorts, see the enumeration. - -### Performance considerations - -The methods allocate memory for the returned array object and a object for each array element. If your application requires optimal performance or if managing memory allocation is critical in your application, consider using the or method. You also have the option of using the method to locate a substring within a string. - -To split a string at a separator character, use the or method to locate a separator character in the string. To split a string at a separator string, use the or method to locate the first character of the separator string. Then use the method to determine whether the characters after that first character are equal to the remaining characters of the separator string. - -In addition, if the same set of characters is used to split strings in multiple method calls, consider creating a single array and referencing it in each method call. This significantly reduces the additional overhead of each method call. - -## Examples - -The following example demonstrates how to extract individual words from a block of text by treating the space character (` `) and tab character (`\t`) as delimiters. The string being split includes both of these characters. - -:::code language="csharp" source="~/snippets/csharp/System/String/Split/basic.cs" interactive="try-dotnet-method" id="Snippet1"::: -:::code language="fsharp" source="~/snippets/fsharp/System/String/Split/basic.fs" id="Snippet1"::: -:::code language="vb" source="~/snippets/visualbasic/system/string.split/basic.vb" id="Snippet1"::: - + method to separate it into substrings. + +Delimiter characters are not included in the elements of the returned array. For example, if the separator array includes the character "-" and the value of the current string instance is "aa-bb-cc", the method returns an array that contains three elements: "aa", "bb", and "cc". + +If this instance does not contain any of the characters in `separator`, the returned array consists of a single element that contains this instance. + +Each element of `separator` defines a separate delimiter character. If two delimiters are adjacent, or a delimiter is found at the beginning or end of this instance, the corresponding element in the returned array contains . + +The following table shows some examples. + +| Language | String value | Separator | Returned array | +|--------------|--------------------------|------------------------|--------------------------------| +| C# | "42, 12, 19" | new Char[] {',', ' '} | {"42", "", "12", "", "19"} | +| Visual Basic | "42, 12, 19" | Char() = {","c, " "c}) | {"42", "", "12", "", "19"} | +| C# | "42..12..19." | new Char[] {'.'} | {"42", "", "12", "", "19", ""} | +| Visual Basic | "42..12..19." | Char() = {"."c} | {"42", "", "12", "", "19", ""} | +| C# | "Banana" | new Char[] {'.'} | {"Banana"} | +| Visual Basic | "Banana" | Char() = {"."c} | {"Banana"} | +| C# | "Darb\nSmarba" | new Char[] {} | {"Darb", "Smarba"} | +| Visual Basic | "Darb" & vbLf & "Smarba" | Char() = {} | {"Darb", "Smarba"} | +| C# | "Darb\nSmarba" | null | {"Darb", "Smarba"} | +| Visual Basic | "Darb" & vbLf & "Smarba" | Nothing | {"Darb", "Smarba"} | + +### The separator array + +Each element of separator defines a separate delimiter that consists of a single character. + +If the `separator` argument is `null` or contains no characters, the method treats white-space characters as the delimiters. White-space characters are defined by the Unicode standard, and the method returns `true` if a white-space character is passed to it. + +### String.Split(Char[]) and compiler overload resolution + +Although the single parameter for this overload of is a character array, you can call it with a single character, as the following example shows. + +:::code language="csharp" source="~/snippets/csharp/System/String/Split/compiler-resolution.cs" interactive="try-dotnet-method" id="Snippet1"::: +:::code language="fsharp" source="~/snippets/fsharp/System/String/Split/compiler-resolution.fs" id="Snippet1"::: +:::code language="vb" source="~/snippets/visualbasic/system/string.split/compiler-resolution.vb" id="Snippet12"::: + +Because the `separator` parameter is decorated with the attribute, compilers will interpret a single character as a single-element character array. This is not the case for other overloads that include a `separator` parameter; you must explicitly pass these overloads a character array as the `separator` argument. + +### Comparison details + +The method extracts the substrings in this string that are delimited by one or more of the characters in the `separator` array, and returns those substrings as elements of an array. + +The method looks for delimiters by performing comparisons using case-sensitive ordinal sort rules. For more information about word, string, and ordinal sorts, see the enumeration. + +### Performance considerations + +The methods allocate memory for the returned array object and a object for each array element. If your application requires optimal performance or if managing memory allocation is critical in your application, consider using the or method. You also have the option of using the method to locate a substring within a string. + +To split a string at a separator character, use the or method to locate a separator character in the string. To split a string at a separator string, use the or method to locate the first character of the separator string. Then use the method to determine whether the characters after that first character are equal to the remaining characters of the separator string. + +In addition, if the same set of characters is used to split strings in multiple method calls, consider creating a single array and referencing it in each method call. This significantly reduces the additional overhead of each method call. + +## Examples + +The following example demonstrates how to extract individual words from a block of text by treating the space character (` `) and tab character (`\t`) as delimiters. The string being split includes both of these characters. + +:::code language="csharp" source="~/snippets/csharp/System/String/Split/basic.cs" interactive="try-dotnet-method" id="Snippet1"::: +:::code language="fsharp" source="~/snippets/fsharp/System/String/Split/basic.fs" id="Snippet1"::: +:::code language="vb" source="~/snippets/visualbasic/system/string.split/basic.vb" id="Snippet1"::: + ]]> @@ -13086,50 +13142,50 @@ The following example demonstrates how to extract individual words from a block Splits a string into a maximum number of substrings based on specified delimiting characters. An array whose elements contain the substrings in this instance that are delimited by one or more characters in . For more information, see the Remarks section. - method returns `true` if they are passed to it. - - Each element of `separator` defines a separate delimiter character. If two delimiters are adjacent, or a delimiter is found at the beginning or end of this instance, the corresponding array element contains . - - If there are more than `count` substrings in this instance, the first `count - 1` substrings are returned in the first `count - 1` elements of the return value, and the remaining characters in this instance are returned in the last element of the return value. - - If `count` is greater than the number of substrings, the available substrings are returned and no exception is thrown. - -The following table shows some examples. - -| Language | String value | Separator | Returned array | -|--------------|--------------------------|------------------------|--------------------------------| -| C# | "42, 12, 19" | new Char[] {',', ' '} | {"42", "", "12", "", "19"} | -| Visual Basic | "42, 12, 19" | Char() = {","c, " "c}) | {"42", "", "12", "", "19"} | -| C# | "42..12..19." | new Char[] {'.'} | {"42", "", "12", "", "19", ""} | -| Visual Basic | "42..12..19." | Char() = {"."c} | {"42", "", "12", "", "19", ""} | -| C# | "Banana" | new Char[] {'.'} | {"Banana"} | -| Visual Basic | "Banana" | Char() = {"."c} | {"Banana"} | -| C# | "Darb\nSmarba" | new Char[] {} | {"Darb", "Smarba"} | -| Visual Basic | "Darb" & vbLf & "Smarba" | Char() = {} | {"Darb", "Smarba"} | -| C# | "Darb\nSmarba" | null | {"Darb", "Smarba"} | -| Visual Basic | "Darb" & vbLf & "Smarba" | Nothing | {"Darb", "Smarba"} | - -### Performance considerations - The methods allocate memory for the returned array object and a object for each array element. If your application requires optimal performance or if managing memory allocation is critical in your application, consider using the or method, and optionally the method, to locate a substring within a string. - - If you are splitting a string at a separator character, use the or method to locate a separator character in the string. If you are splitting a string at a separator string, use the or method to locate the first character of the separator string. Then use the method to determine whether the characters after that first character are equal to the remaining characters of the separator string. - - In addition, if the same set of characters is used to split strings in multiple method calls, consider creating a single array and referencing it in each method call. This significantly reduces the additional overhead of each method call. - -## Examples - The following example demonstrates how `count` can be used to limit the number of strings returned by . - -:::code language="csharp" source="~/snippets/csharp/System/String/Split/limit.cs" interactive="try-dotnet-method" id="Snippet1"::: -:::code language="fsharp" source="~/snippets/fsharp/System/String/Split/limit.fs" id="Snippet1"::: -:::code language="vb" source="~/snippets/visualbasic/system/string.split/limit.vb" id="Snippet1"::: - + method returns `true` if they are passed to it. + + Each element of `separator` defines a separate delimiter character. If two delimiters are adjacent, or a delimiter is found at the beginning or end of this instance, the corresponding array element contains . + + If there are more than `count` substrings in this instance, the first `count - 1` substrings are returned in the first `count - 1` elements of the return value, and the remaining characters in this instance are returned in the last element of the return value. + + If `count` is greater than the number of substrings, the available substrings are returned and no exception is thrown. + +The following table shows some examples. + +| Language | String value | Separator | Returned array | +|--------------|--------------------------|------------------------|--------------------------------| +| C# | "42, 12, 19" | new Char[] {',', ' '} | {"42", "", "12", "", "19"} | +| Visual Basic | "42, 12, 19" | Char() = {","c, " "c}) | {"42", "", "12", "", "19"} | +| C# | "42..12..19." | new Char[] {'.'} | {"42", "", "12", "", "19", ""} | +| Visual Basic | "42..12..19." | Char() = {"."c} | {"42", "", "12", "", "19", ""} | +| C# | "Banana" | new Char[] {'.'} | {"Banana"} | +| Visual Basic | "Banana" | Char() = {"."c} | {"Banana"} | +| C# | "Darb\nSmarba" | new Char[] {} | {"Darb", "Smarba"} | +| Visual Basic | "Darb" & vbLf & "Smarba" | Char() = {} | {"Darb", "Smarba"} | +| C# | "Darb\nSmarba" | null | {"Darb", "Smarba"} | +| Visual Basic | "Darb" & vbLf & "Smarba" | Nothing | {"Darb", "Smarba"} | + +### Performance considerations + The methods allocate memory for the returned array object and a object for each array element. If your application requires optimal performance or if managing memory allocation is critical in your application, consider using the or method, and optionally the method, to locate a substring within a string. + + If you are splitting a string at a separator character, use the or method to locate a separator character in the string. If you are splitting a string at a separator string, use the or method to locate the first character of the separator string. Then use the method to determine whether the characters after that first character are equal to the remaining characters of the separator string. + + In addition, if the same set of characters is used to split strings in multiple method calls, consider creating a single array and referencing it in each method call. This significantly reduces the additional overhead of each method call. + +## Examples + The following example demonstrates how `count` can be used to limit the number of strings returned by . + +:::code language="csharp" source="~/snippets/csharp/System/String/Split/limit.cs" interactive="try-dotnet-method" id="Snippet1"::: +:::code language="fsharp" source="~/snippets/fsharp/System/String/Split/limit.fs" id="Snippet1"::: +:::code language="vb" source="~/snippets/visualbasic/system/string.split/limit.vb" id="Snippet1"::: + ]]> @@ -13209,58 +13265,58 @@ The following table shows some examples. Splits a string into substrings based on specified delimiting characters and options. An array whose elements contain the substrings in this string that are delimited by one or more characters in . For more information, see the Remarks section. - and the length of this instance is zero, the method returns an empty array. - -Each element of `separator` defines a separate delimiter that consists of a single character. If the `options` argument is , and two delimiters are adjacent or a delimiter is found at the beginning or end of this instance, the corresponding array element contains . For example, if `separator` includes two elements, `'-'` and `'_'`, the value of the string instance is "-\_aa-\_", and the value of the `options` argument is , the method returns a string array with the following five elements: - -1. , which represents the empty string that precedes the "-" character at index 0. - -2. , which represents the empty string between the "-" character at index 0 and the "_" character at index 1. - -3. "aa". - -4. , which represents the empty string that follows the "-" character at index 4. - -5. , which represents the empty string that follows the "_" character at index 5. - -### The separator array - -If the `separator` parameter is `null` or contains no characters, white-space characters are assumed to be the delimiters. White-space characters are defined by the Unicode standard and the method returns `true` if they are passed to it. - -To pass `null` for the `char[] separator` parameter, you must indicate the type of the `null` to disambiguate the call from some other overloads, such as . The following example shows several ways to unambiguously identify this overload. - -:::code language="csharp" source="~/snippets/csharp/System/String/Split/identify.cs" interactive="try-dotnet-method" id="Snippet5"::: -:::code language="fsharp" source="~/snippets/fsharp/System/String/Split/identify.fs" id="Snippet5"::: -:::code language="vb" source="~/snippets/visualbasic/system/string.split/identify.vb" id="Snippet5"::: - -### Comparison details - The method extracts the substrings in this string that are delimited by one or more of the characters in the `separator` parameter, and returns those substrings as elements of an array. - - The method looks for delimiters by performing comparisons using case-sensitive ordinal sort rules. For more information about word, string, and ordinal sorts, see the enumeration. - -### Performance considerations - The methods allocate memory for the returned array object and a object for each array element. If your application requires optimal performance or if managing memory allocation is critical in your application, consider using the or method, and optionally the method, to locate a substring within a string. - - If you are splitting a string at a separator character, use the or method to locate a separator character in the string. If you are splitting a string at a separator string, use the or method to locate the first character of the separator string. Then use the method to determine whether the characters after that first character are equal to the remaining characters of the separator string. - - In addition, if the same set of characters is used to split strings in multiple method calls, consider creating a single array and referencing it in each method call. This significantly reduces the additional overhead of each method call. - -## Examples - The following example uses the enumeration to include or exclude substrings generated by the method. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.split3/CPP/omit.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Split/options.cs" interactive="try-dotnet-method" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Split/options.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/system/string.split/omit.vb" id="Snippet1"::: - + and the length of this instance is zero, the method returns an empty array. + +Each element of `separator` defines a separate delimiter that consists of a single character. If the `options` argument is , and two delimiters are adjacent or a delimiter is found at the beginning or end of this instance, the corresponding array element contains . For example, if `separator` includes two elements, `'-'` and `'_'`, the value of the string instance is "-\_aa-\_", and the value of the `options` argument is , the method returns a string array with the following five elements: + +1. , which represents the empty string that precedes the "-" character at index 0. + +2. , which represents the empty string between the "-" character at index 0 and the "_" character at index 1. + +3. "aa". + +4. , which represents the empty string that follows the "-" character at index 4. + +5. , which represents the empty string that follows the "_" character at index 5. + +### The separator array + +If the `separator` parameter is `null` or contains no characters, white-space characters are assumed to be the delimiters. White-space characters are defined by the Unicode standard and the method returns `true` if they are passed to it. + +To pass `null` for the `char[] separator` parameter, you must indicate the type of the `null` to disambiguate the call from some other overloads, such as . The following example shows several ways to unambiguously identify this overload. + +:::code language="csharp" source="~/snippets/csharp/System/String/Split/identify.cs" interactive="try-dotnet-method" id="Snippet5"::: +:::code language="fsharp" source="~/snippets/fsharp/System/String/Split/identify.fs" id="Snippet5"::: +:::code language="vb" source="~/snippets/visualbasic/system/string.split/identify.vb" id="Snippet5"::: + +### Comparison details + The method extracts the substrings in this string that are delimited by one or more of the characters in the `separator` parameter, and returns those substrings as elements of an array. + + The method looks for delimiters by performing comparisons using case-sensitive ordinal sort rules. For more information about word, string, and ordinal sorts, see the enumeration. + +### Performance considerations + The methods allocate memory for the returned array object and a object for each array element. If your application requires optimal performance or if managing memory allocation is critical in your application, consider using the or method, and optionally the method, to locate a substring within a string. + + If you are splitting a string at a separator character, use the or method to locate a separator character in the string. If you are splitting a string at a separator string, use the or method to locate the first character of the separator string. Then use the method to determine whether the characters after that first character are equal to the remaining characters of the separator string. + + In addition, if the same set of characters is used to split strings in multiple method calls, consider creating a single array and referencing it in each method call. This significantly reduces the additional overhead of each method call. + +## Examples + The following example uses the enumeration to include or exclude substrings generated by the method. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.split3/CPP/omit.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Split/options.cs" interactive="try-dotnet-method" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Split/options.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/system/string.split/omit.vb" id="Snippet1"::: + ]]> @@ -13377,78 +13433,78 @@ To pass `null` for the `char[] separator` parameter, you must indicate the type Splits a string into substrings based on a specified delimiting string and, optionally, options. An array whose elements contain the substrings in this string that are delimited by one or more strings in . For more information, see the Remarks section. - method to separate it into substrings. - -Delimiter strings are not included in the elements of the returned array. For example, if the `separator` array includes the string "--" and the value of the current string instance is "aa--bb--cc", the method returns an array that contains three elements: "aa", "bb", and "cc". - -If this instance does not contain any of the strings in `separator`, the returned array consists of a single element that contains this instance. - -If the `options` parameter is and the length of this instance is zero, the method returns an empty array. - -Each element of `separator` defines a separate delimiter that consists of one or more characters. If the `options` argument is , and two delimiters are adjacent or a delimiter is found at the beginning or end of this instance, the corresponding array element contains . For example, if `separator` includes two elements, "-" and "\_", the value of the string instance is "-\_aa-\_", and the value of the `options` argument is , the method returns a string array with the following five elements: - -1. , which represents the empty string that precedes the "-" substring at index 0. - -2. , which represents the empty string between the "-" substring at index 0 and the "_" substring at index 1. - -3. "aa". - -4. , which represents the empty string that follows the "-" substring at index 4. - -5. , which represents the empty string that follows the "_" substring at index 5. - -### The separator array - -If any of the elements in `separator` consists of multiple characters, the entire substring is considered a delimiter. For example, if one of the elements in `separator` is "10", attempting to split the string "This10is10a10string." returns the following four-element array: { "This", "is", "a", "string." }. - -If the `separator` parameter is `null` or contains no non-empty strings, white-space characters are assumed to be the delimiters. White-space characters are defined by the Unicode standard and the method returns `true` if they are passed to it. - -To pass `null` for the `string[] separator` parameter, you must indicate the type of the `null` to disambiguate the call from some other overloads, such as . The following example shows several ways to unambiguously identify this overload. - -:::code language="csharp" source="~/snippets/csharp/System/String/Split/identify.cs" interactive="try-dotnet-method" id="Snippet6"::: -:::code language="fsharp" source="~/snippets/fsharp/System/String/Split/identify.fs" id="Snippet6"::: -:::code language="vb" source="~/snippets/visualbasic/system/string.split/identify.vb" id="Snippet6"::: - -### Comparison details - The method extracts the substrings in this string that are delimited by one or more of the strings in the `separator` parameter, and returns those substrings as elements of an array. - - The method looks for delimiters by performing comparisons using case-sensitive ordinal sort rules. For more information about word, string, and ordinal sorts, see the enumeration. - - The method ignores any element of `separator` whose value is `null` or the empty string (""). - - To avoid ambiguous results when strings in `separator` have characters in common, the operation proceeds from the beginning to the end of the value of the instance, and matches the first element in `separator` that is equal to a delimiter in the instance. The order in which substrings are encountered in the instance takes precedence over the order of elements in `separator`. - - For example, consider an instance whose value is "abcdef". If the first element in `separator` was "ef" and the second element was "bcde", the result of the split operation would be a string array that contains two elements, "a" and "f". This is because the substring in the instance, "bcde", is encountered and matches an element in `separator` before the substring "f" is encountered. - - However, if the first element of `separator` was "bcd" and the second element was "bc", the result of the split operation would be a string array that contains two elements, "a" and "ef". This is because "bcd" is the first delimiter in `separator` that matches a delimiter in the instance. If the order of the separators was reversed so the first element was "bc" and the second element was "bcd", the result would be a string array that contains two elements, "a" and "def". - -### Performance considerations - The methods allocate memory for the returned array object and a object for each array element. If your application requires optimal performance or if managing memory allocation is critical in your application, consider using the or method, and optionally the method, to locate a substring within a string. - - If you are splitting a string at a separator character, use the or method to locate a separator character in the string. If you are splitting a string at a separator string, use the or method to locate the first character of the separator string. Then use the method to determine whether the characters after that first character are equal to the remaining characters of the separator string. - - In addition, if the same set of characters is used to split strings in multiple method calls, consider creating a single array and referencing it in each method call. This significantly reduces the additional overhead of each method call. - -## Examples - -The following example illustrates the difference in the arrays returned by calling a string's method with its `options` parameter equal to and . - -:::code language="csharp" source="~/snippets/csharp/System/String/Split/options.cs" interactive="try-dotnet-method" id="Snippet2"::: -:::code language="fsharp" source="~/snippets/fsharp/System/String/Split/options.fs" id="Snippet2"::: -:::code language="vb" source="~/snippets/visualbasic/system/string.split/options.vb" id="Snippet1"::: - -The following example defines an array of separators that include punctuation and white-space characters. Passing this array along with a value of to the method returns an array that consists of the individual words from the string. - -:::code language="csharp" source="~/snippets/csharp/System/String/Split/options.cs" interactive="try-dotnet-method" id="Snippet3"::: -:::code language="fsharp" source="~/snippets/fsharp/System/String/Split/options.fs" id="Snippet3"::: -:::code language="vb" source="~/snippets/visualbasic/system/string.split/options.vb" id="Snippet7"::: - -Note that the method is called with the `options` argument set to . This prevents the returned array from including values that represent empty substring matches between punctuation marks and white-space characters. - + method to separate it into substrings. + +Delimiter strings are not included in the elements of the returned array. For example, if the `separator` array includes the string "--" and the value of the current string instance is "aa--bb--cc", the method returns an array that contains three elements: "aa", "bb", and "cc". + +If this instance does not contain any of the strings in `separator`, the returned array consists of a single element that contains this instance. + +If the `options` parameter is and the length of this instance is zero, the method returns an empty array. + +Each element of `separator` defines a separate delimiter that consists of one or more characters. If the `options` argument is , and two delimiters are adjacent or a delimiter is found at the beginning or end of this instance, the corresponding array element contains . For example, if `separator` includes two elements, "-" and "\_", the value of the string instance is "-\_aa-\_", and the value of the `options` argument is , the method returns a string array with the following five elements: + +1. , which represents the empty string that precedes the "-" substring at index 0. + +2. , which represents the empty string between the "-" substring at index 0 and the "_" substring at index 1. + +3. "aa". + +4. , which represents the empty string that follows the "-" substring at index 4. + +5. , which represents the empty string that follows the "_" substring at index 5. + +### The separator array + +If any of the elements in `separator` consists of multiple characters, the entire substring is considered a delimiter. For example, if one of the elements in `separator` is "10", attempting to split the string "This10is10a10string." returns the following four-element array: { "This", "is", "a", "string." }. + +If the `separator` parameter is `null` or contains no non-empty strings, white-space characters are assumed to be the delimiters. White-space characters are defined by the Unicode standard and the method returns `true` if they are passed to it. + +To pass `null` for the `string[] separator` parameter, you must indicate the type of the `null` to disambiguate the call from some other overloads, such as . The following example shows several ways to unambiguously identify this overload. + +:::code language="csharp" source="~/snippets/csharp/System/String/Split/identify.cs" interactive="try-dotnet-method" id="Snippet6"::: +:::code language="fsharp" source="~/snippets/fsharp/System/String/Split/identify.fs" id="Snippet6"::: +:::code language="vb" source="~/snippets/visualbasic/system/string.split/identify.vb" id="Snippet6"::: + +### Comparison details + The method extracts the substrings in this string that are delimited by one or more of the strings in the `separator` parameter, and returns those substrings as elements of an array. + + The method looks for delimiters by performing comparisons using case-sensitive ordinal sort rules. For more information about word, string, and ordinal sorts, see the enumeration. + + The method ignores any element of `separator` whose value is `null` or the empty string (""). + + To avoid ambiguous results when strings in `separator` have characters in common, the operation proceeds from the beginning to the end of the value of the instance, and matches the first element in `separator` that is equal to a delimiter in the instance. The order in which substrings are encountered in the instance takes precedence over the order of elements in `separator`. + + For example, consider an instance whose value is "abcdef". If the first element in `separator` was "ef" and the second element was "bcde", the result of the split operation would be a string array that contains two elements, "a" and "f". This is because the substring in the instance, "bcde", is encountered and matches an element in `separator` before the substring "f" is encountered. + + However, if the first element of `separator` was "bcd" and the second element was "bc", the result of the split operation would be a string array that contains two elements, "a" and "ef". This is because "bcd" is the first delimiter in `separator` that matches a delimiter in the instance. If the order of the separators was reversed so the first element was "bc" and the second element was "bcd", the result would be a string array that contains two elements, "a" and "def". + +### Performance considerations + The methods allocate memory for the returned array object and a object for each array element. If your application requires optimal performance or if managing memory allocation is critical in your application, consider using the or method, and optionally the method, to locate a substring within a string. + + If you are splitting a string at a separator character, use the or method to locate a separator character in the string. If you are splitting a string at a separator string, use the or method to locate the first character of the separator string. Then use the method to determine whether the characters after that first character are equal to the remaining characters of the separator string. + + In addition, if the same set of characters is used to split strings in multiple method calls, consider creating a single array and referencing it in each method call. This significantly reduces the additional overhead of each method call. + +## Examples + +The following example illustrates the difference in the arrays returned by calling a string's method with its `options` parameter equal to and . + +:::code language="csharp" source="~/snippets/csharp/System/String/Split/options.cs" interactive="try-dotnet-method" id="Snippet2"::: +:::code language="fsharp" source="~/snippets/fsharp/System/String/Split/options.fs" id="Snippet2"::: +:::code language="vb" source="~/snippets/visualbasic/system/string.split/options.vb" id="Snippet1"::: + +The following example defines an array of separators that include punctuation and white-space characters. Passing this array along with a value of to the method returns an array that consists of the individual words from the string. + +:::code language="csharp" source="~/snippets/csharp/System/String/Split/options.cs" interactive="try-dotnet-method" id="Snippet3"::: +:::code language="fsharp" source="~/snippets/fsharp/System/String/Split/options.fs" id="Snippet3"::: +:::code language="vb" source="~/snippets/visualbasic/system/string.split/options.vb" id="Snippet7"::: + +Note that the method is called with the `options` argument set to . This prevents the returned array from including values that represent empty substring matches between punctuation marks and white-space characters. + ]]> @@ -13494,16 +13550,16 @@ Note that the method is called with the `options` argument set to A character that delimits the substrings in this instance. The maximum number of elements expected in the array. A bitwise combination of the enumeration values that specifies whether to trim substrings and include empty substrings. - Splits a string into a maximum number of substrings based on a specified delimiting character and, optionally, options. - Splits a string into a maximum number of substrings based on the provided character separator, optionally omitting empty substrings from the result. + Splits a string into a maximum number of substrings based on a specified delimiting character and, optionally, options. + Splits a string into a maximum number of substrings based on the provided character separator, optionally omitting empty substrings from the result. An array that contains at most substrings from this instance that are delimited by . - @@ -13570,46 +13626,46 @@ If the string has already been split `count` - 1 times, but the end of the strin Splits a string into a maximum number of substrings based on specified delimiting characters and, optionally, options. An array that contains the substrings in this string that are delimited by one or more characters in . For more information, see the Remarks section. - method returns `true` if they are passed to it. - -To pass `null` for the `char[] separator` parameter, you must indicate the type of the `null` to disambiguate the call from some other overloads, such as . The following example shows several ways to unambiguously identify this overload. - -:::code language="csharp" source="~/snippets/csharp/System/String/Split/identify.cs" interactive="try-dotnet-method" id="Snippet3"::: -:::code language="fsharp" source="~/snippets/fsharp/System/String/Split/identify.fs" id="Snippet3"::: -:::code language="vb" source="~/snippets/visualbasic/system/string.split/identify.vb" id="Snippet3"::: - - If the `count` parameter is zero, or the `options` parameter is and the length of this instance is zero, an empty array is returned. - - Each element of `separator` defines a separate delimiter character. If the `options` parameter is , and two delimiters are adjacent or a delimiter is found at the beginning or end of this instance, the corresponding array element contains . - - If there are more than `count` substrings in this instance, the first `count` minus 1 substrings are returned in the first `count` minus 1 elements of the return value, and the remaining characters in this instance are returned in the last element of the return value. - - If `count` is greater than the number of substrings, the available substrings are returned and no exception is thrown. - -### Performance considerations - The methods allocate memory for the returned array object and a object for each array element. If your application requires optimal performance or if managing memory allocation is critical in your application, consider using the or method, and optionally the method, to locate a substring within a string. - - If you are splitting a string at a separator character, use the or method to locate a separator character in the string. If you are splitting a string at a separator string, use the or method to locate the first character of the separator string. Then use the method to determine whether the characters after that first character are equal to the remaining characters of the separator string. - - In addition, if the same set of characters is used to split strings in multiple method calls, consider creating a single array and referencing it in each method call. This significantly reduces the additional overhead of each method call. - -## Examples - -The following example uses the enumeration to include or exclude substrings generated by the method. - -:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.split3/CPP/omit.cpp" id="Snippet1"::: -:::code language="csharp" source="~/snippets/csharp/System/String/Split/options.cs" interactive="try-dotnet-method" id="Snippet1"::: -:::code language="fsharp" source="~/snippets/fsharp/System/String/Split/options.fs" id="Snippet1"::: -:::code language="vb" source="~/snippets/visualbasic/system/string.split/omit.vb" id="Snippet1"::: - + method returns `true` if they are passed to it. + +To pass `null` for the `char[] separator` parameter, you must indicate the type of the `null` to disambiguate the call from some other overloads, such as . The following example shows several ways to unambiguously identify this overload. + +:::code language="csharp" source="~/snippets/csharp/System/String/Split/identify.cs" interactive="try-dotnet-method" id="Snippet3"::: +:::code language="fsharp" source="~/snippets/fsharp/System/String/Split/identify.fs" id="Snippet3"::: +:::code language="vb" source="~/snippets/visualbasic/system/string.split/identify.vb" id="Snippet3"::: + + If the `count` parameter is zero, or the `options` parameter is and the length of this instance is zero, an empty array is returned. + + Each element of `separator` defines a separate delimiter character. If the `options` parameter is , and two delimiters are adjacent or a delimiter is found at the beginning or end of this instance, the corresponding array element contains . + + If there are more than `count` substrings in this instance, the first `count` minus 1 substrings are returned in the first `count` minus 1 elements of the return value, and the remaining characters in this instance are returned in the last element of the return value. + + If `count` is greater than the number of substrings, the available substrings are returned and no exception is thrown. + +### Performance considerations + The methods allocate memory for the returned array object and a object for each array element. If your application requires optimal performance or if managing memory allocation is critical in your application, consider using the or method, and optionally the method, to locate a substring within a string. + + If you are splitting a string at a separator character, use the or method to locate a separator character in the string. If you are splitting a string at a separator string, use the or method to locate the first character of the separator string. Then use the method to determine whether the characters after that first character are equal to the remaining characters of the separator string. + + In addition, if the same set of characters is used to split strings in multiple method calls, consider creating a single array and referencing it in each method call. This significantly reduces the additional overhead of each method call. + +## Examples + +The following example uses the enumeration to include or exclude substrings generated by the method. + +:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.split3/CPP/omit.cpp" id="Snippet1"::: +:::code language="csharp" source="~/snippets/csharp/System/String/Split/options.cs" interactive="try-dotnet-method" id="Snippet1"::: +:::code language="fsharp" source="~/snippets/fsharp/System/String/Split/options.fs" id="Snippet1"::: +:::code language="vb" source="~/snippets/visualbasic/system/string.split/omit.vb" id="Snippet1"::: + ]]> @@ -13668,12 +13724,12 @@ The following example uses the enumeration to i Splits a string into a maximum number of substrings based on a specified delimiting string and, optionally, options. An array that contains at most substrings from this instance that are delimited by . - @@ -13740,63 +13796,63 @@ If the string has already been split `count` - 1 times, but the end of the strin Splits a string into a maximum number of substrings based on specified delimiting strings and, optionally, options. An array whose elements contain the substrings in this string that are delimited by one or more strings in . For more information, see the Remarks section. - method returns `true` if they are passed to it. - -To pass `null` for the `string[] separator` parameter, you must indicate the type of the `null` to disambiguate the call from some other overloads, such as . The following example shows several ways to unambiguously identify this overload. - -:::code language="csharp" source="~/snippets/csharp/System/String/Split/identify.cs" interactive="try-dotnet-method" id="Snippet4"::: -:::code language="fsharp" source="~/snippets/fsharp/System/String/Split/identify.fs" id="Snippet4"::: -:::code language="vb" source="~/snippets/visualbasic/system/string.split/identify.vb" id="Snippet4"::: - - If the `count` parameter is zero, or the `options` parameter is and the length of this instance is zero, an empty array is returned. - - Each element of `separator` defines a separate delimiter that consists of one or more characters. If the `options` parameter is , and two delimiters are adjacent or a delimiter is found at the beginning or end of this instance, the corresponding array element contains . - - If there are more than `count` substrings in this instance, the first `count` minus 1 substrings are returned in the first `count` minus 1 elements of the return value, and the remaining characters in this instance are returned in the last element of the return value. - - If `count` is greater than the number of substrings, the available substrings are returned and no exception is thrown. - -### The separator array - -If any of the elements in `separator` consists of multiple characters, the entire substring is considered a delimiter. For example, if one of the elements in `separator` is "10", attempting to split the string "This10is10a10string." returns this four-element array: { "This", "is", "a", "string." }. - -### Comparison details - The method extracts the substrings in this string that are delimited by one or more of the strings in the `separator` parameter, and returns those substrings as elements of an array. - - The method looks for delimiters by performing comparisons using case-sensitive ordinal sort rules. For more information about word, string, and ordinal sorts, see the enumeration. - - The method ignores any element of `separator` whose value is `null` or the empty string (""). - - To avoid ambiguous results when strings in `separator` have characters in common, the method proceeds from the beginning to the end of the value of the instance, and matches the first element in `separator` that is equal to a delimiter in the instance. The order in which substrings are encountered in the instance takes precedence over the order of elements in `separator`. - - For example, consider an instance whose value is "abcdef". If the first element in `separator` was "ef" and the second element was "bcde", the result of the split operation would be "a" and "f". This is because the substring in the instance, "bcde", is encountered and matches an element in `separator` before the substring "f" is encountered. - - However, if the first element of `separator` was "bcd" and the second element was "bc", the result of the split operation would be "a" and "ef". This is because "bcd" is the first delimiter in `separator` that matches a delimiter in the instance. If the order of the separators was reversed so the first element was "bc" and the second element was "bcd", the result would be "a" and "def". - -### Performance considerations - The methods allocate memory for the returned array object and a object for each array element. If your application requires optimal performance or if managing memory allocation is critical in your application, consider using the or method, and optionally the method, to locate a substring within a string. - - If you are splitting a string at a separator character, use the or method to locate a separator character in the string. If you are splitting a string at a separator string, use the or method to locate the first character of the separator string. Then use the method to determine whether the characters after that first character are equal to the remaining characters of the separator string. - - In addition, if the same set of characters is used to split strings in multiple method calls, consider creating a single array and referencing it in each method call. This significantly reduces the additional overhead of each method call. - -## Examples - -The following example uses the enumeration to include or exclude substrings generated by the method. - -:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.split3/CPP/omit.cpp" id="Snippet1"::: -:::code language="csharp" source="~/snippets/csharp/System/String/Split/options.cs" interactive="try-dotnet-method" id="Snippet1"::: -:::code language="fsharp" source="~/snippets/fsharp/System/String/Split/options.fs" id="Snippet1"::: -:::code language="vb" source="~/snippets/visualbasic/system/string.split/omit.vb" id="Snippet1"::: - + method returns `true` if they are passed to it. + +To pass `null` for the `string[] separator` parameter, you must indicate the type of the `null` to disambiguate the call from some other overloads, such as . The following example shows several ways to unambiguously identify this overload. + +:::code language="csharp" source="~/snippets/csharp/System/String/Split/identify.cs" interactive="try-dotnet-method" id="Snippet4"::: +:::code language="fsharp" source="~/snippets/fsharp/System/String/Split/identify.fs" id="Snippet4"::: +:::code language="vb" source="~/snippets/visualbasic/system/string.split/identify.vb" id="Snippet4"::: + + If the `count` parameter is zero, or the `options` parameter is and the length of this instance is zero, an empty array is returned. + + Each element of `separator` defines a separate delimiter that consists of one or more characters. If the `options` parameter is , and two delimiters are adjacent or a delimiter is found at the beginning or end of this instance, the corresponding array element contains . + + If there are more than `count` substrings in this instance, the first `count` minus 1 substrings are returned in the first `count` minus 1 elements of the return value, and the remaining characters in this instance are returned in the last element of the return value. + + If `count` is greater than the number of substrings, the available substrings are returned and no exception is thrown. + +### The separator array + +If any of the elements in `separator` consists of multiple characters, the entire substring is considered a delimiter. For example, if one of the elements in `separator` is "10", attempting to split the string "This10is10a10string." returns this four-element array: { "This", "is", "a", "string." }. + +### Comparison details + The method extracts the substrings in this string that are delimited by one or more of the strings in the `separator` parameter, and returns those substrings as elements of an array. + + The method looks for delimiters by performing comparisons using case-sensitive ordinal sort rules. For more information about word, string, and ordinal sorts, see the enumeration. + + The method ignores any element of `separator` whose value is `null` or the empty string (""). + + To avoid ambiguous results when strings in `separator` have characters in common, the method proceeds from the beginning to the end of the value of the instance, and matches the first element in `separator` that is equal to a delimiter in the instance. The order in which substrings are encountered in the instance takes precedence over the order of elements in `separator`. + + For example, consider an instance whose value is "abcdef". If the first element in `separator` was "ef" and the second element was "bcde", the result of the split operation would be "a" and "f". This is because the substring in the instance, "bcde", is encountered and matches an element in `separator` before the substring "f" is encountered. + + However, if the first element of `separator` was "bcd" and the second element was "bc", the result of the split operation would be "a" and "ef". This is because "bcd" is the first delimiter in `separator` that matches a delimiter in the instance. If the order of the separators was reversed so the first element was "bc" and the second element was "bcd", the result would be "a" and "def". + +### Performance considerations + The methods allocate memory for the returned array object and a object for each array element. If your application requires optimal performance or if managing memory allocation is critical in your application, consider using the or method, and optionally the method, to locate a substring within a string. + + If you are splitting a string at a separator character, use the or method to locate a separator character in the string. If you are splitting a string at a separator string, use the or method to locate the first character of the separator string. Then use the method to determine whether the characters after that first character are equal to the remaining characters of the separator string. + + In addition, if the same set of characters is used to split strings in multiple method calls, consider creating a single array and referencing it in each method call. This significantly reduces the additional overhead of each method call. + +## Examples + +The following example uses the enumeration to include or exclude substrings generated by the method. + +:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.split3/CPP/omit.cpp" id="Snippet1"::: +:::code language="csharp" source="~/snippets/csharp/System/String/Split/options.cs" interactive="try-dotnet-method" id="Snippet1"::: +:::code language="fsharp" source="~/snippets/fsharp/System/String/Split/options.fs" id="Snippet1"::: +:::code language="vb" source="~/snippets/visualbasic/system/string.split/omit.vb" id="Snippet1"::: + ]]> @@ -13845,12 +13901,12 @@ The following example uses the enumeration to i if matches the beginning of this string; otherwise, . - @@ -13907,23 +13963,23 @@ This method performs an ordinal (case-sensitive and culture-insensitive) compari if matches the beginning of this string; otherwise, . - ), must be a reference to this same instance, or must match the beginning of this instance. - -This method performs a word (case-sensitive and culture-sensitive) comparison using the current culture. - -## Examples - -The following example defines a `StripStartTags` method that uses the method to remove HTML start tags from the beginning of a string. Note that the `StripStartTags` method is called recursively to ensure that multiple HTML start tags at the beginning of the line are removed. The example does not remove HTML tags embedded in a string. - -:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/stringstartswith/CPP/stringstartswith.cpp" id="Snippet1"::: -:::code language="csharp" source="~/snippets/csharp/System/String/StartsWith/stringstartswith.cs" interactive="try-dotnet" id="Snippet1"::: -:::code language="fsharp" source="~/snippets/fsharp/System/String/StartsWith/stringstartswith.fs" id="Snippet1"::: -:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/stringstartswith/VB/stringstartswith.vb" id="Snippet1"::: - + ), must be a reference to this same instance, or must match the beginning of this instance. + +This method performs a word (case-sensitive and culture-sensitive) comparison using the current culture. + +## Examples + +The following example defines a `StripStartTags` method that uses the method to remove HTML start tags from the beginning of a string. Note that the `StripStartTags` method is called recursively to ensure that multiple HTML start tags at the beginning of the line are removed. The example does not remove HTML tags embedded in a string. + +:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/stringstartswith/CPP/stringstartswith.cpp" id="Snippet1"::: +:::code language="csharp" source="~/snippets/csharp/System/String/StartsWith/stringstartswith.cs" interactive="try-dotnet" id="Snippet1"::: +:::code language="fsharp" source="~/snippets/fsharp/System/String/StartsWith/stringstartswith.fs" id="Snippet1"::: +:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/stringstartswith/VB/stringstartswith.vb" id="Snippet1"::: + ]]> @@ -13991,26 +14047,26 @@ The following example defines a `StripStartTags` method that uses the if this instance begins with ; otherwise, . - method compares the `value` parameter to the substring at the beginning of this string and returns a value that indicates whether they are equal. To be equal, `value` must be a reference to this same string, must be the empty string (""), or must match the beginning of this string. The type of comparison performed by the method depends on the value of the `comparisonType` parameter. The comparison can use the conventions of the current culture ( and ) or the invariant culture ( and ), or it can consist of a character-by-character comparison of code points ( or ). The comparison can also be case-sensitive (, , or ), or it can ignore case (, , ). - -## Examples - The following example searches for the string "the" at the beginning of a longer string that begins with the word "The". As the output from the example shows, a call to the method that performs a culture-insensitive but case-sensitive comparison fails to match the string, while a call that performs a culture- and case-insensitive comparison matches the string. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.string.startswith/cpp/StartsWith2.cpp" id="Snippet2"::: - :::code language="csharp" source="~/snippets/csharp/System/String/StartsWith/StartsWith2.cs" interactive="try-dotnet" id="Snippet2"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/StartsWith/StartsWith2.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.startswith/vb/StartsWith2.vb" id="Snippet2"::: - - The following example determines whether a string starts with a particular substring. It initializes a two-dimensional string array. The first element in the second dimension contains a string, and the second element contains the string to search for at the start of the first string. The results are affected by the choice of culture, whether case is ignored, and whether an ordinal comparison is performed. Note that when the string instance contains a ligature, culture-sensitive comparisons with its consecutive characters successfully match. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.string.startswith/cpp/startswith1.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/StartsWith/startswith1.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/StartsWith/startswith1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.startswith/vb/startswith1.vb" id="Snippet1"::: - + method compares the `value` parameter to the substring at the beginning of this string and returns a value that indicates whether they are equal. To be equal, `value` must be a reference to this same string, must be the empty string (""), or must match the beginning of this string. The type of comparison performed by the method depends on the value of the `comparisonType` parameter. The comparison can use the conventions of the current culture ( and ) or the invariant culture ( and ), or it can consist of a character-by-character comparison of code points ( or ). The comparison can also be case-sensitive (, , or ), or it can ignore case (, , ). + +## Examples + The following example searches for the string "the" at the beginning of a longer string that begins with the word "The". As the output from the example shows, a call to the method that performs a culture-insensitive but case-sensitive comparison fails to match the string, while a call that performs a culture- and case-insensitive comparison matches the string. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.string.startswith/cpp/StartsWith2.cpp" id="Snippet2"::: + :::code language="csharp" source="~/snippets/csharp/System/String/StartsWith/StartsWith2.cs" interactive="try-dotnet" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/StartsWith/StartsWith2.fs" id="Snippet2"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.startswith/vb/StartsWith2.vb" id="Snippet2"::: + + The following example determines whether a string starts with a particular substring. It initializes a two-dimensional string array. The first element in the second dimension contains a string, and the second element contains the string to search for at the start of the first string. The results are affected by the choice of culture, whether case is ignored, and whether an ordinal comparison is performed. Note that when the string instance contains a ligature, culture-sensitive comparisons with its consecutive characters successfully match. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.string.startswith/cpp/startswith1.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/StartsWith/startswith1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/StartsWith/startswith1.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.startswith/vb/startswith1.vb" id="Snippet1"::: + ]]> @@ -14074,20 +14130,20 @@ The following example defines a `StripStartTags` method that uses the if the parameter matches the beginning of this string; otherwise, . - ), must be a reference to this same instance, or must match the beginning of this instance. - - This method performs a comparison using the specified casing and culture. - -## Examples - The following example determines whether a string occurs at the beginning of another string. The method is called several times using case sensitivity, case insensitivity, and different cultures that influence the results of the search. - - :::code language="csharp" source="~/snippets/csharp/System/String/StartsWith/swci.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/StartsWith/swci.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.StartsWithCI/vb/swci.vb" id="Snippet1"::: - + ), must be a reference to this same instance, or must match the beginning of this instance. + + This method performs a comparison using the specified casing and culture. + +## Examples + The following example determines whether a string occurs at the beginning of another string. The method is called several times using case sensitivity, case insensitivity, and different cultures that influence the results of the search. + + :::code language="csharp" source="~/snippets/csharp/System/String/StartsWith/swci.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/StartsWith/swci.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.StartsWithCI/vb/swci.vb" id="Snippet1"::: + ]]> @@ -14104,9 +14160,9 @@ The following example defines a `StripStartTags` method that uses the 4.2.0.0 - Retrieves a substring from this instance. - - This member is overloaded. For complete information about this member, including syntax, usage, and examples, click a name in the overload list. + Retrieves a substring from this instance. + + This member is overloaded. For complete information about this member, including syntax, usage, and examples, click a name in the overload list. @@ -14160,33 +14216,33 @@ The following example defines a `StripStartTags` method that uses the Retrieves a substring from this instance. The substring starts at a specified character position and continues to the end of the string. A string that is equivalent to the substring that begins at in this instance, or if is equal to the length of this instance. - method to extract a substring from a string that begins at a specified character position and ends at the end of the string. The starting character position is zero-based; in other words, the first character in the string is at index 0, not index 1. To extract a substring that begins at a specified character position and ends before the end of the string, call the method. - -> [!NOTE] -> This method does not modify the value of the current instance. Instead, it returns a new string that begins at the `startIndex` position in the current string. - - To extract a substring that begins with a particular character or character sequence, call a method such as or to get the value of `startIndex`. The second example illustrates this; it extracts a key value that begins one character position after the `=` character. - - If `startIndex` is equal to zero, the method returns the original string unchanged. -## Examples - The following example demonstrates obtaining a substring from a string. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/System.String.Substring/cpp/Substring10.cpp" id="Snippet10"::: - :::code language="csharp" source="~/snippets/csharp/System/String/Substring/Substring10.cs" interactive="try-dotnet-method" id="Snippet10"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Substring/Substring10.fs" id="Snippet10"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.String.Substring/vb/Substring10.vb" id="Snippet10"::: - - The following example uses the method to separate key/value pairs that are delimited by an equals (`=`) character. - - :::code language="csharp" source="~/snippets/csharp/System/String/Substring/Substring1.cs" interactive="try-dotnet-method" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Substring/Substring1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.String.Substring/vb/Substring1.vb" id="Snippet1"::: - - The method is used to get the position of the equals character in the string. The call to the method extracts the key name, which starts from the first character in the string and extends for the number of characters returned by the call to the method. The call to the method then extracts the value assigned to the key. It starts at one character position beyond the equals character and extends to the end of the string. - + method to extract a substring from a string that begins at a specified character position and ends at the end of the string. The starting character position is zero-based; in other words, the first character in the string is at index 0, not index 1. To extract a substring that begins at a specified character position and ends before the end of the string, call the method. + +> [!NOTE] +> This method does not modify the value of the current instance. Instead, it returns a new string that begins at the `startIndex` position in the current string. + + To extract a substring that begins with a particular character or character sequence, call a method such as or to get the value of `startIndex`. The second example illustrates this; it extracts a key value that begins one character position after the `=` character. + + If `startIndex` is equal to zero, the method returns the original string unchanged. +## Examples + The following example demonstrates obtaining a substring from a string. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/System.String.Substring/cpp/Substring10.cpp" id="Snippet10"::: + :::code language="csharp" source="~/snippets/csharp/System/String/Substring/Substring10.cs" interactive="try-dotnet-method" id="Snippet10"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Substring/Substring10.fs" id="Snippet10"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.String.Substring/vb/Substring10.vb" id="Snippet10"::: + + The following example uses the method to separate key/value pairs that are delimited by an equals (`=`) character. + + :::code language="csharp" source="~/snippets/csharp/System/String/Substring/Substring1.cs" interactive="try-dotnet-method" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Substring/Substring1.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.String.Substring/vb/Substring1.vb" id="Snippet1"::: + + The method is used to get the position of the equals character in the string. The call to the method extracts the key name, which starts from the first character in the string and extends for the number of characters returned by the call to the method. The call to the method then extracts the value assigned to the key. It starts at one character position beyond the equals character and extends to the end of the string. + ]]> @@ -14258,71 +14314,71 @@ The following example defines a `StripStartTags` method that uses the Retrieves a substring from this instance. The substring starts at a specified character position and has a specified length. A string that is equivalent to the substring of length that begins at in this instance, or if is equal to the length of this instance and is zero. - method to extract a substring from a string that begins at a specified character position and ends before the end of the string. The starting character position is zero-based; in other words, the first character in the string is at index 0, not index 1. To extract a substring that begins at a specified character position and continues to the end of the string, call the method. - -> [!NOTE] -> This method does not modify the value of the current instance. Instead, it returns a new string with `length` characters starting from the `startIndex` position in the current string. - - The `length` parameter represents the total number of characters to extract from the current string instance. This includes the starting character found at index `startIndex`. In other words, the method attempts to extract characters from index `startIndex` to index `startIndex` + `length` - 1. - - To extract a substring that begins with a particular character or character sequence, call a method such as or to get the value of `startIndex`. - - If the substring should extend from `startIndex` to a specified character sequence, you can call a method such as or to get the index of the ending character or character sequence. You can then convert that value to an index position in the string as follows: - -- If you've searched for a single character that is to mark the end of the substring, the `length` parameter equals `endIndex` - `startIndex` + 1, where `endIndex` is the return value of the or method. The following example extracts a continuous block of "b" characters from a string. - - :::code language="csharp" source="~/snippets/csharp/System/String/Substring/Substring2.cs" interactive="try-dotnet-method" id="Snippet2"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Substring/Substring2.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.String.Substring/vb/Substring2.vb" id="Snippet2"::: - -- If you've searched for multiple characters that are to mark the end of the substring, the `length` parameter equals `endIndex` + `endMatchLength` - `startIndex`, where `endIndex` is the return value of the or method, and `endMatchLength` is the length of the character sequence that marks the end of the substring. The following example extracts a block of text that contains an XML `` element. - - :::code language="csharp" source="~/snippets/csharp/System/String/Substring/Substring3.cs" interactive="try-dotnet-method" id="Snippet3"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Substring/Substring3.fs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.String.Substring/vb/Substring3.vb" id="Snippet3"::: - -- If the character or character sequence is not included in the end of the substring, the `length` parameter equals `endIndex` - `startIndex`, where `endIndex` is the return value of the or method. - - If `startIndex` is equal to zero and `length` equals the length of the current string, the method returns the original string unchanged. - -## Examples - The following example illustrates a simple call to the method that extracts two characters from a string starting at the sixth character position (that is, at index five). - - :::code language="csharp" source="~/snippets/csharp/System/String/Substring/Substring4.cs" interactive="try-dotnet-method" id="Snippet4"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Substring/Substring4.fs" id="Snippet4"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.String.Substring/vb/Substring4.vb" id="Snippet4"::: - - The following example uses the method in the following three cases to isolate substrings within a string. In two cases the substrings are used in comparisons, and in the third case an exception is thrown because invalid parameters are specified. - -- It extracts the single character at the third position in the string (at index 2) and compares it with a "c". This comparison returns `true`. - -- It extracts zero characters starting at the fourth position in the string (at index 3) and passes it to the method. This returns true because the call to the method returns . - -- It attempts to extract one character starting at the fourth position in the string. Because there is no character at that position, the method call throws an exception. - - :::code language="csharp" source="~/snippets/csharp/System/String/Substring/source.cs" interactive="try-dotnet-method" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Substring/source.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_Classic/classic String.Substring1 Example/VB/source.vb" id="Snippet1"::: - - The following example uses the method to separate key/value pairs that are delimited by an equals (`=`) character. - - :::code language="csharp" source="~/snippets/csharp/System/String/Substring/Substring1.cs" interactive="try-dotnet-method" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/Substring/Substring1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.String.Substring/vb/Substring1.vb" id="Snippet1"::: - - The method is used to get the position of the equals character in the string. The call to the method extracts the key name, which starts from the first character in the string and extends for the number of characters returned by the call to the method. The call to the method then extracts the value assigned to the key. It starts at one character position beyond the equals character and extends to the end of the string. - + method to extract a substring from a string that begins at a specified character position and ends before the end of the string. The starting character position is zero-based; in other words, the first character in the string is at index 0, not index 1. To extract a substring that begins at a specified character position and continues to the end of the string, call the method. + +> [!NOTE] +> This method does not modify the value of the current instance. Instead, it returns a new string with `length` characters starting from the `startIndex` position in the current string. + + The `length` parameter represents the total number of characters to extract from the current string instance. This includes the starting character found at index `startIndex`. In other words, the method attempts to extract characters from index `startIndex` to index `startIndex` + `length` - 1. + + To extract a substring that begins with a particular character or character sequence, call a method such as or to get the value of `startIndex`. + + If the substring should extend from `startIndex` to a specified character sequence, you can call a method such as or to get the index of the ending character or character sequence. You can then convert that value to an index position in the string as follows: + +- If you've searched for a single character that is to mark the end of the substring, the `length` parameter equals `endIndex` - `startIndex` + 1, where `endIndex` is the return value of the or method. The following example extracts a continuous block of "b" characters from a string. + + :::code language="csharp" source="~/snippets/csharp/System/String/Substring/Substring2.cs" interactive="try-dotnet-method" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Substring/Substring2.fs" id="Snippet2"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.String.Substring/vb/Substring2.vb" id="Snippet2"::: + +- If you've searched for multiple characters that are to mark the end of the substring, the `length` parameter equals `endIndex` + `endMatchLength` - `startIndex`, where `endIndex` is the return value of the or method, and `endMatchLength` is the length of the character sequence that marks the end of the substring. The following example extracts a block of text that contains an XML `` element. + + :::code language="csharp" source="~/snippets/csharp/System/String/Substring/Substring3.cs" interactive="try-dotnet-method" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Substring/Substring3.fs" id="Snippet3"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.String.Substring/vb/Substring3.vb" id="Snippet3"::: + +- If the character or character sequence is not included in the end of the substring, the `length` parameter equals `endIndex` - `startIndex`, where `endIndex` is the return value of the or method. + + If `startIndex` is equal to zero and `length` equals the length of the current string, the method returns the original string unchanged. + +## Examples + The following example illustrates a simple call to the method that extracts two characters from a string starting at the sixth character position (that is, at index five). + + :::code language="csharp" source="~/snippets/csharp/System/String/Substring/Substring4.cs" interactive="try-dotnet-method" id="Snippet4"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Substring/Substring4.fs" id="Snippet4"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.String.Substring/vb/Substring4.vb" id="Snippet4"::: + + The following example uses the method in the following three cases to isolate substrings within a string. In two cases the substrings are used in comparisons, and in the third case an exception is thrown because invalid parameters are specified. + +- It extracts the single character at the third position in the string (at index 2) and compares it with a "c". This comparison returns `true`. + +- It extracts zero characters starting at the fourth position in the string (at index 3) and passes it to the method. This returns true because the call to the method returns . + +- It attempts to extract one character starting at the fourth position in the string. Because there is no character at that position, the method call throws an exception. + + :::code language="csharp" source="~/snippets/csharp/System/String/Substring/source.cs" interactive="try-dotnet-method" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Substring/source.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_Classic/classic String.Substring1 Example/VB/source.vb" id="Snippet1"::: + + The following example uses the method to separate key/value pairs that are delimited by an equals (`=`) character. + + :::code language="csharp" source="~/snippets/csharp/System/String/Substring/Substring1.cs" interactive="try-dotnet-method" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/Substring/Substring1.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.String.Substring/vb/Substring1.vb" id="Snippet1"::: + + The method is used to get the position of the equals character in the string. The call to the method extracts the key name, which starts from the first character in the string and extends for the number of characters returned by the call to the method. The call to the method then extracts the value assigned to the key. It starts at one character position beyond the equals character and extends to the end of the string. + ]]> - plus indicates a position not within this instance. - - -or- - - or is less than zero. + plus indicates a position not within this instance. + +-or- + + or is less than zero. @@ -14370,11 +14426,11 @@ The following example defines a `StripStartTags` method that uses the Returns an enumerator that iterates through the current object. A strongly-typed enumerator that can be used to iterate through the current object. - instance is cast to an interface object. For more information, see the method. - + instance is cast to an interface object. For more information, see the method. + ]]> @@ -14424,11 +14480,11 @@ The following example defines a `StripStartTags` method that uses the Returns an enumerator that iterates through the current object. An enumerator that can be used to iterate through the current string. - instance is cast to an interface. For more information, see the method. - + instance is cast to an interface. For more information, see the method. + ]]> @@ -14466,32 +14522,47 @@ The following example defines a `StripStartTags` method that uses the An object that evaluates to a . Compares this instance with a specified and indicates whether this instance precedes, follows, or appears in the same position in the sort order as the specified . - A 32-bit signed integer that indicates whether this instance precedes, follows, or appears in the same position in the sort order as the parameter. - -ValueConditionLess than zeroThis instance precedes .ZeroThis instance has the same position in the sort order as .Greater than zeroThis instance follows , or is . + A 32-bit signed integer that indicates whether this instance precedes, follows, or appears in the same position in the sort order as the parameter. + + Value + Condition + + + Less than zero + This instance precedes . + + + Zero + This instance has the same position in the sort order as . + + + Greater than zero + This instance follows , or is . + + - object. - -> [!CAUTION] -> The method was designed primarily for use in sorting or alphabetizing operations. It should not be used when the primary purpose of the method call is to determine whether two strings are equivalent. To determine whether two strings are equivalent, call the method. - -This method performs a word (case-sensitive and culture-sensitive) comparison using the current culture. For more information about word, string, and ordinal sorts, see . - -For more information about the behavior of this method, see the Remarks section of the method. - -## Examples - -The following example uses the method with an . Because it attempts to compare a instance to a `TestClass` object, the method throws an . - -:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/ExToString/CPP/extostring.cpp" id="Snippet1"::: -:::code language="csharp" source="~/snippets/csharp/System/String/CompareTo/extostring.cs" id="Snippet1"::: -:::code language="fsharp" source="~/snippets/fsharp/System/String/CompareTo/extostring.fs" id="Snippet1"::: -:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ExToString/VB/extostring.vb" id="Snippet1"::: - + object. + +> [!CAUTION] +> The method was designed primarily for use in sorting or alphabetizing operations. It should not be used when the primary purpose of the method call is to determine whether two strings are equivalent. To determine whether two strings are equivalent, call the method. + +This method performs a word (case-sensitive and culture-sensitive) comparison using the current culture. For more information about word, string, and ordinal sorts, see . + +For more information about the behavior of this method, see the Remarks section of the method. + +## Examples + +The following example uses the method with an . Because it attempts to compare a instance to a `TestClass` object, the method throws an . + +:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/ExToString/CPP/extostring.cpp" id="Snippet1"::: +:::code language="csharp" source="~/snippets/csharp/System/String/CompareTo/extostring.cs" id="Snippet1"::: +:::code language="fsharp" source="~/snippets/fsharp/System/String/CompareTo/extostring.fs" id="Snippet1"::: +:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ExToString/VB/extostring.vb" id="Snippet1"::: + ]]> @@ -14528,17 +14599,17 @@ The following example uses the method with an Returns the for the class. The enumerated constant, . - enumerated constant for the type. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.gettypecode/CPP/gtc.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/GetTypeCode/gtc.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/GetTypeCode/gtc.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.gettypecode/VB/gtc.vb" id="Snippet1"::: - + enumerated constant for the type. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.gettypecode/CPP/gtc.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/GetTypeCode/gtc.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/GetTypeCode/gtc.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.gettypecode/VB/gtc.vb" id="Snippet1"::: + ]]> @@ -14590,11 +14661,11 @@ The following example displays the enumerated constant fo if the value of the current string is ; if the value of the current string is . - instance is cast to an interface. The recommended alternative is to call the method. - + instance is cast to an interface. The recommended alternative is to call the method. + ]]> The value of the current string is not or . @@ -14652,11 +14723,11 @@ The following example displays the enumerated constant fo For a description of this member, see . The converted value of the current object. - instance is cast to an interface. The recommended alternative is to call the method. - + instance is cast to an interface. The recommended alternative is to call the method. + ]]> The value of the current object cannot be parsed. @@ -14709,11 +14780,11 @@ The following example displays the enumerated constant fo For a description of this member, see . The character at index 0 in the current object. - instance is cast to an interface. The recommended alternative is to call the method. - + instance is cast to an interface. The recommended alternative is to call the method. + ]]> @@ -14770,11 +14841,11 @@ The following example displays the enumerated constant fo For a description of this member, see . The converted value of the current object. - instance is cast to an interface. The recommended alternative is to call the method. - + instance is cast to an interface. The recommended alternative is to call the method. + ]]> @@ -14831,11 +14902,11 @@ The following example displays the enumerated constant fo For a description of this member, see . The converted value of the current object. - instance is cast to an interface. The recommended alternative is to call the method. - + instance is cast to an interface. The recommended alternative is to call the method. + ]]> The value of the current object cannot be parsed. @@ -14894,11 +14965,11 @@ The following example displays the enumerated constant fo For a description of this member, see . The converted value of the current object. - instance is cast to an interface. The recommended alternative is to call the method. - + instance is cast to an interface. The recommended alternative is to call the method. + ]]> The value of the current object cannot be parsed. @@ -14957,11 +15028,11 @@ The following example displays the enumerated constant fo For a description of this member, see . The converted value of the current object. - instance is cast to an interface. The recommended alternative is to call the method. - + instance is cast to an interface. The recommended alternative is to call the method. + ]]> The value of the current object cannot be parsed. @@ -15020,11 +15091,11 @@ The following example displays the enumerated constant fo For a description of this member, see . The converted value of the current object. - instance is cast to an interface. The recommended alternative is to call the method. - + instance is cast to an interface. The recommended alternative is to call the method. + ]]> @@ -15081,11 +15152,11 @@ The following example displays the enumerated constant fo For a description of this member, see . The converted value of the current object. - instance is cast to an interface. The recommended alternative is to call the method. - + instance is cast to an interface. The recommended alternative is to call the method. + ]]> @@ -15146,11 +15217,11 @@ The following example displays the enumerated constant fo For a description of this member, see . The converted value of the current object. - instance is cast to an interface. The recommended alternative is to call the method. - + instance is cast to an interface. The recommended alternative is to call the method. + ]]> The value of the current object cannot be parsed. @@ -15209,11 +15280,11 @@ The following example displays the enumerated constant fo For a description of this member, see . The converted value of the current object. - instance is cast to an interface. The recommended alternative is to call the method. - + instance is cast to an interface. The recommended alternative is to call the method. + ]]> @@ -15247,20 +15318,20 @@ The following example displays the enumerated constant fo - An object that supplies culture-specific formatting information. - --or- - + An object that supplies culture-specific formatting information. + +-or- + to use the formatting conventions of the current culture. For a description of this member, see . A instance equivalent to the value of this instance. - instance is cast to an interface. - + instance is cast to an interface. + ]]> @@ -15313,11 +15384,11 @@ This member is an explicit interface member implementation. It can be used only For a description of this member, see . The converted value of the current object. - instance is cast to an interface. The recommended alternative is to call the method. - + instance is cast to an interface. The recommended alternative is to call the method. + ]]> @@ -15381,11 +15452,11 @@ This member is an explicit interface member implementation. It can be used only For a description of this member, see . The converted value of the current object. - instance is cast to an interface. The recommended alternative is to call the method. - + instance is cast to an interface. The recommended alternative is to call the method. + ]]> The value of the current object cannot be parsed. @@ -15448,11 +15519,11 @@ This member is an explicit interface member implementation. It can be used only For a description of this member, see . The converted value of the current object. - instance is cast to an interface. The recommended alternative is to call the method. - + instance is cast to an interface. The recommended alternative is to call the method. + ]]> The value of the current object cannot be parsed. @@ -15515,11 +15586,11 @@ This member is an explicit interface member implementation. It can be used only For a description of this member, see . The converted value of the current object. - instance is cast to an interface. The recommended alternative is to call the method. - + instance is cast to an interface. The recommended alternative is to call the method. + ]]> @@ -15748,32 +15819,32 @@ This member is an explicit interface member implementation. It can be used only Copies the characters in this instance to a Unicode character array. A Unicode character array whose elements are the individual characters of this instance. If this instance is an empty string, the returned array is empty and has a zero length. - object) in a string to a character array. The first character copied is at index zero of the returned character array; the last character copied is at index - 1. - - To create a string from the characters in a character array, call the constructor. - - To create a byte array that contains the encoded characters in a string, instantiate the appropriate object and call its method. Some of the standard encodings available in .NET include the following: - -|Encoding|Object| -|--------------|------------| -|ASCII|| -|UTF-7|| -|UTF-8|| -|UTF-16|| -|UTF-32|| - - For more information, see [Character Encoding in .NET](/dotnet/standard/base-types/character-encoding). - -## Examples - The following example calls the method to extract the characters in a string to a character array. It then displays the original string and the elements in the array. - - :::code language="csharp" source="~/snippets/csharp/System/String/ToCharArray/ToCharArray1.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/ToCharArray/ToCharArray1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.tochararray/vb/ToCharArray1.vb" id="Snippet1"::: - + object) in a string to a character array. The first character copied is at index zero of the returned character array; the last character copied is at index - 1. + + To create a string from the characters in a character array, call the constructor. + + To create a byte array that contains the encoded characters in a string, instantiate the appropriate object and call its method. Some of the standard encodings available in .NET include the following: + +|Encoding|Object| +|--------------|------------| +|ASCII|| +|UTF-7|| +|UTF-8|| +|UTF-16|| +|UTF-32|| + + For more information, see [Character Encoding in .NET](/dotnet/standard/base-types/character-encoding). + +## Examples + The following example calls the method to extract the characters in a string to a character array. It then displays the original string and the elements in the array. + + :::code language="csharp" source="~/snippets/csharp/System/String/ToCharArray/ToCharArray1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/ToCharArray/ToCharArray1.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.tochararray/vb/ToCharArray1.vb" id="Snippet1"::: + ]]> @@ -15833,43 +15904,43 @@ This member is an explicit interface member implementation. It can be used only Copies the characters in a specified substring in this instance to a Unicode character array. A Unicode character array whose elements are the number of characters in this instance starting from character position . - constructor. - - The `startIndex` parameter is zero-based. That is, the index of the first character in the string instance is zero. - - If `length` is zero, the returned array is empty and has a zero length. If this instance is `null` or an empty string (""), the returned array is empty and has a zero length. - - To create a byte array that contains the encoded characters in a portion of a string, instantiate the appropriate object and call its method. Some of the standard encodings available in .NET include: - -|Encoding|Object| -|--------------|------------| -|ASCII|| -|UTF-7|| -|UTF-8|| -|UTF-16|| -|UTF-32|| - - For more information, see [Character Encoding in .NET](/dotnet/standard/base-types/character-encoding). - -## Examples - The following example converts a substring within a string to an array of characters, then enumerates and displays the elements of the array. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.ToCharArray1/CPP/tocharry1.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/ToCharArray/tocharry1.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/ToCharArray/tocharry1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.ToCharArray1/VB/tocharry1.vb" id="Snippet1"::: - + constructor. + + The `startIndex` parameter is zero-based. That is, the index of the first character in the string instance is zero. + + If `length` is zero, the returned array is empty and has a zero length. If this instance is `null` or an empty string (""), the returned array is empty and has a zero length. + + To create a byte array that contains the encoded characters in a portion of a string, instantiate the appropriate object and call its method. Some of the standard encodings available in .NET include: + +|Encoding|Object| +|--------------|------------| +|ASCII|| +|UTF-7|| +|UTF-8|| +|UTF-16|| +|UTF-32|| + + For more information, see [Character Encoding in .NET](/dotnet/standard/base-types/character-encoding). + +## Examples + The following example converts a substring within a string to an array of characters, then enumerates and displays the elements of the array. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.ToCharArray1/CPP/tocharry1.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/ToCharArray/tocharry1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/ToCharArray/tocharry1.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.ToCharArray1/VB/tocharry1.vb" id="Snippet1"::: + ]]> - or is less than zero. - - -or- - - plus is greater than the length of this instance. + or is less than zero. + +-or- + + plus is greater than the length of this instance. @@ -15930,25 +16001,25 @@ This member is an explicit interface member implementation. It can be used only Returns a copy of this string converted to lowercase. A string in lowercase. - [!NOTE] -> This method does not modify the value of the current instance. Instead, it returns a new string in which all characters in the current instance are converted to lowercase. - -## Security Considerations - The casing operation that results from calling the method takes the casing conventions of the current culture into account. If you need the lowercase or uppercase version of an operating system identifier, such as a file name, named pipe, or registry key, use the or methods. This produces the same result in every culture (unlike the method) and performs more efficiently. - -## Examples - The following example converts several mixed case strings to lowercase. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/stringlowerupper/CPP/stringtolower.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/ToLower/stringtolower.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/ToLower/stringtolower.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/stringlowerupper/VB/stringtolower.vb" id="Snippet1"::: - + [!NOTE] +> This method does not modify the value of the current instance. Instead, it returns a new string in which all characters in the current instance are converted to lowercase. + +## Security Considerations + The casing operation that results from calling the method takes the casing conventions of the current culture into account. If you need the lowercase or uppercase version of an operating system identifier, such as a file name, named pipe, or registry key, use the or methods. This produces the same result in every culture (unlike the method) and performs more efficiently. + +## Examples + The following example converts several mixed case strings to lowercase. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/stringlowerupper/CPP/stringtolower.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/ToLower/stringtolower.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/ToLower/stringtolower.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/stringlowerupper/VB/stringtolower.vb" id="Snippet1"::: + ]]> @@ -16014,25 +16085,25 @@ This member is an explicit interface member implementation. It can be used only Returns a copy of this string converted to lowercase, using the casing rules of the specified culture. The lowercase equivalent of the current string. - [!NOTE] -> This method does not modify the value of the current instance. Instead, it returns a new string in which all characters in the current instance are converted to lowercase. - -## Security Considerations - If you pass the method a object other than , the casing operation will take culture-specific rules into account. If you need the lowercase or uppercase version of an operating system identifier, such as a file name, named pipe, or registry key, use the or method. This produces the same result in every culture and performs more efficiently. - -## Examples - The following example converts two strings of uppercase characters to lowercase characters using the English-United States and Turkish-Turkey cultures, then compares the lowercase strings. The uppercase strings are identical except that for each occurrence of the Unicode LATIN CAPITAL LETTER I in one string, the other string contains LATIN CAPITAL LETTER I WITH DOT ABOVE. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.tolower1/CPP/tolower.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/ToLower/tolower.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/ToLower/tolower.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.tolower1/VB/tolower.vb" id="Snippet1"::: - + [!NOTE] +> This method does not modify the value of the current instance. Instead, it returns a new string in which all characters in the current instance are converted to lowercase. + +## Security Considerations + If you pass the method a object other than , the casing operation will take culture-specific rules into account. If you need the lowercase or uppercase version of an operating system identifier, such as a file name, named pipe, or registry key, use the or method. This produces the same result in every culture and performs more efficiently. + +## Examples + The following example converts two strings of uppercase characters to lowercase characters using the English-United States and Turkish-Turkey cultures, then compares the lowercase strings. The uppercase strings are identical except that for each occurrence of the Unicode LATIN CAPITAL LETTER I in one string, the other string contains LATIN CAPITAL LETTER I WITH DOT ABOVE. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.tolower1/CPP/tolower.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/ToLower/tolower.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/ToLower/tolower.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.tolower1/VB/tolower.vb" id="Snippet1"::: + ]]> @@ -16086,26 +16157,26 @@ This member is an explicit interface member implementation. It can be used only Returns a copy of this object converted to lowercase using the casing rules of the invariant culture. The lowercase equivalent of the current string. - property. - - If your application depends on the case of a string changing in a predictable way that is unaffected by the current culture, use the method. The method is equivalent to `ToLower(CultureInfo.InvariantCulture)`. The method is recommended when a collection of strings must appear in a predictable order in a user interface control. - -> [!NOTE] -> This method does not modify the value of the current instance. Instead, it returns a new string in which all characters in the current instance are converted to lowercase. - -## Security Considerations - If you need the lowercase or uppercase version of an operating system identifier, such as a file name, named pipe, or registry key, use the or methods. - -## Examples - The following example defines a string array that contains a single word in a number of languages. The method is used to populate the elements of a parallel array with the case-insensitive version of each word. The method is used to sort the case-sensitive array based on the order of elements in the lowercase array to ensure that elements appear in the same order regardless of language. - - :::code language="csharp" source="~/snippets/csharp/System/String/ToLowerInvariant/tolowerinvariant.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/ToLowerInvariant/tolowerinvariant.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.tolowerinvariant/vb/tolowerinvariant.vb" id="Snippet1"::: - + property. + + If your application depends on the case of a string changing in a predictable way that is unaffected by the current culture, use the method. The method is equivalent to `ToLower(CultureInfo.InvariantCulture)`. The method is recommended when a collection of strings must appear in a predictable order in a user interface control. + +> [!NOTE] +> This method does not modify the value of the current instance. Instead, it returns a new string in which all characters in the current instance are converted to lowercase. + +## Security Considerations + If you need the lowercase or uppercase version of an operating system identifier, such as a file name, named pipe, or registry key, use the or methods. + +## Examples + The following example defines a string array that contains a single word in a number of languages. The method is used to populate the elements of a parallel array with the case-insensitive version of each word. The method is used to sort the case-sensitive array based on the order of elements in the lowercase array to ensure that elements appear in the same order regardless of language. + + :::code language="csharp" source="~/snippets/csharp/System/String/ToLowerInvariant/tolowerinvariant.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/ToLowerInvariant/tolowerinvariant.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.tolowerinvariant/vb/tolowerinvariant.vb" id="Snippet1"::: + ]]> @@ -16175,19 +16246,19 @@ This member is an explicit interface member implementation. It can be used only Returns this instance of ; no actual conversion is performed. The current string. - method.Note that the example does not explicitly call the method. Instead, the method is called implicitly by the [composite formatting](/dotnet/standard/base-types/composite-formatting) feature. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.tostring/CPP/string.tostring.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/ToString/string.tostring.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/ToString/string.tostring.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.tostring/VB/string.tostring.vb" id="Snippet1"::: - + method.Note that the example does not explicitly call the method. Instead, the method is called implicitly by the [composite formatting](/dotnet/standard/base-types/composite-formatting) feature. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/string.tostring/CPP/string.tostring.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/ToString/string.tostring.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/ToString/string.tostring.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.tostring/VB/string.tostring.vb" id="Snippet1"::: + ]]> @@ -16251,13 +16322,13 @@ This member is an explicit interface member implementation. It can be used only Returns this instance of ; no actual conversion is performed. The current string. - @@ -16317,27 +16388,27 @@ This member is an explicit interface member implementation. It can be used only Returns a copy of this string converted to uppercase. The uppercase equivalent of the current string. - [!NOTE] -> This method does not modify the value of the current instance. Instead, it returns a new string in which all characters in the current instance are converted to uppercase. - - The method is often used to convert a string to uppercase so that it can be used in a case-insensitive comparison. A better method to perform case-insensitive comparison is to call a string comparison method that has a parameter whose value you set to for a culture-sensitive, case-insensitive comparison. - -## Security Considerations - The casing operation that results from calling the method takes the casing conventions of the current culture into account. If you need the lowercase or uppercase version of an operating system identifier, such as a file name, named pipe, or registry key, use the or method. This produces the same result in every culture (unlike the method) and performs more efficiently. - -## Examples - The following example calls the method to convert a series of one-character strings that contain each character in the Basic Latin, Latin-1 Supplement, and Latin Extended-A character sets. It then displays each string whose uppercase character is different from its lowercase character. - - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.ToUpper/cpp/ToUpperEx.cpp" id="Snippet1"::: - :::code language="csharp" source="~/snippets/csharp/System/String/ToUpper/ToUpperEx.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/ToUpper/ToUpperEx.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.ToUpper/vb/ToUpperEx.vb" id="Snippet1"::: - + [!NOTE] +> This method does not modify the value of the current instance. Instead, it returns a new string in which all characters in the current instance are converted to uppercase. + + The method is often used to convert a string to uppercase so that it can be used in a case-insensitive comparison. A better method to perform case-insensitive comparison is to call a string comparison method that has a parameter whose value you set to for a culture-sensitive, case-insensitive comparison. + +## Security Considerations + The casing operation that results from calling the method takes the casing conventions of the current culture into account. If you need the lowercase or uppercase version of an operating system identifier, such as a file name, named pipe, or registry key, use the or method. This produces the same result in every culture (unlike the method) and performs more efficiently. + +## Examples + The following example calls the method to convert a series of one-character strings that contain each character in the Basic Latin, Latin-1 Supplement, and Latin Extended-A character sets. It then displays each string whose uppercase character is different from its lowercase character. + + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.ToUpper/cpp/ToUpperEx.cpp" id="Snippet1"::: + :::code language="csharp" source="~/snippets/csharp/System/String/ToUpper/ToUpperEx.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/ToUpper/ToUpperEx.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.ToUpper/vb/ToUpperEx.vb" id="Snippet1"::: + ]]> @@ -16403,24 +16474,24 @@ This member is an explicit interface member implementation. It can be used only Returns a copy of this string converted to uppercase, using the casing rules of the specified culture. The uppercase equivalent of the current string. - [!NOTE] -> This method does not modify the value of the current instance. Instead, it returns a new string in which all characters in the current instance are converted to uppercase. - -## Security Considerations - If you pass the method a object other than , the casing operation will take culture-specific rules into account. If you need the lowercase or uppercase version of an operating system identifier, such as a file name, named pipe, or registry key, use the or method. This produces the same result in every culture and performs more efficiently. - -## Examples - The following example converts a string of lowercase characters to two strings of uppercase characters using the English-United States and Turkish-Turkey cultures, then compares the uppercase strings. The uppercase strings are identical except that for each occurrence of the Unicode LATIN CAPITAL LETTER I in one string, the other string contains LATIN CAPITAL LETTER I WITH DOT ABOVE. - - :::code language="csharp" source="~/snippets/csharp/System/String/ToUpper/toupper.cs" interactive="try-dotnet" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/ToUpper/toupper.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.toupper1/VB/toupper.vb" id="Snippet1"::: - + [!NOTE] +> This method does not modify the value of the current instance. Instead, it returns a new string in which all characters in the current instance are converted to uppercase. + +## Security Considerations + If you pass the method a object other than , the casing operation will take culture-specific rules into account. If you need the lowercase or uppercase version of an operating system identifier, such as a file name, named pipe, or registry key, use the or method. This produces the same result in every culture and performs more efficiently. + +## Examples + The following example converts a string of lowercase characters to two strings of uppercase characters using the English-United States and Turkish-Turkey cultures, then compares the uppercase strings. The uppercase strings are identical except that for each occurrence of the Unicode LATIN CAPITAL LETTER I in one string, the other string contains LATIN CAPITAL LETTER I WITH DOT ABOVE. + + :::code language="csharp" source="~/snippets/csharp/System/String/ToUpper/toupper.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/ToUpper/toupper.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/string.toupper1/VB/toupper.vb" id="Snippet1"::: + ]]> @@ -16475,26 +16546,26 @@ This member is an explicit interface member implementation. It can be used only Returns a copy of this object converted to uppercase using the casing rules of the invariant culture. The uppercase equivalent of the current string. - property. - - If your application depends on the case of a string changing in a predictable way that is unaffected by the current culture, use the method. The method is equivalent to `ToUpper(CultureInfo.InvariantCulture)`. The method is recommended when a collection of strings must appear in a predictable order in a user interface control. - -> [!NOTE] -> This method does not modify the value of the current instance. Instead, it returns a new string in which all characters in the current instance are converted to uppercase. - -## Security Considerations - If you need the lowercase or uppercase version of an operating system identifier, such as a file name, named pipe, or registry key, use the or methods. - -## Examples - The following example defines a string array that contains a single word in a number of languages. The method is used to populate the elements of a parallel array with the case-insensitive version of each word. The method is used to sort the case-sensitive array based on the order of elements in the uppercase array to ensure that elements appear in the same order regardless of language. - - :::code language="csharp" source="~/snippets/csharp/System/String/ToUpperInvariant/toupperinvariant.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/String/ToUpperInvariant/toupperinvariant.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.toupperinvariant/vb/toupperinvariant.vb" id="Snippet1"::: - + property. + + If your application depends on the case of a string changing in a predictable way that is unaffected by the current culture, use the method. The method is equivalent to `ToUpper(CultureInfo.InvariantCulture)`. The method is recommended when a collection of strings must appear in a predictable order in a user interface control. + +> [!NOTE] +> This method does not modify the value of the current instance. Instead, it returns a new string in which all characters in the current instance are converted to uppercase. + +## Security Considerations + If you need the lowercase or uppercase version of an operating system identifier, such as a file name, named pipe, or registry key, use the or methods. + +## Examples + The following example defines a string array that contains a single word in a number of languages. The method is used to populate the elements of a parallel array with the case-insensitive version of each word. The method is used to sort the case-sensitive array based on the order of elements in the uppercase array to ensure that elements appear in the same order regardless of language. + + :::code language="csharp" source="~/snippets/csharp/System/String/ToUpperInvariant/toupperinvariant.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/String/ToUpperInvariant/toupperinvariant.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.toupperinvariant/vb/toupperinvariant.vb" id="Snippet1"::: + ]]> @@ -16557,28 +16628,28 @@ This member is an explicit interface member implementation. It can be used only Removes all leading and trailing white-space characters from the current string. The string that remains after all white-space characters are removed from the start and end of the current string. If no characters can be trimmed from the current instance, the method returns the current instance unchanged. - [!NOTE] -> If the `Trim` method removes any characters from the current instance, this method does not modify the value of the current instance. Instead, it returns a new string in which all leading and trailing white space characters found in the current instance are removed. - -If the current string equals or all the characters in the current instance consist of white-space characters, the method returns . - -White-space characters are defined by the Unicode standard. The `Trim` method removes any leading and trailing characters that produce a return value of `true` when they are passed to the method. - -## Examples - -The following example uses the method to remove any extra white space from strings entered by the user before concatenating them. - -:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Trim/cpp/trim2.cpp" id="Snippet2"::: -:::code language="csharp" source="~/snippets/csharp/System/String/Trim/Trim2.cs" id="Snippet2"::: -:::code language="fsharp" source="~/snippets/fsharp/System/String/Trim/Trim2.fs" id="Snippet2"::: -:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Trim/vb/Trim2.vb" id="Snippet2"::: - + [!NOTE] +> If the `Trim` method removes any characters from the current instance, this method does not modify the value of the current instance. Instead, it returns a new string in which all leading and trailing white space characters found in the current instance are removed. + +If the current string equals or all the characters in the current instance consist of white-space characters, the method returns . + +White-space characters are defined by the Unicode standard. The `Trim` method removes any leading and trailing characters that produce a return value of `true` when they are passed to the method. + +## Examples + +The following example uses the method to remove any extra white space from strings entered by the user before concatenating them. + +:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Trim/cpp/trim2.cpp" id="Snippet2"::: +:::code language="csharp" source="~/snippets/csharp/System/String/Trim/Trim2.cs" id="Snippet2"::: +:::code language="fsharp" source="~/snippets/fsharp/System/String/Trim/Trim2.fs" id="Snippet2"::: +:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Trim/vb/Trim2.vb" id="Snippet2"::: + ]]> @@ -16625,17 +16696,17 @@ The following example uses the Removes all leading and trailing instances of a character from the current string. The string that remains after all instances of the character are removed from the start and end of the current string. If no characters can be trimmed from the current instance, the method returns the current instance unchanged. - [!NOTE] -> If the `Trim(System.Char)` method removes any characters from the current instance, this method does not modify the value of the current instance. Instead, it returns a new string in which all leading and trailing `trimChar` characters found in the current instance are removed. - -If the current string equals or all the characters in the current instance consist of `trimChar` characters, the method returns . - + [!NOTE] +> If the `Trim(System.Char)` method removes any characters from the current instance, this method does not modify the value of the current instance. Instead, it returns a new string in which all leading and trailing `trimChar` characters found in the current instance are removed. + +If the current string equals or all the characters in the current instance consist of `trimChar` characters, the method returns . + ]]> @@ -16703,28 +16774,28 @@ If the current string equals Removes all leading and trailing occurrences of a set of characters specified in an array from the current string. The string that remains after all occurrences of the characters in the parameter are removed from the start and end of the current string. If is or an empty array, white-space characters are removed instead. If no characters can be trimmed from the current instance, the method returns the current instance unchanged. - [!NOTE] -> If the `Trim(System.Char[])` method removes any characters from the current instance, this method does not modify the value of the current instance. Instead, it returns a new string in which all leading and trailing `trimChars` characters found in the current instance are removed. - -If the current string equals or all the characters in the current instance consist of characters in the `trimChars` array, the method returns . - -If `trimChars` is `null` or an empty array, this method removes any leading or trailing characters that result in the method returning `true` when they are passed to the method. - -## Examples - -The following example uses the `Trim(System.Char[])` method to remove space, asterisk (*), and apostrophe (') characters from a string. - -:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Trim/cpp/trim1.cpp" id="Snippet1"::: -:::code language="csharp" source="~/snippets/csharp/System/String/Trim/Trim1.cs" interactive="try-dotnet-method" id="Snippet1"::: -:::code language="fsharp" source="~/snippets/fsharp/System/String/Trim/Trim1.fs" id="Snippet1"::: -:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Trim/vb/Trim1.vb" id="Snippet1"::: - + [!NOTE] +> If the `Trim(System.Char[])` method removes any characters from the current instance, this method does not modify the value of the current instance. Instead, it returns a new string in which all leading and trailing `trimChars` characters found in the current instance are removed. + +If the current string equals or all the characters in the current instance consist of characters in the `trimChars` array, the method returns . + +If `trimChars` is `null` or an empty array, this method removes any leading or trailing characters that result in the method returning `true` when they are passed to the method. + +## Examples + +The following example uses the `Trim(System.Char[])` method to remove space, asterisk (*), and apostrophe (') characters from a string. + +:::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.String.Trim/cpp/trim1.cpp" id="Snippet1"::: +:::code language="csharp" source="~/snippets/csharp/System/String/Trim/Trim1.cs" interactive="try-dotnet-method" id="Snippet1"::: +:::code language="fsharp" source="~/snippets/fsharp/System/String/Trim/Trim1.fs" id="Snippet1"::: +:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.Trim/vb/Trim1.vb" id="Snippet1"::: + ]]> @@ -16769,15 +16840,15 @@ The following example uses the `Trim(System.Char[])` method to remove space, ast Removes all the trailing white-space characters from the current string. The string that remains after all white-space characters are removed from the end of the current string. If no characters can be trimmed from the current instance, the method returns the current instance unchanged. - [!NOTE] -> If the `TrimEnd` method removes any characters from the current instance, this method does not modify the value of the current instance. Instead, it returns a new string in which all trailing white-space characters are removed from the current string. - + [!NOTE] +> If the `TrimEnd` method removes any characters from the current instance, this method does not modify the value of the current instance. Instead, it returns a new string in which all trailing white-space characters are removed from the current string. + ]]> @@ -16818,15 +16889,15 @@ The `TrimEnd` method removes from the current string all trailing white-space ch Removes all the trailing occurrences of a character from the current string. The string that remains after all occurrences of the character are removed from the end of the current string. If no characters can be trimmed from the current instance, the method returns the current instance unchanged. - [!NOTE] -> If the `TrimEnd(System.Char)` method removes any characters from the current instance, this method does not modify the value of the current instance. Instead, it returns a new string in which all trailing `trimChar` characters are removed from the current string. - + [!NOTE] +> If the `TrimEnd(System.Char)` method removes any characters from the current instance, this method does not modify the value of the current instance. Instead, it returns a new string in which all trailing `trimChar` characters are removed from the current string. + ]]> @@ -16894,23 +16965,23 @@ The `TrimEnd(System.Char)` method removes from the current string all trailing ` Removes all the trailing occurrences of a set of characters specified in an array from the current string. The string that remains after all occurrences of the characters in the parameter are removed from the end of the current string. If is or an empty array, Unicode white-space characters are removed instead. If no characters can be trimmed from the current instance, the method returns the current instance unchanged. - [!NOTE] -> If the `TrimEnd(System.Char[])` method removes any characters from the current instance, this method does not modify the value of the current instance. Instead, it returns a new string in which all trailing characters found in `trimChars` are removed from the current string. - -## Examples - -The following example demonstrates how you can use the `TrimEnd(System.Char[])` method to trim white space or punctuation marks from the end of a string. - -:::code language="csharp" source="~/snippets/csharp/System/String/TrimEnd/sample2.cs" interactive="try-dotnet-method" id="Snippet2"::: -:::code language="fsharp" source="~/snippets/fsharp/System/String/TrimEnd/sample2.fs" id="Snippet2"::: -:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.TrimEnd/vb/Sample2.vb" id="Snippet2"::: - + [!NOTE] +> If the `TrimEnd(System.Char[])` method removes any characters from the current instance, this method does not modify the value of the current instance. Instead, it returns a new string in which all trailing characters found in `trimChars` are removed from the current string. + +## Examples + +The following example demonstrates how you can use the `TrimEnd(System.Char[])` method to trim white space or punctuation marks from the end of a string. + +:::code language="csharp" source="~/snippets/csharp/System/String/TrimEnd/sample2.cs" interactive="try-dotnet-method" id="Snippet2"::: +:::code language="fsharp" source="~/snippets/fsharp/System/String/TrimEnd/sample2.fs" id="Snippet2"::: +:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.TrimEnd/vb/Sample2.vb" id="Snippet2"::: + ]]> @@ -16955,15 +17026,15 @@ The following example demonstrates how you can use the `TrimEnd(System.Char[])` Removes all the leading white-space characters from the current string. The string that remains after all white-space characters are removed from the start of the current string. If no characters can be trimmed from the current instance, the method returns the current instance unchanged. - [!NOTE] -> If the `TrimStart` method removes any characters from the current instance, this method does not modify the value of the current instance. Instead, it returns a new string in which all leading white space characters found in the current instance are removed. - + [!NOTE] +> If the `TrimStart` method removes any characters from the current instance, this method does not modify the value of the current instance. Instead, it returns a new string in which all leading white space characters found in the current instance are removed. + ]]> @@ -17004,15 +17075,15 @@ The `TrimStart` method removes from the current string all leading white-space c Removes all the leading occurrences of a specified character from the current string. The string that remains after all occurrences of the character are removed from the start of the current string. If no characters can be trimmed from the current instance, the method returns the current instance unchanged. - [!NOTE] -> If the `TrimStart(System.Char)` method removes any characters from the current instance, this method does not modify the value of the current instance. Instead, it returns a new string in which all leading `trimChar` characters found in the current instance are removed. - + [!NOTE] +> If the `TrimStart(System.Char)` method removes any characters from the current instance, this method does not modify the value of the current instance. Instead, it returns a new string in which all leading `trimChar` characters found in the current instance are removed. + ]]> @@ -17080,35 +17151,35 @@ The `TrimStart(System.Char)` method removes from the current string all leading Removes all the leading occurrences of a set of characters specified in an array from the current string. The string that remains after all occurrences of characters in the parameter are removed from the start of the current string. If is or an empty array, white-space characters are removed instead. If no characters can be trimmed from the current instance, the method returns the current instance unchanged. - [!NOTE] -> If the `TrimStart(System.Char[])` method removes any characters from the current instance, this method does not modify the value of the current instance. Instead, it returns a new string in which all leading characters that are in the `trimChars` parameter found in the current instance are removed. - -## Examples - -The following example demonstrates the basic functionality of the method: - -:::code language="csharp" source="~/snippets/csharp/System/String/TrimStart/sample.cs" interactive="try-dotnet-method" id="Snippet1"::: -:::code language="fsharp" source="~/snippets/fsharp/System/String/TrimStart/sample.fs" id="Snippet1"::: -:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.TrimStart/vb/sample.vb" id="Snippet1"::: - -The following example uses the method to trim white space and comment characters from lines of source code. The `StripComments` method wraps a call to and passes it a character array that contains a space and the comment character, which is an apostrophe ( ' ) in Visual Basic and a slash ( / ) in C# or F#. The method is also called to remove leading white space when evaluating whether a string is a comment. - -:::code language="csharp" source="~/snippets/csharp/System/String/TrimStart/sample.cs" id="Snippet2"::: -:::code language="fsharp" source="~/snippets/fsharp/System/String/TrimStart/sample.fs" id="Snippet2"::: -:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.TrimStart/vb/sample.vb" id="Snippet2"::: - -The following example then illustrates a call to the `StripComments` method. - -:::code language="csharp" source="~/snippets/csharp/System/String/TrimStart/sample.cs" id="Snippet3"::: -:::code language="fsharp" source="~/snippets/fsharp/System/String/TrimStart/sample.fs" id="Snippet3"::: -:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.TrimStart/vb/sample.vb" id="Snippet3"::: - + [!NOTE] +> If the `TrimStart(System.Char[])` method removes any characters from the current instance, this method does not modify the value of the current instance. Instead, it returns a new string in which all leading characters that are in the `trimChars` parameter found in the current instance are removed. + +## Examples + +The following example demonstrates the basic functionality of the method: + +:::code language="csharp" source="~/snippets/csharp/System/String/TrimStart/sample.cs" interactive="try-dotnet-method" id="Snippet1"::: +:::code language="fsharp" source="~/snippets/fsharp/System/String/TrimStart/sample.fs" id="Snippet1"::: +:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.TrimStart/vb/sample.vb" id="Snippet1"::: + +The following example uses the method to trim white space and comment characters from lines of source code. The `StripComments` method wraps a call to and passes it a character array that contains a space and the comment character, which is an apostrophe ( ' ) in Visual Basic and a slash ( / ) in C# or F#. The method is also called to remove leading white space when evaluating whether a string is a comment. + +:::code language="csharp" source="~/snippets/csharp/System/String/TrimStart/sample.cs" id="Snippet2"::: +:::code language="fsharp" source="~/snippets/fsharp/System/String/TrimStart/sample.fs" id="Snippet2"::: +:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.TrimStart/vb/sample.vb" id="Snippet2"::: + +The following example then illustrates a call to the `StripComments` method. + +:::code language="csharp" source="~/snippets/csharp/System/String/TrimStart/sample.cs" id="Snippet3"::: +:::code language="fsharp" source="~/snippets/fsharp/System/String/TrimStart/sample.fs" id="Snippet3"::: +:::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.String.TrimStart/vb/sample.vb" id="Snippet3"::: + ]]> diff --git a/xml/System/StringComparer.xml b/xml/System/StringComparer.xml index dc04cc652f7..78b56891e9d 100644 --- a/xml/System/StringComparer.xml +++ b/xml/System/StringComparer.xml @@ -83,31 +83,31 @@ Represents a string comparison operation that uses specific case and culture-based or ordinal comparison rules. - class embodies string-based comparison, equality, and hash code operations that take into account both case and culture-specific comparison rules. You can use the class to create a type-specific comparison to sort the elements in a generic collection. Classes such as , , , and use the class for sorting purposes. - - A comparison operation that is represented by the class is defined to be either case-sensitive or case-insensitive, and use either word (culture-sensitive) or ordinal (culture-insensitive) comparison rules. For more information about word and ordinal comparison rules, see . + class embodies string-based comparison, equality, and hash code operations that take into account both case and culture-specific comparison rules. You can use the class to create a type-specific comparison to sort the elements in a generic collection. Classes such as , , , and use the class for sorting purposes. + + A comparison operation that is represented by the class is defined to be either case-sensitive or case-insensitive, and use either word (culture-sensitive) or ordinal (culture-insensitive) comparison rules. For more information about word and ordinal comparison rules, see . > [!NOTE] > You can download the [Sorting Weight Tables](https://www.microsoft.com/download/details.aspx?id=10921), a set of text files that contain information on the character weights used in sorting and comparison operations for Windows operating systems, and the [Default Unicode Collation Element Table](https://www.unicode.org/Public/UCA/latest/allkeys.txt), the latest version of the sort weight table for Linux and macOS. The specific version of the sort weight table on Linux and macOS depends on the version of the [International Components for Unicode](https://icu.unicode.org/) libraries installed on the system. For information on ICU versions and the Unicode versions that they implement, see [Downloading ICU](https://icu.unicode.org/download). -## Implemented properties +## Implemented properties + +You might be confused about how to use the class properties because of a seeming contradiction. The class is declared `abstract` (`MustInherit` in Visual Basic), which means its members can be invoked only on an object of a class derived from the class. The contradiction is that each property of the class is declared `static` (`Shared` in Visual Basic), which means the property can be invoked without first creating a derived class. -You might be confused about how to use the class properties because of a seeming contradiction. The class is declared `abstract` (`MustInherit` in Visual Basic), which means its members can be invoked only on an object of a class derived from the class. The contradiction is that each property of the class is declared `static` (`Shared` in Visual Basic), which means the property can be invoked without first creating a derived class. - - You can call a property directly because each property actually returns an instance of an anonymous class that is derived from the class. Consequently, the type of each property value is , which is the base class of the anonymous class, not the type of the anonymous class itself. Each class property returns a object that supports predefined case and comparison rules. - -## Examples + You can call a property directly because each property actually returns an instance of an anonymous class that is derived from the class. Consequently, the type of each property value is , which is the base class of the anonymous class, not the type of the anonymous class itself. Each class property returns a object that supports predefined case and comparison rules. + +## Examples + +The following example demonstrates the properties and the method of the class. The example illustrates how different objects sort three versions of the Latin letter I. -The following example demonstrates the properties and the method of the class. The example illustrates how different objects sort three versions of the Latin letter I. - :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.StringComparer/cpp/omni.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/StringComparer/Overview/omni.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/StringComparer/Overview/omni.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.StringComparer/vb/omni.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.StringComparer/vb/omni.vb" id="Snippet1"::: + ]]> @@ -217,31 +217,40 @@ The following example demonstrates the properties and the An object to compare to . An object to compare to . When overridden in a derived class, compares two objects and returns an indication of their relative sort order. - A signed integer that indicates the relative values of and , as shown in the following table. - - Value - - Meaning - - Less than zero - - precedes in the sort order, or is and is not . - - Zero - - is equal to , or and are both . - - Greater than zero - - follows in the sort order, or is and is not . - - + A signed integer that indicates the relative values of and , as shown in the following table. + + Value + + + Meaning + + + + + Less than zero + + + precedes in the sort order, or is and is not . + + + Zero + + + is equal to , or and are both . + + + Greater than zero + + + follows in the sort order, or is and is not . + + - method is slightly more efficient than the method because no conversion of the `x` and `y` arguments is needed to perform the comparison. - + method is slightly more efficient than the method because no conversion of the `x` and `y` arguments is needed to perform the comparison. + ]]> Neither nor is a object, and neither nor implements the interface. @@ -303,31 +312,40 @@ The following example demonstrates the properties and the A string to compare to . A string to compare to . When overridden in a derived class, compares two strings and returns an indication of their relative sort order. - A signed integer that indicates the relative values of and , as shown in the following table. - - Value - - Meaning - - Less than zero - - precedes in the sort order, or is and is not . - - Zero - - is equal to , or and are both . - - Greater than zero - - follows in the sort order, or is and is not . - - + A signed integer that indicates the relative values of and , as shown in the following table. + + Value + + + Meaning + + + + + Less than zero + + + precedes in the sort order, or is and is not . + + + Zero + + + is equal to , or and are both . + + + Greater than zero + + + follows in the sort order, or is and is not . + + - method is slightly more efficient than the method because no conversion of the `x` and `y` arguments is needed to perform the comparison. - + method is slightly more efficient than the method because no conversion of the `x` and `y` arguments is needed to perform the comparison. + ]]> @@ -378,16 +396,16 @@ The following example demonstrates the properties and the Creates a object that compares strings according to the rules of a specified culture. A new object that performs string comparisons according to the comparison rules used by the parameter and the case rule specified by the parameter. - method of the class. The example illustrates how different objects sort three versions of the Latin letter I. - + method of the class. The example illustrates how different objects sort three versions of the Latin letter I. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.StringComparer/cpp/omni.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/StringComparer/Overview/omni.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/StringComparer/Overview/omni.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.StringComparer/vb/omni.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.StringComparer/vb/omni.vb" id="Snippet1"::: + ]]> @@ -483,33 +501,33 @@ The following example demonstrates the properties and the Gets a object that performs a case-sensitive string comparison using the word comparison rules of the current culture. A new object. - returned by the property can be used when strings are linguistically relevant. For example, if strings are displayed to the user, or if strings are the result of user interaction, culture-sensitive string comparison should be used to order the string data. - - The current culture is the object associated with the current thread. - - The property actually returns an instance of an anonymous class derived from the class. - - Each call to the property `get` accessor returns a new object, as the following code shows. - + returned by the property can be used when strings are linguistically relevant. For example, if strings are displayed to the user, or if strings are the result of user interaction, culture-sensitive string comparison should be used to order the string data. + + The current culture is the object associated with the current thread. + + The property actually returns an instance of an anonymous class derived from the class. + + Each call to the property `get` accessor returns a new object, as the following code shows. + :::code language="csharp" source="~/snippets/csharp/System/StringComparer/CurrentCulture/CompareObjects.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/StringComparer/CurrentCulture/CompareObjects.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.StringComparer.CurrentCulture/vb/CompareObjects.vb" id="Snippet1"::: - - To improve performance, you can store the object in a local variable rather than retrieve the value of the property multiple times. - - - -## Examples - The following code example demonstrates the properties and the method of the class. The example illustrates how different objects sort three versions of the Latin letter I. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.StringComparer.CurrentCulture/vb/CompareObjects.vb" id="Snippet1"::: + + To improve performance, you can store the object in a local variable rather than retrieve the value of the property multiple times. + + + +## Examples + The following code example demonstrates the properties and the method of the class. The example illustrates how different objects sort three versions of the Latin letter I. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.StringComparer/cpp/omni.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/StringComparer/Overview/omni.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/StringComparer/Overview/omni.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.StringComparer/vb/omni.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.StringComparer/vb/omni.vb" id="Snippet1"::: + ]]> Best Practices for Using Strings in .NET @@ -557,25 +575,25 @@ The following example demonstrates the properties and the Gets a object that performs case-insensitive string comparisons using the word comparison rules of the current culture. A new object for string comparison. - object associated with the current thread; it is returned by the property. - - The returned by the property can be used when strings are linguistically relevant but their case is not. For example, if strings are displayed to the user but case is unimportant, culture-sensitive, case-insensitive string comparison should be used to order the string data. -[!INCLUDE[platform-note](~/includes/c-and-posix-cultures.md)] + The returned by the property can be used when strings are linguistically relevant but their case is not. For example, if strings are displayed to the user but case is unimportant, culture-sensitive, case-insensitive string comparison should be used to order the string data. + +[!INCLUDE[platform-note](~/includes/c-and-posix-cultures.md)] + + The property actually returns an instance of an anonymous class derived from the class. + + Each call to the property `get` accessor returns a new object, as the following code shows. - The property actually returns an instance of an anonymous class derived from the class. - - Each call to the property `get` accessor returns a new object, as the following code shows. - :::code language="csharp" source="~/snippets/csharp/System/StringComparer/CurrentCulture/CompareObjects.cs" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/StringComparer/CurrentCulture/CompareObjects.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.StringComparer.CurrentCulture/vb/CompareObjects.vb" id="Snippet2"::: - - To improve performance, you can store the object in a local variable rather than retrieve the value of the property multiple times. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.StringComparer.CurrentCulture/vb/CompareObjects.vb" id="Snippet2"::: + + To improve performance, you can store the object in a local variable rather than retrieve the value of the property multiple times. + ]]> Best Practices for Using Strings in .NET @@ -649,11 +667,11 @@ The following example demonstrates the properties and the if and refer to the same object, or and are both the same type of object and those objects are equal, or both and are ; otherwise, . - method may be slightly more efficient than the method. - + method may be slightly more efficient than the method. + ]]> @@ -717,11 +735,11 @@ The following example demonstrates the properties and the if and refer to the same object, or and are equal, or and are ; otherwise, . - method may be slightly more efficient than the method. - + method may be slightly more efficient than the method. + ]]> @@ -826,13 +844,13 @@ The following example demonstrates the properties and the When overridden in a derived class, gets the hash code for the specified object. A 32-bit signed hash code calculated from the value of the parameter. - method is more efficient than the method because the `obj` parameter does not have to be unboxed to perform the operation. - - The method allocates an amount of memory that is proportional to the size of `obj` to calculate the hash code of `obj`. In the case of large strings, trying to retrieve the hash code can throw an . Instead, you can use an alternate algorithm that allocates a fixed amount of memory when calculating hash codes. To use this algorithm, add the [](/dotnet/framework/configure-apps/file-schema/runtime/netfx45-cultureawarecomparergethashcode-longstrings-element) element to the [\](/dotnet/framework/configure-apps/file-schema/runtime/runtime-element) section of your application's configuration file. - + method is more efficient than the method because the `obj` parameter does not have to be unboxed to perform the operation. + + The method allocates an amount of memory that is proportional to the size of `obj` to calculate the hash code of `obj`. In the case of large strings, trying to retrieve the hash code can throw an . Instead, you can use an alternate algorithm that allocates a fixed amount of memory when calculating hash codes. To use this algorithm, add the [](/dotnet/framework/configure-apps/file-schema/runtime/netfx45-cultureawarecomparergethashcode-longstrings-element) element to the [\](/dotnet/framework/configure-apps/file-schema/runtime/runtime-element) section of your application's configuration file. + ]]> Not enough memory is available to allocate the buffer that is required to compute the hash code. @@ -889,13 +907,13 @@ The following example demonstrates the properties and the When overridden in a derived class, gets the hash code for the specified string. A 32-bit signed hash code calculated from the value of the parameter. - method is more efficient than the method because the `obj` parameter does not have to be unboxed to perform the operation. - - The method allocates an amount of memory that is proportional to the size of `obj` to calculate the hash code of `obj`. In the case of large strings, trying to retrieve the hash code can throw an . Instead, you can use an alternate algorithm that allocates a fixed amount of memory when calculating hash codes. To use this algorithm, add the [](/dotnet/framework/configure-apps/file-schema/runtime/netfx45-cultureawarecomparergethashcode-longstrings-element) element to the [\](/dotnet/framework/configure-apps/file-schema/runtime/runtime-element) section of your application's configuration file. - + method is more efficient than the method because the `obj` parameter does not have to be unboxed to perform the operation. + + The method allocates an amount of memory that is proportional to the size of `obj` to calculate the hash code of `obj`. In the case of large strings, trying to retrieve the hash code can throw an . Instead, you can use an alternate algorithm that allocates a fixed amount of memory when calculating hash codes. To use this algorithm, add the [](/dotnet/framework/configure-apps/file-schema/runtime/netfx45-cultureawarecomparergethashcode-longstrings-element) element to the [\](/dotnet/framework/configure-apps/file-schema/runtime/runtime-element) section of your application's configuration file. + ]]> Not enough memory is available to allocate the buffer that is required to compute the hash code. @@ -942,25 +960,25 @@ The following example demonstrates the properties and the Gets a object that performs a case-sensitive string comparison using the word comparison rules of the invariant culture. A new object. - returned by the property compares strings in a linguistically relevant manner, but it is not suitable for display in any particular culture. Its major application is to order strings in a way that will be identical across cultures. - - The invariant culture is the object returned by the property. - - The property actually returns an instance of an anonymous class derived from the class. - - - -## Examples - The following code example demonstrates the properties and the method of the class. The example illustrates how different objects sort three versions of the Latin letter I. - + returned by the property compares strings in a linguistically relevant manner, but it is not suitable for display in any particular culture. Its major application is to order strings in a way that will be identical across cultures. + + The invariant culture is the object returned by the property. + + The property actually returns an instance of an anonymous class derived from the class. + + + +## Examples + The following code example demonstrates the properties and the method of the class. The example illustrates how different objects sort three versions of the Latin letter I. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.StringComparer/cpp/omni.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/StringComparer/Overview/omni.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/StringComparer/Overview/omni.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.StringComparer/vb/omni.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.StringComparer/vb/omni.vb" id="Snippet1"::: + ]]> Best Practices for Using Strings in .NET @@ -1005,15 +1023,15 @@ The following example demonstrates the properties and the Gets a object that performs a case-insensitive string comparison using the word comparison rules of the invariant culture. A new object. - returned by the property compares strings in a linguistically relevant manner that ignores case, but it is not suitable for display in any particular culture. Its major application is to order strings in a way that will be identical across cultures. - - The invariant culture is the object returned by the property. - - The property actually returns an instance of an anonymous class derived from the class. - + returned by the property compares strings in a linguistically relevant manner that ignores case, but it is not suitable for display in any particular culture. Its major application is to order strings in a way that will be identical across cultures. + + The invariant culture is the object returned by the property. + + The property actually returns an instance of an anonymous class derived from the class. + ]]> Best Practices for Using Strings in .NET @@ -1186,23 +1204,23 @@ A "well-known ordinal comparer" describes a comparer that behaves identically to Gets a object that performs a case-sensitive ordinal string comparison. A object. - returned by the property performs a simple byte comparison that is independent of language. This is most appropriate when comparing strings that are generated programmatically or when comparing case-sensitive resources such as passwords. - - The property actually returns an instance of an anonymous class derived from the class. - - - -## Examples - The following code example demonstrates the properties and the method of the class. The example illustrates how different objects sort three versions of the Latin letter I. - + returned by the property performs a simple byte comparison that is independent of language. This is most appropriate when comparing strings that are generated programmatically or when comparing case-sensitive resources such as passwords. + + The property actually returns an instance of an anonymous class derived from the class. + + + +## Examples + The following code example demonstrates the properties and the method of the class. The example illustrates how different objects sort three versions of the Latin letter I. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.StringComparer/cpp/omni.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/StringComparer/Overview/omni.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/StringComparer/Overview/omni.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.StringComparer/vb/omni.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.StringComparer/vb/omni.vb" id="Snippet1"::: + ]]> Best Practices for Using Strings in .NET @@ -1250,23 +1268,23 @@ A "well-known ordinal comparer" describes a comparer that behaves identically to Gets a object that performs a case-insensitive ordinal string comparison. A object. - returned by the property treats the characters in the strings to compare as if they were converted to uppercase using the conventions of the invariant culture, and then performs a simple byte comparison that is independent of language. This is most appropriate when comparing strings that are generated programmatically or when comparing case-insensitive resources such as paths and filenames. - - The property actually returns an instance of an anonymous class derived from the class. - - - -## Examples - The following code example demonstrates the properties and the method of the class. The example illustrates how different objects sort three versions of the Latin letter I. - + returned by the property treats the characters in the strings to compare as if they were converted to uppercase using the conventions of the invariant culture, and then performs a simple byte comparison that is independent of language. This is most appropriate when comparing strings that are generated programmatically or when comparing case-insensitive resources such as paths and filenames. + + The property actually returns an instance of an anonymous class derived from the class. + + + +## Examples + The following code example demonstrates the properties and the method of the class. The example illustrates how different objects sort three versions of the Latin letter I. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.StringComparer/cpp/omni.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/StringComparer/Overview/omni.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/StringComparer/Overview/omni.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.StringComparer/vb/omni.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.StringComparer/vb/omni.vb" id="Snippet1"::: + ]]> Best Practices for Using Strings in .NET diff --git a/xml/System/StringComparison.xml b/xml/System/StringComparison.xml index cd3aa2b00dc..99ebc51bef0 100644 --- a/xml/System/StringComparison.xml +++ b/xml/System/StringComparison.xml @@ -54,28 +54,28 @@ Specifies the culture, case, and sort rules to be used by certain overloads of the and methods. - enumeration is used to specify whether a string comparison should use the current culture or the invariant culture, word or ordinal sort rules, and be case-sensitive or case-insensitive. - + enumeration is used to specify whether a string comparison should use the current culture or the invariant culture, word or ordinal sort rules, and be case-sensitive or case-insensitive. + > [!IMPORTANT] -> When you call a string comparison method such as , , or , you should always call an overload that includes a parameter of type so that you can specify the type of comparison that the method performs. For more information, see [Best Practices for Using Strings](/dotnet/standard/base-types/best-practices-strings). - - An operation that uses word sort rules performs a culture-sensitive comparison wherein certain nonalphanumeric Unicode characters might have special weights assigned to them. Using word sort rules and the conventions of a specific culture, the hyphen ("-") might have a very small weight assigned to it so that "coop" and "co-op" appear next to each other in a sorted list. - -[!INCLUDE[platform-note](~/includes/c-and-posix-cultures.md)] - - An operation that uses ordinal sort rules performs a comparison based on the numeric value (Unicode code point) of each in the string. An ordinal comparison is fast but culture-insensitive. When you use ordinal sort rules to sort strings that start with Unicode characters (U+), the string U+xxxx comes before the string U+yyyy if the value of xxxx is numerically less than yyyy. - - For more information about comparisons, see the class remarks. For more information about culture, see the class remarks. For guidelines on when to use ordinal or culture-sensitive comparison rules or the rules of the invariant culture, see [Best Practices for Using Strings](/dotnet/standard/base-types/best-practices-strings). For a set of text files that contain information on the character weights used in sorting and comparison operations for Windows operating systems, see [Sorting Weight Tables](https://www.microsoft.com/download/details.aspx?id=10921). For the sort weight table for Linux and macOS, see the [Default Unicode Collation Element Table](https://www.unicode.org/Public/UCA/latest/allkeys.txt). - -## Examples +> When you call a string comparison method such as , , or , you should always call an overload that includes a parameter of type so that you can specify the type of comparison that the method performs. For more information, see [Best Practices for Using Strings](/dotnet/standard/base-types/best-practices-strings). + + An operation that uses word sort rules performs a culture-sensitive comparison wherein certain nonalphanumeric Unicode characters might have special weights assigned to them. Using word sort rules and the conventions of a specific culture, the hyphen ("-") might have a very small weight assigned to it so that "coop" and "co-op" appear next to each other in a sorted list. + +[!INCLUDE[platform-note](~/includes/c-and-posix-cultures.md)] + + An operation that uses ordinal sort rules performs a comparison based on the numeric value (Unicode code point) of each in the string. An ordinal comparison is fast but culture-insensitive. When you use ordinal sort rules to sort strings that start with Unicode characters (U+), the string U+xxxx comes before the string U+yyyy if the value of xxxx is numerically less than yyyy. + + For more information about comparisons, see the class remarks. For more information about culture, see the class remarks. For guidelines on when to use ordinal or culture-sensitive comparison rules or the rules of the invariant culture, see [Best Practices for Using Strings](/dotnet/standard/base-types/best-practices-strings). For a set of text files that contain information on the character weights used in sorting and comparison operations for Windows operating systems, see [Sorting Weight Tables](https://www.microsoft.com/download/details.aspx?id=10921). For the sort weight table for Linux and macOS, see the [Default Unicode Collation Element Table](https://www.unicode.org/Public/UCA/latest/allkeys.txt). + +## Examples The following example compares three sets of strings by using each member of the enumeration. The comparisons use the conventions of the English (United States), Thai (Thailand), and Turkish (Turkey) cultures. Note that the strings "a" and "a-" are considered equivalent in the "th-TH" culture but not in the others, while "i" and "İ" are considered equivalent in the "tr-TR" culture when case is ignored but not in the other cultures. - + :::code language="csharp" source="~/snippets/csharp/System/String/Equals/equals_ex3.cs" id="Snippet3"::: :::code language="fsharp" source="~/snippets/fsharp/System/String/Equals/equals_ex3.fs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.equals/vb/equals_ex3.vb" id="Snippet3"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.string.equals/vb/equals_ex3.vb" id="Snippet3"::: ]]> diff --git a/xml/System/StringNormalizationExtensions.xml b/xml/System/StringNormalizationExtensions.xml index 66c35e94570..25522a47266 100644 --- a/xml/System/StringNormalizationExtensions.xml +++ b/xml/System/StringNormalizationExtensions.xml @@ -70,12 +70,12 @@ Provides extension methods to work with string normalization. - class are designed to work with .NET implementations that do not support the and methods. However, these methods are included in the class in .NET Standard 2.0 and are therefore available on all .NET implementations that support the .NET Standard 2.0. For more information, see [.NET Standard](/dotnet/standard/net-standard). - + ]]> diff --git a/xml/System/SystemException.xml b/xml/System/SystemException.xml index 2bea65ccbae..a7d46375d4a 100644 --- a/xml/System/SystemException.xml +++ b/xml/System/SystemException.xml @@ -59,16 +59,16 @@ Serves as the base class for system exceptions namespace. - , , and . - + , , and . + > [!IMPORTANT] -> Because serves as the base class of a variety of exception types, your code should not throw a exception, nor should it attempt to handle a exception unless you intend to re-throw the original exception. - - uses the HRESULT COR_E_SYSTEM, that has the value 0x80131501. - +> Because serves as the base class of a variety of exception types, your code should not throw a exception, nor should it attempt to handle a exception unless you intend to re-throw the original exception. + + uses the HRESULT COR_E_SYSTEM, that has the value 0x80131501. + ]]> @@ -120,18 +120,18 @@ Initializes a new instance of the class. - property of the new instance to a system-supplied message that describes the error, such as "A system error has occurred." This message takes into account the current system culture. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The localized error message string.| - + property of the new instance to a system-supplied message that describes the error, such as "A system error has occurred." This message takes into account the current system culture. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The localized error message string.| + ]]> @@ -174,18 +174,18 @@ The message that describes the error. Initializes a new instance of the class with a specified error message. - . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The error message string.| - + . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The error message string.| + ]]> @@ -247,11 +247,11 @@ The contextual information about the source or destination. Initializes a new instance of the class with serialized data. - XML and SOAP Serialization @@ -297,18 +297,18 @@ The exception that is the cause of the current exception. If the parameter is not a null reference ( in Visual Basic), the current exception is raised in a block that handles the inner exception. Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception. - property. The property returns the same value that is passed into the constructor, or a null reference (`Nothing` in Visual Basic) if the property does not supply the inner exception value to the constructor. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||The inner exception reference.| -||The error message string.| - + property. The property returns the same value that is passed into the constructor, or a null reference (`Nothing` in Visual Basic) if the property does not supply the inner exception value to the constructor. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||The inner exception reference.| +||The error message string.| + ]]> diff --git a/xml/System/ThreadStaticAttribute.xml b/xml/System/ThreadStaticAttribute.xml index 45c6de7ab12..f636dd21b91 100644 --- a/xml/System/ThreadStaticAttribute.xml +++ b/xml/System/ThreadStaticAttribute.xml @@ -60,33 +60,33 @@ Indicates that the value of a static field is unique for each thread. - is not shared between threads. Each executing thread has a separate instance of the field, and independently sets and gets values for that field. If the field is accessed on a different thread, it will contain a different value. - - Note that in addition to applying the attribute to a field, you must also define it as a `static` field (in C# or F#) or a `Shared` field (in Visual Basic). - + is not shared between threads. Each executing thread has a separate instance of the field, and independently sets and gets values for that field. If the field is accessed on a different thread, it will contain a different value. + + Note that in addition to applying the attribute to a field, you must also define it as a `static` field (in C# or F#) or a `Shared` field (in Visual Basic). + > [!NOTE] -> Do not specify initial values for fields marked with `ThreadStaticAttribute`, because such initialization occurs only once, when the class constructor executes, and therefore affects only one thread. If you do not specify an initial value, you can rely on the field being initialized to its default value if it is a value type, or to `null` if it is a reference type. - - Use this attribute as it is, and do not derive from it. - - For more information about using attributes, see [Attributes](/dotnet/standard/attributes/). - - - -## Examples - The following example instantiates a random number generator, creates ten threads in addition to the main thread, and then generates two million random numbers in each thread. It uses the attribute to calculate the sum and the count of random numbers per thread. It also defines two additional per-thread fields, `previous` and `abnormal`, that allows it to detect corruption of the random number generator. - +> Do not specify initial values for fields marked with `ThreadStaticAttribute`, because such initialization occurs only once, when the class constructor executes, and therefore affects only one thread. If you do not specify an initial value, you can rely on the field being initialized to its default value if it is a value type, or to `null` if it is a reference type. + + Use this attribute as it is, and do not derive from it. + + For more information about using attributes, see [Attributes](/dotnet/standard/attributes/). + + + +## Examples + The following example instantiates a random number generator, creates ten threads in addition to the main thread, and then generates two million random numbers in each thread. It uses the attribute to calculate the sum and the count of random numbers per thread. It also defines two additional per-thread fields, `previous` and `abnormal`, that allows it to detect corruption of the random number generator. + :::code language="csharp" source="~/snippets/csharp/System/ThreadStaticAttribute/Overview/threadsafe2a.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/ThreadStaticAttribute/Overview/threadsafe2a.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.threadstaticattribute/vb/threadsafe2a.vb" id="Snippet1"::: - - The example uses the `lock` statement in C#, the `lock` function in F#, and the `SyncLock` construct in Visual Basic to synchronize access to the random number generator. This prevents corruption of the random number generator, which typically results in its returning a value of zero for all subsequent calls. - - The example also uses the class to ensure that each thread has finished generating random numbers before it displays the total number of calls. Otherwise, if the main thread completes execution before the additional threads that it spawns, it displays an inaccurate value for the total number of method calls. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.threadstaticattribute/vb/threadsafe2a.vb" id="Snippet1"::: + + The example uses the `lock` statement in C#, the `lock` function in F#, and the `SyncLock` construct in Visual Basic to synchronize access to the random number generator. This prevents corruption of the random number generator, which typically results in its returning a value of zero for all subsequent calls. + + The example also uses the class to ensure that each thread has finished generating random numbers before it displays the total number of calls. Otherwise, if the main thread completes execution before the additional threads that it spawns, it displays an inaccurate value for the total number of method calls. + ]]> diff --git a/xml/System/TimeOnly.xml b/xml/System/TimeOnly.xml index 33543ebf61a..e9e1c75815a 100644 --- a/xml/System/TimeOnly.xml +++ b/xml/System/TimeOnly.xml @@ -249,8 +249,7 @@ A positive or negative time interval. When this method returns, contains the number of excess days, if any, that resulted from wrapping during this addition operation. - Returns a new that adds the value of the specified time span to the value of this instance. - If the result wraps past the end of the day, this method returns the number of excess days as an out parameter. + Returns a new that adds the value of the specified time span to the value of this instance. If the result wraps past the end of the day, this method returns the number of excess days as an out parameter. An object whose value is the sum of the time represented by this instance and the time interval represented by value. To be added. @@ -306,8 +305,7 @@ A number of whole and fractional hours. The value parameter can be negative or positive. When this method returns, contains the number of excess days, if any, that resulted from wrapping during this addition operation. - Returns a new that adds the specified number of hours to the value of this instance. - If the result wraps past the end of the day, this method returns the number of excess days as an out parameter. + Returns a new that adds the specified number of hours to the value of this instance. If the result wraps past the end of the day, this method returns the number of excess days as an out parameter. An object whose value is the sum of the time represented by this instance and the number of hours represented by value. To be added. @@ -363,8 +361,7 @@ A number of whole and fractional minutes. The value parameter can be negative or positive. When this method returns, contains the number of excess days, if any, that resulted from wrapping during this addition operation. - Returns a new that adds the specified number of minutes to the value of this instance. - If the result wraps past the end of the day, this method returns the number of excess days as an out parameter. + Returns a new that adds the specified number of minutes to the value of this instance. If the result wraps past the end of the day, this method returns the number of excess days as an out parameter. An object whose value is the sum of the time represented by this instance and the number of minutes represented by value. To be added. @@ -402,9 +399,9 @@ A boxed object to compare, or . Compares the value of this instance to a specified object that contains a specified value, and returns an integer that indicates whether this instance is earlier than, the same as, or later than the specified value. A signed number indicating the relative values of this instance and the value parameter. - Less than zero if this instance is earlier than value. - Zero if this instance is the same as value. - Greater than zero if this instance is later than value. + Less than zero if this instance is earlier than value. + Zero if this instance is the same as value. + Greater than zero if this instance is later than value. To be added. @@ -436,11 +433,11 @@ Compares the value of this instance to a specified value and indicates whether this instance is earlier than, the same as, or later than the specified value. A signed number indicating the relative values of this instance and the value parameter. -- Less than zero if this instance is earlier than value. + - Less than zero if this instance is earlier than value. -- Zero if this instance is the same as value. + - Zero if this instance is the same as value. -- Greater than zero if this instance is later than value. + - Greater than zero if this instance is later than value. To be added. @@ -782,7 +779,7 @@ The starting time of day, inclusive. The ending time of day, exclusive. Determines if a time falls within the range provided. - Supports both "normal" ranges such as 10:00-12:00, and ranges that span midnight such as 23:00-01:00. + Supports both "normal" ranges such as 10:00-12:00, and ranges that span midnight such as 23:00-01:00. , if the time falls within the range, otherwise. @@ -1391,8 +1388,7 @@ If `start` and `end` are equal, this method returns `false`, meaning there is ze A span containing the time to convert. An array of allowable formats of . - Converts the specified span to its equivalent using the specified array of formats. - The format of the string representation must match at least one of the specified formats exactly or an exception is thrown. + Converts the specified span to its equivalent using the specified array of formats. The format of the string representation must match at least one of the specified formats exactly or an exception is thrown. A instance. To be added. @@ -1436,8 +1432,7 @@ If `start` and `end` are equal, this method returns `false`, meaning there is ze A string containing a time to convert. A format specifier that defines the required format of . - Converts the specified string representation of a time to its equivalent using the specified format. - The format of the string representation must match the specified format exactly or an exception is thrown. + Converts the specified string representation of a time to its equivalent using the specified format. The format of the string representation must match the specified format exactly or an exception is thrown. A instance. To be added. @@ -1483,8 +1478,7 @@ If `start` and `end` are equal, this method returns `false`, meaning there is ze A span containing the time to convert. An array of allowable formats of . - Converts the specified span to a equivalent using the specified array of formats. - The format of the string representation must match at least one of the specified formats exactly or an exception is thrown. + Converts the specified span to a equivalent using the specified array of formats. The format of the string representation must match at least one of the specified formats exactly or an exception is thrown. A instance. To be added. @@ -1534,8 +1528,7 @@ If `start` and `end` are equal, this method returns `false`, meaning there is ze The format specifier that defines the required format of . The culture-specific formatting information about . A bitwise combination of enumeration values that indicates the permitted format of . A typical value to specify is . - Converts the specified span representation of a time to its equivalent using the specified format, culture-specific format information, and style. - The format of the string representation must match the specified format exactly or an exception is thrown. + Converts the specified span representation of a time to its equivalent using the specified format, culture-specific format information, and style. The format of the string representation must match the specified format exactly or an exception is thrown. A instance. To be added. @@ -1587,8 +1580,7 @@ If `start` and `end` are equal, this method returns `false`, meaning there is ze An array of allowable formats of . The culture-specific formatting information about . A bitwise combination of enumeration values that indicates the permitted format of . A typical value to specify is . - Converts the specified span representation of a time to its equivalent using the specified array of formats, culture-specific format information, and style. - The format of the string representation must match at least one of the specified formats exactly or an exception is thrown. + Converts the specified span representation of a time to its equivalent using the specified array of formats, culture-specific format information, and style. The format of the string representation must match at least one of the specified formats exactly or an exception is thrown. A instance. To be added. @@ -1642,8 +1634,7 @@ If `start` and `end` are equal, this method returns `false`, meaning there is ze The format specifier that defines the required format of . The culture-specific formatting information about . A bitwise combination of the enumeration values that provides additional information about , about style elements that may be present in , or about the conversion from to a value. A typical value to specify is . - Converts the specified string representation of a time to its equivalent using the specified format, culture-specific format information, and style. - The format of the string representation must match the specified format exactly or an exception is thrown. + Converts the specified string representation of a time to its equivalent using the specified format, culture-specific format information, and style. The format of the string representation must match the specified format exactly or an exception is thrown. A instance. To be added. @@ -1699,8 +1690,7 @@ If `start` and `end` are equal, this method returns `false`, meaning there is ze An array of allowable formats of . The culture-specific formatting information about . A bitwise combination of enumeration values that indicates the permitted format of . A typical value to specify is . - Converts the specified string representation of a time to its equivalent using the specified array of formats, culture-specific format information, and style. - The format of the string representation must match at least one of the specified formats exactly or an exception is thrown. + Converts the specified string representation of a time to its equivalent using the specified array of formats, culture-specific format information, and style. The format of the string representation must match at least one of the specified formats exactly or an exception is thrown. A instance. To be added. @@ -2399,8 +2389,7 @@ The accepted standard formats are 'r', 'R', 'o', 'O', 't', and 'T'. A span containing the time to convert. The required format of . When this method returns, contains the value equivalent to the time contained in , if the conversion succeeded, or TimeOnly.MinValue if the conversion failed. The conversion fails if is an empty string or does not contain a time that corresponds to the pattern specified in . This parameter is passed uninitialized. - Converts the specified span representation of a time to its equivalent using the specified format and style. - The format of the string representation must match the specified format exactly. The method returns a value that indicates whether the conversion succeeded. + Converts the specified span representation of a time to its equivalent using the specified format and style. The format of the string representation must match the specified format exactly. The method returns a value that indicates whether the conversion succeeded. if was converted successfully; otherwise, . To be added. @@ -2503,8 +2492,7 @@ The accepted standard formats are 'r', 'R', 'o', 'O', 't', and 'T'. A string containing the time to convert. The required format of . When this method returns, contains the value equivalent to the time contained in , if the conversion succeeded, or TimeOnly.MinValue if the conversion failed. The conversion fails if is an empty string or does not contain a time that corresponds to the pattern specified in format. This parameter is passed uninitialized. - Converts the specified string representation of a time to its equivalent using the specified format and style. - The format of the string representation must match the specified format exactly. The method returns a value that indicates whether the conversion succeeded. + Converts the specified string representation of a time to its equivalent using the specified format and style. The format of the string representation must match the specified format exactly. The method returns a value that indicates whether the conversion succeeded. if was converted successfully; otherwise, . To be added. @@ -2610,8 +2598,7 @@ The accepted standard formats are 'r', 'R', 'o', 'O', 't', and 'T'. An object that supplies culture-specific formatting information about . A bitwise combination of one or more enumeration values that indicate the permitted format of . When this method returns, contains the value equivalent to the time contained in , if the conversion succeeded, or TimeOnly.MinValue if the conversion failed. The conversion fails if is an empty string or does not contain a time that corresponds to the pattern specified in format. This parameter is passed uninitialized. - Converts the specified span representation of a time to its equivalent using the specified format, culture-specific format information, and style. - The format of the string representation must match the specified format exactly. The method returns a value that indicates whether the conversion succeeded. + Converts the specified span representation of a time to its equivalent using the specified format, culture-specific format information, and style. The format of the string representation must match the specified format exactly. The method returns a value that indicates whether the conversion succeeded. if was converted successfully; otherwise, . To be added. @@ -2731,8 +2718,7 @@ The accepted standard formats are 'r', 'R', 'o', 'O', 't', and 'T'. An object that supplies culture-specific formatting information about . A bitwise combination of one or more enumeration values that indicate the permitted format of . When this method returns, contains the value equivalent to the time contained in , if the conversion succeeded, or TimeOnly.MinValue if the conversion failed. The conversion fails if is an empty string or does not contain a time that corresponds to the pattern specified in format. This parameter is passed uninitialized. - Converts the specified span representation of a time to its equivalent using the specified format, culture-specific format information, and style. - The format of the string representation must match the specified format exactly. The method returns a value that indicates whether the conversion succeeded. + Converts the specified span representation of a time to its equivalent using the specified format, culture-specific format information, and style. The format of the string representation must match the specified format exactly. The method returns a value that indicates whether the conversion succeeded. if was converted successfully; otherwise, . To be added. diff --git a/xml/System/TimeProvider.xml b/xml/System/TimeProvider.xml index aaa0edb26cd..b13186a7d80 100644 --- a/xml/System/TimeProvider.xml +++ b/xml/System/TimeProvider.xml @@ -81,17 +81,12 @@ Creates a new instance, using values to measure time intervals. The newly created instance. - The delegate specified by the callback parameter is invoked once after elapses, and thereafter each time the time interval elapses. - - If is zero, the callback is invoked immediately. If is -1 milliseconds, is not invoked; the timer is disabled, but can be re-enabled by calling the method. - - If is 0 or -1 milliseconds and is positive, is invoked once; the periodic behavior of the timer is disabled, but can be re-enabled using the method. - - The returned instance is implicitly rooted while the timer is still scheduled. - + The delegate specified by the callback parameter is invoked once after elapses, and thereafter each time the time interval elapses. + If is zero, the callback is invoked immediately. If is -1 milliseconds, is not invoked; the timer is disabled, but can be re-enabled by calling the method. + If is 0 or -1 milliseconds and is positive, is invoked once; the periodic behavior of the timer is disabled, but can be re-enabled using the method. + The returned instance is implicitly rooted while the timer is still scheduled. - captures the and stores that with the for use in invoking each time it's called. That capture can be suppressed with . - + captures the and stores that with the for use in invoking each time it's called. That capture can be suppressed with . is . diff --git a/xml/System/TimeSpan.xml b/xml/System/TimeSpan.xml index b3b1d1c089f..b0bf3dcfd1b 100644 --- a/xml/System/TimeSpan.xml +++ b/xml/System/TimeSpan.xml @@ -655,25 +655,34 @@ The specified `days`, `hours`, `minutes`, `seconds`, `milliseconds`, and `micros The first time interval to compare. The second time interval to compare. Compares two values and returns an integer that indicates whether the first value is shorter than, equal to, or longer than the second value. - One of the following values. - - Value - - Description - - -1 - - is shorter than . - - 0 - - is equal to . - - 1 - - is longer than . - - + One of the following values. + + Value + + + Description + + + + + -1 + + + is shorter than . + + + 0 + + + is equal to . + + + 1 + + + is longer than . + + An object to compare, or . Compares this instance to a specified object and returns an integer that indicates whether this instance is shorter than, equal to, or longer than the specified object. - One of the following values. - - Value - - Description - - -1 - - This instance is shorter than . - - 0 - - This instance is equal to . - - 1 - - This instance is longer than , or is . - - + One of the following values. + + Value + + + Description + + + + + -1 + + + This instance is shorter than . + + + 0 + + + This instance is equal to . + + + 1 + + + This instance is longer than , or is . + + An object to compare to this instance. Compares this instance to a specified object and returns an integer that indicates whether this instance is shorter than, equal to, or longer than the object. - A signed number indicating the relative values of this instance and . - - Value - - Description - - A negative integer - - This instance is shorter than . - - Zero - - This instance is equal to . - - A positive integer - - This instance is longer than . - - + A signed number indicating the relative values of this instance and . + + Value + + + Description + + + + + A negative integer + + + This instance is shorter than . + + + Zero + + + This instance is equal to . + + + A positive integer + + + This instance is longer than . + + is less than TimeSpan.MinValue or greater than TimeSpan.MaxValue. - -or- +-or- - is . + is . - -or- +-or- - is . + is . is equal to . @@ -1474,13 +1501,13 @@ The specified `days`, `hours`, `minutes`, `seconds`, `milliseconds`, and `micros is less than TimeSpan.MinValue or greater than TimeSpan.MaxValue. - -or- +-or- - is . + is . - -or- +-or- - is . + is . is equal to . @@ -1604,13 +1631,13 @@ The specified `days`, `hours`, `minutes`, `seconds`, `milliseconds`, and `micros is less than TimeSpan.MinValue or greater than TimeSpan.MaxValue. - -or- +-or- - is . + is . - -or- +-or- - is . + is . is equal to . @@ -1690,13 +1717,13 @@ The specified `days`, `hours`, `minutes`, `seconds`, `milliseconds`, and `micros is less than TimeSpan.MinValue or greater than TimeSpan.MaxValue. - -or- +-or- - is . + is . - -or- +-or- - is . + is . is equal to . @@ -1776,13 +1803,13 @@ The specified `days`, `hours`, `minutes`, `seconds`, `milliseconds`, and `micros is less than TimeSpan.MinValue or greater than TimeSpan.MaxValue. - -or- +-or- - is . + is . - -or- +-or- - is . + is . is equal to . @@ -3420,9 +3447,9 @@ When a time interval component in the string to be parsed contains more than sev represents a number that is less than TimeSpan.MinValue or greater than TimeSpan.MaxValue. - -or- +-or- - At least one of the days, hours, minutes, or seconds components is outside its valid range. +At least one of the days, hours, minutes, or seconds components is outside its valid range. @@ -3599,9 +3626,9 @@ When a time interval component in the string to be parsed contains more than sev represents a number that is less than TimeSpan.MinValue or greater than TimeSpan.MaxValue. - -or- +-or- - At least one of the days, hours, minutes, or seconds components in is outside its valid range. +At least one of the days, hours, minutes, or seconds components in is outside its valid range. @@ -3724,9 +3751,9 @@ When a time interval component in the string to be parsed contains more than sev represents a number that is less than TimeSpan.MinValue or greater than TimeSpan.MaxValue. - -or- +-or- - At least one of the days, hours, minutes, or seconds components in is outside its valid range. +At least one of the days, hours, minutes, or seconds components in is outside its valid range. Standard TimeSpan Format Strings Custom TimeSpan Format Strings @@ -3839,9 +3866,9 @@ When a time interval component in the string to be parsed contains more than sev represents a number that is less than TimeSpan.MinValue or greater than TimeSpan.MaxValue. - -or- +-or- - At least one of the days, hours, minutes, or seconds components in is outside its valid range. +At least one of the days, hours, minutes, or seconds components in is outside its valid range. Standard TimeSpan Format Strings Custom TimeSpan Format Strings @@ -4077,9 +4104,9 @@ When a time interval component in the string to be parsed contains more than sev represents a number that is less than TimeSpan.MinValue or greater than TimeSpan.MaxValue. - -or- +-or- - At least one of the days, hours, minutes, or seconds components in is outside its valid range. +At least one of the days, hours, minutes, or seconds components in is outside its valid range. Standard TimeSpan Format Strings Custom TimeSpan Format Strings @@ -4198,9 +4225,9 @@ When a time interval component in the string to be parsed contains more than sev represents a number that is less than TimeSpan.MinValue or greater than TimeSpan.MaxValue. - -or- +-or- - At least one of the days, hours, minutes, or seconds components in is outside its valid range. +At least one of the days, hours, minutes, or seconds components in is outside its valid range. Standard TimeSpan Format Strings Custom TimeSpan Format Strings @@ -4372,9 +4399,24 @@ When a time interval component in the string to be parsed contains more than sev An object to compare, or . Compares this instance to a specified object and returns an integer that indicates whether this instance is shorter than, equal to, or longer than the specified object. - - One of the following values: - ValueDescription-1This instance is shorter than .0This instance is equal to .1This instance is longer than , or is . + One of the following values: + + Value + Description + + + -1 + This instance is shorter than . + + + 0 + This instance is equal to . + + + 1 + This instance is longer than , or is . + + - [System.Obsolete("System.TimeZone has been deprecated. Please investigate the use of System.TimeZoneInfo instead.")] - [<System.Obsolete("System.TimeZone has been deprecated. Please investigate the use of System.TimeZoneInfo instead.")>] + [System.Obsolete("System.TimeZone has been deprecated. Please investigate the use of System.TimeZoneInfo instead.")] + [<System.Obsolete("System.TimeZone has been deprecated. Please investigate the use of System.TimeZoneInfo instead.")>] [System.Obsolete("System.TimeZone has been deprecated. Investigate the use of System.TimeZoneInfo instead.")] @@ -67,31 +67,31 @@ Represents a time zone. - [!IMPORTANT] -> Whenever possible, use the class instead of the class. - - You can use the class to retrieve information about the current time zone, and to convert times from local time to Coordinated Universal Time (UTC) or vice versa. However, you cannot use the class to represent time zones other than the local zone or to handle date and time conversions from one time zone to another. For this purpose, use the class. You can use this class to retrieve information on any time zone defined on the local system, to create custom time zones, and to convert times from one time zone to another. - - The class supports only a single daylight saving time adjustment rule for the local time zone. As a result, the class can accurately report daylight saving time information or convert between UTC and local time only for the period in which the latest adjustment rule is in effect. In contrast, the class supports multiple adjustment rules, which makes it possible to work with historic time zone data. - - - -## Examples - The following example references and displays selected `TimeZone` class elements. - +> Whenever possible, use the class instead of the class. + + You can use the class to retrieve information about the current time zone, and to convert times from local time to Coordinated Universal Time (UTC) or vice versa. However, you cannot use the class to represent time zones other than the local zone or to handle date and time conversions from one time zone to another. For this purpose, use the class. You can use this class to retrieve information on any time zone defined on the local system, to create custom time zones, and to convert times from one time zone to another. + + The class supports only a single daylight saving time adjustment rule for the local time zone. As a result, the class can accurately report daylight saving time information or convert between UTC and local time only for the period in which the latest adjustment rule is in effect. In contrast, the class supports multiple adjustment rules, which makes it possible to work with historic time zone data. + + + +## Examples + The following example references and displays selected `TimeZone` class elements. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.TimeZone.Class/CPP/tzclass.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/TimeZone/Overview/tzclass.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone.Class/VB/tzclass.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone.Class/VB/tzclass.vb" id="Snippet1"::: + ]]> - In addition to providing implementations for its members (those marked in Visual Basic), it is important that classes derived from override the default behavior of the method. This is because the default behavior of in the .NET Framework version 2.0 does not depend on a call to , as it did in the .NET Framework versions 1.0 and 1.1. For details, see the method. + In addition to providing implementations for its members (those marked in Visual Basic), it is important that classes derived from override the default behavior of the method. This is because the default behavior of in the .NET Framework version 2.0 does not depend on a call to , as it did in the .NET Framework versions 1.0 and 1.1. For details, see the method. @@ -170,20 +170,20 @@ Gets the time zone of the current computer. A object that represents the current local time zone. - property corresponds to the property. Whenever possible, use the property. - - - -## Examples - The following example references the `CurrentTimeZone` property and displays the names for standard time and daylight saving time for the local time zone. - + property corresponds to the property. Whenever possible, use the property. + + + +## Examples + The following example references the `CurrentTimeZone` property and displays the names for standard time and daylight saving time for the local time zone. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.TimeZone.Class/CPP/tzclass.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/TimeZone/Overview/tzclass.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone.Class/VB/tzclass.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone.Class/VB/tzclass.vb" id="Snippet1"::: + ]]> @@ -229,22 +229,22 @@ Gets the daylight saving time zone name. The daylight saving time zone name. - property corresponds to the property. Whenever possible, use the property. - - - -## Examples - The following example references and displays the `DaylightName` property of the current time zone. - + property corresponds to the property. Whenever possible, use the property. + + + +## Examples + The following example references and displays the `DaylightName` property of the current time zone. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.TimeZone.Class/CPP/tzclass.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/TimeZone/Overview/tzclass.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone.Class/VB/tzclass.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone.Class/VB/tzclass.vb" id="Snippet1"::: + ]]> @@ -291,13 +291,13 @@ Returns the daylight saving time period for a particular year. A object that contains the start and end date for daylight saving time in . - object, where the value of and is , and the value of is a initialized to 0 ticks. - + object, where the value of and is , and the value of is a initialized to 0 ticks. + ]]> @@ -349,24 +349,24 @@ Returns the Coordinated Universal Time (UTC) offset for the specified local time. The Coordinated Universal Time (UTC) offset from . - property. If the value of the property is or , the method returns the offset of the local time zone. If the value of the property is , the method returns an offset equal to . - - If the local time zone observes daylight saving time, applies the current adjustment rule to `time` when determining the offset of the local time zone. That is, the offset returned by reflects whether `time` falls in the time zone's standard time or its daylight saving time. - + property. If the value of the property is or , the method returns the offset of the local time zone. If the value of the property is , the method returns an offset equal to . + + If the local time zone observes daylight saving time, applies the current adjustment rule to `time` when determining the offset of the local time zone. That is, the offset returned by reflects whether `time` falls in the time zone's standard time or its daylight saving time. + > [!NOTE] -> The method recognizes only the current daylight saving time adjustment rule for the local time zone. As a result, it is guaranteed to accurately return the UTC offset of a local time only during the period in which the latest adjustment rule is in effect. It may return inaccurate results if `time` is a historic date and time value that was subject to a previous adjustment rule. - - The method corresponds to the method. Whenever possible, use the method. - - Because the date and time value represented by `time` and this value's offset from UTC are not tightly coupled, a local or unspecified date and time value can return a different offset value when run on different computers or when run on the same computer under different time zones. If this behavior is undesirable, use a value instead. The data type tightly couples a date and time value with its offset from UTC. - +> The method recognizes only the current daylight saving time adjustment rule for the local time zone. As a result, it is guaranteed to accurately return the UTC offset of a local time only during the period in which the latest adjustment rule is in effect. It may return inaccurate results if `time` is a historic date and time value that was subject to a previous adjustment rule. + + The method corresponds to the method. Whenever possible, use the method. + + Because the date and time value represented by `time` and this value's offset from UTC are not tightly coupled, a local or unspecified date and time value can return a different offset value when run on different computers or when run on the same computer under different time zones. If this behavior is undesirable, use a value instead. The data type tightly couples a date and time value with its offset from UTC. + ]]> @@ -424,13 +424,13 @@ if is in a daylight saving time period; otherwise, . - class supports a single daylight saving time adjustment rule, the method applies the current adjustment rule to any date, regardless of whether the adjustment rule was in effect on that date. Assuming that the operating system itself has accurate historic daylight saving time data, a more accurate result is available by using the method. Whenever possible, use the method. - + class supports a single daylight saving time adjustment rule, the method applies the current adjustment rule to any date, regardless of whether the adjustment rule was in effect on that date. Assuming that the operating system itself has accurate historic daylight saving time data, a more accurate result is available by using the method. Whenever possible, use the method. + ]]> @@ -480,11 +480,11 @@ if is in ; otherwise, . - method provides the same functionality as this overload of the method. Whenever possible, use the method. - + method provides the same functionality as this overload of the method. Whenever possible, use the method. + ]]> @@ -529,20 +529,20 @@ Gets the standard time zone name. The standard time zone name. - property corresponds to the property. Whenever possible, use the property. - - - -## Examples - The following example references and displays the `StandardName` property of the current time zone. - + property corresponds to the property. Whenever possible, use the property. + + + +## Examples + The following example references and displays the `StandardName` property of the current time zone. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.TimeZone.Class/CPP/tzclass.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/TimeZone/Overview/tzclass.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone.Class/VB/tzclass.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone.Class/VB/tzclass.vb" id="Snippet1"::: + ]]> An attempt was made to set this property to . @@ -590,33 +590,28 @@ Returns the local time that corresponds to a specified date and time value. A object whose value is the local time that corresponds to . - value returned by this method. - -|`time` parameter|Behavior|Return value| -|----------------------|--------------|------------------| -|A Coordinated Universal Time (UTC) time ().|Converts the time from UTC to the local time.|A object whose value is the local time that corresponds to `time`.| -|A local time ().|No conversion necessary.|The same value represented by the `time` parameter.| -|An unspecified time ().|Assumes that the time is UTC and converts it from UTC to the local time.|A object whose value is the local time that corresponds to `time`.| - - If the local time zone observes daylight saving time, applies the current adjustment rule to `time` when performing the conversion. - + value returned by this method. + +|`time` parameter|Behavior|Return value| +|----------------------|--------------|------------------| +|A Coordinated Universal Time (UTC) time ().|Converts the time from UTC to the local time.|A object whose value is the local time that corresponds to `time`.| +|A local time ().|No conversion necessary.|The same value represented by the `time` parameter.| +|An unspecified time ().|Assumes that the time is UTC and converts it from UTC to the local time.|A object whose value is the local time that corresponds to `time`.| + + If the local time zone observes daylight saving time, applies the current adjustment rule to `time` when performing the conversion. + > [!NOTE] -> The method recognizes only the current daylight saving time adjustment rule for the local time zone. As a result, it is guaranteed to accurately return the local time corresponding to a particular UTC time only during the period in which the latest adjustment rule is in effect. It may return inaccurate results if `time` is a historic date and time value that was subject to a previous adjustment rule. - - The method corresponds to the method with its `destinationTimeZone` parameter set to . Whenever possible, use the method. - +> The method recognizes only the current daylight saving time adjustment rule for the local time zone. As a result, it is guaranteed to accurately return the local time corresponding to a particular UTC time only during the period in which the latest adjustment rule is in effect. It may return inaccurate results if `time` is a historic date and time value that was subject to a previous adjustment rule. + + The method corresponds to the method with its `destinationTimeZone` parameter set to . Whenever possible, use the method. + ]]> - Although it is not required, in most cases derived classes running under the .NET Framework version 2.0 should override the default implementation of this method. In the .NET Framework versions 1.0 and 1.1, the method called the method and adjusted for daylight saving time when returning the local time. However, starting with the .NET Framework 2.0, the behavior of the default implementation depends on the property of the parameter. If its value is , this method returns unchanged. If its value is either or , this method assumes is UTC and converts it to the local system time without calling the method. - - The following code provides a simple override of the default implementation of the method. In this code, the variable represents a private instance of the class: - - :::code language="csharp" source="~/snippets/csharp/System/TimeZone/ToLocalTime/TimeZone_ToLocalTime.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone.ToLocalTime/VB/TimeZone_ToLocalTime.vb" id="Snippet1"::: + Although it is not required, in most cases derived classes running under the .NET Framework version 2.0 should override the default implementation of this method. In the .NET Framework versions 1.0 and 1.1, the method called the method and adjusted for daylight saving time when returning the local time. However, starting with the .NET Framework 2.0, the behavior of the default implementation depends on the property of the parameter. If its value is , this method returns unchanged. If its value is either or , this method assumes is UTC and converts it to the local system time without calling the method. The following code provides a simple override of the default implementation of the method. In this code, the variable represents a private instance of the class: :::code language="csharp" source="~/snippets/csharp/System/TimeZone/ToLocalTime/TimeZone_ToLocalTime.cs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone.ToLocalTime/VB/TimeZone_ToLocalTime.vb" id="Snippet1"::: @@ -662,20 +657,20 @@ Returns the Coordinated Universal Time (UTC) that corresponds to a specified time. A object whose value is the Coordinated Universal Time (UTC) that corresponds to . - applies the current adjustment rule to the `time` parameter when performing the conversion. - + applies the current adjustment rule to the `time` parameter when performing the conversion. + > [!NOTE] -> The method recognizes only the current daylight saving time adjustment rule for the local time zone. As a result, it is guaranteed to accurately return the Coordinated Universal Time (UTC) corresponding to a particular local time only during the period in which the latest adjustment rule is in effect. It may return inaccurate results if `time` is a historic date and time value that was subject to a previous adjustment rule. - - If the `time` parameter is an ambiguous time, the method assumes that it is a standard time. (An ambiguous time is one that can map either to a standard time or to a daylight saving time in the local time zone.) If `time` is an invalid time, the method simply subtracts the local time from the local time zone's UTC offset to return UTC. (An invalid time is one that does not exist because of the application of daylight saving time adjustment rules.) - - Because `time` is interpreted in relation to the current time zone on the current system, the date and time returned by this method can differ if an application is run on different computers or on the same computer with different time zones. For cases in which a date and time value must represent a single, unambiguous point in time, use a value to represent the local time. - - The method corresponds to the method overload with a parameter whose property does not equal . Whenever possible, use the method overload. - +> The method recognizes only the current daylight saving time adjustment rule for the local time zone. As a result, it is guaranteed to accurately return the Coordinated Universal Time (UTC) corresponding to a particular local time only during the period in which the latest adjustment rule is in effect. It may return inaccurate results if `time` is a historic date and time value that was subject to a previous adjustment rule. + + If the `time` parameter is an ambiguous time, the method assumes that it is a standard time. (An ambiguous time is one that can map either to a standard time or to a daylight saving time in the local time zone.) If `time` is an invalid time, the method simply subtracts the local time from the local time zone's UTC offset to return UTC. (An invalid time is one that does not exist because of the application of daylight saving time adjustment rules.) + + Because `time` is interpreted in relation to the current time zone on the current system, the date and time returned by this method can differ if an application is run on different computers or on the same computer with different time zones. For cases in which a date and time value must represent a single, unambiguous point in time, use a value to represent the local time. + + The method corresponds to the method overload with a parameter whose property does not equal . Whenever possible, use the method overload. + ]]> diff --git a/xml/System/TimeZoneInfo+AdjustmentRule.xml b/xml/System/TimeZoneInfo+AdjustmentRule.xml index 53289a81d1a..63714414300 100644 --- a/xml/System/TimeZoneInfo+AdjustmentRule.xml +++ b/xml/System/TimeZoneInfo+AdjustmentRule.xml @@ -75,84 +75,84 @@ Provides information about a time zone adjustment, such as the transition to and from daylight saving time. - class defines the effective start and end dates of a particular time change to and from daylight saving time, respectively, as well as its delta (the exact amount by which the adjustment causes the time zone's standard time to change). In addition, two properties return objects that define when each transition to and from standard time occurs. - + class defines the effective start and end dates of a particular time change to and from daylight saving time, respectively, as well as its delta (the exact amount by which the adjustment causes the time zone's standard time to change). In addition, two properties return objects that define when each transition to and from standard time occurs. + > [!NOTE] -> An instance of the class is immutable. Once an object has been created, its values cannot be modified. - - To create a object, call the `static` (`Shared` in Visual Basic) method. You can then supply an array of objects to two of the overloads of the method. To retrieve the adjustment rules of a particular time zone, call its method, which returns an array of objects. - - - -## Examples - The following example retrieves all time zones defined on the local system and displays complete information about their adjustment rules. - +> An instance of the class is immutable. Once an object has been created, its values cannot be modified. + + To create a object, call the `static` (`Shared` in Visual Basic) method. You can then supply an array of objects to two of the overloads of the method. To retrieve the adjustment rules of a particular time zone, call its method, which returns an array of objects. + + + +## Examples + The following example retrieves all time zones defined on the local system and displays complete information about their adjustment rules. + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo+AdjustmentRule/Overview/System.TimeZone2.AdjustmentRule.Class.cs" id="Snippet3"::: :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo+AdjustmentRule/Overview/System.TimeZone2.AdjustmentRule.Class.fs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.AdjustmentRule.Class/vb/System.TimeZone2.AdjustmentRule.Class.vb" id="Snippet3"::: - - The following is a small portion of the output that is generated by the example. The exact output will vary depending on the operating system and the date on which the example is run. - -``` -Morocco Standard Time Adjustment rules - Adjustment rule #1 - Start Date: Tuesday, January 01, 2008 - End Date: Wednesday, December 31, 2008 - Time Change: 1:00 hours - Annual Start: The Last Saturday of May at 11:59 PM - Annual End: The Last Sunday of August at 11:59 PM - Adjustment rule #2 - Start Date: Thursday, January 01, 2009 - End Date: Thursday, December 31, 2009 - Time Change: 1:00 hours - Annual Start: The Last Sunday of May at 11:59 PM - Annual End: The Third Thursday of August at 11:59 PM - -Coordinated Universal Time has no adjustment rules - -GMT Standard Time Adjustment rules - Start Date: Monday, January 01, 0001 - End Date: Friday, December 31, 9999 - Time Change: 1:00 hours - Annual Start: The Last Sunday of March at 1:00 AM - Annual End: The Last Sunday of October at 2:00 AM - -Greenwich Standard Time has no adjustment rules - -W. Europe Standard Time Adjustment rules - Start Date: Monday, January 01, 0001 - End Date: Friday, December 31, 9999 - Time Change: 1:00 hours - Annual Start: The Last Sunday of March at 2:00 AM - Annual End: The Last Sunday of October at 3:00 AM - -Central Europe Standard Time Adjustment rules - Start Date: Monday, January 01, 0001 - End Date: Friday, December 31, 9999 - Time Change: 1:00 hours - Annual Start: The Last Sunday of March at 2:00 AM - Annual End: The Last Sunday of October at 3:00 AM - -Romance Standard Time Adjustment rules - Start Date: Monday, January 01, 0001 - End Date: Friday, December 31, 9999 - Time Change: 1:00 hours - Annual Start: The Last Sunday of March at 2:00 AM - Annual End: The Last Sunday of October at 3:00 AM - -Central European Standard Time Adjustment rules - Start Date: Monday, January 01, 0001 - End Date: Friday, December 31, 9999 - Time Change: 1:00 hours - Annual Start: The Last Sunday of March at 2:00 AM - Annual End: The Last Sunday of October at 3:00 AM - -W. Central Africa Standard Time has no adjustment rules -``` - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.AdjustmentRule.Class/vb/System.TimeZone2.AdjustmentRule.Class.vb" id="Snippet3"::: + + The following is a small portion of the output that is generated by the example. The exact output will vary depending on the operating system and the date on which the example is run. + +``` +Morocco Standard Time Adjustment rules + Adjustment rule #1 + Start Date: Tuesday, January 01, 2008 + End Date: Wednesday, December 31, 2008 + Time Change: 1:00 hours + Annual Start: The Last Saturday of May at 11:59 PM + Annual End: The Last Sunday of August at 11:59 PM + Adjustment rule #2 + Start Date: Thursday, January 01, 2009 + End Date: Thursday, December 31, 2009 + Time Change: 1:00 hours + Annual Start: The Last Sunday of May at 11:59 PM + Annual End: The Third Thursday of August at 11:59 PM + +Coordinated Universal Time has no adjustment rules + +GMT Standard Time Adjustment rules + Start Date: Monday, January 01, 0001 + End Date: Friday, December 31, 9999 + Time Change: 1:00 hours + Annual Start: The Last Sunday of March at 1:00 AM + Annual End: The Last Sunday of October at 2:00 AM + +Greenwich Standard Time has no adjustment rules + +W. Europe Standard Time Adjustment rules + Start Date: Monday, January 01, 0001 + End Date: Friday, December 31, 9999 + Time Change: 1:00 hours + Annual Start: The Last Sunday of March at 2:00 AM + Annual End: The Last Sunday of October at 3:00 AM + +Central Europe Standard Time Adjustment rules + Start Date: Monday, January 01, 0001 + End Date: Friday, December 31, 9999 + Time Change: 1:00 hours + Annual Start: The Last Sunday of March at 2:00 AM + Annual End: The Last Sunday of October at 3:00 AM + +Romance Standard Time Adjustment rules + Start Date: Monday, January 01, 0001 + End Date: Friday, December 31, 9999 + Time Change: 1:00 hours + Annual Start: The Last Sunday of March at 2:00 AM + Annual End: The Last Sunday of October at 3:00 AM + +Central European Standard Time Adjustment rules + Start Date: Monday, January 01, 0001 + End Date: Friday, December 31, 9999 + Time Change: 1:00 hours + Annual Start: The Last Sunday of March at 2:00 AM + Annual End: The Last Sunday of October at 3:00 AM + +W. Central Africa Standard Time has no adjustment rules +``` + ]]> @@ -238,64 +238,64 @@ W. Central Africa Standard Time has no adjustment rules Creates a new adjustment rule for a particular time zone. An object that represents the new adjustment rule. - objects returned by calls to this method can then be passed as the `adjustmentRules` parameter to two overloads of the method. The example illustrates this procedure. - + objects returned by calls to this method can then be passed as the `adjustmentRules` parameter to two overloads of the method. The example illustrates this procedure. + > [!NOTE] -> The method can be used only to define an adjustment rule for a new time zone; it cannot be used to modify an adjustment rule for an existing time zone. - - The `dateStart` and `dateEnd` parameters must be date values without a time component or an is thrown. The time component can be removed by retrieving a value from the date and time's property as shown in the following statements: - -``` -DateTime.MinValue.Date -DateTime.MaxValue.Date -DateTime.Now.Date -dateVariable.Date -``` - - The property of the `dateStart` and `dateEnd` parameters must also be . - - The value of the `daylightDelta` parameter can range from -14 to 14. The sum of the `daylightDelta` parameter and the `baseUtcOffset` parameter used in the call to the method must also range from -14 to 14 or an is thrown. - +> The method can be used only to define an adjustment rule for a new time zone; it cannot be used to modify an adjustment rule for an existing time zone. + + The `dateStart` and `dateEnd` parameters must be date values without a time component or an is thrown. The time component can be removed by retrieving a value from the date and time's property as shown in the following statements: + +``` +DateTime.MinValue.Date +DateTime.MaxValue.Date +DateTime.Now.Date +dateVariable.Date +``` + + The property of the `dateStart` and `dateEnd` parameters must also be . + + The value of the `daylightDelta` parameter can range from -14 to 14. The sum of the `daylightDelta` parameter and the `baseUtcOffset` parameter used in the call to the method must also range from -14 to 14 or an is thrown. + > [!NOTE] -> The `daylightDelta` parameter defines the difference between a time zone's standard time and its daylight saving time. It is not intended to define the time zone's standard time offset from Coordinated Universal Time (UTC). The class assumes that this offset from UTC is constant throughout the life of the time zone. To reflect a change in a time zone's offset from UTC that is not caused by the application of an adjustment rule, you must use the method to create a new custom time zone. - - - -## Examples - The following example creates an alternate Central Standard Time zone and defines three adjustment rules for the periods 1976-1986, 1987-2006, and 2007 and beyond. These rules are added to a generic object whose elements are then copied to a array. This array is then used in the call to the method. - +> The `daylightDelta` parameter defines the difference between a time zone's standard time and its daylight saving time. It is not intended to define the time zone's standard time offset from Coordinated Universal Time (UTC). The class assumes that this offset from UTC is constant throughout the life of the time zone. To reflect a change in a time zone's offset from UTC that is not caused by the application of an adjustment rule, you must use the method to create a new custom time zone. + + + +## Examples + The following example creates an alternate Central Standard Time zone and defines three adjustment rules for the periods 1976-1986, 1987-2006, and 2007 and beyond. These rules are added to a generic object whose elements are then copied to a array. This array is then used in the call to the method. + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo+AdjustmentRule/Overview/System.TimeZone2.AdjustmentRule.Class.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo+AdjustmentRule/Overview/System.TimeZone2.AdjustmentRule.Class.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.AdjustmentRule.Class/vb/System.TimeZone2.AdjustmentRule.Class.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.AdjustmentRule.Class/vb/System.TimeZone2.AdjustmentRule.Class.vb" id="Snippet1"::: + ]]> - The property of the or parameter does not equal . - - -or- - - The parameter is equal to the parameter. - - -or- - - The or parameter includes a time of day value. + The property of the or parameter does not equal . + +-or- + +The parameter is equal to the parameter. + +-or- + +The or parameter includes a time of day value. - is earlier than . - - -or- - - is less than -14 or greater than 14. - - -or- - - The property of the parameter is not equal to 0. - - -or- - - The property of the parameter does not equal a whole number of seconds. + is earlier than . + +-or- + + is less than -14 or greater than 14. + +-or- + +The property of the parameter is not equal to 0. + +-or- + +The property of the parameter does not equal a whole number of seconds. @@ -380,33 +380,33 @@ dateVariable.Date Gets the date when the adjustment rule ceases to be in effect. A value that indicates the end date of the adjustment rule. - property is a date value without a time component. - - Because the end date of the current adjustment rule is typically not known, you can assign `DateTime.MaxValue.Date` to the property when you create a custom adjustment rule. - + property is a date value without a time component. + + Because the end date of the current adjustment rule is typically not known, you can assign `DateTime.MaxValue.Date` to the property when you create a custom adjustment rule. + > [!IMPORTANT] -> Unless there is a compelling reason to do otherwise, you should define the adjustment rule's end date to occur within the time interval during which the time zone observes standard time. Unless there is a compelling reason to do so, you should not define the adjustment rule's end date to occur within the time interval during which the time zone observes daylight saving time. For example, if a time zone's transition from daylight saving time occurs on the third Sunday of March and its transition to daylight saving time occurs on the first Sunday of October, the effective end date of the adjustment rule should not be December 31 of a particular year, since that date occurs within the period of daylight saving time. - - By default, the registry in Windows XP defines a single adjustment rule whose end date is Friday, December 31, 9999 (the value of `DateTime.MaxValue.Date`), for each time zone. For time zones in the United States, the registry in Windows Vista defines two adjustment rules: - -- Monday, January 01, 0001, to Sunday, December 31, 2006. - -- Monday, January 01, 2007, to Friday, December 31, 9999. - - This means that, although time zone adjustment rules stored in the registry are useful for performing current time zone-related operations, they cannot be reliably used for retrieving historical time zone information. For information about defining a custom time zone with multiple adjustment rules that can be used in a historical time zone-aware application, see [How to: Create Time Zones with Adjustment Rules](/dotnet/standard/datetime/create-time-zones-with-adjustment-rules). - - - -## Examples - The following example displays information about all of the time zones defined in the local computer's system registry, including the starting and ending dates of their adjustment rules. - +> Unless there is a compelling reason to do otherwise, you should define the adjustment rule's end date to occur within the time interval during which the time zone observes standard time. Unless there is a compelling reason to do so, you should not define the adjustment rule's end date to occur within the time interval during which the time zone observes daylight saving time. For example, if a time zone's transition from daylight saving time occurs on the third Sunday of March and its transition to daylight saving time occurs on the first Sunday of October, the effective end date of the adjustment rule should not be December 31 of a particular year, since that date occurs within the period of daylight saving time. + + By default, the registry in Windows XP defines a single adjustment rule whose end date is Friday, December 31, 9999 (the value of `DateTime.MaxValue.Date`), for each time zone. For time zones in the United States, the registry in Windows Vista defines two adjustment rules: + +- Monday, January 01, 0001, to Sunday, December 31, 2006. + +- Monday, January 01, 2007, to Friday, December 31, 9999. + + This means that, although time zone adjustment rules stored in the registry are useful for performing current time zone-related operations, they cannot be reliably used for retrieving historical time zone information. For information about defining a custom time zone with multiple adjustment rules that can be used in a historical time zone-aware application, see [How to: Create Time Zones with Adjustment Rules](/dotnet/standard/datetime/create-time-zones-with-adjustment-rules). + + + +## Examples + The following example displays information about all of the time zones defined in the local computer's system registry, including the starting and ending dates of their adjustment rules. + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo+AdjustmentRule/DateEnd/DateStart1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo+AdjustmentRule/DateEnd/DateStart1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.TimeZoneInfo.AdjustmentRule.DateStart/vb/DateStart1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.TimeZoneInfo.AdjustmentRule.DateStart/vb/DateStart1.vb" id="Snippet1"::: + ]]> @@ -450,33 +450,33 @@ dateVariable.Date Gets the date when the adjustment rule takes effect. A value that indicates when the adjustment rule takes effect. - property is a date value without a time component. It defines the date on which a particular adjustment rule goes into effect. This is the date in which a set of transitions (which typically are defined by one transition to daylight savings time and one transition back to standard time) go into effect. For example, an adjustment rule might go into effect on January 1, 2017, that provides for a transition to daylight savings time on the second Sunday of March and for a transition back to standard time on the first Sunday of November. Note that the starting date of the adjustment rule is not tied to the date of the first transition. - - You can assign `DateTime.MinValue.Date` to the property when you create a custom adjustment rule for use in a time zone-aware application that does not have to work with historic time zone information. - + property is a date value without a time component. It defines the date on which a particular adjustment rule goes into effect. This is the date in which a set of transitions (which typically are defined by one transition to daylight savings time and one transition back to standard time) go into effect. For example, an adjustment rule might go into effect on January 1, 2017, that provides for a transition to daylight savings time on the second Sunday of March and for a transition back to standard time on the first Sunday of November. Note that the starting date of the adjustment rule is not tied to the date of the first transition. + + You can assign `DateTime.MinValue.Date` to the property when you create a custom adjustment rule for use in a time zone-aware application that does not have to work with historic time zone information. + > [!IMPORTANT] -> Unless there is a compelling reason to do otherwise, you should define the adjustment rule's start date to occur within the time interval during which the time zone observes standard time. Unless there is a compelling reason to do so, you should not define the adjustment rule's start date to occur within the time interval during which the time zone observes daylight saving time. For example, if a time zone's transition from daylight saving time occurs on the third Sunday of March and its transition to daylight saving time occurs on the first Sunday of October, the effective start date of the adjustment rule should not be January 1 of a particular year, since that date occurs within the period of daylight saving time. - - By default, the registry in Windows XP defines a single adjustment rule whose start date is Monday, January 01, 0001 (the value of `DateTime.MinValue.Date`), for each time zone. For time zones in the United States, the registry in Windows Vista defines two adjustment rules: - -- Monday, January 01, 0001, to Sunday, December 31, 2006. - -- Monday, January 01, 2007, to Friday, December 31, 9999. - - This means that, although time zone adjustment rules stored in the registry are useful for performing current time zone-related operations, they cannot be reliably used for retrieving historical time zone information. For information about defining a custom time zone with multiple adjustment rules that can be used in a historical time zone-aware application, see [How to: Create Time Zones with Adjustment Rules](/dotnet/standard/datetime/create-time-zones-with-adjustment-rules). - - - -## Examples - The following example displays information about all of the time zones defined in the local computer's system registry, including the starting and ending dates of their adjustment rules. - +> Unless there is a compelling reason to do otherwise, you should define the adjustment rule's start date to occur within the time interval during which the time zone observes standard time. Unless there is a compelling reason to do so, you should not define the adjustment rule's start date to occur within the time interval during which the time zone observes daylight saving time. For example, if a time zone's transition from daylight saving time occurs on the third Sunday of March and its transition to daylight saving time occurs on the first Sunday of October, the effective start date of the adjustment rule should not be January 1 of a particular year, since that date occurs within the period of daylight saving time. + + By default, the registry in Windows XP defines a single adjustment rule whose start date is Monday, January 01, 0001 (the value of `DateTime.MinValue.Date`), for each time zone. For time zones in the United States, the registry in Windows Vista defines two adjustment rules: + +- Monday, January 01, 0001, to Sunday, December 31, 2006. + +- Monday, January 01, 2007, to Friday, December 31, 9999. + + This means that, although time zone adjustment rules stored in the registry are useful for performing current time zone-related operations, they cannot be reliably used for retrieving historical time zone information. For information about defining a custom time zone with multiple adjustment rules that can be used in a historical time zone-aware application, see [How to: Create Time Zones with Adjustment Rules](/dotnet/standard/datetime/create-time-zones-with-adjustment-rules). + + + +## Examples + The following example displays information about all of the time zones defined in the local computer's system registry, including the starting and ending dates of their adjustment rules. + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo+AdjustmentRule/DateEnd/DateStart1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo+AdjustmentRule/DateEnd/DateStart1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.TimeZoneInfo.AdjustmentRule.DateStart/vb/DateStart1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.TimeZoneInfo.AdjustmentRule.DateStart/vb/DateStart1.vb" id="Snippet1"::: + ]]> @@ -520,22 +520,22 @@ dateVariable.Date Gets the amount of time that is required to form the time zone's daylight saving time. This amount of time is added to the time zone's offset from Coordinated Universal Time (UTC). A object that indicates the amount of time to add to the standard time changes as a result of the adjustment rule. - property can range from 14 hours to -14 hours. - + property can range from 14 hours to -14 hours. + > [!NOTE] -> The property measures the difference between the time zone's standard time and its daylight saving time. It does not apply to changes in a time zone's standard offset from Coordinated Universal Time (UTC). To represent a time zone that has changed its standard time offset from UTC, you must call the method to create a new time zone. - - The most common value of the property is 1.0 hours. The application of the daylight saving time adjustment rule increases the time zone's offset from Coordinated Universal Time (UTC) by one hour. - +> The property measures the difference between the time zone's standard time and its daylight saving time. It does not apply to changes in a time zone's standard offset from Coordinated Universal Time (UTC). To represent a time zone that has changed its standard time offset from UTC, you must call the method to create a new time zone. + + The most common value of the property is 1.0 hours. The application of the daylight saving time adjustment rule increases the time zone's offset from Coordinated Universal Time (UTC) by one hour. + ]]> @@ -579,11 +579,11 @@ TimeZoneTime = BaseUtcOffset + DaylightDelta + UtcTime Gets information about the annual transition from daylight saving time back to standard time. A object that defines the annual transition from daylight saving time back to the time zone's standard time. - object returned by the property defines either a fixed-date rule or a floating-date rule for the return to standard time. A fixed-date rule provides the month, day, and time of day on which the transition occurs. A floating-date rule provides the month, week, day of the week, and time of day on which the transition occurs. - + object returned by the property defines either a fixed-date rule or a floating-date rule for the return to standard time. A fixed-date rule provides the month, day, and time of day on which the transition occurs. A floating-date rule provides the month, week, day of the week, and time of day on which the transition occurs. + ]]> @@ -627,11 +627,11 @@ TimeZoneTime = BaseUtcOffset + DaylightDelta + UtcTime Gets information about the annual transition from standard time to daylight saving time. A object that defines the annual transition from a time zone's standard time to daylight saving time. - object returned by the property defines either a fixed-date rule or a floating-date rule for the transition to daylight saving time. A fixed-date rule provides the month, day, and time of day on which the transition occurs. A floating-date rule provides the month, the week, the day of the week, and the time of day on which the transition occurs. - + object returned by the property defines either a fixed-date rule or a floating-date rule for the transition to daylight saving time. A fixed-date rule provides the month, day, and time of day on which the transition occurs. A floating-date rule provides the month, the week, the day of the week, and the time of day on which the transition occurs. + ]]> @@ -737,28 +737,28 @@ TimeZoneTime = BaseUtcOffset + DaylightDelta + UtcTime if both objects have equal values; otherwise, . - objects are equal, the method compares the member values of each object. Two adjustment rules are equal if they have the same effective dates, the same delta, and identical values for the objects returned by their and properties. - - - -## Examples - The following example calls the method to compare the adjustment rules for Central Standard Time with those for Canada Central Standard Time and Mexico Standard Time. - + objects are equal, the method compares the member values of each object. Two adjustment rules are equal if they have the same effective dates, the same delta, and identical values for the objects returned by their and properties. + + + +## Examples + The following example calls the method to compare the adjustment rules for Central Standard Time with those for Canada Central Standard Time and Mexico Standard Time. + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo+AdjustmentRule/Overview/System.TimeZone2.AdjustmentRule.Class.cs" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo+AdjustmentRule/Overview/System.TimeZone2.AdjustmentRule.Class.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.AdjustmentRule.Class/vb/System.TimeZone2.AdjustmentRule.Class.vb" id="Snippet2"::: - - This code displays the following output to the console: - -``` -Comparing Central Standard Time rule for 1/1/0001 to 12/31/9999 with: - Canada Central Standard Time has no adjustment rules. - Mexican CST for 1/1/0001 to 12/31/9999: Equal -``` - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.AdjustmentRule.Class/vb/System.TimeZone2.AdjustmentRule.Class.vb" id="Snippet2"::: + + This code displays the following output to the console: + +``` +Comparing Central Standard Time rule for 1/1/0001 to 12/31/9999 with: + Canada Central Standard Time has no adjustment rules. + Mexican CST for 1/1/0001 to 12/31/9999: Equal +``` + ]]> diff --git a/xml/System/TimeZoneInfo+TransitionTime.xml b/xml/System/TimeZoneInfo+TransitionTime.xml index 8ea1f09a958..adae385a3f5 100644 --- a/xml/System/TimeZoneInfo+TransitionTime.xml +++ b/xml/System/TimeZoneInfo+TransitionTime.xml @@ -79,27 +79,27 @@ Provides information about a specific time change, such as the change from daylight saving time to standard time or vice versa, in a particular time zone. - structure to indicate when a transition from standard time to daylight saving time, or from daylight saving time back to standard time, occurs. This structure supports both fixed-date rules and floating-date rules. Use fixed-date rules for time transitions that occur on a specific day of a specific month (such as 2:00 A.M. on November 3). Use floating-date rules for time transitions that occur on a specific day of a specific week of a specific month (such as 2:00 A.M. on the first Sunday of November). - - The following table compares the properties used in fixed-date and floating-date transitions: - -||Month|Week|Day|Time| -|-|-----------|----------|---------|----------| -|Fixed-date rule||N/A||| -|Floating-date rule||||| - - For both fixed-date and floating-date transitions, the property gets the time at which the time change occurs. For transitions from standard to daylight saving time, this is the time zone's standard time value. For transitions from daylight saving to standard time, this is the time zone's daylight saving time value. This is a value whose date component is ignored; its year, month, and day value must always equal 1. - + structure to indicate when a transition from standard time to daylight saving time, or from daylight saving time back to standard time, occurs. This structure supports both fixed-date rules and floating-date rules. Use fixed-date rules for time transitions that occur on a specific day of a specific month (such as 2:00 A.M. on November 3). Use floating-date rules for time transitions that occur on a specific day of a specific week of a specific month (such as 2:00 A.M. on the first Sunday of November). + + The following table compares the properties used in fixed-date and floating-date transitions: + +||Month|Week|Day|Time| +|-|-----------|----------|---------|----------| +|Fixed-date rule||N/A||| +|Floating-date rule||||| + + For both fixed-date and floating-date transitions, the property gets the time at which the time change occurs. For transitions from standard to daylight saving time, this is the time zone's standard time value. For transitions from daylight saving to standard time, this is the time zone's daylight saving time value. This is a value whose date component is ignored; its year, month, and day value must always equal 1. + > [!NOTE] -> An instance of the structure is immutable. Once an object has been created, its values cannot be modified. - - A object can be created by calling the `static` (`Shared` in Visual Basic) and methods to create a fixed or floating-date rule, respectively. The starting and ending objects are then supplied as parameters to the method to create a new adjustment rule that includes this transition time information. - - The and properties of an object return a object. - +> An instance of the structure is immutable. Once an object has been created, its values cannot be modified. + + A object can be created by calling the `static` (`Shared` in Visual Basic) and methods to create a fixed or floating-date rule, respectively. The starting and ending objects are then supplied as parameters to the method to create a new adjustment rule that includes this transition time information. + + The and properties of an object return a object. + ]]> @@ -151,38 +151,38 @@ Defines a time change that uses a fixed-date rule (that is, a time change that occurs on a specific day of a specific month). Data about the time change. - value whose year, month, and date values must all equal 1. - - - -## Examples - The following example creates time zone transitions for an imaginary time zone by using both a fixed-date rule and a floating-date rule. The fixed-date rule defines a time zone adjustment that starts at 2:00 A.M. on March 15 and ends at 3:00 A.M. on November 15 for the years 1900 to 1955. - + value whose year, month, and date values must all equal 1. + + + +## Examples + The following example creates time zone transitions for an imaginary time zone by using both a fixed-date rule and a floating-date rule. The fixed-date rule defines a time zone adjustment that starts at 2:00 A.M. on March 15 and ends at 3:00 A.M. on November 15 for the years 1900 to 1955. + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo+TransitionTime/CreateFixedDateRule/System.TimeZone2.TransitionTime.Class.cs" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo+TransitionTime/CreateFixedDateRule/System.TimeZone2.TransitionTime.Class.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.TransitionTime.Class/vb/System.TimeZone2.TransitionTime.Class.vb" id="Snippet2"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.TransitionTime.Class/vb/System.TimeZone2.TransitionTime.Class.vb" id="Snippet2"::: + ]]> - The parameter has a non-default date component. - - -or- - - The parameter's property is not . - - -or- - - The parameter does not represent a whole number of milliseconds. - The parameter is less than 1 or greater than 12. - - -or- - - The parameter is less than 1 or greater than 31. + The parameter has a non-default date component. + +-or- + +The parameter's property is not . + +-or- + +The parameter does not represent a whole number of milliseconds. + The parameter is less than 1 or greater than 12. + +-or- + +The parameter is less than 1 or greater than 31. @@ -234,43 +234,43 @@ Defines a time change that uses a floating-date rule (that is, a time change that occurs on a specific day of a specific week of a specific month). Data about the time change. - value whose year, month, and date values must all equal 1. - - - -## Examples - The following example creates time zone transitions for an imaginary time zone by using both a fixed-date rule and a floating-date rule. The floating-date rule defines a time zone adjustment that starts at 2:00 A.M. on the last Sunday of March and ends at 3:00 A.M. on the fourth Sunday in October for the years 1956 onward. - + value whose year, month, and date values must all equal 1. + + + +## Examples + The following example creates time zone transitions for an imaginary time zone by using both a fixed-date rule and a floating-date rule. The floating-date rule defines a time zone adjustment that starts at 2:00 A.M. on the last Sunday of March and ends at 3:00 A.M. on the fourth Sunday in October for the years 1956 onward. + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo+TransitionTime/CreateFixedDateRule/System.TimeZone2.TransitionTime.Class.cs" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo+TransitionTime/CreateFixedDateRule/System.TimeZone2.TransitionTime.Class.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.TransitionTime.Class/vb/System.TimeZone2.TransitionTime.Class.vb" id="Snippet2"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.TransitionTime.Class/vb/System.TimeZone2.TransitionTime.Class.vb" id="Snippet2"::: + ]]> - The parameter has a non-default date component. - - -or- - - The parameter does not represent a whole number of milliseconds. - - -or- - - The parameter's property is not . + The parameter has a non-default date component. + +-or- + +The parameter does not represent a whole number of milliseconds. + +-or- + +The parameter's property is not . - is less than 1 or greater than 12. - - -or- - - is less than 1 or greater than 5. - - -or- - - The parameter is not a member of the enumeration. + is less than 1 or greater than 12. + +-or- + + is less than 1 or greater than 5. + +-or- + +The parameter is not a member of the enumeration. @@ -312,24 +312,24 @@ Gets the day on which the time change occurs. The day on which the time change occurs. - property returns a valid value only if the property is `true`. - - The property value corresponds to the value of the `day` parameter of the method. If its value is greater than the number of days in the month of the transition, the transition occurs on the last day of the month. - - The property indicates the day of the month on which a fixed-date rule is applied (for example, April 15). In contrast, the property indicates the day of the week on which a floating-date rule is applied (for example, the second Sunday of November). - - - -## Examples - The following example enumerates the time zones found on the local computer and displays transition time information for all fixed-date transitions. The time information includes the day on which the time change occurs. - + property returns a valid value only if the property is `true`. + + The property value corresponds to the value of the `day` parameter of the method. If its value is greater than the number of days in the month of the transition, the transition occurs on the last day of the month. + + The property indicates the day of the month on which a fixed-date rule is applied (for example, April 15). In contrast, the property indicates the day of the week on which a floating-date rule is applied (for example, the second Sunday of November). + + + +## Examples + The following example enumerates the time zones found on the local computer and displays transition time information for all fixed-date transitions. The time information includes the day on which the time change occurs. + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo+TransitionTime/CreateFixedDateRule/System.TimeZone2.TransitionTime.Class.cs" id="Snippet3"::: :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo+TransitionTime/CreateFixedDateRule/System.TimeZone2.TransitionTime.Class.fs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.TransitionTime.Class/vb/System.TimeZone2.TransitionTime.Class.vb" id="Snippet3"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.TransitionTime.Class/vb/System.TimeZone2.TransitionTime.Class.vb" id="Snippet3"::: + ]]> @@ -373,22 +373,22 @@ Gets the day of the week on which the time change occurs. The day of the week on which the time change occurs. - property returns a valid value only if the property is `false`. - - The property indicates the day of the week on which a floating-date rule is applied (for example, the second Sunday of November). In contrast, the property indicates the day of the month on which a fixed-date rule is applied (for example, April 15). - - - -## Examples - The following example enumerates the time zones found on the local computer and displays transition time information for all floating-date transitions. The time information includes the day of the week on which the time change occurs. - + property returns a valid value only if the property is `false`. + + The property indicates the day of the week on which a floating-date rule is applied (for example, the second Sunday of November). In contrast, the property indicates the day of the month on which a fixed-date rule is applied (for example, April 15). + + + +## Examples + The following example enumerates the time zones found on the local computer and displays transition time information for all floating-date transitions. The time information includes the day of the week on which the time change occurs. + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo+TransitionTime/CreateFixedDateRule/System.TimeZone2.TransitionTime.Class.cs" id="Snippet4"::: :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo+TransitionTime/CreateFixedDateRule/System.TimeZone2.TransitionTime.Class.fs" id="Snippet4"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.TransitionTime.Class/vb/System.TimeZone2.TransitionTime.Class.vb" id="Snippet4"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.TransitionTime.Class/vb/System.TimeZone2.TransitionTime.Class.vb" id="Snippet4"::: + ]]> @@ -461,20 +461,20 @@ if the two objects are equal; otherwise, . - object and must have property values identical to the current object. - - - -## Examples - The following example illustrates calls to the method. - + object and must have property values identical to the current object. + + + +## Examples + The following example illustrates calls to the method. + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo+TransitionTime/CreateFixedDateRule/System.TimeZone2.TransitionTime.Class.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo+TransitionTime/CreateFixedDateRule/System.TimeZone2.TransitionTime.Class.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.TransitionTime.Class/vb/System.TimeZone2.TransitionTime.Class.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.TransitionTime.Class/vb/System.TimeZone2.TransitionTime.Class.vb" id="Snippet1"::: + ]]> @@ -526,20 +526,20 @@ if the two objects have identical property values; otherwise, . - objects are equal, this method performs a property-by-property comparison. The method returns `true` only if the current object and the `other` object have identical values for each of the object's six property values. - - - -## Examples - The following example illustrates calls to the method. - + objects are equal, this method performs a property-by-property comparison. The method returns `true` only if the current object and the `other` object have identical values for each of the object's six property values. + + + +## Examples + The following example illustrates calls to the method. + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo+TransitionTime/CreateFixedDateRule/System.TimeZone2.TransitionTime.Class.cs" id="Snippet7"::: :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo+TransitionTime/CreateFixedDateRule/System.TimeZone2.TransitionTime.Class.fs" id="Snippet7"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.TransitionTime.Class/vb/System.TimeZone2.TransitionTime.Class.vb" id="Snippet7"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.TransitionTime.Class/vb/System.TimeZone2.TransitionTime.Class.vb" id="Snippet7"::: + ]]> @@ -626,30 +626,30 @@ if the time change rule is fixed-date; if the time change rule is floating-date. - property determines which properties of a object have valid values. The following table indicates which properties are affected by the value of the property. - -|TransitionTime property|IsFixedDateRule = true|IsFixedDateRule = false| -|-----------------------------|-----------------------------|------------------------------| -|`Day`|Valid|Unused| -|`DayOfWeek`|Unused|Valid| -|`Week`|Unused|Valid| -|`Month`|Valid|Valid| -|`TimeOfDay`|Valid|Valid| - - - -## Examples - The following example lists the transition times to and from daylight saving time for all time zones that are available on the local system. For time zones with fixed-date rules, it displays transition time information from the properties of the object. For time zones without fixed-date rules, it uses a object that represents the current system calendar to determine the actual start and end dates of the transition. The example displays the results to the console. - + property determines which properties of a object have valid values. The following table indicates which properties are affected by the value of the property. + +|TransitionTime property|IsFixedDateRule = true|IsFixedDateRule = false| +|-----------------------------|-----------------------------|------------------------------| +|`Day`|Valid|Unused| +|`DayOfWeek`|Unused|Valid| +|`Week`|Unused|Valid| +|`Month`|Valid|Valid| +|`TimeOfDay`|Valid|Valid| + + + +## Examples + The following example lists the transition times to and from daylight saving time for all time zones that are available on the local system. For time zones with fixed-date rules, it displays transition time information from the properties of the object. For time zones without fixed-date rules, it uses a object that represents the current system calendar to determine the actual start and end dates of the transition. The example displays the results to the console. + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo+TransitionTime/CreateFixedDateRule/example1.cs" id="Snippet5"::: :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo+TransitionTime/CreateFixedDateRule/example1.fs" id="Snippet5"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.TransitionTime.Class/vb/example1.vb" id="Snippet5"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.TransitionTime.Class/vb/example1.vb" id="Snippet5"::: + ]]> @@ -693,22 +693,22 @@ Gets the month in which the time change occurs. The month in which the time change occurs. - property range from 1 to 12. - - The property is used for both fixed-date and floating-date rules. - - - -## Examples - The following example enumerates the time zones found on the local computer and displays transition time information for all floating-date transitions. The time information includes the month in which the time change occurs. - + property range from 1 to 12. + + The property is used for both fixed-date and floating-date rules. + + + +## Examples + The following example enumerates the time zones found on the local computer and displays transition time information for all floating-date transitions. The time information includes the month in which the time change occurs. + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo+TransitionTime/CreateFixedDateRule/System.TimeZone2.TransitionTime.Class.cs" id="Snippet4"::: :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo+TransitionTime/CreateFixedDateRule/System.TimeZone2.TransitionTime.Class.fs" id="Snippet4"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.TransitionTime.Class/vb/System.TimeZone2.TransitionTime.Class.vb" id="Snippet4"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.TransitionTime.Class/vb/System.TimeZone2.TransitionTime.Class.vb" id="Snippet4"::: + ]]> @@ -768,11 +768,11 @@ if and have identical values; otherwise, . - objects are equal if they have identical values for each of their six properties. Otherwise, they are unequal. - + objects are equal if they have identical values for each of their six properties. Otherwise, they are unequal. + The equivalent method for this operator is .]]> @@ -832,11 +832,11 @@ if and have any different member values; otherwise, . - objects are unequal if they have different values for any of their six properties. Otherwise, they are equal. - + objects are unequal if they have different values for any of their six properties. Otherwise, they are equal. + The equivalent method for this operator is .]]> @@ -982,24 +982,24 @@ Gets the hour, minute, and second at which the time change occurs. The time of day at which the time change occurs. - value represents the time of the transition in the time zone's standard time. For transitions from daylight saving time to standard time, it represents the time of the transition in the time zone's daylight saving time. - - The property defines only the time of a time change, but not its date. The date is determined by the and properties for fixed-rule changes, and by the , , and properties for floating-rule changes. The date component of this value is ignored; the value of the year, month, and day is always 1. - - The property is used for both fixed-date and floating-date transitions. - - - -## Examples - The following example enumerates the time zones found on the local computer and displays transition time information for those time zones that have adjustment rules. The time information includes the time of day at which the time change occurs. - + value represents the time of the transition in the time zone's standard time. For transitions from daylight saving time to standard time, it represents the time of the transition in the time zone's daylight saving time. + + The property defines only the time of a time change, but not its date. The date is determined by the and properties for fixed-rule changes, and by the , , and properties for floating-rule changes. The date component of this value is ignored; the value of the year, month, and day is always 1. + + The property is used for both fixed-date and floating-date transitions. + + + +## Examples + The following example enumerates the time zones found on the local computer and displays transition time information for those time zones that have adjustment rules. The time information includes the time of day at which the time change occurs. + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo+TransitionTime/CreateFixedDateRule/System.TimeZone2.TransitionTime.Class.cs" id="Snippet6"::: :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo+TransitionTime/CreateFixedDateRule/System.TimeZone2.TransitionTime.Class.fs" id="Snippet6"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.TransitionTime.Class/vb/System.TimeZone2.TransitionTime.Class.vb" id="Snippet6"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.TransitionTime.Class/vb/System.TimeZone2.TransitionTime.Class.vb" id="Snippet6"::: + ]]> @@ -1043,32 +1043,32 @@ Gets the week of the month in which a time change occurs. The week of the month in which the time change occurs. - property is used only for time changes with floating-date rules. Valid values can range from 1 to 5. - - The property defines the month in which the time change occurs. The property determines the week on which the transition occurs. The property defines the day of the week on which the transition occurs. The value of the property is determined as shown in the following table. - -|If the Week property value is|The transition occurs on| -|-----------------------------------|------------------------------| -|1|The first occurrence of the value in .| -|2|The second occurrence of the value in .| -|3|The third occurrence of the value in .| -|4|The fourth occurrence of the value in .| -|5|The last occurrence of the value in .| - - For example, if a transition occurs on the first Sunday of March, the value of the property is 1. If it occurs on the last Sunday of March, the value of the property is 5. - - - -## Examples - The following example enumerates the time zones found on the local computer and displays transition time information for all floating-date transitions. The time information includes the week of the month in which the time change occurs. The example also defines a `WeekOfMonth` enumeration to display a string that represents the ordinal value of the property rather than an integer. - + property is used only for time changes with floating-date rules. Valid values can range from 1 to 5. + + The property defines the month in which the time change occurs. The property determines the week on which the transition occurs. The property defines the day of the week on which the transition occurs. The value of the property is determined as shown in the following table. + +|If the Week property value is|The transition occurs on| +|-----------------------------------|------------------------------| +|1|The first occurrence of the value in .| +|2|The second occurrence of the value in .| +|3|The third occurrence of the value in .| +|4|The fourth occurrence of the value in .| +|5|The last occurrence of the value in .| + + For example, if a transition occurs on the first Sunday of March, the value of the property is 1. If it occurs on the last Sunday of March, the value of the property is 5. + + + +## Examples + The following example enumerates the time zones found on the local computer and displays transition time information for all floating-date transitions. The time information includes the week of the month in which the time change occurs. The example also defines a `WeekOfMonth` enumeration to display a string that represents the ordinal value of the property rather than an integer. + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo+TransitionTime/CreateFixedDateRule/System.TimeZone2.TransitionTime.Class.cs" id="Snippet4"::: :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo+TransitionTime/CreateFixedDateRule/System.TimeZone2.TransitionTime.Class.fs" id="Snippet4"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.TransitionTime.Class/vb/System.TimeZone2.TransitionTime.Class.vb" id="Snippet4"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.TransitionTime.Class/vb/System.TimeZone2.TransitionTime.Class.vb" id="Snippet4"::: + ]]> diff --git a/xml/System/TimeZoneInfo.xml b/xml/System/TimeZoneInfo.xml index 1835366371b..4bd2eeba7c3 100644 --- a/xml/System/TimeZoneInfo.xml +++ b/xml/System/TimeZoneInfo.xml @@ -90,41 +90,41 @@ Represents any time zone in the world. - class offers significant enhancements over the class, which provides only limited functionality. - - The class recognizes only the local time zone, and can convert times between Coordinated Universal Time (UTC) and local time. A object can represent any time zone, and methods of the class can be used to convert the time in one time zone to the corresponding time in any other time zone. The members of the class support the following operations: - -- Retrieving a time zone that is already defined by the operating system. - -- Enumerating the time zones that are available on a system. - -- Converting times between different time zones. - -- Creating a new time zone that is not already defined by the operating system. - -- Serializing a time zone for later retrieval. - -> [!NOTE] -> An instance of the class is immutable. Once an object has been instantiated, its values cannot be modified. - - You cannot instantiate a object using the `new` keyword. Instead, you must call one of the static members of the class shown in the following table. - -|Static member name|Description| -|------------------------|-----------------| -| method|Creates a custom time zone from application-supplied data.| -| method|Instantiates a time zone based on its identifier.| -| method|Deserializes a string value to re-create a previously serialized object.| -| method|Returns an enumerable of objects that represents all time zones that are available on the local system.| -| property|Instantiates a object that represents the local time zone.| -| property|Instantiates a object that represents the UTC zone.| - - You can use the method to create a time zone that is not defined in the local system registry on Windows systems or by the [ICU Library's Time Zone Data](https://unicode-org.github.io/icu/userguide/datetime/timezone/) on Linux or macOS. You can then use the property to save the time zone object's information as a string, which can be stored in some form that is accessible to the application. You can use the method to convert a serialized string back to a object. - + class offers significant enhancements over the class, which provides only limited functionality. + + The class recognizes only the local time zone, and can convert times between Coordinated Universal Time (UTC) and local time. A object can represent any time zone, and methods of the class can be used to convert the time in one time zone to the corresponding time in any other time zone. The members of the class support the following operations: + +- Retrieving a time zone that is already defined by the operating system. + +- Enumerating the time zones that are available on a system. + +- Converting times between different time zones. + +- Creating a new time zone that is not already defined by the operating system. + +- Serializing a time zone for later retrieval. + +> [!NOTE] +> An instance of the class is immutable. Once an object has been instantiated, its values cannot be modified. + + You cannot instantiate a object using the `new` keyword. Instead, you must call one of the static members of the class shown in the following table. + +|Static member name|Description| +|------------------------|-----------------| +| method|Creates a custom time zone from application-supplied data.| +| method|Instantiates a time zone based on its identifier.| +| method|Deserializes a string value to re-create a previously serialized object.| +| method|Returns an enumerable of objects that represents all time zones that are available on the local system.| +| property|Instantiates a object that represents the local time zone.| +| property|Instantiates a object that represents the UTC zone.| + + You can use the method to create a time zone that is not defined in the local system registry on Windows systems or by the [ICU Library's Time Zone Data](https://unicode-org.github.io/icu/userguide/datetime/timezone/) on Linux or macOS. You can then use the property to save the time zone object's information as a string, which can be stored in some form that is accessible to the application. You can use the method to convert a serialized string back to a object. + ]]> @@ -172,31 +172,31 @@ Gets the time difference between the current time zone's standard time and Coordinated Universal Time (UTC). An object that indicates the time difference between the current time zone's standard time and Coordinated Universal Time (UTC). - property can range from 14 hours (for a time zone that is 14 hours ahead of Coordinated Universal Time (UTC)) to -14 hours (for a time zone that is 14 hours behind UTC). Time zones that are ahead of UTC have a positive offset; time zones that are behind UTC have a negative offset. - - The value is represented as a whole number of minutes. It cannot include a fractional number of minutes. - -> [!NOTE] -> Because is a property of the object rather than the object, the class applies a single offset from UTC to all of a time zone's adjustments. To reflect a time zone that has modified its offset from UTC, you must create a new time zone using the method. - - The property differs from the method in the following ways: - -- The property returns the difference between UTC and the time zone's standard time; the method returns the difference between UTC and the time zone's time at a particular point in time. - -- The method reflects the application of any adjustment rules to the time zone; the property does not. - - - -## Examples - The following example uses the property to display the difference between the local time and Coordinated Universal Time (UTC). - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/BaseUtcOffset/TimeZone2_Examples.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/BaseUtcOffset/TimeZone2_Examples.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Class/VB/TimeZone2_Examples.vb" id="Snippet1"::: - + property can range from 14 hours (for a time zone that is 14 hours ahead of Coordinated Universal Time (UTC)) to -14 hours (for a time zone that is 14 hours behind UTC). Time zones that are ahead of UTC have a positive offset; time zones that are behind UTC have a negative offset. + + The value is represented as a whole number of minutes. It cannot include a fractional number of minutes. + +> [!NOTE] +> Because is a property of the object rather than the object, the class applies a single offset from UTC to all of a time zone's adjustments. To reflect a time zone that has modified its offset from UTC, you must create a new time zone using the method. + + The property differs from the method in the following ways: + +- The property returns the difference between UTC and the time zone's standard time; the method returns the difference between UTC and the time zone's time at a particular point in time. + +- The method reflects the application of any adjustment rules to the time zone; the property does not. + + + +## Examples + The following example uses the property to display the difference between the local time and Coordinated Universal Time (UTC). + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/BaseUtcOffset/TimeZone2_Examples.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/BaseUtcOffset/TimeZone2_Examples.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Class/VB/TimeZone2_Examples.vb" id="Snippet1"::: + ]]> @@ -241,19 +241,19 @@ Clears cached time zone data. - objects that are no longer references to or . For example, in the following code, the second call to the method throws an because the `local` variable is no longer considered equal to . - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/ClearCachedData/System.TimeZone2.BestPractices.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/ClearCachedData/System.TimeZone2.BestPractices.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.BestPractices/vb/System.TimeZone2.BestPractices.vb" id="Snippet1"::: - + objects that are no longer references to or . For example, in the following code, the second call to the method throws an because the `local` variable is no longer considered equal to . + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/ClearCachedData/System.TimeZone2.BestPractices.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/ClearCachedData/System.TimeZone2.BestPractices.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.BestPractices/vb/System.TimeZone2.BestPractices.vb" id="Snippet1"::: + ]]> @@ -321,42 +321,42 @@ Converts a time to the time in a particular time zone. The date and time in the destination time zone. - method applies any adjustment rules in effect in the `destinationTimeZone` time zone. - - This overload of the method determines the source time zone from the value of the `dateTime` parameter's property, as the following table shows. - -|Kind property value|Source time zone|Method behavior| -|-------------------------|----------------------|---------------------| -|||Converts the local time to the time in `destinationTimeZone`.| -|||Converts Coordinated Universal Time (UTC) to the time in `destinationTimeZone`.| -||Assumed to be .|Converts the local time to the time in `destinationTimeZone`.| - - The property of the returned value is set as shown in the following table. - -|Condition|Returned Kind property value| -|---------------|----------------------------------| -|The `destinationTimeZone` is .|| -|The `destinationTimeZone` is .|| -|All other date and time values and destination time zones.|| - - If the value of the `dateTime` parameter is an ambiguous local time, it is interpreted as a standard time. If the `dateTime` parameter is an invalid local time, this method throws an . - - If the conversion of `dateTime` results in a date and time value that is earlier than or later than , this method returns or , respectively. - - You can also convert to or from UTC by calling the and methods. - - - -## Examples - The following example converts an array of date and time values to times in the Eastern Time zone of the U.S. and Canada. It shows that the source time zone depends on the property of the source value. It also illustrates that the method takes time zone adjustments into account, because a time zone adjustment occurs in both the source and destination time zones at 2:00 A.M. on November 7, 2010. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/ConvertTime/converttime1.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/ConvertTime/converttime1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.timezoneinfo.converttime/vb/converttime1.vb" id="Snippet1"::: - + method applies any adjustment rules in effect in the `destinationTimeZone` time zone. + + This overload of the method determines the source time zone from the value of the `dateTime` parameter's property, as the following table shows. + +|Kind property value|Source time zone|Method behavior| +|-------------------------|----------------------|---------------------| +|||Converts the local time to the time in `destinationTimeZone`.| +|||Converts Coordinated Universal Time (UTC) to the time in `destinationTimeZone`.| +||Assumed to be .|Converts the local time to the time in `destinationTimeZone`.| + + The property of the returned value is set as shown in the following table. + +|Condition|Returned Kind property value| +|---------------|----------------------------------| +|The `destinationTimeZone` is .|| +|The `destinationTimeZone` is .|| +|All other date and time values and destination time zones.|| + + If the value of the `dateTime` parameter is an ambiguous local time, it is interpreted as a standard time. If the `dateTime` parameter is an invalid local time, this method throws an . + + If the conversion of `dateTime` results in a date and time value that is earlier than or later than , this method returns or , respectively. + + You can also convert to or from UTC by calling the and methods. + + + +## Examples + The following example converts an array of date and time values to times in the Eastern Time zone of the U.S. and Canada. It shows that the source time zone depends on the property of the source value. It also illustrates that the method takes time zone adjustments into account, because a time zone adjustment occurs in both the source and destination time zones at 2:00 A.M. on November 7, 2010. + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/ConvertTime/converttime1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/ConvertTime/converttime1.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.timezoneinfo.converttime/vb/converttime1.vb" id="Snippet1"::: + ]]> The value of the parameter represents an invalid time. @@ -413,26 +413,26 @@ Converts a time to the time in a particular time zone. The date and time in the destination time zone. - method applies any adjustment rules in effect in the `destinationTimeZone` time zone. - - This overload differs from the other overloads of the method by accepting a value as its first parameter. This identifies the date and time as an offset from Coordinated Universal Time (UTC) rather than as the date and time in a particular time zone. As a result, the `dateTimeOffset` parameter cannot represent either an ambiguous time or an invalid time. - - In converting the `dateTimeOffset` value to the time in the destination time zone, this method takes into account any adjustment rules in effect in the destination time zone. - - If the conversion of `dateTimeOffset` results in a date and time value that is earlier than or later than , this method returns or , respectively. - - - -## Examples - The following example converts an array of values to times in the Eastern Time zone of the U.S. and Canada. It illustrates that the method takes time zone adjustments into account, because a time zone adjustment occurs in both the source and destination time zones at 2:00 A.M. on November 7, 2010. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/ConvertTime/converttime2.cs" id="Snippet2"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/ConvertTime/converttime2.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.timezoneinfo.converttime/vb/converttime2.vb" id="Snippet2"::: - + method applies any adjustment rules in effect in the `destinationTimeZone` time zone. + + This overload differs from the other overloads of the method by accepting a value as its first parameter. This identifies the date and time as an offset from Coordinated Universal Time (UTC) rather than as the date and time in a particular time zone. As a result, the `dateTimeOffset` parameter cannot represent either an ambiguous time or an invalid time. + + In converting the `dateTimeOffset` value to the time in the destination time zone, this method takes into account any adjustment rules in effect in the destination time zone. + + If the conversion of `dateTimeOffset` results in a date and time value that is earlier than or later than , this method returns or , respectively. + + + +## Examples + The following example converts an array of values to times in the Eastern Time zone of the U.S. and Canada. It illustrates that the method takes time zone adjustments into account, because a time zone adjustment occurs in both the source and destination time zones at 2:00 A.M. on November 7, 2010. + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/ConvertTime/converttime2.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/ConvertTime/converttime2.fs" id="Snippet2"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.timezoneinfo.converttime/vb/converttime2.vb" id="Snippet2"::: + ]]> The value of the parameter is . @@ -488,62 +488,62 @@ Converts a time from one time zone to another. The date and time in the destination time zone that corresponds to the parameter in the source time zone. - method applies any adjustment rules in effect in the `destinationTimeZone` time zone. - - The value of the property of the `dateTime` parameter must correspond to the `sourceTimeZone` parameter, as the following table shows. - -|DateTime.Kind value|sourceTimeZone value|Method behavior| -|-------------------------|--------------------------|---------------------| -||Equals .|Converts `dateTime` to the destination time zone's time.| -||Does not equal .|Throws an .| -||Equals .|Converts `dateTime` to the destination time zone's time.| -||Does not equal .|Throws an .| -||Any.|Converts `dateTime` to the destination time zone's time.| - - You can also convert to or from Coordinated Universal Time (UTC) by calling the and methods. - - The property of the returned value is set as shown in the following table. - -|Condition|Returned Kind property value| -|---------------|----------------------------------| -|The `destinationTimeZone` argument is .|| -|The `destinationTimeZone` argument is .|| -|All other date and time values, source time zones, and destination time zones.|| - - If the value of the `dateTime` parameter is an ambiguous time in the source time zone, it is interpreted as a standard time. If the `dateTime` parameter is an invalid time in the source time zone, this method throws an . - - If the conversion of `dateTime` results in a date and time value that is earlier than or later than , this method returns or , respectively. - - The method throws an exception if the property of the `dateTime` argument is but the `sourceTimeZone` argument is not . To determine whether the source time zone is the local time zone or the universal time zone, the method tests for reference equality instead of testing for value equality with the method. Note that objects that represent the local time zone and that are retrieved by calling the method do not have referential equality with . Furthermore, objects that represent the local or universal time zone and that are retrieved by iterating the collection returned by the method do not have referential equality with or . As an alternative, you can call the method. - - - -## Examples - The following example illustrates the use of the method to convert from Hawaiian Standard Time to local time. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/ConvertTime/TimeZone2Concepts.cs" id="Snippet9"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/ConvertTime/TimeZone2Concepts.fs" id="Snippet9"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Concepts/VB/TimeZone2Concepts.vb" id="Snippet9"::: - + method applies any adjustment rules in effect in the `destinationTimeZone` time zone. + + The value of the property of the `dateTime` parameter must correspond to the `sourceTimeZone` parameter, as the following table shows. + +|DateTime.Kind value|sourceTimeZone value|Method behavior| +|-------------------------|--------------------------|---------------------| +||Equals .|Converts `dateTime` to the destination time zone's time.| +||Does not equal .|Throws an .| +||Equals .|Converts `dateTime` to the destination time zone's time.| +||Does not equal .|Throws an .| +||Any.|Converts `dateTime` to the destination time zone's time.| + + You can also convert to or from Coordinated Universal Time (UTC) by calling the and methods. + + The property of the returned value is set as shown in the following table. + +|Condition|Returned Kind property value| +|---------------|----------------------------------| +|The `destinationTimeZone` argument is .|| +|The `destinationTimeZone` argument is .|| +|All other date and time values, source time zones, and destination time zones.|| + + If the value of the `dateTime` parameter is an ambiguous time in the source time zone, it is interpreted as a standard time. If the `dateTime` parameter is an invalid time in the source time zone, this method throws an . + + If the conversion of `dateTime` results in a date and time value that is earlier than or later than , this method returns or , respectively. + + The method throws an exception if the property of the `dateTime` argument is but the `sourceTimeZone` argument is not . To determine whether the source time zone is the local time zone or the universal time zone, the method tests for reference equality instead of testing for value equality with the method. Note that objects that represent the local time zone and that are retrieved by calling the method do not have referential equality with . Furthermore, objects that represent the local or universal time zone and that are retrieved by iterating the collection returned by the method do not have referential equality with or . As an alternative, you can call the method. + + + +## Examples + The following example illustrates the use of the method to convert from Hawaiian Standard Time to local time. + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/ConvertTime/TimeZone2Concepts.cs" id="Snippet9"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/ConvertTime/TimeZone2Concepts.fs" id="Snippet9"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Concepts/VB/TimeZone2Concepts.vb" id="Snippet9"::: + ]]> - The property of the parameter is , but the parameter does not equal . - - -or- - - The property of the parameter is , but the parameter does not equal . - - -or- - - The parameter is an invalid time (that is, it represents a time that does not exist because of a time zone's adjustment rules). - The parameter is . - - -or- - - The parameter is . + The property of the parameter is , but the parameter does not equal . + +-or- + +The property of the parameter is , but the parameter does not equal . + +-or- + +The parameter is an invalid time (that is, it represents a time that does not exist because of a time zone's adjustment rules). + The parameter is . + +-or- + +The parameter is . Converting Times Between Time Zones @@ -604,34 +604,34 @@ Converts a time to the time in another time zone based on the time zone's identifier. The date and time in the destination time zone. - method applies any adjustment rules in effect in the `destinationTimeZoneId` time zone. - - This overload is largely identical to calling the method, except that it allows you to specify the destination time zone by its identifier rather than by an object reference. This method is most useful when you must convert a time without retrieving the time zone object that corresponds to it and you do not need to know whether the converted time is standard or daylight saving time. - - The method determines the source time zone from the value of the `dateTime` parameter's property, as the following table shows. - -|Kind property value|Source time zone|Method behavior| -|-------------------------|----------------------|---------------------| -|||Converts the local time to the time in `destinationTimeZone`.| -|||Converts Coordinated Universal Time (UTC) to the time in `destinationTimeZone`.| -||Assumed to be .|Converts the local time to the time in `destinationTimeZone`.| - - The property of the returned value is set as shown in the following table. - -|Condition|Returned Kind property value| -|---------------|----------------------------------| -|The `destinationTimeZone` is `TimeZoneInfo.Utc.Id`.|| -|Any other `destinationTimeZone` value.|| - - If the value of the `dateTime` parameter is an ambiguous local time, it is interpreted as a standard time. If the `dateTime` parameter is an invalid local time, this method throws an . - - If the conversion of `dateTime` results in a date and time value that is earlier than or later than , this method returns or , respectively. - - This method retrieves information on the time zone whose identifier is specified by the `destinationTimeZoneId` parameter from the registry on Windows systems and from the [ICU Library](https://unicode-org.github.io/icu/userguide/datetime/timezone/) on Linux and macOS. It cannot retrieve a time zone object that is created using the method. The `destinationTimeZoneId` parameter must correspond exactly to the time zone's identifier in length, but not in case, for a successful match to occur; that is, the comparison of `destinationTimeZoneId` with time zone identifiers is case-insensitive. - + method applies any adjustment rules in effect in the `destinationTimeZoneId` time zone. + + This overload is largely identical to calling the method, except that it allows you to specify the destination time zone by its identifier rather than by an object reference. This method is most useful when you must convert a time without retrieving the time zone object that corresponds to it and you do not need to know whether the converted time is standard or daylight saving time. + + The method determines the source time zone from the value of the `dateTime` parameter's property, as the following table shows. + +|Kind property value|Source time zone|Method behavior| +|-------------------------|----------------------|---------------------| +|||Converts the local time to the time in `destinationTimeZone`.| +|||Converts Coordinated Universal Time (UTC) to the time in `destinationTimeZone`.| +||Assumed to be .|Converts the local time to the time in `destinationTimeZone`.| + + The property of the returned value is set as shown in the following table. + +|Condition|Returned Kind property value| +|---------------|----------------------------------| +|The `destinationTimeZone` is `TimeZoneInfo.Utc.Id`.|| +|Any other `destinationTimeZone` value.|| + + If the value of the `dateTime` parameter is an ambiguous local time, it is interpreted as a standard time. If the `dateTime` parameter is an invalid local time, this method throws an . + + If the conversion of `dateTime` results in a date and time value that is earlier than or later than , this method returns or , respectively. + + This method retrieves information on the time zone whose identifier is specified by the `destinationTimeZoneId` parameter from the registry on Windows systems and from the [ICU Library](https://unicode-org.github.io/icu/userguide/datetime/timezone/) on Linux and macOS. It cannot retrieve a time zone object that is created using the method. The `destinationTimeZoneId` parameter must correspond exactly to the time zone's identifier in length, but not in case, for a successful match to occur; that is, the comparison of `destinationTimeZoneId` with time zone identifiers is case-insensitive. + ]]> @@ -687,21 +687,21 @@ Converts a time to the time in another time zone based on the time zone's identifier. The date and time in the destination time zone. - method applies any adjustment rules in effect in the `destinationTimeZoneId` time zone. - - This overload is identical to calling the method, except that it allows you to specify the destination time zone by its identifier rather than by an object reference. This method is most useful when you must convert a time without retrieving the time zone object that corresponds to it and you do not need to know whether the converted time is standard or daylight saving time. - - Because the `dateTimeOffset` parameter represents a date and time together with that time's offset from Coordinated Universal Time (UTC), it cannot represent either an ambiguous time or an invalid time. - - This method retrieves the time zone whose identifier is specified by the `destinationTimeZoneId` parameter from the registry on Windows systems and from the [ICU Library](https://unicode-org.github.io/icu/userguide/datetime/timezone/) on Linux and macOS. It cannot retrieve a time zone object that is created using the method. The `destinationTimeZoneId` parameter must correspond exactly to the time zone's identifier in length, but not in case, for a successful match to occur; that is, the comparison of `destinationTimeZoneId` with time zone identifiers is case-insensitive. - - In converting the `dateTimeOffset` value to the time in the destination time zone, the method takes into account any adjustment rules in effect in the destination time zone. - - If the conversion of `dateTimeOffset` results in a date and time value that is earlier than or later than , this method returns or , respectively. - + method applies any adjustment rules in effect in the `destinationTimeZoneId` time zone. + + This overload is identical to calling the method, except that it allows you to specify the destination time zone by its identifier rather than by an object reference. This method is most useful when you must convert a time without retrieving the time zone object that corresponds to it and you do not need to know whether the converted time is standard or daylight saving time. + + Because the `dateTimeOffset` parameter represents a date and time together with that time's offset from Coordinated Universal Time (UTC), it cannot represent either an ambiguous time or an invalid time. + + This method retrieves the time zone whose identifier is specified by the `destinationTimeZoneId` parameter from the registry on Windows systems and from the [ICU Library](https://unicode-org.github.io/icu/userguide/datetime/timezone/) on Linux and macOS. It cannot retrieve a time zone object that is created using the method. The `destinationTimeZoneId` parameter must correspond exactly to the time zone's identifier in length, but not in case, for a successful match to occur; that is, the comparison of `destinationTimeZoneId` with time zone identifiers is case-insensitive. + + In converting the `dateTimeOffset` value to the time in the destination time zone, the method takes into account any adjustment rules in effect in the destination time zone. + + If the conversion of `dateTimeOffset` results in a date and time value that is earlier than or later than , this method returns or , respectively. + ]]> @@ -759,60 +759,60 @@ Converts a time from one time zone to another based on time zone identifiers. The date and time in the destination time zone that corresponds to the parameter in the source time zone. - method applies any adjustment rules in effect in the `destinationTimeZoneId` time zone. - - Although it is similar to the method, you can use to specify the source and destination time zones using their identifiers instead of their objects. This method is most useful when you must convert a time without retrieving the time zone object that corresponds to it and you do not need to know whether the converted time is standard or daylight saving time. - - This method retrieves the time zones whose identifiers are the `sourceTimeZoneId` and `destinationTimeZoneId` parameters from the registry on Windows systems and from the [ICU Library](https://unicode-org.github.io/icu/userguide/datetime/timezone/) on Linux and macOS. It cannot retrieve time zone objects that are created using the method. - - The value of the property of the `dateTime` parameter must correspond to the `sourceTimeZoneId` parameter, as the following table shows. - -|DateTime.Kind value|sourceTimeZone value|Method behavior| -|-------------------------|--------------------------|---------------------| -||Equals `TimeZoneInfo.Utc.Id`.|Converts `dateTime` to the destination time zone's time.| -||Does not equal `TimeZoneInfo.Utc.Id`.|Throws an .| -||Equals `TimeZoneInfo.Local.Id`.|Converts `dateTime` to the destination time zone's time.| -||Does not equal `TimeZoneInfo.Local.Id`.|Throws an .| -||Any.|Converts `dateTime` to the destination time zone's time.| - - Because it relies on calls to the method, the method performs a case-insensitive search to locate the time zones that correspond to `sourceTimeZoneId` and `destinationTimeZoneId`. - - If the value of the `dateTime` parameter is an ambiguous time in the source time zone, it is interpreted as a standard time. If the `dateTime` parameter is an invalid time in the source time zone, this method throws an . - - The property of the returned value is set to unless the destination time zone is Coordinated Universal Time (UTC), in which case it is set to . - - - -## Examples - The following example uses the method to display the time that corresponds to the local system time in eight cities of the world. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/ConvertTimeBySystemTimeZoneId/System.TimeZone2.Conversions.cs" id="Snippet3"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/ConvertTimeBySystemTimeZoneId/System.TimeZone2.Conversions.fs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Conversions/vb/System.TimeZone2.Conversions.vb" id="Snippet3"::: - + method applies any adjustment rules in effect in the `destinationTimeZoneId` time zone. + + Although it is similar to the method, you can use to specify the source and destination time zones using their identifiers instead of their objects. This method is most useful when you must convert a time without retrieving the time zone object that corresponds to it and you do not need to know whether the converted time is standard or daylight saving time. + + This method retrieves the time zones whose identifiers are the `sourceTimeZoneId` and `destinationTimeZoneId` parameters from the registry on Windows systems and from the [ICU Library](https://unicode-org.github.io/icu/userguide/datetime/timezone/) on Linux and macOS. It cannot retrieve time zone objects that are created using the method. + + The value of the property of the `dateTime` parameter must correspond to the `sourceTimeZoneId` parameter, as the following table shows. + +|DateTime.Kind value|sourceTimeZone value|Method behavior| +|-------------------------|--------------------------|---------------------| +||Equals `TimeZoneInfo.Utc.Id`.|Converts `dateTime` to the destination time zone's time.| +||Does not equal `TimeZoneInfo.Utc.Id`.|Throws an .| +||Equals `TimeZoneInfo.Local.Id`.|Converts `dateTime` to the destination time zone's time.| +||Does not equal `TimeZoneInfo.Local.Id`.|Throws an .| +||Any.|Converts `dateTime` to the destination time zone's time.| + + Because it relies on calls to the method, the method performs a case-insensitive search to locate the time zones that correspond to `sourceTimeZoneId` and `destinationTimeZoneId`. + + If the value of the `dateTime` parameter is an ambiguous time in the source time zone, it is interpreted as a standard time. If the `dateTime` parameter is an invalid time in the source time zone, this method throws an . + + The property of the returned value is set to unless the destination time zone is Coordinated Universal Time (UTC), in which case it is set to . + + + +## Examples + The following example uses the method to display the time that corresponds to the local system time in eight cities of the world. + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/ConvertTimeBySystemTimeZoneId/System.TimeZone2.Conversions.cs" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/ConvertTimeBySystemTimeZoneId/System.TimeZone2.Conversions.fs" id="Snippet3"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Conversions/vb/System.TimeZone2.Conversions.vb" id="Snippet3"::: + ]]> - The property of the parameter does not correspond to the source time zone. - - -or- - - is an invalid time in the source time zone. + The property of the parameter does not correspond to the source time zone. + +-or- + + is an invalid time in the source time zone. - is . - - -or- - - is . + is . + +-or- + + is . The time zone identifiers were found, but the registry data is corrupted. The user does not have the permissions required to read from the registry keys that hold time zone data. - The identifier was not found on the local system. - - -or- - - The identifier was not found on the local system. + The identifier was not found on the local system. + +-or- + +The identifier was not found on the local system. Converting Times Between Time Zones @@ -861,29 +861,29 @@ Converts a Coordinated Universal Time (UTC) to the time in a specified time zone. The date and time in the destination time zone. Its property is if is ; otherwise, its property is . - method applies any adjustment rules in effect in the `destinationTimeZone` time zone. - - The precise behavior of this method depends on the value of the property of the `dateTime` parameter, as the following table shows. - -|DateTime.Kind property|Conversion| -|----------------------------|----------------| -||Throws an .| -| or |Converts from Coordinated Universal Time (UTC).| - - If the conversion of `dateTime` results in a date and time value that is earlier than or later than , this method returns or , respectively. - - - -## Examples - The following example converts Coordinated Universal Time (UTC) to Central Time. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/ConvertTime/TimeZone2Concepts.cs" id="Snippet8"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/ConvertTime/TimeZone2Concepts.fs" id="Snippet8"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Concepts/VB/TimeZone2Concepts.vb" id="Snippet8"::: - + method applies any adjustment rules in effect in the `destinationTimeZone` time zone. + + The precise behavior of this method depends on the value of the property of the `dateTime` parameter, as the following table shows. + +|DateTime.Kind property|Conversion| +|----------------------------|----------------| +||Throws an .| +| or |Converts from Coordinated Universal Time (UTC).| + + If the conversion of `dateTime` results in a date and time value that is earlier than or later than , this method returns or , respectively. + + + +## Examples + The following example converts Coordinated Universal Time (UTC) to Central Time. + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/ConvertTime/TimeZone2Concepts.cs" id="Snippet8"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/ConvertTime/TimeZone2Concepts.fs" id="Snippet8"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Concepts/VB/TimeZone2Concepts.vb" id="Snippet8"::: + ]]> The property of is . @@ -946,33 +946,33 @@ Converts the specified date and time to Coordinated Universal Time (UTC). The Coordinated Universal Time (UTC) that corresponds to the parameter. The value's property is always set to . - property of the `dateTime` parameter, as the following table shows. - -|DateTime.Kind property|Conversion| -|----------------------------|----------------| -||Converts from local time to Coordinated Universal Time (UTC).| -||Assumes `dateTime` is local time and converts from local time to UTC.| -||Returns `dateTime` unchanged.| - - If `dateTime` corresponds to an ambiguous local time, this method assumes that it is standard local time. If `dateTime` corresponds to an invalid local time, the method throws an . - -> [!NOTE] -> If the current computer's local time zone includes multiple adjustment rules, this overload of the method can return results that differ from the and methods. always applies the current adjustment rule to time zone conversion, whether or not `dateTime` lies within its date range. And when executing on .NET Framework 3.5, also applies the current adjustment rule to time zone conversion, whether or not `dateTime` lies within its date range. - - If the UTC equivalent of `dateTime` is earlier than or later that , this method returns or , respectively. - - - -## Examples - The following example illustrates the conversion of time values whose property is , , and , respectively. It also illustrates the conversion of ambiguous and invalid times. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/ConvertTimeBySystemTimeZoneId/System.TimeZone2.Conversions.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/ConvertTimeBySystemTimeZoneId/System.TimeZone2.Conversions.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Conversions/vb/System.TimeZone2.Conversions.vb" id="Snippet1"::: - + property of the `dateTime` parameter, as the following table shows. + +|DateTime.Kind property|Conversion| +|----------------------------|----------------| +||Converts from local time to Coordinated Universal Time (UTC).| +||Assumes `dateTime` is local time and converts from local time to UTC.| +||Returns `dateTime` unchanged.| + + If `dateTime` corresponds to an ambiguous local time, this method assumes that it is standard local time. If `dateTime` corresponds to an invalid local time, the method throws an . + +> [!NOTE] +> If the current computer's local time zone includes multiple adjustment rules, this overload of the method can return results that differ from the and methods. always applies the current adjustment rule to time zone conversion, whether or not `dateTime` lies within its date range. And when executing on .NET Framework 3.5, also applies the current adjustment rule to time zone conversion, whether or not `dateTime` lies within its date range. + + If the UTC equivalent of `dateTime` is earlier than or later that , this method returns or , respectively. + + + +## Examples + The following example illustrates the conversion of time values whose property is , , and , respectively. It also illustrates the conversion of ambiguous and invalid times. + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/ConvertTimeBySystemTimeZoneId/System.TimeZone2.Conversions.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/ConvertTimeBySystemTimeZoneId/System.TimeZone2.Conversions.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Conversions/vb/System.TimeZone2.Conversions.vb" id="Snippet1"::: + ]]> @@ -1027,36 +1027,36 @@ Converts the time in a specified time zone to Coordinated Universal Time (UTC). The Coordinated Universal Time (UTC) that corresponds to the parameter. The object's property is always set to . - property of the `dateTime` parameter equals and the `sourceTimeZone` parameter equals , this method returns `dateTime` without performing any conversion. - - If `dateTime` corresponds to an ambiguous time, this method assumes that it is the standard time of the source time zone. If `dateTime` corresponds to an invalid time, this method throws an . - - If the Coordinated Universal Time (UTC) equivalent of `dateTime` is earlier than or later that , this method returns or , respectively. - - - -## Examples - The following example retrieves the current date from the local system and converts it to Coordinated Universal Time (UTC), then converts it to Tokyo Standard Time, and finally converts from Tokyo Standard Time back to UTC. Note that the two UTC times are identical. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/ConvertTimeBySystemTimeZoneId/convertdt2.cs" id="Snippet2"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/ConvertTimeBySystemTimeZoneId/convertdt2.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Conversions/vb/convertdt2.vb" id="Snippet2"::: - + property of the `dateTime` parameter equals and the `sourceTimeZone` parameter equals , this method returns `dateTime` without performing any conversion. + + If `dateTime` corresponds to an ambiguous time, this method assumes that it is the standard time of the source time zone. If `dateTime` corresponds to an invalid time, this method throws an . + + If the Coordinated Universal Time (UTC) equivalent of `dateTime` is earlier than or later that , this method returns or , respectively. + + + +## Examples + The following example retrieves the current date from the local system and converts it to Coordinated Universal Time (UTC), then converts it to Tokyo Standard Time, and finally converts from Tokyo Standard Time back to UTC. Note that the two UTC times are identical. + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/ConvertTimeBySystemTimeZoneId/convertdt2.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/ConvertTimeBySystemTimeZoneId/convertdt2.fs" id="Snippet2"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Conversions/vb/convertdt2.vb" id="Snippet2"::: + ]]> - . is and does not equal . - - -or- - - . is and does not equal . - - -or- - - returns . + . is and does not equal . + +-or- + +. is and does not equal . + +-or- + + returns . is . Converting Times Between Time Zones @@ -1136,45 +1136,45 @@ Creates a custom time zone with a specified identifier, an offset from Coordinated Universal Time (UTC), a display name, and a standard time display name. The new time zone. - method is suitable for creating a time zone that has no adjustments (that is, a time zone that does not support daylight saving time). To define a time zone that includes adjustments for daylight saving time, use either the or the method. - - The following table shows the relationship between the parameters that are provided to the method and the properties of the object that are returned by the method call. - -|CreateCustomTimeZone parameter|TimeZoneInfo property| -|------------------------------------|---------------------------| -|`id`|| -|`baseUtcOffset`|| -|`displayName`|| -|`standardDisplayName`|| - - Typically, the time zone's standard time name and its identifier are the same. However, the length of the time zone's identifier should not exceed 32 characters. The string passed to the `displayName` parameter follows a fairly standard format. The first portion of the display name is the time zone's base offset from Coordinated Universal Time, which is indicated by the acronym GMT (for Greenwich Mean Time), enclosed in parentheses. This is followed by a string that identifies the time zone itself, or one or more of the cities, regions, or countries in the time zone, or both. For example: - -``` -(GMT+02:00) Athens, Beirut, Istanbul, Minsk -(GMT-02:00) Mid-Atlantic -(GMT-07:00) Mountain Time (US & Canada) -``` - - - -## Examples - The following example creates a custom time zone for the Mawson and Holme Bay regions of Antarctica. It then displays the result of converting the local time to the time in the new time zone. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/CreateCustomTimeZone/System.TimeZone2.CreateTimeZone.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/CreateCustomTimeZone/System.TimeZone2.CreateTimeZone.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.CreateTimeZone/vb/System.TimeZone2.CreateTimeZone.vb" id="Snippet1"::: - + method is suitable for creating a time zone that has no adjustments (that is, a time zone that does not support daylight saving time). To define a time zone that includes adjustments for daylight saving time, use either the or the method. + + The following table shows the relationship between the parameters that are provided to the method and the properties of the object that are returned by the method call. + +|CreateCustomTimeZone parameter|TimeZoneInfo property| +|------------------------------------|---------------------------| +|`id`|| +|`baseUtcOffset`|| +|`displayName`|| +|`standardDisplayName`|| + + Typically, the time zone's standard time name and its identifier are the same. However, the length of the time zone's identifier should not exceed 32 characters. The string passed to the `displayName` parameter follows a fairly standard format. The first portion of the display name is the time zone's base offset from Coordinated Universal Time, which is indicated by the acronym GMT (for Greenwich Mean Time), enclosed in parentheses. This is followed by a string that identifies the time zone itself, or one or more of the cities, regions, or countries in the time zone, or both. For example: + +``` +(GMT+02:00) Athens, Beirut, Istanbul, Minsk +(GMT-02:00) Mid-Atlantic +(GMT-07:00) Mountain Time (US & Canada) +``` + + + +## Examples + The following example creates a custom time zone for the Mawson and Holme Bay regions of Antarctica. It then displays the result of converting the local time to the time in the new time zone. + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/CreateCustomTimeZone/System.TimeZone2.CreateTimeZone.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/CreateCustomTimeZone/System.TimeZone2.CreateTimeZone.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.CreateTimeZone/vb/System.TimeZone2.CreateTimeZone.vb" id="Snippet1"::: + ]]> The parameter is . - The parameter is an empty string (""). - - -or- - - The parameter does not represent a whole number of minutes. + The parameter is an empty string (""). + +-or- + +The parameter does not represent a whole number of minutes. The parameter is greater than 14 hours or less than -14 hours. How to: Create Time Zones Without Adjustment Rules @@ -1253,75 +1253,75 @@ Creates a custom time zone with a specified identifier, an offset from Coordinated Universal Time (UTC), a display name, a standard time name, a daylight saving time name, and daylight saving time rules. A object that represents the new time zone. - method is suitable for creating a time zone that supports daylight saving time. To define a time zone that does not support daylight saving time, use either the or the method. - - The following table shows the relationship between the parameters that are provided to the method and the members of the object that are returned by the method call. - -|CreateCustomTimeZone parameter|TimeZoneInfo member| -|------------------------------------|-------------------------| -|`id`|| -|`baseUtcOffset`|| -|`displayName`|| -|`standardDisplayName`|| -|`daylightDisplayName`|| -|`adjustmentRules`|An array of objects returned by the method.| - - Typically, the time zone's standard time name and its identifier are the same. However, the length of the time zone's identifier should not exceed 32 characters. The string passed to the `displayName` parameter follows a fairly standard format. The first portion of the display name is the time zone's base offset from Coordinated Universal Time, which is indicated by the acronym GMT (for Greenwich Mean Time), enclosed in parentheses. This is followed by a string that identifies the time zone itself, or one or more of the cities, regions, or countries in the time zone, or both. For example: - -``` -(GMT+02:00) Athens, Beirut, Istanbul, Minsk -(GMT-02:00) Mid-Atlantic -(GMT-07:00) Mountain Time (US & Canada) -``` - - The `baseUtcOffset` parameter defines the custom time zone's offset from Coordinated Universal Time (UTC) for all of the time zone's adjustment rules. In other words, the object model assumes that the time zone's offset from UTC is constant throughout the life of the time zone, and exists independent of particular adjustment rules. To reflect a time zone that has changed its offset from UTC, you must create a new time zone object. - - A time zone's adjustment rules are defined by doing the following: - -1. Calling either the or the method to define the starting and ending transition time for each adjustment rule. - -2. Calling the method for each adjustment rule. - -3. Assigning the adjustment rules to an array that can be passed as the `adjustmentRules` parameter. - - - -## Examples - The following example creates a custom time zone for the Palmer station and Anvers Island in Antarctica. It then converts the local time to the time in the new time zone and displays the result. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/CreateCustomTimeZone/System.TimeZone2.CreateTimeZone.cs" id="Snippet2"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/CreateCustomTimeZone/System.TimeZone2.CreateTimeZone.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.CreateTimeZone/vb/System.TimeZone2.CreateTimeZone.vb" id="Snippet2"::: - + method is suitable for creating a time zone that supports daylight saving time. To define a time zone that does not support daylight saving time, use either the or the method. + + The following table shows the relationship between the parameters that are provided to the method and the members of the object that are returned by the method call. + +|CreateCustomTimeZone parameter|TimeZoneInfo member| +|------------------------------------|-------------------------| +|`id`|| +|`baseUtcOffset`|| +|`displayName`|| +|`standardDisplayName`|| +|`daylightDisplayName`|| +|`adjustmentRules`|An array of objects returned by the method.| + + Typically, the time zone's standard time name and its identifier are the same. However, the length of the time zone's identifier should not exceed 32 characters. The string passed to the `displayName` parameter follows a fairly standard format. The first portion of the display name is the time zone's base offset from Coordinated Universal Time, which is indicated by the acronym GMT (for Greenwich Mean Time), enclosed in parentheses. This is followed by a string that identifies the time zone itself, or one or more of the cities, regions, or countries in the time zone, or both. For example: + +``` +(GMT+02:00) Athens, Beirut, Istanbul, Minsk +(GMT-02:00) Mid-Atlantic +(GMT-07:00) Mountain Time (US & Canada) +``` + + The `baseUtcOffset` parameter defines the custom time zone's offset from Coordinated Universal Time (UTC) for all of the time zone's adjustment rules. In other words, the object model assumes that the time zone's offset from UTC is constant throughout the life of the time zone, and exists independent of particular adjustment rules. To reflect a time zone that has changed its offset from UTC, you must create a new time zone object. + + A time zone's adjustment rules are defined by doing the following: + +1. Calling either the or the method to define the starting and ending transition time for each adjustment rule. + +2. Calling the method for each adjustment rule. + +3. Assigning the adjustment rules to an array that can be passed as the `adjustmentRules` parameter. + + + +## Examples + The following example creates a custom time zone for the Palmer station and Anvers Island in Antarctica. It then converts the local time to the time in the new time zone and displays the result. + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/CreateCustomTimeZone/System.TimeZone2.CreateTimeZone.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/CreateCustomTimeZone/System.TimeZone2.CreateTimeZone.fs" id="Snippet2"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.CreateTimeZone/vb/System.TimeZone2.CreateTimeZone.vb" id="Snippet2"::: + ]]> The parameter is . - The parameter is an empty string (""). - - -or- - - The parameter does not represent a whole number of minutes. + The parameter is an empty string (""). + +-or- + +The parameter does not represent a whole number of minutes. The parameter is greater than 14 hours or less than -14 hours. - The adjustment rules specified in the parameter overlap. - - -or- - - The adjustment rules specified in the parameter are not in chronological order. - - -or- - - One or more elements in are . - - -or- - - A date can have multiple adjustment rules applied to it. - - -or- - - The sum of the parameter and the value of one or more objects in the array is greater than 14 hours or less than -14 hours. + The adjustment rules specified in the parameter overlap. + +-or- + +The adjustment rules specified in the parameter are not in chronological order. + +-or- + +One or more elements in are . + +-or- + +A date can have multiple adjustment rules applied to it. + +-or- + +The sum of the parameter and the value of one or more objects in the array is greater than 14 hours or less than -14 hours. How to: Create Time Zones with Adjustment Rules @@ -1402,76 +1402,76 @@ Creates a custom time zone with a specified identifier, an offset from Coordinated Universal Time (UTC), a display name, a standard time name, a daylight saving time name, daylight saving time rules, and a value that indicates whether the returned object reflects daylight saving time information. The new time zone. If the parameter is , the returned object has no daylight saving time data. - method to create a custom time zone whose support for daylight saving time can be determined by conditions at run time. - - The following table shows the relationship between the parameters that are provided to the method and the members of the object that are returned by the method call. - -|CreateCustomTimeZone parameter|TimeZoneInfo property| -|------------------------------------|---------------------------| -|`id`|| -|`baseUtcOffset`|| -|`displayName`|| -|`standardDisplayName`|| -|`daylightDisplayName`| if `disableDaylightSavingTime` is `false`; if `disableDaylightSavingTime` is `true`.| -|`adjustmentRules`|An array of objects returned by the method if `disableDaylightSavingTime` is `false`; an empty array returned by the method if `disableDaylightSavingTime` is `true`.| -|`disableDaylightSavingTime`|Not .| - - Typically, the time zone's standard time name and its identifier are the same. However, the length of the time zone's identifier should not exceed 32 characters. The string passed to the `displayName` parameter follows a fairly standard format. The first portion of the display name is the time zone's base offset from Coordinated Universal Time, which is indicated by the acronym GMT (for Greenwich Mean Time), enclosed in parentheses. This is followed by a string that identifies the time zone itself, or one or more of the cities, regions, or countries in the time zone, or both. For example: - -``` -(GMT+02:00) Athens, Beirut, Istanbul, Minsk -(GMT-02:00) Mid-Atlantic -(GMT-07:00) Mountain Time (US & Canada) -``` - - A time zone's adjustment rules are defined by doing the following: - -1. Calling either the or the method to define the starting and ending transition rules for each adjustment rule. - -2. Calling the method for each adjustment rule. - -3. Assigning the adjustment rules to an array that can be passed as the `adjustmentRules` parameter. - - If `disableDaylightSavingTime` parameter is `false`, the operation of this method is identical to the overload. If `disableDaylightSavingTime` is `true`, the returned object includes no adjustment rules and a property whose value is an empty string. - - - -## Examples - The following example creates a custom time zone for the Palmer station and Anvers Island in Antarctica. It sets the `disableDaylightSavingTime` parameter in the call to the method to `true`. It then displays the new time zone's daylight saving time name, if one is present, and the number of adjustment rules to confirm that the new time zone has no daylight saving time information. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/CreateCustomTimeZone/System.TimeZone2.CreateTimeZone.cs" interactive="try-dotnet-method" id="Snippet3"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/CreateCustomTimeZone/System.TimeZone2.CreateTimeZone.fs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.CreateTimeZone/vb/System.TimeZone2.CreateTimeZone.vb" id="Snippet3"::: - + method to create a custom time zone whose support for daylight saving time can be determined by conditions at run time. + + The following table shows the relationship between the parameters that are provided to the method and the members of the object that are returned by the method call. + +|CreateCustomTimeZone parameter|TimeZoneInfo property| +|------------------------------------|---------------------------| +|`id`|| +|`baseUtcOffset`|| +|`displayName`|| +|`standardDisplayName`|| +|`daylightDisplayName`| if `disableDaylightSavingTime` is `false`; if `disableDaylightSavingTime` is `true`.| +|`adjustmentRules`|An array of objects returned by the method if `disableDaylightSavingTime` is `false`; an empty array returned by the method if `disableDaylightSavingTime` is `true`.| +|`disableDaylightSavingTime`|Not .| + + Typically, the time zone's standard time name and its identifier are the same. However, the length of the time zone's identifier should not exceed 32 characters. The string passed to the `displayName` parameter follows a fairly standard format. The first portion of the display name is the time zone's base offset from Coordinated Universal Time, which is indicated by the acronym GMT (for Greenwich Mean Time), enclosed in parentheses. This is followed by a string that identifies the time zone itself, or one or more of the cities, regions, or countries in the time zone, or both. For example: + +``` +(GMT+02:00) Athens, Beirut, Istanbul, Minsk +(GMT-02:00) Mid-Atlantic +(GMT-07:00) Mountain Time (US & Canada) +``` + + A time zone's adjustment rules are defined by doing the following: + +1. Calling either the or the method to define the starting and ending transition rules for each adjustment rule. + +2. Calling the method for each adjustment rule. + +3. Assigning the adjustment rules to an array that can be passed as the `adjustmentRules` parameter. + + If `disableDaylightSavingTime` parameter is `false`, the operation of this method is identical to the overload. If `disableDaylightSavingTime` is `true`, the returned object includes no adjustment rules and a property whose value is an empty string. + + + +## Examples + The following example creates a custom time zone for the Palmer station and Anvers Island in Antarctica. It sets the `disableDaylightSavingTime` parameter in the call to the method to `true`. It then displays the new time zone's daylight saving time name, if one is present, and the number of adjustment rules to confirm that the new time zone has no daylight saving time information. + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/CreateCustomTimeZone/System.TimeZone2.CreateTimeZone.cs" interactive="try-dotnet-method" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/CreateCustomTimeZone/System.TimeZone2.CreateTimeZone.fs" id="Snippet3"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.CreateTimeZone/vb/System.TimeZone2.CreateTimeZone.vb" id="Snippet3"::: + ]]> The parameter is . - The parameter is an empty string (""). - - -or- - - The parameter does not represent a whole number of minutes. + The parameter is an empty string (""). + +-or- + +The parameter does not represent a whole number of minutes. The parameter is greater than 14 hours or less than -14 hours. - The adjustment rules specified in the parameter overlap. - - -or- - - The adjustment rules specified in the parameter are not in chronological order. - - -or- - - One or more elements in are . - - -or- - - A date can have multiple adjustment rules applied to it. - - -or- - - The sum of the parameter and the value of one or more objects in the array is greater than 14 hours or less than -14 hours. + The adjustment rules specified in the parameter overlap. + +-or- + +The adjustment rules specified in the parameter are not in chronological order. + +-or- + +One or more elements in are . + +-or- + +A date can have multiple adjustment rules applied to it. + +-or- + +The sum of the parameter and the value of one or more objects in the array is greater than 14 hours or less than -14 hours. How to: Create Time Zones Without Adjustment Rules How to: Create Time Zones with Adjustment Rules @@ -1519,26 +1519,26 @@ Gets the display name for the current time zone's daylight saving time. The display name for the time zone's daylight saving time. - property whose value is not or `null` does not necessarily indicate that the time zone supports daylight saving time. To determine whether the time zone supports daylight saving time, check the value of its property. - - In most cases, the `DaylightName` property of system-defined time zones is not or `null`. However, the property of custom time zones can be set to . This occurs when custom time zones are created by the or the overload and the `disableDaylightSavingTime` parameter is `true`. Therefore, your code should never assume that the value of the property is not `null` or empty. - - The property is equivalent to the property of the class. - - - -## Examples - The following example defines a method named `DisplayDateWithTimeZoneName` that uses the method to determine whether to display a time zone's standard time name or daylight saving time name. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/DaylightName/IsDaylightSavingTime.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/DaylightName/IsDaylightSavingTime.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.IsDaylightSavingTime/vb/IsDaylightSavingTime.vb" id="Snippet1"::: - + property whose value is not or `null` does not necessarily indicate that the time zone supports daylight saving time. To determine whether the time zone supports daylight saving time, check the value of its property. + + In most cases, the `DaylightName` property of system-defined time zones is not or `null`. However, the property of custom time zones can be set to . This occurs when custom time zones are created by the or the overload and the `disableDaylightSavingTime` parameter is `true`. Therefore, your code should never assume that the value of the property is not `null` or empty. + + The property is equivalent to the property of the class. + + + +## Examples + The following example defines a method named `DisplayDateWithTimeZoneName` that uses the method to determine whether to display a time zone's standard time name or daylight saving time name. + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/DaylightName/IsDaylightSavingTime.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/DaylightName/IsDaylightSavingTime.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.IsDaylightSavingTime/vb/IsDaylightSavingTime.vb" id="Snippet1"::: + ]]> @@ -1586,29 +1586,29 @@ Gets the general display name that represents the time zone. The time zone's general display name. - object that represents the local time zone and outputs its display name, standard time name, and daylight saving time name. The output is displayed for a system in the U.S. Pacific Standard Time zone. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/BaseUtcOffset/ShowTimeZoneNames1.cs" id="Snippet2"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/BaseUtcOffset/ShowTimeZoneNames1.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Class/VB/ShowTimeZoneNames1.vb" id="Snippet2"::: - + object that represents the local time zone and outputs its display name, standard time name, and daylight saving time name. The output is displayed for a system in the U.S. Pacific Standard Time zone. + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/BaseUtcOffset/ShowTimeZoneNames1.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/BaseUtcOffset/ShowTimeZoneNames1.fs" id="Snippet2"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Class/VB/ShowTimeZoneNames1.vb" id="Snippet2"::: + ]]> @@ -1680,28 +1680,28 @@ if is a object that is equal to the current instance; otherwise, . - object and compares it with the current instance. The test for equality is based on a comparison of values. The current instance and `obj` are considered to be equal under the following conditions: - -- The run-time type of `obj` is . - -- The two objects have the same property value. - -- The two objects have the same adjustment rules. - - If `obj` is `null`, this method returns `false`. - - - -## Examples - The following example uses the method to determine whether the local time zone is Pacific Time or Eastern Time. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/Equals/equals1.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/Equals/equals1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.timezoneinfo.equals/vb/equals1.vb" id="Snippet1"::: - + object and compares it with the current instance. The test for equality is based on a comparison of values. The current instance and `obj` are considered to be equal under the following conditions: + +- The run-time type of `obj` is . + +- The two objects have the same property value. + +- The two objects have the same adjustment rules. + + If `obj` is `null`, this method returns `false`. + + + +## Examples + The following example uses the method to determine whether the local time zone is Pacific Time or Eastern Time. + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/Equals/equals1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/Equals/equals1.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.timezoneinfo.equals/vb/equals1.vb" id="Snippet1"::: + ]]> @@ -1771,36 +1771,36 @@ if the two objects are equal; otherwise, . - objects are considered to be equal under the following conditions: - -- The value of their property is the same. - -- They have the same adjustment rules. - - returns the Boolean value that results from evaluating the following expression: - - ```csharp - other.Id == this.Id && HasSameRules(other); - ``` - - ```vb - other.Id = me.Id AndAlso HasSameRules(other) - ``` - - If the `other` parameter is an uninitialized object, this method returns `false`. - - - -## Examples - The following example uses the method to determine whether the local time zone is Pacific Time or Eastern Time. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/BaseUtcOffset/TimeZone2_Examples.cs" id="Snippet7"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/BaseUtcOffset/TimeZone2_Examples.fs" id="Snippet7"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Class/VB/TimeZone2_Examples.vb" id="Snippet7"::: - + objects are considered to be equal under the following conditions: + +- The value of their property is the same. + +- They have the same adjustment rules. + + returns the Boolean value that results from evaluating the following expression: + + ```csharp + other.Id == this.Id && HasSameRules(other); + ``` + + ```vb + other.Id = me.Id AndAlso HasSameRules(other) + ``` + + If the `other` parameter is an uninitialized object, this method returns `false`. + + + +## Examples + The following example uses the method to determine whether the local time zone is Pacific Time or Eastern Time. + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/BaseUtcOffset/TimeZone2_Examples.cs" id="Snippet7"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/BaseUtcOffset/TimeZone2_Examples.fs" id="Snippet7"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Class/VB/TimeZone2_Examples.vb" id="Snippet7"::: + ]]> @@ -1850,22 +1850,22 @@ Instantiates a new object based on its identifier. An object whose identifier is the value of the parameter. - objects returned by the method. - - On Windows systems, `FindSystemTimeZoneById` tries to match `id` to the subkey names of the HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Time Zones branch of the registry. On Linux and macOS, it uses time zone information available in the [ICU Library](https://unicode-org.github.io/icu/userguide/datetime/timezone/). If the registry or the library does not have the information for the time zone you desire, you can create a particular time zone either by calling one of the overloads of the method or by calling to deserialize a object that represents the required time zone. However, time zones created by these method calls are not system-defined time and cannot be retrieved using the method. These custom time zones can be accessed only through the object reference returned by the or method call. - -This method returns a new instance for each method call; it does not return cached objects. This may impact performance in applications that call the `FindSystemTimeZoneById` method repeatedly with the same identifier. - -## Examples - The following example uses the method to retrieve the Tokyo Standard Time zone. This object is then used to convert the local time to the time in Tokyo and to determine whether it is Tokyo Standard Time or Tokyo Daylight Time. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/ConvertTimeBySystemTimeZoneId/convertdt2.cs" id="Snippet2"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/ConvertTimeBySystemTimeZoneId/convertdt2.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Conversions/vb/convertdt2.vb" id="Snippet2"::: - + objects returned by the method. + + On Windows systems, `FindSystemTimeZoneById` tries to match `id` to the subkey names of the HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Time Zones branch of the registry. On Linux and macOS, it uses time zone information available in the [ICU Library](https://unicode-org.github.io/icu/userguide/datetime/timezone/). If the registry or the library does not have the information for the time zone you desire, you can create a particular time zone either by calling one of the overloads of the method or by calling to deserialize a object that represents the required time zone. However, time zones created by these method calls are not system-defined time and cannot be retrieved using the method. These custom time zones can be accessed only through the object reference returned by the or method call. + +This method returns a new instance for each method call; it does not return cached objects. This may impact performance in applications that call the `FindSystemTimeZoneById` method repeatedly with the same identifier. + +## Examples + The following example uses the method to retrieve the Tokyo Standard Time zone. This object is then used to convert the local time to the time in Tokyo and to determine whether it is Tokyo Standard Time or Tokyo Daylight Time. + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/ConvertTimeBySystemTimeZoneId/convertdt2.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/ConvertTimeBySystemTimeZoneId/convertdt2.fs" id="Snippet2"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Conversions/vb/convertdt2.vb" id="Snippet2"::: + ]]> The system does not have enough memory to hold information about the time zone. @@ -1920,20 +1920,20 @@ This method returns a new instance for each method ca Deserializes a string to re-create an original serialized object. The original serialized object. - method in a standalone executable or use an application's setup program to save the time zone as a string. The application can then retrieve this string from its storage location and instantiate it using the method. - - - -## Examples - The following example tries to retrieve the Antarctica/South Pole time zone from the local system. If it fails, the code tries to retrieve information about the time zone from a text file in the application directory. If this attempt fails, the code creates the time zone and writes information about the time zone to the text file. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/CreateCustomTimeZone/System.TimeZone2.CreateTimeZone.cs" id="Snippet4"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/CreateCustomTimeZone/System.TimeZone2.CreateTimeZone.fs" id="Snippet4"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.CreateTimeZone/vb/System.TimeZone2.CreateTimeZone.vb" id="Snippet4"::: - + method in a standalone executable or use an application's setup program to save the time zone as a string. The application can then retrieve this string from its storage location and instantiate it using the method. + + + +## Examples + The following example tries to retrieve the Antarctica/South Pole time zone from the local system. If it fails, the code tries to retrieve information about the time zone from a text file in the application directory. If this attempt fails, the code creates the time zone and writes information about the time zone to the text file. + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/CreateCustomTimeZone/System.TimeZone2.CreateTimeZone.cs" id="Snippet4"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/CreateCustomTimeZone/System.TimeZone2.CreateTimeZone.fs" id="Snippet4"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.CreateTimeZone/vb/System.TimeZone2.CreateTimeZone.vb" id="Snippet4"::: + ]]> The parameter is . @@ -1983,26 +1983,26 @@ This method returns a new instance for each method ca Retrieves an array of objects that apply to the current object. An array of objects for this time zone. - method retrieves an array of objects. Each object in the array defines the effective start and end date of that time zone adjustment, as well as its delta (the exact amount by which the adjustment causes the time to change). In addition, two properties return objects that define when each annual transition to and from standard time occurs. - - If a time zone has multiple adjustment rules, they are generally ordered from earliest (at index 0) to latest (at index - 1). - - If a time zone has no adjustment rules, the method returns an empty array (an array whose is zero). - - Any modifications to the elements of the array returned by the method are not reflected in the adjustment rules that belong to a particular time zone. To modify a time zone's adjustment rules (such as to reflect its historical transition to and from daylight saving time) you must create a new time zone with the appropriate adjustment rules, rather than modify the existing one. - - - -## Examples - The following example retrieves all time zones that are defined on the local system and displays complete information about their adjustment rules to the console. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo+AdjustmentRule/Overview/System.TimeZone2.AdjustmentRule.Class.cs" id="Snippet3"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo+AdjustmentRule/Overview/System.TimeZone2.AdjustmentRule.Class.fs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.AdjustmentRule.Class/vb/System.TimeZone2.AdjustmentRule.Class.vb" id="Snippet3"::: - + method retrieves an array of objects. Each object in the array defines the effective start and end date of that time zone adjustment, as well as its delta (the exact amount by which the adjustment causes the time to change). In addition, two properties return objects that define when each annual transition to and from standard time occurs. + + If a time zone has multiple adjustment rules, they are generally ordered from earliest (at index 0) to latest (at index - 1). + + If a time zone has no adjustment rules, the method returns an empty array (an array whose is zero). + + Any modifications to the elements of the array returned by the method are not reflected in the adjustment rules that belong to a particular time zone. To modify a time zone's adjustment rules (such as to reflect its historical transition to and from daylight saving time) you must create a new time zone with the appropriate adjustment rules, rather than modify the existing one. + + + +## Examples + The following example retrieves all time zones that are defined on the local system and displays complete information about their adjustment rules to the console. + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo+AdjustmentRule/Overview/System.TimeZone2.AdjustmentRule.Class.cs" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo+AdjustmentRule/Overview/System.TimeZone2.AdjustmentRule.Class.fs" id="Snippet3"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.AdjustmentRule.Class/vb/System.TimeZone2.AdjustmentRule.Class.vb" id="Snippet3"::: + ]]> The system does not have enough memory to make an in-memory copy of the adjustment rules. @@ -2069,36 +2069,36 @@ This method returns a new instance for each method ca Returns information about the possible dates and times that an ambiguous date and time can be mapped to. An array of objects that represents possible Coordinated Universal Time (UTC) offsets that a particular date and time can be mapped to. - property and the object, as the following table shows. - -|TimeZoneInfo object type|Kind property value|Behavior| -|------------------------------|-------------------------|--------------| -|| or |Returns ambiguous time offsets for `dateTime`.| -|||Converts `dateTime` to the local time, and then returns ambiguous time offsets for that time.| -||Any value.|Throws an .| -|Any other time zone.| or |Converts `dateTime` to the specified time zone, and then determines whether that time is ambiguous.| -|Any other time zone.||Determines whether `dateTime` is ambiguous in the specified time zone.| - - The order of objects in the array returned by this method is undefined. However, you can determine which element represents an offset from the time zone's standard time by comparing its value with the time zone's property. To map an ambiguous time to a time zone's standard time, see [How to: Resolve Ambiguous Times](/dotnet/standard/datetime/resolve-ambiguous-times). - - - -## Examples - The following example defines a method named `ShowPossibleUtcTimes` that uses the method to map an ambiguous time to its possible corresponding Coordinated Universal Time (UTC) times. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/GetAmbiguousTimeOffsets/System.TimeZone2.GetAmbiguousTimeOffsets.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/GetAmbiguousTimeOffsets/System.TimeZone2.GetAmbiguousTimeOffsets.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.GetAmbiguousTimeOffsets/vb/System.TimeZone2.GetAmbiguousTimeOffsets.vb" id="Snippet1"::: - - The method can then be called using code such as the following: - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/GetAmbiguousTimeOffsets/System.TimeZone2.GetAmbiguousTimeOffsets.cs" id="Snippet2"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/GetAmbiguousTimeOffsets/System.TimeZone2.GetAmbiguousTimeOffsets.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.GetAmbiguousTimeOffsets/vb/System.TimeZone2.GetAmbiguousTimeOffsets.vb" id="Snippet2"::: - + property and the object, as the following table shows. + +|TimeZoneInfo object type|Kind property value|Behavior| +|------------------------------|-------------------------|--------------| +|| or |Returns ambiguous time offsets for `dateTime`.| +|||Converts `dateTime` to the local time, and then returns ambiguous time offsets for that time.| +||Any value.|Throws an .| +|Any other time zone.| or |Converts `dateTime` to the specified time zone, and then determines whether that time is ambiguous.| +|Any other time zone.||Determines whether `dateTime` is ambiguous in the specified time zone.| + + The order of objects in the array returned by this method is undefined. However, you can determine which element represents an offset from the time zone's standard time by comparing its value with the time zone's property. To map an ambiguous time to a time zone's standard time, see [How to: Resolve Ambiguous Times](/dotnet/standard/datetime/resolve-ambiguous-times). + + + +## Examples + The following example defines a method named `ShowPossibleUtcTimes` that uses the method to map an ambiguous time to its possible corresponding Coordinated Universal Time (UTC) times. + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/GetAmbiguousTimeOffsets/System.TimeZone2.GetAmbiguousTimeOffsets.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/GetAmbiguousTimeOffsets/System.TimeZone2.GetAmbiguousTimeOffsets.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.GetAmbiguousTimeOffsets/vb/System.TimeZone2.GetAmbiguousTimeOffsets.vb" id="Snippet1"::: + + The method can then be called using code such as the following: + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/GetAmbiguousTimeOffsets/System.TimeZone2.GetAmbiguousTimeOffsets.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/GetAmbiguousTimeOffsets/System.TimeZone2.GetAmbiguousTimeOffsets.fs" id="Snippet2"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.GetAmbiguousTimeOffsets/vb/System.TimeZone2.GetAmbiguousTimeOffsets.vb" id="Snippet2"::: + ]]> @@ -2155,13 +2155,13 @@ This method returns a new instance for each method ca Returns information about the possible dates and times that an ambiguous date and time can be mapped to. An array of objects that represents possible Coordinated Universal Time (UTC) offsets that a particular date and time can be mapped to. - property of the `dateTimeOffset` parameter and the object. If the value of the property corresponds to the current time zone's possible offsets from Coordinated Universal Time (UTC) for that date and time, the method returns the possible offsets. Otherwise, it converts `dateTimeOffset` to the time in the current time zone, and then returns the possible offsets of that date and time. - - The order of objects in the array returned by this method is undefined. However, you can determine which element represents an offset from the time zone's standard time by comparing its value with the time zone's property. To map an ambiguous time to a time zone's standard time, see [How to: Resolve Ambiguous Times](/dotnet/standard/datetime/resolve-ambiguous-times). - + property of the `dateTimeOffset` parameter and the object. If the value of the property corresponds to the current time zone's possible offsets from Coordinated Universal Time (UTC) for that date and time, the method returns the possible offsets. Otherwise, it converts `dateTimeOffset` to the time in the current time zone, and then returns the possible offsets of that date and time. + + The order of objects in the array returned by this method is undefined. However, you can determine which element represents an offset from the time zone's standard time by comparing its value with the time zone's property. To map an ambiguous time to a time zone's standard time, see [How to: Resolve Ambiguous Times](/dotnet/standard/datetime/resolve-ambiguous-times). + ]]> @@ -2215,11 +2215,11 @@ This method returns a new instance for each method ca Serves as a hash function for hashing algorithms and data structures such as hash tables. A 32-bit signed integer that serves as the hash code for this object. - method, see . - + method, see . + ]]> @@ -2280,32 +2280,32 @@ This method returns a new instance for each method ca Returns a sorted collection of all the time zones about which information is available on the local system. A read-only collection of objects. - method retrieves all available time zone information from the subkeys of the registry's HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Time Zones key on Windows systems and from the [ICU Library](https://unicode-org.github.io/icu/userguide/datetime/timezone/) on Linux and macOS. If it is unable to successfully retrieve and parse values for particular string properties of individual objects, this method sets their value to an empty string (""). - -> [!IMPORTANT] -> The method returns a collection of objects only for time zones defined in the Windows registry or the ICU library. It does not include time zones created using the overloads of the method. These are accessible only through the object reference returned by the time zone creation method. - - The collection returned by this method is sorted by UTC offset and, for time zones that have the same UTC offset, by the display name using the current culture. For information about the display name, see . - - The object returned by this method supports the interface, which means that it can be iterated using the `foreach` (in C#) or `For Each…Next` (in Visual Basic) statements. Each iteration of the loop provides the next object in the collection. - - The collection of objects represents time zones defined on the local computer; it does not necessarily provide complete information for all time zones during all time periods. If your application requires time zones not found on the local computer, you can create custom time zones using the overloads of the method. For more information, see [How to: Create Time Zones Without Adjustment Rules](/dotnet/standard/datetime/create-time-zones-without-adjustment-rules) and [How to: Create Time Zones with Adjustment Rules](/dotnet/standard/datetime/create-time-zones-with-adjustment-rules). - - You can also determine whether an individual time zone is defined on the local computer by calling the method and providing the identifier of the time zone you want to retrieve as a parameter. - - - -## Examples - The following example retrieves a collection of time zone objects that represent the time zones defined on a computer and writes information about them to a text file. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/BaseUtcOffset/getsystemtimezones1.cs" id="Snippet6"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/BaseUtcOffset/getsystemtimezones1.fs" id="Snippet6"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Class/VB/getsystemtimezones1.vb" id="Snippet6"::: - :::code language="powershell" source="~/snippets/powershell/VS_Snippets_CLR_System/System.TimeZone2.Class/PS/Timezone2_Examples.ps1"::: - + method retrieves all available time zone information from the subkeys of the registry's HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Time Zones key on Windows systems and from the [ICU Library](https://unicode-org.github.io/icu/userguide/datetime/timezone/) on Linux and macOS. If it is unable to successfully retrieve and parse values for particular string properties of individual objects, this method sets their value to an empty string (""). + +> [!IMPORTANT] +> The method returns a collection of objects only for time zones defined in the Windows registry or the ICU library. It does not include time zones created using the overloads of the method. These are accessible only through the object reference returned by the time zone creation method. + + The collection returned by this method is sorted by UTC offset and, for time zones that have the same UTC offset, by the display name using the current culture. For information about the display name, see . + + The object returned by this method supports the interface, which means that it can be iterated using the `foreach` (in C#) or `For Each…Next` (in Visual Basic) statements. Each iteration of the loop provides the next object in the collection. + + The collection of objects represents time zones defined on the local computer; it does not necessarily provide complete information for all time zones during all time periods. If your application requires time zones not found on the local computer, you can create custom time zones using the overloads of the method. For more information, see [How to: Create Time Zones Without Adjustment Rules](/dotnet/standard/datetime/create-time-zones-without-adjustment-rules) and [How to: Create Time Zones with Adjustment Rules](/dotnet/standard/datetime/create-time-zones-with-adjustment-rules). + + You can also determine whether an individual time zone is defined on the local computer by calling the method and providing the identifier of the time zone you want to retrieve as a parameter. + + + +## Examples + The following example retrieves a collection of time zone objects that represent the time zones defined on a computer and writes information about them to a text file. + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/BaseUtcOffset/getsystemtimezones1.cs" id="Snippet6"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/BaseUtcOffset/getsystemtimezones1.fs" id="Snippet6"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Class/VB/getsystemtimezones1.vb" id="Snippet6"::: + :::code language="powershell" source="~/snippets/powershell/VS_Snippets_CLR_System/System.TimeZone2.Class/PS/Timezone2_Examples.ps1"::: + ]]> There is insufficient memory to store all time zone information. @@ -2341,11 +2341,9 @@ This method returns a new instance for each method ca If , The collection returned may not necessarily be sorted. - Returns a containing all valid TimeZone's from the local machine. - This method does *not* throw TimeZoneNotFoundException or InvalidTimeZoneException. + Returns a containing all valid TimeZone's from the local machine. This method does *not* throw TimeZoneNotFoundException or InvalidTimeZoneException. To be added. - By setting the skipSorting parameter to , the method will attempt to avoid sorting the returned collection. - This option can be beneficial when the caller does not require a sorted list and aims to enhance the performance. + By setting the skipSorting parameter to , the method will attempt to avoid sorting the returned collection. This option can be beneficial when the caller does not require a sorted list and aims to enhance the performance. @@ -2408,24 +2406,24 @@ This method returns a new instance for each method ca Calculates the offset or difference between the time in this time zone and Coordinated Universal Time (UTC) for a particular date and time. An object that indicates the time difference between the two time zones. - property, which returns the difference between Coordinated Universal Time (UTC) and the time zone's standard time and, therefore, does not take adjustment rules into account. - - If the `dateTime` parameter's property does not correspond to the time zone object, this method performs the necessary conversion before returning a result. For example, this can occur if the property is but the time zone object is not the local time zone. If `dateTime` is ambiguous, or if the converted time is ambiguous, this method interprets the ambiguous time as a standard time. If `dateTime` is invalid, this method returns a object that reflects the difference between UTC and the time zone's standard time. - - The method is similar in operation to the method of the class. - - - -## Examples - The following example illustrates the use of the method with different time zones and with date values that have different property values. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/GetUtcOffset/System.TimeZone2.GetUtcOffset.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/GetUtcOffset/System.TimeZone2.GetUtcOffset.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.GetUtcOffset/vb/System.TimeZone2.GetUtcOffset.vb" id="Snippet1"::: - + property, which returns the difference between Coordinated Universal Time (UTC) and the time zone's standard time and, therefore, does not take adjustment rules into account. + + If the `dateTime` parameter's property does not correspond to the time zone object, this method performs the necessary conversion before returning a result. For example, this can occur if the property is but the time zone object is not the local time zone. If `dateTime` is ambiguous, or if the converted time is ambiguous, this method interprets the ambiguous time as a standard time. If `dateTime` is invalid, this method returns a object that reflects the difference between UTC and the time zone's standard time. + + The method is similar in operation to the method of the class. + + + +## Examples + The following example illustrates the use of the method with different time zones and with date values that have different property values. + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/GetUtcOffset/System.TimeZone2.GetUtcOffset.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/GetUtcOffset/System.TimeZone2.GetUtcOffset.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.GetUtcOffset/vb/System.TimeZone2.GetUtcOffset.vb" id="Snippet1"::: + ]]> @@ -2478,11 +2476,11 @@ This method returns a new instance for each method ca Calculates the offset or difference between the time in this time zone and Coordinated Universal Time (UTC) for a particular date and time. An object that indicates the time difference between Coordinated Universal Time (UTC) and the current time zone. - property, which returns the difference between Coordinated Universal Time (UTC) and the time zone's standard time and, therefore, does not take adjustment rules into account. - + property, which returns the difference between Coordinated Universal Time (UTC) and the time zone's standard time and, therefore, does not take adjustment rules into account. + ]]> @@ -2563,20 +2561,20 @@ This method returns a new instance for each method ca if the two time zones have identical adjustment rules and an identical base offset; otherwise, . - method, the method indicates whether two time zones have the same base offset (as defined by the property) and the same adjustment rules. Unlike the method, does not compare time zone identifiers (as defined by the property). - - - -## Examples - Typically, a number of time zones defined in the registry on Windows and the [ICU Library](https://unicode-org.github.io/icu/userguide/datetime/timezone/) on Linux and macOS have the same offset from Coordinated Universal Time (UTC) and the same adjustment rules. The following example displays a list of these time zones to the console. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/HasSameRules/HasSameRules.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/HasSameRules/HasSameRules.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.HasSameRules/vb/HasSameRules.vb" id="Snippet1"::: - + method, the method indicates whether two time zones have the same base offset (as defined by the property) and the same adjustment rules. Unlike the method, does not compare time zone identifiers (as defined by the property). + + + +## Examples + Typically, a number of time zones defined in the registry on Windows and the [ICU Library](https://unicode-org.github.io/icu/userguide/datetime/timezone/) on Linux and macOS have the same offset from Coordinated Universal Time (UTC) and the same adjustment rules. The following example displays a list of these time zones to the console. + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/HasSameRules/HasSameRules.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/HasSameRules/HasSameRules.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.HasSameRules/vb/HasSameRules.vb" id="Snippet1"::: + ]]> The parameter is . @@ -2623,25 +2621,25 @@ This method returns a new instance for each method ca Gets the time zone identifier. The time zone identifier. - method to instantiate a object that represents a particular time zone. - -> [!IMPORTANT] -> Although a key name in the Windows registry can be a maximum of 255 characters, we recommend that an identifier that you assign to a custom time zone be 32 characters or fewer. The longer the identifier, the greater the probability that an incorrect key name will be supplied when retrieving it. - - The value of the property is usually, but not always, identical to that of the property. The identifier of the Coordinated Universal Time zone is UTC. - - - -## Examples - The following example lists the identifier of each of the time zones defined on the local computer. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/BaseUtcOffset/TimeZone2_Examples.cs" id="Snippet5"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/BaseUtcOffset/TimeZone2_Examples.fs" id="Snippet5"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Class/VB/TimeZone2_Examples.vb" id="Snippet5"::: - + method to instantiate a object that represents a particular time zone. + +> [!IMPORTANT] +> Although a key name in the Windows registry can be a maximum of 255 characters, we recommend that an identifier that you assign to a custom time zone be 32 characters or fewer. The longer the identifier, the greater the probability that an incorrect key name will be supplied when retrieving it. + + The value of the property is usually, but not always, identical to that of the property. The identifier of the Coordinated Universal Time zone is UTC. + + + +## Examples + The following example lists the identifier of each of the time zones defined on the local computer. + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/BaseUtcOffset/TimeZone2_Examples.cs" id="Snippet5"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/BaseUtcOffset/TimeZone2_Examples.fs" id="Snippet5"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Class/VB/TimeZone2_Examples.vb" id="Snippet5"::: + ]]> @@ -2707,33 +2705,33 @@ This method returns a new instance for each method ca if the parameter is ambiguous; otherwise, . - method always return `false`. - - For time zones that do observe daylight saving time, the precise behavior of this method depends on the relationship between the property and the object, as the following table shows. - -|TimeZoneInfo object type|Kind property value|Behavior| -|------------------------------|-------------------------|--------------| -|| or |Determines whether the `dateTime` parameter is ambiguous.| -|||Converts `dateTime` to the local time and then determines whether that time is ambiguous.| -|| or |Returns `false`.| -|||If `dateTime` is ambiguous, assumes it is a standard time, converts it to UTC, and returns `false`.| -|Any other time zone.| or |Converts `dateTime` to the time in the specified time zone and then determines whether that time is ambiguous.| -|Any other time zone.||Determines whether `dateTime` is ambiguous.| - - - -## Examples - In the Pacific Time zone, daylight saving time ends at 2:00 A.M. on November 4, 2007. The following example passes the time at one-minute intervals from 12:59 A.M. on November 4, 2007, to 2:01 A.M. on November 4, 2007, to the method of a object that represents the Pacific Time zone. The console output indicates that all times from 1:00 A.M. on November 4, 2007, to 1:59 A.M. on November 4, 2007, are ambiguous. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/BaseUtcOffset/TimeZone2_Examples.cs" id="Snippet8"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/BaseUtcOffset/TimeZone2_Examples.fs" id="Snippet8"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Class/VB/TimeZone2_Examples.vb" id="Snippet8"::: - + method always return `false`. + + For time zones that do observe daylight saving time, the precise behavior of this method depends on the relationship between the property and the object, as the following table shows. + +|TimeZoneInfo object type|Kind property value|Behavior| +|------------------------------|-------------------------|--------------| +|| or |Determines whether the `dateTime` parameter is ambiguous.| +|||Converts `dateTime` to the local time and then determines whether that time is ambiguous.| +|| or |Returns `false`.| +|||If `dateTime` is ambiguous, assumes it is a standard time, converts it to UTC, and returns `false`.| +|Any other time zone.| or |Converts `dateTime` to the time in the specified time zone and then determines whether that time is ambiguous.| +|Any other time zone.||Determines whether `dateTime` is ambiguous.| + + + +## Examples + In the Pacific Time zone, daylight saving time ends at 2:00 A.M. on November 4, 2007. The following example passes the time at one-minute intervals from 12:59 A.M. on November 4, 2007, to 2:01 A.M. on November 4, 2007, to the method of a object that represents the Pacific Time zone. The console output indicates that all times from 1:00 A.M. on November 4, 2007, to 1:59 A.M. on November 4, 2007, are ambiguous. + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/BaseUtcOffset/TimeZone2_Examples.cs" id="Snippet8"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/BaseUtcOffset/TimeZone2_Examples.fs" id="Snippet8"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Class/VB/TimeZone2_Examples.vb" id="Snippet8"::: + ]]> The property of the value is and is an invalid time. @@ -2788,13 +2786,13 @@ This method returns a new instance for each method ca if the parameter is ambiguous in the current time zone; otherwise, . - property of the `dateTimeOffset` parameter and the current time zone. If the value of the property is a possible offset from the UTC of the current time zone, the method determines whether that date and time is ambiguous. Otherwise, it converts `dateTimeOffset` to the time in the current time zone, and then determines whether that date and time is ambiguous. - + property of the `dateTimeOffset` parameter and the current time zone. If the value of the property is a possible offset from the UTC of the current time zone, the method determines whether that date and time is ambiguous. Otherwise, it converts `dateTimeOffset` to the time in the current time zone, and then determines whether that date and time is ambiguous. + ]]> @@ -2860,44 +2858,44 @@ This method returns a new instance for each method ca if the parameter is a daylight saving time; otherwise, . - is affected by the relationship between the time zone represented by the object and the property of the `dateTime` parameter, as the following table shows. - -|TimeZoneInfo object|DateTime.Kind property|Result| -|-------------------------|----------------------------|------------| -||`DateTimeKind.Local`|Determines whether `dateTime` is daylight saving time.| -||`DateTimeKind.Utc`|Converts `dateTime` from Coordinated Universal Time (UTC) to local time and determines whether it is daylight saving time.| -||`DateTimeKind.Unspecified`|Assumes that `dateTime` represents local time and determines whether it is daylight saving time.| -||`DateTimeKind.Local`, `DateTimeKind.Unspecified`, or `DateTimeKind.Utc`|Returns `false` (UTC does not support daylight saving time).| -|Any other object.|`DateTimeKind.Local`|Converts the local time to the equivalent time of the object and then determines whether the latter is daylight saving time.| -|Any other object.|`DateTimeKind.Utc`|Converts UTC to the equivalent time of the object and then determines whether the latter is daylight saving time.| -|Any other object.|`DateTimeKind.Unspecified`|Determines whether `dateTime` is daylight saving time.| - - If the time zone represented by the object does not support daylight saving time, the method always returns `false`. A number of time zones, including , do not observe daylight saving time. To determine whether a time zone supports daylight saving time, retrieve the value of its property. - - If the `dateTime` parameter specifies an ambiguous time in the current object's time zone, the method interprets `dateTime` as standard time and returns `false` if its property is or . If the property is , this method will select the correct ambiguous time and indicate whether it is a daylight saving time. - - Because the method can return `false` for a date and time that is ambiguous (that is, a date and time that can represent either a standard time or a daylight saving time in a particular time zone), the method can be paired with the method to determine whether a time may be a daylight saving time. Because an ambiguous time is one that can be both a daylight saving time and a standard time, the method can be called first to determine whether a date and time may be a daylight saving time. If the method returns `false`, the method can be called to determine whether the value is a daylight saving time. The following example illustrates this technique. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/DaylightName/IsDaylightSavingTime.cs" id="Snippet2"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/DaylightName/IsDaylightSavingTime.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.IsDaylightSavingTime/vb/IsDaylightSavingTime.vb" id="Snippet2"::: - - If the `dateTime` parameter specifies an invalid time, the method call throws an if the value of the `dateTime` parameter's property is ; otherwise, the method returns `false`. - - Call the method to determine whether to use a time zone's value or its value when displaying the time zone name. See the Example section for an illustration. - - - -## Examples - The following example defines a method named `DisplayDateWithTimeZoneName` that uses the method to determine whether to display a time zone's standard time name or daylight saving time name. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/DaylightName/IsDaylightSavingTime.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/DaylightName/IsDaylightSavingTime.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.IsDaylightSavingTime/vb/IsDaylightSavingTime.vb" id="Snippet1"::: - + is affected by the relationship between the time zone represented by the object and the property of the `dateTime` parameter, as the following table shows. + +|TimeZoneInfo object|DateTime.Kind property|Result| +|-------------------------|----------------------------|------------| +||`DateTimeKind.Local`|Determines whether `dateTime` is daylight saving time.| +||`DateTimeKind.Utc`|Converts `dateTime` from Coordinated Universal Time (UTC) to local time and determines whether it is daylight saving time.| +||`DateTimeKind.Unspecified`|Assumes that `dateTime` represents local time and determines whether it is daylight saving time.| +||`DateTimeKind.Local`, `DateTimeKind.Unspecified`, or `DateTimeKind.Utc`|Returns `false` (UTC does not support daylight saving time).| +|Any other object.|`DateTimeKind.Local`|Converts the local time to the equivalent time of the object and then determines whether the latter is daylight saving time.| +|Any other object.|`DateTimeKind.Utc`|Converts UTC to the equivalent time of the object and then determines whether the latter is daylight saving time.| +|Any other object.|`DateTimeKind.Unspecified`|Determines whether `dateTime` is daylight saving time.| + + If the time zone represented by the object does not support daylight saving time, the method always returns `false`. A number of time zones, including , do not observe daylight saving time. To determine whether a time zone supports daylight saving time, retrieve the value of its property. + + If the `dateTime` parameter specifies an ambiguous time in the current object's time zone, the method interprets `dateTime` as standard time and returns `false` if its property is or . If the property is , this method will select the correct ambiguous time and indicate whether it is a daylight saving time. + + Because the method can return `false` for a date and time that is ambiguous (that is, a date and time that can represent either a standard time or a daylight saving time in a particular time zone), the method can be paired with the method to determine whether a time may be a daylight saving time. Because an ambiguous time is one that can be both a daylight saving time and a standard time, the method can be called first to determine whether a date and time may be a daylight saving time. If the method returns `false`, the method can be called to determine whether the value is a daylight saving time. The following example illustrates this technique. + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/DaylightName/IsDaylightSavingTime.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/DaylightName/IsDaylightSavingTime.fs" id="Snippet2"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.IsDaylightSavingTime/vb/IsDaylightSavingTime.vb" id="Snippet2"::: + + If the `dateTime` parameter specifies an invalid time, the method call throws an if the value of the `dateTime` parameter's property is ; otherwise, the method returns `false`. + + Call the method to determine whether to use a time zone's value or its value when displaying the time zone name. See the Example section for an illustration. + + + +## Examples + The following example defines a method named `DisplayDateWithTimeZoneName` that uses the method to determine whether to display a time zone's standard time name or daylight saving time name. + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/DaylightName/IsDaylightSavingTime.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/DaylightName/IsDaylightSavingTime.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.IsDaylightSavingTime/vb/IsDaylightSavingTime.vb" id="Snippet1"::: + ]]> The property of the value is and is an invalid time. @@ -2952,13 +2950,13 @@ This method returns a new instance for each method ca if the parameter is a daylight saving time; otherwise, . - is affected by the relationship between the time zone represented by the object and the property of the `dateTimeOffset` parameter. If `dateTimeOffset` does not correspond to the current time zone's offset from Coordinated Universal Time (UTC), the method converts that time to the time in the current time zone. It then determines whether that date and time is a daylight saving time. - - If the time zone represented by the object does not support daylight saving time, the method always returns `false`. To determine whether a time zone supports daylight saving time, retrieve the value of its property. - + is affected by the relationship between the time zone represented by the object and the property of the `dateTimeOffset` parameter. If `dateTimeOffset` does not correspond to the current time zone's offset from Coordinated Universal Time (UTC), the method converts that time to the time in the current time zone. It then determines whether that date and time is a daylight saving time. + + If the time zone represented by the object does not support daylight saving time, the method always returns `false`. To determine whether a time zone supports daylight saving time, retrieve the value of its property. + ]]> @@ -3012,29 +3010,29 @@ This method returns a new instance for each method ca if is invalid; otherwise, . - property of the `dateTime` parameter affects whether `dateTime` represents an invalid time, as the following table shows. - -|DateTime.Kind property|TimeZoneInfo object (if applicable)|Behavior| -|----------------------------|-------------------------------------------|--------------| -|||Determines whether the time is invalid.| -|| or a non-local time zone.|Converts `dateTime` to the time of the object and returns `false`.| -||Not applicable.|Assumes `dateTime` is the time of the object and determines whether it is invalid.| -||Not applicable.|Returns `false`.| - - - -## Examples - In the Pacific Time zone, daylight saving time begins at 2:00 A.M. on April 2, 2006. The following code passes the time at one-minute intervals from 1:59 A.M. on April 2, 2006, to 3:01 A.M. on April 2, 2006, to the method of a object that represents the Pacific Time zone. The console output indicates that all times from 2:00 A.M. on April 2, 2006, to 2:59 A.M. on April 2, 2006, are invalid. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/BaseUtcOffset/TimeZone2_Examples.cs" id="Snippet9"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/BaseUtcOffset/TimeZone2_Examples.fs" id="Snippet9"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Class/VB/TimeZone2_Examples.vb" id="Snippet9"::: - + property of the `dateTime` parameter affects whether `dateTime` represents an invalid time, as the following table shows. + +|DateTime.Kind property|TimeZoneInfo object (if applicable)|Behavior| +|----------------------------|-------------------------------------------|--------------| +|||Determines whether the time is invalid.| +|| or a non-local time zone.|Converts `dateTime` to the time of the object and returns `false`.| +||Not applicable.|Assumes `dateTime` is the time of the object and determines whether it is invalid.| +||Not applicable.|Returns `false`.| + + + +## Examples + In the Pacific Time zone, daylight saving time begins at 2:00 A.M. on April 2, 2006. The following code passes the time at one-minute intervals from 1:59 A.M. on April 2, 2006, to 3:01 A.M. on April 2, 2006, to the method of a object that represents the Pacific Time zone. The console output indicates that all times from 2:00 A.M. on April 2, 2006, to 2:59 A.M. on April 2, 2006, are invalid. + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/BaseUtcOffset/TimeZone2_Examples.cs" id="Snippet9"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/BaseUtcOffset/TimeZone2_Examples.fs" id="Snippet9"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Class/VB/TimeZone2_Examples.vb" id="Snippet9"::: + ]]> @@ -3089,37 +3087,37 @@ This method returns a new instance for each method ca Gets a object that represents the local time zone. An object that represents the local time zone. - [!IMPORTANT] -> You should always access the local time zone through the property rather than assigning the local time zone to a object variable. This prevents the object variable from being invalidated by a call to the method. - - On Windows systems, the object returned by the property reflects the setting of the **Automatically adjust clock for Daylight Saving Time** checkbox in the Control Panel **Date and Time** application. If the checkbox is unchecked, the cached copy of the local time zone contains no daylight saving time information. This means that: - -- The local time zone's method returns an array whose length is zero. - -- The local time zone's property returns `false`. - -- The local time zone has no ambiguous or invalid times (all calls to or return `false`). - -- All calls to with individual local times return false. - - This is not true, however, if a reference to the local time zone is retrieved using the method. - - The property corresponds to the property of the class. - - - -## Examples - The following example retrieves a object that represents the local time zone and outputs its display name, standard time name, and daylight saving time name. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/BaseUtcOffset/ShowTimeZoneNames1.cs" id="Snippet2"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/BaseUtcOffset/ShowTimeZoneNames1.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Class/VB/ShowTimeZoneNames1.vb" id="Snippet2"::: - + [!IMPORTANT] +> You should always access the local time zone through the property rather than assigning the local time zone to a object variable. This prevents the object variable from being invalidated by a call to the method. + + On Windows systems, the object returned by the property reflects the setting of the **Automatically adjust clock for Daylight Saving Time** checkbox in the Control Panel **Date and Time** application. If the checkbox is unchecked, the cached copy of the local time zone contains no daylight saving time information. This means that: + +- The local time zone's method returns an array whose length is zero. + +- The local time zone's property returns `false`. + +- The local time zone has no ambiguous or invalid times (all calls to or return `false`). + +- All calls to with individual local times return false. + + This is not true, however, if a reference to the local time zone is retrieved using the method. + + The property corresponds to the property of the class. + + + +## Examples + The following example retrieves a object that represents the local time zone and outputs its display name, standard time name, and daylight saving time name. + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/BaseUtcOffset/ShowTimeZoneNames1.cs" id="Snippet2"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/BaseUtcOffset/ShowTimeZoneNames1.fs" id="Snippet2"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Class/VB/ShowTimeZoneNames1.vb" id="Snippet2"::: + ]]> How to: Access the Predefined UTC and Local Time Zone Objects @@ -3168,24 +3166,24 @@ This method returns a new instance for each method ca Gets the display name for the time zone's standard time. The display name of the time zone's standard time. - property is identical to the property of the class. - - If the operating system language is English, the value of the property is usually, but not always, identical to that of the property. - - - -## Examples - The following example defines a method named `DisplayDateWithTimeZoneName` that uses the method to determine whether to display a time zone's standard time name or daylight saving time name. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/DaylightName/IsDaylightSavingTime.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/DaylightName/IsDaylightSavingTime.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.IsDaylightSavingTime/vb/IsDaylightSavingTime.vb" id="Snippet1"::: - + property is identical to the property of the class. + + If the operating system language is English, the value of the property is usually, but not always, identical to that of the property. + + + +## Examples + The following example defines a method named `DisplayDateWithTimeZoneName` that uses the method to determine whether to display a time zone's standard time name or daylight saving time name. + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/DaylightName/IsDaylightSavingTime.cs" id="Snippet1"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/DaylightName/IsDaylightSavingTime.fs" id="Snippet1"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.IsDaylightSavingTime/vb/IsDaylightSavingTime.vb" id="Snippet1"::: + ]]> @@ -3234,20 +3232,20 @@ This method returns a new instance for each method ca if the time zone supports daylight saving time; otherwise, . - property for the local time zone returned by the property reflects the setting of the Control Panel **Date and Time** application's checkbox that defines whether the system automatically adjusts for daylight saving time. If it is unchecked, or if no checkbox is displayed for a time zone, the value of this property is `false`. - - - -## Examples - The following example retrieves a collection of all time zones that are available on a local system and displays the names of those that do not support daylight saving time. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/BaseUtcOffset/TimeZone2_Examples.cs" id="Snippet4"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/BaseUtcOffset/TimeZone2_Examples.fs" id="Snippet4"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Class/VB/TimeZone2_Examples.vb" id="Snippet4"::: - + property for the local time zone returned by the property reflects the setting of the Control Panel **Date and Time** application's checkbox that defines whether the system automatically adjusts for daylight saving time. If it is unchecked, or if no checkbox is displayed for a time zone, the value of this property is `false`. + + + +## Examples + The following example retrieves a collection of all time zones that are available on a local system and displays the names of those that do not support daylight saving time. + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/BaseUtcOffset/TimeZone2_Examples.cs" id="Snippet4"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/BaseUtcOffset/TimeZone2_Examples.fs" id="Snippet4"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Class/VB/TimeZone2_Examples.vb" id="Snippet4"::: + ]]> @@ -3396,28 +3394,28 @@ This method returns a new instance for each method ca Converts the current object to a serialized string. A string that represents the current object. - method to instantiate the necessary time zones as objects. The application can then call the method to convert the time zone object to a string. - - The object should also be stored in a location where the application can retrieve it when needed. Possible locations include: - -- The registry on Windows systems. - -- An application resource file. - -- An external file, such as a text file. - - - -## Examples - The following example tries to retrieve the Antarctica/South Pole time zone from the local system. If it fails, the code tries to retrieve information about the time zone from a text file in the application directory. If this attempt fails, the code creates the time zone and writes information about it to the text file. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/CreateCustomTimeZone/System.TimeZone2.CreateTimeZone.cs" id="Snippet4"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/CreateCustomTimeZone/System.TimeZone2.CreateTimeZone.fs" id="Snippet4"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.CreateTimeZone/vb/System.TimeZone2.CreateTimeZone.vb" id="Snippet4"::: - + method to instantiate the necessary time zones as objects. The application can then call the method to convert the time zone object to a string. + + The object should also be stored in a location where the application can retrieve it when needed. Possible locations include: + +- The registry on Windows systems. + +- An application resource file. + +- An external file, such as a text file. + + + +## Examples + The following example tries to retrieve the Antarctica/South Pole time zone from the local system. If it fails, the code tries to retrieve information about the time zone from a text file in the application directory. If this attempt fails, the code creates the time zone and writes information about it to the text file. + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/CreateCustomTimeZone/System.TimeZone2.CreateTimeZone.cs" id="Snippet4"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/CreateCustomTimeZone/System.TimeZone2.CreateTimeZone.fs" id="Snippet4"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.CreateTimeZone/vb/System.TimeZone2.CreateTimeZone.vb" id="Snippet4"::: + ]]> @@ -3468,11 +3466,11 @@ This method returns a new instance for each method ca Returns the current object's display name. The value of the property of the current object. - objects to a list control such as the control, the control automatically calls the method to extract a string that describes each object to be represented in the list. As a result, you do not need to store a meaningful description of the object as a string, and the user does not need to use that string to extract the object from the collection. See [How to: Enumerate Time Zones Present on a Computer](/dotnet/standard/datetime/enumerate-time-zones) for more detail. - + objects to a list control such as the control, the control automatically calls the method to extract a string that describes each object to be represented in the list. As a result, you do not need to store a meaningful description of the object as a string, and the user does not need to use that string to extract the object from the collection. See [How to: Enumerate Time Zones Present on a Computer](/dotnet/standard/datetime/enumerate-time-zones) for more detail. + ]]> @@ -3525,18 +3523,18 @@ This method returns a new instance for each method ca if the ID conversion succeeded, otherwise. - @@ -3589,18 +3587,18 @@ If the application is running on a Windows OS version that lacks the ICU library if the ID conversion succeeded, otherwise. - @@ -3664,18 +3662,18 @@ If the application is running on a Windows OS version that lacks the ICU library if the ID conversion succeeded, otherwise. - @@ -3771,25 +3769,25 @@ If the application is running on a Windows OS version that lacks the ICU library Gets a object that represents the Coordinated Universal Time (UTC) zone. An object that represents the Coordinated Universal Time (UTC) zone. - object is not retrieved from the registry on Windows systems and from the [ICU Library](https://unicode-org.github.io/icu/userguide/datetime/timezone/) on Linux and macOS. - -> [!IMPORTANT] -> You should always access the Coordinated Universal Time (UTC) zone through the property rather than assigning the UTC time zone to a object variable. This prevents the object variable from being invalidated by a call to the method. - - Coordinated Universal Time was previously known as Greenwich Mean Time (GMT). - - - -## Examples - The following example retrieves a object that represents Coordinated Universal Time (UTC) and outputs its display name, standard time name, and daylight saving time name. - - :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/BaseUtcOffset/TimeZone2_Examples.cs" id="Snippet3"::: - :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/BaseUtcOffset/TimeZone2_Examples.fs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Class/VB/TimeZone2_Examples.vb" id="Snippet3"::: - + object is not retrieved from the registry on Windows systems and from the [ICU Library](https://unicode-org.github.io/icu/userguide/datetime/timezone/) on Linux and macOS. + +> [!IMPORTANT] +> You should always access the Coordinated Universal Time (UTC) zone through the property rather than assigning the UTC time zone to a object variable. This prevents the object variable from being invalidated by a call to the method. + + Coordinated Universal Time was previously known as Greenwich Mean Time (GMT). + + + +## Examples + The following example retrieves a object that represents Coordinated Universal Time (UTC) and outputs its display name, standard time name, and daylight saving time name. + + :::code language="csharp" source="~/snippets/csharp/System/TimeZoneInfo/BaseUtcOffset/TimeZone2_Examples.cs" id="Snippet3"::: + :::code language="fsharp" source="~/snippets/fsharp/System/TimeZoneInfo/BaseUtcOffset/TimeZone2_Examples.fs" id="Snippet3"::: + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZone2.Class/VB/TimeZone2_Examples.vb" id="Snippet3"::: + ]]> How to: Access the Predefined UTC and Local Time Zone Objects diff --git a/xml/System/TimeZoneNotFoundException.xml b/xml/System/TimeZoneNotFoundException.xml index 13526fd0a4c..9481c198710 100644 --- a/xml/System/TimeZoneNotFoundException.xml +++ b/xml/System/TimeZoneNotFoundException.xml @@ -67,21 +67,21 @@ The exception that is thrown when a time zone cannot be found. - and methods when a time zone identifier cannot be found on the local system, or when there is no data associated with a particular time zone identifier. - - Because the registry serves as the repository of time zone information in Windows XP and Windows Vista, this exception indicates that the registry contains no information about a particular time zone. Time zone information is stored in the subkeys of HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Time Zones. - - If an application depends on the presence of a particular time zone and the attempt to retrieve it throws a , the application can handle the exception in either of two ways: - -- By calling the method to deserialize a saved object. - -- By calling one of the overloads of the method to create a time zone. - - See the examples for the and methods. - + and methods when a time zone identifier cannot be found on the local system, or when there is no data associated with a particular time zone identifier. + + Because the registry serves as the repository of time zone information in Windows XP and Windows Vista, this exception indicates that the registry contains no information about a particular time zone. Time zone information is stored in the subkeys of HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Time Zones. + + If an application depends on the presence of a particular time zone and the attempt to retrieve it throws a , the application can handle the exception in either of two ways: + +- By calling the method to deserialize a saved object. + +- By calling one of the overloads of the method to create a time zone. + + See the examples for the and methods. + ]]> @@ -131,11 +131,11 @@ Initializes a new instance of the class with a system-supplied message. - class. This constructor initializes the property of the new instance to a system-supplied message that describes the error, such as "The time zone '*timeZoneName*' was not found on the local computer." This message is localized for the current system culture. - + class. This constructor initializes the property of the new instance to a system-supplied message that describes the error, such as "The time zone '*timeZoneName*' was not found on the local computer." This message is localized for the current system culture. + ]]> @@ -180,11 +180,11 @@ A string that describes the exception. Initializes a new instance of the class with the specified message string. - property. The string should be localized for the current culture. - + property. The string should be localized for the current culture. + ]]> @@ -248,18 +248,18 @@ The stream that contains the serialized data. Initializes a new instance of the class from serialized data. - object. Instead, it is called by the object's method when deserializing the object from a stream. - + object. Instead, it is called by the object's method when deserializing the object from a stream. + ]]> - The parameter is . - - -or- - - The parameter is . + The parameter is . + +-or- + +The parameter is . @@ -304,22 +304,22 @@ The exception that is the cause of the current exception. Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception. - overload to handle an exception in a `try`…`catch` block. The `innerException` parameter should be a reference to the exception object handled in the `catch` block, or it can be `null`. This value is then assigned to the object's property. - - The `message` string is assigned to the property. The string should be localized for the current culture. - - - -## Examples - The following example tries to retrieve a nonexistent time zone, which throws a . The exception handler wraps the exception in a new object, which the exception handler returns to the caller. The caller's exception handler then displays information about both the outer and inner exception. - + overload to handle an exception in a `try`…`catch` block. The `innerException` parameter should be a reference to the exception object handled in the `catch` block, or it can be `null`. This value is then assigned to the object's property. + + The `message` string is assigned to the property. The string should be localized for the current culture. + + + +## Examples + The following example tries to retrieve a nonexistent time zone, which throws a . The exception handler wraps the exception in a new object, which the exception handler returns to the caller. The caller's exception handler then displays information about both the outer and inner exception. + :::code language="csharp" source="~/snippets/csharp/System/InvalidTimeZoneException/.ctor/TimeZoneNotFoundException.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/InvalidTimeZoneException/.ctor/TimeZoneNotFoundException.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZoneNotFoundException.Class/vb/TimeZoneNotFoundException.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TimeZoneNotFoundException.Class/vb/TimeZoneNotFoundException.vb" id="Snippet1"::: + ]]> diff --git a/xml/System/TimeoutException.xml b/xml/System/TimeoutException.xml index 8945ba55141..e7bdf40e00f 100644 --- a/xml/System/TimeoutException.xml +++ b/xml/System/TimeoutException.xml @@ -69,25 +69,25 @@ The exception that is thrown when the time allotted for a process or operation has expired. - exception is thrown, consult the documentation for the type whose method timed out. For information about handling the time-out, see the documentation for the method that threw the exception. - - uses the HRESULT, COR_E_TIMEOUT, which has the value 0x80131505. - - For a list of initial property values for an instance of , see the constructors. - - - -## Examples - The following code example demonstrates the use of in conjunction with members of the class. - + exception is thrown, consult the documentation for the type whose method timed out. For information about handling the time-out, see the documentation for the method that threw the exception. + + uses the HRESULT, COR_E_TIMEOUT, which has the value 0x80131505. + + For a list of initial property values for an instance of , see the constructors. + + + +## Examples + The following code example demonstrates the use of in conjunction with members of the class. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/TimeoutException.class/cpp/to.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/TimeoutException/Overview/to.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TimeoutException/Overview/to.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/TimeoutException.class/VB/to.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/TimeoutException.class/VB/to.vb" id="Snippet1"::: + ]]> @@ -143,18 +143,18 @@ Initializes a new instance of the class. - property of the new instance with a system-supplied error message. This message takes into account the current system culture. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The localized error message string.| - + property of the new instance with a system-supplied error message. This message takes into account the current system culture. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The localized error message string.| + ]]> @@ -200,18 +200,18 @@ The message that describes the error. Initializes a new instance of the class with the specified error message. - property of the new instance using the value of the `message` parameter. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The error message string.| - + property of the new instance using the value of the `message` parameter. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The error message string.| + ]]> @@ -272,11 +272,11 @@ The object that contains contextual information about the source or destination. The parameter is reserved for future use, and can be specified as . Initializes a new instance of the class with serialized data. - The parameter is . @@ -329,20 +329,20 @@ The exception that is the cause of the current exception. If the parameter is not , the current exception is raised in a block that handles the inner exception. Initializes a new instance of the class with the specified error message and inner exception. - property of the new instance using the value of the `message` parameter. - - An exception that is thrown as a direct result of a previous exception should include a reference to the previous exception in the property. The property returns the same value that is passed to the constructor, or `null` if the property does not supply the inner exception value to the constructor. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||The error message string.| -||The inner exception reference.| - + property of the new instance using the value of the `message` parameter. + + An exception that is thrown as a direct result of a previous exception should include a reference to the previous exception in the property. The property returns the same value that is passed to the constructor, or `null` if the property does not supply the inner exception value to the constructor. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||The error message string.| +||The inner exception reference.| + ]]> diff --git a/xml/System/Tuple.xml b/xml/System/Tuple.xml index 5d675f8531c..bddab2a2482 100644 --- a/xml/System/Tuple.xml +++ b/xml/System/Tuple.xml @@ -53,49 +53,49 @@ Provides static methods for creating tuple objects. - property of a object. - - Tuples are commonly used in four ways: - -- To represent a single set of data. For example, a tuple can represent a database record, and its components can represent individual fields of the record. - -- To provide easy access to, and manipulation of, a data set. - -- To return multiple values from a method without using `out` parameters (in C#) or `ByRef` parameters (in Visual Basic). - -- To pass multiple values to a method through a single parameter. For example, the method has a single parameter that lets you supply one value to the method that the thread executes at startup time. If you supply a object as the method argument, you can supply the thread's startup routine with three items of data. - - The class does not itself represent a tuple. Instead, it is a class that provides static methods for creating instances of the tuple types that are supported by the .NET Framework. It provides helper methods that you can call to instantiate tuple objects without having to explicitly specify the type of each tuple component. - - Although you can create an instance of a tuple class by calling its class constructor, the code to do so can be cumbersome. The following example uses a class constructor to create a 7-tuple or septuple that contains population data for New York City for each census from 1950 through 2000. - + property of a object. + + Tuples are commonly used in four ways: + +- To represent a single set of data. For example, a tuple can represent a database record, and its components can represent individual fields of the record. + +- To provide easy access to, and manipulation of, a data set. + +- To return multiple values from a method without using `out` parameters (in C#) or `ByRef` parameters (in Visual Basic). + +- To pass multiple values to a method through a single parameter. For example, the method has a single parameter that lets you supply one value to the method that the thread executes at startup time. If you supply a object as the method argument, you can supply the thread's startup routine with three items of data. + + The class does not itself represent a tuple. Instead, it is a class that provides static methods for creating instances of the tuple types that are supported by the .NET Framework. It provides helper methods that you can call to instantiate tuple objects without having to explicitly specify the type of each tuple component. + + Although you can create an instance of a tuple class by calling its class constructor, the code to do so can be cumbersome. The following example uses a class constructor to create a 7-tuple or septuple that contains population data for New York City for each census from 1950 through 2000. + :::code language="csharp" source="~/snippets/csharp/System/Tuple/Overview/example1.cs" interactive="try-dotnet-method" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Tuple/Overview/example1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple.class/vb/example1.vb" id="Snippet1"::: - - Creating the same tuple object by using a helper method is more straightforward, as the following example shows. - + + Creating the same tuple object by using a helper method is more straightforward, as the following example shows. + :::code language="csharp" source="~/snippets/csharp/System/Tuple/Overview/example1.cs" interactive="try-dotnet-method" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/Tuple/Overview/example1.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple.class/vb/example1.vb" id="Snippet2"::: - - The helper methods directly support the creation of tuple objects that have from one to eight components (that is, singletons through octuples). Although there is no practical limit to the number of components a tuple may have, helper methods are not available to create a tuple with nine or more components. To create such a tuple, you must call the constructor. - + + The helper methods directly support the creation of tuple objects that have from one to eight components (that is, singletons through octuples). Although there is no practical limit to the number of components a tuple may have, helper methods are not available to create a tuple with nine or more components. To create such a tuple, you must call the constructor. + > [!NOTE] -> For additional information and examples that use tuples, see the documentation for the individual tuple types in the .NET Framework. These are listed in the See Also section at the end of this topic. - - - -## Examples - The following example creates an 8-tuple (octuple) that contains prime numbers that are less than 20. - +> For additional information and examples that use tuples, see the documentation for the individual tuple types in the .NET Framework. These are listed in the See Also section at the end of this topic. + + + +## Examples + The following example creates an 8-tuple (octuple) that contains prime numbers that are less than 20. + :::code language="csharp" source="~/snippets/csharp/System/Tuple/Overview/createntuple.cs" interactive="try-dotnet-method" id="Snippet17"::: :::code language="fsharp" source="~/snippets/fsharp/System/Tuple/Overview/createntuple.fs" id="Snippet17"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple.create/vb/createntuple.vb" id="Snippet17"::: - + ]]> @@ -175,21 +175,21 @@ Creates a new 1-tuple, or singleton. A tuple whose value is (). - is a helper method that you can call to instantiate a 1-tuple object without having to explicitly specify the type of its component. The following example uses the method to instantiate a 1-tuple whose component is of type . - + is a helper method that you can call to instantiate a 1-tuple object without having to explicitly specify the type of its component. The following example uses the method to instantiate a 1-tuple whose component is of type . + :::code language="csharp" source="~/snippets/csharp/System/Tuple/Overview/create1.cs" interactive="try-dotnet-method" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Tuple/Overview/create1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple.create/vb/create1.vb" id="Snippet1"::: - - This code is equivalent to the following call to the class constructor. - + + This code is equivalent to the following call to the class constructor. + :::code language="csharp" source="~/snippets/csharp/System/Tuple/Overview/create1.cs" interactive="try-dotnet-method" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/Tuple/Overview/create1.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple.create/vb/create1.vb" id="Snippet2"::: - + ]]> @@ -260,17 +260,17 @@ Creates a new 2-tuple, or pair. A 2-tuple whose value is (, ). - is a helper method that you can call to instantiate a 2-tuple object without having to explicitly specify the types of its components. The following example uses the method to instantiate a 2-tuple. - + is a helper method that you can call to instantiate a 2-tuple object without having to explicitly specify the types of its components. The following example uses the method to instantiate a 2-tuple. + :::code language="csharp" source="~/snippets/csharp/System/Tuple/Overview/create1.cs" interactive="try-dotnet-method" id="Snippet3"::: :::code language="fsharp" source="~/snippets/fsharp/System/Tuple/Overview/create1.fs" id="Snippet3"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple.create/vb/create1.vb" id="Snippet3"::: - - This code is equivalent to the following call to the class constructor. - + + This code is equivalent to the following call to the class constructor. + :::code language="csharp" source="~/snippets/csharp/System/Tuple/Overview/create1.cs" interactive="try-dotnet-method" id="Snippet4"::: :::code language="fsharp" source="~/snippets/fsharp/System/Tuple/Overview/create1.fs" id="Snippet4"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple.create/vb/create1.vb" id="Snippet4"::: @@ -356,21 +356,21 @@ Creates a new 3-tuple, or triple. A 3-tuple whose value is (, , ). - is a helper method that you can call to instantiate a 3-tuple object without having to explicitly specify the types of its components. The following example uses the method to instantiate a 3-tuple. - + is a helper method that you can call to instantiate a 3-tuple object without having to explicitly specify the types of its components. The following example uses the method to instantiate a 3-tuple. + :::code language="csharp" source="~/snippets/csharp/System/Tuple/Overview/create1.cs" interactive="try-dotnet-method" id="Snippet5"::: :::code language="fsharp" source="~/snippets/fsharp/System/Tuple/Overview/create1.fs" id="Snippet5"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple.create/vb/create1.vb" id="Snippet5"::: - - This code is equivalent to the following call to the class constructor. - + + This code is equivalent to the following call to the class constructor. + :::code language="csharp" source="~/snippets/csharp/System/Tuple/Overview/create1.cs" interactive="try-dotnet-method" id="Snippet6"::: :::code language="fsharp" source="~/snippets/fsharp/System/Tuple/Overview/create1.fs" id="Snippet6"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple.create/vb/create1.vb" id="Snippet6"::: - + ]]> @@ -463,21 +463,21 @@ Creates a new 4-tuple, or quadruple. A 4-tuple whose value is (, , , ). - is a helper method that you can call to instantiate a 4-tuple object without having to explicitly specify the types of its components. The following example uses the method to instantiate a 4-tuple. - + is a helper method that you can call to instantiate a 4-tuple object without having to explicitly specify the types of its components. The following example uses the method to instantiate a 4-tuple. + :::code language="csharp" source="~/snippets/csharp/System/Tuple/Overview/create1.cs" interactive="try-dotnet-method" id="Snippet7"::: :::code language="fsharp" source="~/snippets/fsharp/System/Tuple/Overview/create1.fs" id="Snippet7"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple.create/vb/create1.vb" id="Snippet7"::: - - This code is equivalent to the following call to the class constructor. - + + This code is equivalent to the following call to the class constructor. + :::code language="csharp" source="~/snippets/csharp/System/Tuple/Overview/create1.cs" interactive="try-dotnet-method" id="Snippet8"::: :::code language="fsharp" source="~/snippets/fsharp/System/Tuple/Overview/create1.fs" id="Snippet8"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple.create/vb/create1.vb" id="Snippet8"::: - + ]]> @@ -581,21 +581,21 @@ Creates a new 5-tuple, or quintuple. A 5-tuple whose value is (, , , , ). - is a helper method that you can call to instantiate a 5-tuple object without having to explicitly specify the types of its components. The following example uses the method to instantiate a 5-tuple. - + is a helper method that you can call to instantiate a 5-tuple object without having to explicitly specify the types of its components. The following example uses the method to instantiate a 5-tuple. + :::code language="csharp" source="~/snippets/csharp/System/Tuple/Overview/create1.cs" interactive="try-dotnet-method" id="Snippet9"::: :::code language="fsharp" source="~/snippets/fsharp/System/Tuple/Overview/create1.fs" id="Snippet9"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple.create/vb/create1.vb" id="Snippet9"::: - - This code is equivalent to the following call to the class constructor. - + + This code is equivalent to the following call to the class constructor. + :::code language="csharp" source="~/snippets/csharp/System/Tuple/Overview/create1.cs" interactive="try-dotnet-method" id="Snippet10"::: :::code language="fsharp" source="~/snippets/fsharp/System/Tuple/Overview/create1.fs" id="Snippet10"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple.create/vb/create1.vb" id="Snippet10"::: - + ]]> @@ -710,21 +710,21 @@ Creates a new 6-tuple, or sextuple. A 6-tuple whose value is (, , , , , ). - is a helper method that you can call to instantiate a 6-tuple object without having to explicitly specify the types of its components. The following example uses the method to instantiate a 6-tuple. - + is a helper method that you can call to instantiate a 6-tuple object without having to explicitly specify the types of its components. The following example uses the method to instantiate a 6-tuple. + :::code language="csharp" source="~/snippets/csharp/System/Tuple/Overview/create1.cs" interactive="try-dotnet-method" id="Snippet11"::: :::code language="fsharp" source="~/snippets/fsharp/System/Tuple/Overview/create1.fs" id="Snippet11"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple.create/vb/create1.vb" id="Snippet11"::: - - This code is equivalent to the following call to the class constructor. - + + This code is equivalent to the following call to the class constructor. + :::code language="csharp" source="~/snippets/csharp/System/Tuple/Overview/create1.cs" interactive="try-dotnet-method" id="Snippet12"::: :::code language="fsharp" source="~/snippets/fsharp/System/Tuple/Overview/create1.fs" id="Snippet12"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple.create/vb/create1.vb" id="Snippet12"::: - + ]]> @@ -850,21 +850,21 @@ Creates a new 7-tuple, or septuple. A 7-tuple whose value is (, , , , , , ). - is a helper method that you can call to instantiate a 7-tuple object without having to explicitly specify the types of its components. The following example uses the method to instantiate a 7-tuple. - + is a helper method that you can call to instantiate a 7-tuple object without having to explicitly specify the types of its components. The following example uses the method to instantiate a 7-tuple. + :::code language="csharp" source="~/snippets/csharp/System/Tuple/Overview/create1.cs" interactive="try-dotnet-method" id="Snippet13"::: :::code language="fsharp" source="~/snippets/fsharp/System/Tuple/Overview/create1.fs" id="Snippet13"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple.create/vb/create1.vb" id="Snippet13"::: - - This code is equivalent to the following call to the class constructor. - + + This code is equivalent to the following call to the class constructor. + :::code language="csharp" source="~/snippets/csharp/System/Tuple/Overview/create1.cs" interactive="try-dotnet-method" id="Snippet14"::: :::code language="fsharp" source="~/snippets/fsharp/System/Tuple/Overview/create1.fs" id="Snippet14"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple.create/vb/create1.vb" id="Snippet14"::: - + ]]> @@ -1001,29 +1001,29 @@ Creates a new 8-tuple, or octuple. An 8-tuple (octuple) whose value is (, , , , , , , ). - is a helper method that you can call to instantiate an 8-tuple without having to explicitly specify the types of its components. - + is a helper method that you can call to instantiate an 8-tuple without having to explicitly specify the types of its components. + > [!NOTE] -> You must call the constructor to create a tuple with nine or more components unless your language provides a special syntax for this purpose. The static (`Shared` in Visual Basic) methods of the class cannot be used to create a tuple with nine or more components. - - - -## Examples - The following example creates an 8-tuple whose components are prime numbers that are less than 20. - +> You must call the constructor to create a tuple with nine or more components unless your language provides a special syntax for this purpose. The static (`Shared` in Visual Basic) methods of the class cannot be used to create a tuple with nine or more components. + + + +## Examples + The following example creates an 8-tuple whose components are prime numbers that are less than 20. + :::code language="csharp" source="~/snippets/csharp/System/Tuple/Overview/createntuple.cs" interactive="try-dotnet-method" id="Snippet17"::: :::code language="fsharp" source="~/snippets/fsharp/System/Tuple/Overview/createntuple.fs" id="Snippet17"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple.create/vb/createntuple.vb" id="Snippet17"::: - This is equivalent to the following example, which uses the class constructor instead of the factory creation method. Note that instantiating a object in this way involves considerably more code, because you must declare a nested object as the object's eighth component to produce an octuple. - + This is equivalent to the following example, which uses the class constructor instead of the factory creation method. Note that instantiating a object in this way involves considerably more code, because you must declare a nested object as the object's eighth component to produce an octuple. + :::code language="csharp" source="~/snippets/csharp/System/Tuple/Overview/ctor8.cs" id="Snippet20"::: :::code language="fsharp" source="~/snippets/fsharp/System/Tuple/Overview/ctor8.fs" id="Snippet20"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple.create/vb/ctor8.vb" id="Snippet20"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple.create/vb/ctor8.vb" id="Snippet20"::: + ]]> diff --git a/xml/System/TupleExtensions.xml b/xml/System/TupleExtensions.xml index fcdc0a582a2..af97a69a0ec 100644 --- a/xml/System/TupleExtensions.xml +++ b/xml/System/TupleExtensions.xml @@ -58,11 +58,11 @@ Provides extension methods for tuples to interoperate with language support for tuples in C#. - @@ -140,11 +140,11 @@ When this method returns, contains the value of the single element. Deconstructs a tuple with 1 element into a separate variable. - @@ -226,11 +226,11 @@ When this method returns, contains the value of the second element. Deconstructs a tuple with 2 elements into separate variables. - @@ -323,11 +323,11 @@ When this method returns, contains the value of the third element. Deconstructs a tuple with 3 elements into separate variables. - @@ -431,11 +431,11 @@ When this method returns, contains the value of the fourth element. Deconstructs a tuple with 4 elements into separate variables. - @@ -550,11 +550,11 @@ When this method returns, contains the value of the fifth element. Deconstructs a tuple with 5 elements into separate variables. - @@ -680,11 +680,11 @@ When this method returns, contains the value of the sixth element. Deconstructs a tuple with 6 elements into separate variables. - @@ -821,11 +821,11 @@ When this method returns, contains the value of the seventh element. Deconstructs a tuple with 7 elements into separate variables. - @@ -973,13 +973,13 @@ When this method returns, contains the value of the eighth element, or . Deconstructs a tuple with 8 elements into separate variables. - , `item8` is an element in a nested tuple. - + , `item8` is an element in a nested tuple. + ]]> @@ -1138,13 +1138,13 @@ When this method returns, contains the value of the ninth element, or . Deconstructs a tuple with 9 elements into separate variables. - , `item8` and `item9` are elements of nested tuples. - + , `item8` and `item9` are elements of nested tuples. + ]]> @@ -1314,13 +1314,13 @@ When this method returns, contains the value of the tenth element, or . Deconstructs a tuple with 10 elements into separate variables. - , `item8` through `item10` are elements of nested tuples. - + , `item8` through `item10` are elements of nested tuples. + ]]> @@ -1501,13 +1501,13 @@ When this method returns, contains the value of the eleventh element, or . Deconstructs a tuple with 11 elements into separate variables. - , `item8` through `item11` are elements of nested tuples. - + , `item8` through `item11` are elements of nested tuples. + ]]> @@ -1699,13 +1699,13 @@ When this method returns, contains the value of the twelfth element, or . Deconstructs a tuple with 12 elements into separate variables. - , `item8` through `item12` are elements of nested tuples. - + , `item8` through `item12` are elements of nested tuples. + ]]> @@ -1908,13 +1908,13 @@ When this method returns, contains the value of the thirteenth element, or . Deconstructs a tuple with 13 elements into separate variables. - , `item8` through `item13` are elements of nested tuples. - + , `item8` through `item13` are elements of nested tuples. + ]]> @@ -2350,13 +2350,13 @@ When this method returns, contains the value of the fifteenth element, or . Deconstructs a tuple with 15 elements into separate variables. - , `item8` through `item15` are elements of nested tuples. - + , `item8` through `item15` are elements of nested tuples. + ]]> @@ -2592,13 +2592,13 @@ When this method returns, contains the value of the sixteenth element, or . Deconstructs a tuple with 16 elements into separate variables. - , `item8` through `item16` are elements of nested tuples. - + , `item8` through `item16` are elements of nested tuples. + ]]> @@ -2845,13 +2845,13 @@ When this method returns, contains the value of the seventeenth element, or . Deconstructs a tuple with 17 elements into separate variables. - , `item8` through `item17` are elements of nested tuples. - + , `item8` through `item17` are elements of nested tuples. + ]]> @@ -3109,13 +3109,13 @@ When this method returns, contains the value of the eighteenth element, or . Deconstructs a tuple with 18 elements into separate variables. - , `item8` through `item18` are elements of nested tuples. - + , `item8` through `item18` are elements of nested tuples. + ]]> @@ -3384,13 +3384,13 @@ When this method returns, contains the value of the nineteenth element, or . Deconstructs a tuple with 19 elements into separate variables. - , `item8` through `item19` are elements of nested tuples. - + , `item8` through `item19` are elements of nested tuples. + ]]> @@ -3958,13 +3958,13 @@ When this method returns, contains the value of the twenty-first element, or . Deconstructs a tuple with 21 elements into separate variables. - , `item8` through `item21` are elements of nested tuples. - + , `item8` through `item21` are elements of nested tuples. + ]]> @@ -4043,7 +4043,7 @@ The type of the first element. The value tuple instance to convert to a tuple. - Converts an instance of the structure to an instance of the class. + Converts an instance of the structure to an instance of the class. The converted tuple. To be added. @@ -4101,7 +4101,7 @@ The type of the first element. The type of the second element. The value tuple instance to convert to a tuple. - Converts an instance of the structure to an instance of the class. + Converts an instance of the structure to an instance of the class. The converted tuple. To be added. @@ -4161,7 +4161,7 @@ The type of the second element. The type of the third element. The value tuple instance to convert to a tuple. - Converts an instance of the structure to an instance of the class. + Converts an instance of the structure to an instance of the class. The converted tuple. To be added. @@ -4223,7 +4223,7 @@ The type of the third element. The type of the fourth element. The value tuple instance to convert to a tuple. - Converts an instance of the structure to an instance of the class. + Converts an instance of the structure to an instance of the class. The converted tuple. To be added. @@ -4287,7 +4287,7 @@ The type of the fourth element. The type of the fifth element. The value tuple instance to convert to a tuple. - Converts an instance of the structure to an instance of the class. + Converts an instance of the structure to an instance of the class. The converted tuple. To be added. @@ -4353,7 +4353,7 @@ The type of the fifth element. The type of the sixth element. The value tuple instance to convert to a tuple. - Converts an instance of the structure to an instance of the class. + Converts an instance of the structure to an instance of the class. The converted tuple. To be added. @@ -4421,7 +4421,7 @@ The type of the sixth element. The type of the seventh element. The value tuple instance to convert to a tuple. - Converts an instance of the structure to an instance of the class. + Converts an instance of the structure to an instance of the class. The converted tuple. To be added. @@ -4491,7 +4491,7 @@ The type of the seventh element. The type of the eighth element, or . The value tuple instance to convert to a tuple. - Converts an instance of the structure to an instance of the class. + Converts an instance of the structure to an instance of the class. The converted tuple. To be added. @@ -4563,7 +4563,7 @@ The type of the eighth element, or . The type of the ninth element, or . The value tuple instance to convert to a tuple. - Converts an instance of the structure to an instance of the class. + Converts an instance of the structure to an instance of the class. The converted tuple. To be added. @@ -4637,7 +4637,7 @@ The type of the ninth element, or . The type of the tenth element, or . The value tuple instance to convert to a tuple. - Converts an instance of the structure to an instance of the class. + Converts an instance of the structure to an instance of the class. The converted tuple. To be added. @@ -4713,7 +4713,7 @@ The type of the tenth element, or . The type of the eleventh element, or . The value tuple instance to convert to a tuple. - Converts an instance of the structure to an instance of the class. + Converts an instance of the structure to an instance of the class. The converted tuple. To be added. @@ -4791,7 +4791,7 @@ The type of the eleventh element, or . The type of the twelfth element, or . The value tuple instance to convert to a tuple. - Converts an instance of the structure to an instance of the class. + Converts an instance of the structure to an instance of the class. The converted tuple. To be added. @@ -4871,7 +4871,7 @@ The type of the twelfth element, or . The type of the thirteenth element, or . The value tuple instance to convert to a tuple. - Converts an instance of the structure to an instance of the class. + Converts an instance of the structure to an instance of the class. The converted tuple. To be added. @@ -4953,7 +4953,7 @@ The type of the thirteenth element, or . The type of the fourteenth element, or . The value tuple instance to convert to a tuple. - Converts an instance of the structure to an instance of the class. + Converts an instance of the structure to an instance of the class. The converted tuple. To be added. @@ -5037,7 +5037,7 @@ The type of the fourteenth element, or . The type of the fifteenth element, or . The value tuple instance to convert to a tuple. - Converts an instance of the structure to an instance of the class. + Converts an instance of the structure to an instance of the class. The converted tuple. To be added. @@ -5123,7 +5123,7 @@ The type of the fifteenth element, or . The type of the sixteenth element, or . The value tuple instance to convert to a tuple. - Converts an instance of the structure to an instance of the class. + Converts an instance of the structure to an instance of the class. The converted tuple. To be added. @@ -5211,7 +5211,7 @@ The type of the sixteenth element, or . The type of the seventeenth element, or . The value tuple instance to convert to a tuple. - Converts an instance of the structure to an instance of the class. + Converts an instance of the structure to an instance of the class. The converted tuple. To be added. @@ -5301,7 +5301,7 @@ The type of the seventeenth element, or . The type of the eighteenth element, or . The value tuple instance to convert to a tuple. - Converts an instance of the structure to an instance of the class. + Converts an instance of the structure to an instance of the class. The converted tuple. To be added. @@ -5393,7 +5393,7 @@ The type of the eighteenth element, or . The type of the nineteenth element, or . The value tuple instance to convert to a tuple. - Converts an instance of the structure to an instance of the class. + Converts an instance of the structure to an instance of the class. The converted tuple. To be added. @@ -5487,7 +5487,7 @@ The type of the nineteenth element, or . The type of the twentieth element, or . The value tuple instance to convert to a tuple. - Converts an instance of the structure to an instance of the class. + Converts an instance of the structure to an instance of the class. The converted tuple. To be added. @@ -5583,7 +5583,7 @@ The type of the twentieth element, or . The type of the twenty-first element, or . The value tuple instance to convert to a tuple. - Converts an instance of the structure to an instance of the class. + Converts an instance of the structure to an instance of the class. The converted tuple. To be added. @@ -5654,7 +5654,7 @@ The type of the first element. The tuple object to convert to a value tuple. - Converts an instance of the class to an instance of the structure. + Converts an instance of the class to an instance of the structure. The converted value tuple instance. To be added. @@ -5712,7 +5712,7 @@ The type of the first element. The type of the second element. The tuple object to convert to a value tuple. - Converts an instance of the class to an instance of the structure. + Converts an instance of the class to an instance of the structure. The converted value tuple instance. To be added. @@ -5772,7 +5772,7 @@ The type of the second element. The type of the third element. The tuple object to convert to a value tuple. - Converts an instance of the class to an instance of the structure. + Converts an instance of the class to an instance of the structure. The converted value tuple instance. To be added. @@ -5834,7 +5834,7 @@ The type of the third element. The type of the fourth element. The tuple object to convert to a value tuple. - Converts an instance of the class to an instance of the structure. + Converts an instance of the class to an instance of the structure. The converted value tuple instance. To be added. @@ -5898,7 +5898,7 @@ The type of the fourth element. The type of the fifth element. The tuple object to convert to a value tuple. - Converts an instance of the class to an instance of the structure. + Converts an instance of the class to an instance of the structure. The converted value tuple instance. To be added. @@ -5964,7 +5964,7 @@ The type of the fifth element. The type of the sixth element. The tuple object to convert to a value tuple. - Converts an instance of the class to an instance of the structure. + Converts an instance of the class to an instance of the structure. The converted value tuple instance. To be added. @@ -6032,7 +6032,7 @@ The type of the sixth element. The type of the seventh element. The tuple object to convert to a value tuple. - Converts an instance of the class to an instance of the structure. + Converts an instance of the class to an instance of the structure. The converted value tuple instance. To be added. @@ -6102,7 +6102,7 @@ The type of the seventh element. The type of the eighth element, or . The tuple object to convert to a value tuple. - Converts an instance of the class to an instance of the structure. + Converts an instance of the class to an instance of the structure. The converted value tuple instance. To be added. @@ -6174,7 +6174,7 @@ The type of the eighth element, or . The type of the ninth element, or . The tuple object to convert to a value tuple. - Converts an instance of the class to an instance of the structure. + Converts an instance of the class to an instance of the structure. The converted value tuple instance. To be added. @@ -6248,7 +6248,7 @@ The type of the ninth element, or . The type of the tenth element, or . The tuple object to convert to a value tuple. - Converts an instance of the class to an instance of the structure. + Converts an instance of the class to an instance of the structure. The converted value tuple instance. To be added. @@ -6324,7 +6324,7 @@ The type of the tenth element, or . The type of the eleventh element, or . The tuple object to convert to a value tuple. - Converts an instance of the class to an instance of the structure. + Converts an instance of the class to an instance of the structure. The converted value tuple instance. To be added. @@ -6402,7 +6402,7 @@ The type of the eleventh element, or . The type of the twelfth element, or . The tuple object to convert to a value tuple. - Converts an instance of the class to an instance of the structure. + Converts an instance of the class to an instance of the structure. The converted value tuple instance. To be added. @@ -6482,7 +6482,7 @@ The type of the twelfth element, or . The type of the thirteenth element, or . The tuple object to convert to a value tuple. - Converts an instance of the class to an instance of the structure. + Converts an instance of the class to an instance of the structure. The converted value tuple instance. To be added. @@ -6564,7 +6564,7 @@ The type of the thirteenth element, or . The type of the fourteenth element, or . The tuple object to convert to a value tuple. - Converts an instance of the class to an instance of the structure. + Converts an instance of the class to an instance of the structure. The converted value tuple instance. To be added. @@ -6648,7 +6648,7 @@ The type of the fourteenth element, or . The type of the fifteenth element, or . The tuple object to convert to a value tuple. - Converts an instance of the class to an instance of the structure. + Converts an instance of the class to an instance of the structure. The converted value tuple instance. To be added. @@ -6734,7 +6734,7 @@ The type of the fifteenth element, or . The type of the sixteenth element, or . The tuple object to convert to a value tuple. - Converts an instance of the class to an instance of the structure. + Converts an instance of the class to an instance of the structure. The converted value tuple instance. To be added. @@ -6822,7 +6822,7 @@ The type of the sixteenth element, or . The type of the seventeenth element, or . The tuple object to convert to a value tuple. - Converts an instance of the class to an instance of the structure. + Converts an instance of the class to an instance of the structure. The converted value tuple instance. To be added. @@ -6912,7 +6912,7 @@ The type of the seventeenth element, or . The type of the eighteenth element, or . The tuple object to convert to a value tuple. - Converts an instance of the class to an instance of the structure. + Converts an instance of the class to an instance of the structure. The converted value tuple instance. To be added. @@ -7004,7 +7004,7 @@ The type of the eighteenth element, or . The type of the nineteenth element, or . The tuple object to convert to a value tuple. - Converts an instance of the class to an instance of the structure. + Converts an instance of the class to an instance of the structure. The converted value tuple instance. To be added. @@ -7098,7 +7098,7 @@ The type of the nineteenth element, or . The type of the twentieth element, or . The tuple object to convert to a value tuple. - Converts an instance of the class to an instance of the structure. + Converts an instance of the class to an instance of the structure. The converted value tuple instance. To be added. @@ -7194,7 +7194,7 @@ The type of the twentieth element, or . The type of the twenty-first element, or . The tuple object to convert to a value tuple. - Converts an instance of the class to an instance of the structure. + Converts an instance of the class to an instance of the structure. The converted value tuple instance. To be added. diff --git a/xml/System/Tuple`1.xml b/xml/System/Tuple`1.xml index 73c488a3284..50a38302168 100644 --- a/xml/System/Tuple`1.xml +++ b/xml/System/Tuple`1.xml @@ -82,13 +82,13 @@ The type of the tuple's only component. Represents a 1-tuple, or singleton. - class represents a 1-tuple, or singleton, which is a tuple that has a single component. A singleton is used comparatively rarely in application development. - - You can instantiate a object by calling either the constructor or the static method. You can retrieve the value of the tuple's single component by using the read-only instance property. - + class represents a 1-tuple, or singleton, which is a tuple that has a single component. A singleton is used comparatively rarely in application development. + + You can instantiate a object by calling either the constructor or the static method. You can retrieve the value of the tuple's single component by using the read-only instance property. + ]]> @@ -146,21 +146,21 @@ The value of the tuple's only component. Initializes a new instance of the class. - method to instantiate a 1-tuple object without having to explicitly specify the type of its component. The following example uses the method to instantiate a 1-tuple whose component is of type . - + method to instantiate a 1-tuple object without having to explicitly specify the type of its component. The following example uses the method to instantiate a 1-tuple whose component is of type . + :::code language="csharp" source="~/snippets/csharp/System/Tuple/Overview/create1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/Tuple/Overview/create1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple.create/vb/create1.vb" id="Snippet1"::: - - This is equivalent to the following call to the class constructor. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple.create/vb/create1.vb" id="Snippet1"::: + + This is equivalent to the following call to the class constructor. + :::code language="csharp" source="~/snippets/csharp/System/Tuple/Overview/create1.cs" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/Tuple/Overview/create1.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple.create/vb/create1.vb" id="Snippet2"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple.create/vb/create1.vb" id="Snippet2"::: + ]]> @@ -223,32 +223,32 @@ if the current instance is equal to the specified object; otherwise, . - object. - -- Its single component is of the same type as the current instance. - -- Its single component is equal to that of the current instance. Equality is determined by the default object equality comparer for each component. - - - -## Examples - The following example calls the method to compare a object whose component is a value with three objects whose components have the following characteristics: - -- Same type () and same value. - -- Same type (), but different value. - -- Different type (), but same value. - + object. + +- Its single component is of the same type as the current instance. + +- Its single component is equal to that of the current instance. Equality is determined by the default object equality comparer for each component. + + + +## Examples + The following example calls the method to compare a object whose component is a value with three objects whose components have the following characteristics: + +- Same type () and same value. + +- Same type (), but different value. + +- Different type (), but same value. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1/Equals/equals1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1/Equals/equals1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`1.equals/vb/equals1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`1.equals/vb/equals1.vb" id="Snippet1"::: + ]]> @@ -344,26 +344,26 @@ Gets the value of the object's single component. The value of the current object's single component. - component in one of two ways: - -- By calling the `GetType` method on the value that is returned by the property. - -- By retrieving the object that represents the object, and retrieving the first element from the array that is returned by its method. - - The example illustrates both approaches. - - - -## Examples - The following example displays information about two singletons and their components. - + component in one of two ways: + +- By calling the `GetType` method on the value that is returned by the property. + +- By retrieving the object that represents the object, and retrieving the first element from the array that is returned by its method. + + The example illustrates both approaches. + + + +## Examples + The following example displays information about two singletons and their components. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1/Item1/item1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1/Item1/item1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`1.item1/vb/item1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`1.item1/vb/item1.vb" id="Snippet1"::: + ]]> @@ -414,43 +414,52 @@ An object to compare with the current instance. An object that provides custom rules for comparison. Compares the current object to a specified object by using a specified comparer, and returns an integer that indicates whether the current object is before, after, or in the same position as the specified object in the sort order. - A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. - - Value - - Description - - A negative integer - - This instance precedes . - - Zero - - This instance and have the same position in the sort order. - - A positive integer - - This instance follows . - - + A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. + + Value + + + Description + + + + + A negative integer + + + This instance precedes . + + + Zero + + + This instance and have the same position in the sort order. + + + A positive integer + + + This instance follows . + + - parameters to order the members of a collection. For example, it is called by the method and the method of a object that is instantiated by using the constructor. - + parameters to order the members of a collection. For example, it is called by the method and the method of a object that is instantiated by using the constructor. + > [!CAUTION] -> The method is intended for use in sorting operations. It should not be used when the primary purpose of a comparison is to determine whether two objects are equal. To determine whether two objects are equal, call the method. - - - -## Examples - The following example defines a generic class named `DescendingComparer` that implements the interface. `DescendingComparer` sorts objects in descending rather than ascending order by reversing the value returned by the default comparer for a particular type. An instance of the generic `DescendingComparer` class is then passed to the method to sort an array of objects in descending order. Note that the example does not directly call the method. This method is called implicitly by the method for each element in the array. - +> The method is intended for use in sorting operations. It should not be used when the primary purpose of a comparison is to determine whether two objects are equal. To determine whether two objects are equal, call the method. + + + +## Examples + The following example defines a generic class named `DescendingComparer` that implements the interface. `DescendingComparer` sorts objects in descending rather than ascending order by reversing the value returned by the default comparer for a particular type. An instance of the generic `DescendingComparer` class is then passed to the method to sort an array of objects in descending order. Note that the example does not directly call the method. This method is called implicitly by the method for each element in the array. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1/System.Collections.IStructuralComparable.CompareTo/compareto2.cs" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1/System.Collections.IStructuralComparable.CompareTo/compareto2.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`1.compareto/vb/compareto2.vb" id="Snippet2"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`1.compareto/vb/compareto2.vb" id="Snippet2"::: + ]]> @@ -514,22 +523,22 @@ if the current instance is equal to the specified object; otherwise, . - instance is cast to an interface. - - The implementation is called only if `other` is not `null`, and if it can be successfully cast (in C#) or converted (in Visual Basic) to a object whose single component is of the same type as the current instance. The method is passed the component of the current instance and the component of the object represented by the `other` parameter. - - - -## Examples - The following example defines an implementation that considers two floating-point values to be equal if they are approximately equal to each other (that is, if one value is within .01 percent of the other). - + instance is cast to an interface. + + The implementation is called only if `other` is not `null`, and if it can be successfully cast (in C#) or converted (in Visual Basic) to a object whose single component is of the same type as the current instance. The method is passed the component of the current instance and the component of the object represented by the `other` parameter. + + + +## Examples + The following example defines an implementation that considers two floating-point values to be equal if they are approximately equal to each other (that is, if one value is within .01 percent of the other). + :::code language="csharp" source="~/snippets/csharp/System/TupleT1/Equals/equals2.cs" interactive="try-dotnet" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1/Equals/equals2.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`1.equals/vb/equals2.vb" id="Snippet2"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`1.equals/vb/equals2.vb" id="Snippet2"::: + ]]> @@ -581,15 +590,15 @@ Calculates the hash code for the current object by using a specified computation method. A 32-bit signed integer hash code. - instance is cast to an interface. - - The method simply wraps a call to the `comparer` object's implementation. - - The algorithm used to compute the hash code should return the same hash code for two objects that are considered to be equal. - + instance is cast to an interface. + + The method simply wraps a call to the `comparer` object's implementation. + + The algorithm used to compute the hash code should return the same hash code for two objects that are considered to be equal. + ]]> @@ -638,47 +647,56 @@ An object to compare with the current instance. Compares the current object to a specified object, and returns an integer that indicates whether the current object is before, after, or in the same position as the specified object in the sort order. - A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. - - Value - - Description - - A negative integer - - This instance precedes . - - Zero - - This instance and have the same position in the sort order. - - A positive integer - - This instance follows . - - + A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. + + Value + + + Description + + + + + A negative integer + + + This instance precedes . + + + Zero + + + This instance and have the same position in the sort order. + + + A positive integer + + + This instance follows . + + - instance is cast to an interface. - - This method provides the implementation for the class. Although the method can be called directly, it is most commonly called by the default overloads of collection sorting methods, such as and , to order the members of a collection. - + instance is cast to an interface. + + This method provides the implementation for the class. Although the method can be called directly, it is most commonly called by the default overloads of collection sorting methods, such as and , to order the members of a collection. + > [!CAUTION] -> The method is intended for use in sorting operations. It should not be used when the primary purpose of a comparison is to determine whether two objects are equal. To determine whether two objects are equal, call the method. - - The method uses the default object comparer. - - - -## Examples - The following example creates an array of singletons whose component is a value. It displays the value of each tuple component in unsorted order, sorts the array, and then displays the values in sorted order. Note that the example does not directly call the method. This method is called implicitly by the method for each element in the array. - +> The method is intended for use in sorting operations. It should not be used when the primary purpose of a comparison is to determine whether two objects are equal. To determine whether two objects are equal, call the method. + + The method uses the default object comparer. + + + +## Examples + The following example creates an array of singletons whose component is a value. It displays the value of each tuple component in unsorted order, sorts the array, and then displays the values in sorted order. Note that the example does not directly call the method. This method is called implicitly by the method for each element in the array. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1/System.Collections.IStructuralComparable.CompareTo/compareto1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1/System.Collections.IStructuralComparable.CompareTo/compareto1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`1.compareto/vb/compareto1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`1.compareto/vb/compareto1.vb" id="Snippet1"::: + ]]> @@ -733,11 +751,11 @@ Gets the value of the element. The value of the element. - property is an explicit interface implementation. To call it, you must cast or convert the object to an interface object. - + property is an explicit interface implementation. To call it, you must cast or convert the object to an interface object. + ]]> @@ -780,11 +798,11 @@ Gets the number of elements in the . 1, the number of elements in a object. - property is an explicit interface implementation. To call it, you must cast or convert the object to an interface object. - + property is an explicit interface implementation. To call it, you must cast or convert the object to an interface object. + ]]> @@ -835,20 +853,20 @@ Returns a string that represents the value of this instance. The string representation of this object. - property. If the value of is `null`, it is represented as . - - - -## Examples - The following example illustrates the method. - + property. If the value of is `null`, it is represented as . + + + +## Examples + The following example illustrates the method. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1/ToString/tostring1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1/ToString/tostring1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`1.tostring/vb/tostring1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`1.tostring/vb/tostring1.vb" id="Snippet1"::: + ]]> diff --git a/xml/System/Tuple`2.xml b/xml/System/Tuple`2.xml index ab99b4643cc..94c3fc3572a 100644 --- a/xml/System/Tuple`2.xml +++ b/xml/System/Tuple`2.xml @@ -99,31 +99,31 @@ The type of the tuple's second component. Represents a 2-tuple, or pair. - class represents a 2-tuple, or pair, which is a tuple that has two components. A 2-tuple is similar to a structure. - - You can instantiate a object by calling either the constructor or the static method. You can retrieve the values of the tuple's components by using the read-only and instance properties. - - Tuples are commonly used in four different ways: - -- To represent a single set of data. For example, a tuple can represent a record in a database, and its components can represent that record's fields. - -- To provide easy access to, and manipulation of, a data set. The following example defines an array of objects that contain the names of students and their corresponding test scores. It then iterates the array to calculate the mean test score. - + class represents a 2-tuple, or pair, which is a tuple that has two components. A 2-tuple is similar to a structure. + + You can instantiate a object by calling either the constructor or the static method. You can retrieve the values of the tuple's components by using the read-only and instance properties. + + Tuples are commonly used in four different ways: + +- To represent a single set of data. For example, a tuple can represent a record in a database, and its components can represent that record's fields. + +- To provide easy access to, and manipulation of, a data set. The following example defines an array of objects that contain the names of students and their corresponding test scores. It then iterates the array to calculate the mean test score. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2/Overview/example1.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2/Overview/example1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`2.class/vb/example1.vb" id="Snippet1"::: -- To return multiple values from a method without the use of `out` parameters (in C#) or `ByRef` parameters (in Visual Basic). For example, the following example uses a object to return the quotient and the remainder that result from integer division. - +- To return multiple values from a method without the use of `out` parameters (in C#) or `ByRef` parameters (in Visual Basic). For example, the following example uses a object to return the quotient and the remainder that result from integer division. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2/Overview/item1.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2/Overview/item1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`2.item1/vb/item1.vb" id="Snippet1"::: -- To pass multiple values to a method through a single parameter. For example, the method has a single parameter that lets you supply one value to the method that the thread executes at startup. If you supply a object as the method argument, you can supply the thread's startup routine with two items of data. - +- To pass multiple values to a method through a single parameter. For example, the method has a single parameter that lets you supply one value to the method that the thread executes at startup. If you supply a object as the method argument, you can supply the thread's startup routine with two items of data. + ]]> @@ -177,21 +177,21 @@ The value of the tuple's second component. Initializes a new instance of the class. - method to instantiate a 2-tuple object without having to explicitly specify the types of its components. The following example uses the method to instantiate a 2-tuple whose components are of type and . - + method to instantiate a 2-tuple object without having to explicitly specify the types of its components. The following example uses the method to instantiate a 2-tuple whose components are of type and . + :::code language="csharp" source="~/snippets/csharp/System/Tuple/Overview/create1.cs" interactive="try-dotnet-method" id="Snippet3"::: :::code language="fsharp" source="~/snippets/fsharp/System/Tuple/Overview/create1.fs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple.create/vb/create1.vb" id="Snippet3"::: - - This is equivalent to the following call to the class constructor. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple.create/vb/create1.vb" id="Snippet3"::: + + This is equivalent to the following call to the class constructor. + :::code language="csharp" source="~/snippets/csharp/System/Tuple/Overview/create1.cs" interactive="try-dotnet-method" id="Snippet4"::: :::code language="fsharp" source="~/snippets/fsharp/System/Tuple/Overview/create1.fs" id="Snippet4"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple.create/vb/create1.vb" id="Snippet4"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple.create/vb/create1.vb" id="Snippet4"::: + ]]> @@ -254,22 +254,22 @@ if the current instance is equal to the specified object; otherwise, . - object. - -- Its two components are of the same types as the current instance. - -- Its two components are equal to those of the current instance. Equality is determined by the default object equality comparer for each component. - - - -## Examples - The following example calls the method to determine whether any of the objects in an array of objects are equal to one another. The output reflects the fact that the method returns `true` when comparing objects whose components have equal values. - + object. + +- Its two components are of the same types as the current instance. + +- Its two components are equal to those of the current instance. Equality is determined by the default object equality comparer for each component. + + + +## Examples + The following example calls the method to determine whether any of the objects in an array of objects are equal to one another. The output reflects the fact that the method returns `true` when comparing objects whose components have equal values. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2/Equals/equals1.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2/Equals/equals1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`2.equals/vb/equals1.vb" id="Snippet1"::: @@ -359,24 +359,24 @@ Gets the value of the current object's first component. The value of the current object's first component. - component in one of two ways: - -- By calling the `GetType` method on the value that is returned by the property. - -- By retrieving the object that represents the object, and retrieving the first element from the array that is returned by its method. - - - -## Examples - The example illustrates the use of the and properties to define a method that returns multiple values in the form of a 2-tuple. - + component in one of two ways: + +- By calling the `GetType` method on the value that is returned by the property. + +- By retrieving the object that represents the object, and retrieving the first element from the array that is returned by its method. + + + +## Examples + The example illustrates the use of the and properties to define a method that returns multiple values in the form of a 2-tuple. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2/Overview/item1.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2/Overview/item1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`2.item1/vb/item1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`2.item1/vb/item1.vb" id="Snippet1"::: + ]]> @@ -420,24 +420,24 @@ Gets the value of the current object's second component. The value of the current object's second component. - component in one of two ways: - -- By calling the `GetType` method on the value that is returned by the property. - -- By retrieving the object that represents the object, and retrieving the second element from the array that is returned by its method. - - - -## Examples - The example illustrates the use of the and properties to define a method that returns multiple values in the form of a 2-tuple. - + component in one of two ways: + +- By calling the `GetType` method on the value that is returned by the property. + +- By retrieving the object that represents the object, and retrieving the second element from the array that is returned by its method. + + + +## Examples + The example illustrates the use of the and properties to define a method that returns multiple values in the form of a 2-tuple. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2/Overview/item1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2/Overview/item1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`2.item1/vb/item1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`2.item1/vb/item1.vb" id="Snippet1"::: + ]]> @@ -488,45 +488,54 @@ An object to compare with the current instance. An object that provides custom rules for comparison. Compares the current object to a specified object by using a specified comparer, and returns an integer that indicates whether the current object is before, after, or in the same position as the specified object in the sort order. - A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. - - Value - - Description - - A negative integer - - This instance precedes . - - Zero - - This instance and have the same position in the sort order. - - A positive integer - - This instance follows . - - + A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. + + Value + + + Description + + + + + A negative integer + + + This instance precedes . + + + Zero + + + This instance and have the same position in the sort order. + + + A positive integer + + + This instance follows . + + - instance is cast to an interface. - - Although this method can be called directly, it is most commonly called by collection sorting methods that include parameters to order the members of a collection. For example, it is called by the method and the method of a object that is instantiated by using the constructor. - + instance is cast to an interface. + + Although this method can be called directly, it is most commonly called by collection sorting methods that include parameters to order the members of a collection. For example, it is called by the method and the method of a object that is instantiated by using the constructor. + > [!CAUTION] -> The method is intended for use in sorting operations. It should not be used when the primary purpose of a comparison is to determine whether two objects are equal. To determine whether two objects are equal, call the method. - - - -## Examples - The following example creates an array of objects that consist of a student's name and test score. It displays the component of each tuple in the array in unsorted order, sorts the array, and then calls to display the value of each tuple in sorted order. To sort the array, the example defines a generic `ScoreComparer` class that implements the interface and sorts the objects in ascending order by the value of their second component rather than their first component. Note that the example does not directly call the method. This method is called implicitly by the method for each element in the array. - +> The method is intended for use in sorting operations. It should not be used when the primary purpose of a comparison is to determine whether two objects are equal. To determine whether two objects are equal, call the method. + + + +## Examples + The following example creates an array of objects that consist of a student's name and test score. It displays the component of each tuple in the array in unsorted order, sorts the array, and then calls to display the value of each tuple in sorted order. To sort the array, the example defines a generic `ScoreComparer` class that implements the interface and sorts the objects in ascending order by the value of their second component rather than their first component. Note that the example does not directly call the method. This method is called implicitly by the method for each element in the array. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2/System.Collections.IStructuralComparable.CompareTo/compareto2.cs" interactive="try-dotnet" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2/System.Collections.IStructuralComparable.CompareTo/compareto2.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`2.compareto/vb/compareto2.vb" id="Snippet2"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`2.compareto/vb/compareto2.vb" id="Snippet2"::: + ]]> @@ -590,22 +599,22 @@ if the current instance is equal to the specified object; otherwise, . - instance is cast to an interface. - - The implementation is called only if `other` is not `null`, and if it can be successfully cast (in C#) or converted (in Visual Basic) to a object whose components are of the same types as the current instance. The method first passes the values of the objects to be compared to the implementation. If this method call returns `true`, the method is called again and passed the values of the two objects. - - - -## Examples - The following example defines an `Item2Comparer` class that implements the interface and changes the way in which objects are evaluated for equality. The method always returns `true` when it is passed the property values of two objects, and it calls the method to evaluate their property values. As a result, the method tests for equality based only on the value of the property. The output illustrates the result for a data set of objects that record the names of runners and the distances that they ran. - + instance is cast to an interface. + + The implementation is called only if `other` is not `null`, and if it can be successfully cast (in C#) or converted (in Visual Basic) to a object whose components are of the same types as the current instance. The method first passes the values of the objects to be compared to the implementation. If this method call returns `true`, the method is called again and passed the values of the two objects. + + + +## Examples + The following example defines an `Item2Comparer` class that implements the interface and changes the way in which objects are evaluated for equality. The method always returns `true` when it is passed the property values of two objects, and it calls the method to evaluate their property values. As a result, the method tests for equality based only on the value of the property. The output illustrates the result for a data set of objects that record the names of runners and the distances that they ran. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2/Equals/equals2.cs" interactive="try-dotnet" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2/Equals/equals2.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`2.equals/vb/equals2.vb" id="Snippet2"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`2.equals/vb/equals2.vb" id="Snippet2"::: + ]]> @@ -657,15 +666,15 @@ Calculates the hash code for the current object by using a specified computation method. A 32-bit signed integer hash code. - instance is cast to an interface. - - The method simply wraps a call to the `comparer` object's implementation. - - The algorithm used to compute the hash code should return the same hash code for two objects that are considered to be equal. - + instance is cast to an interface. + + The method simply wraps a call to the `comparer` object's implementation. + + The algorithm used to compute the hash code should return the same hash code for two objects that are considered to be equal. + ]]> @@ -714,47 +723,56 @@ An object to compare with the current instance. Compares the current object to a specified object and returns an integer that indicates whether the current object is before, after, or in the same position as the specified object in the sort order. - A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. - - Value - - Description - - A negative integer - - This instance precedes . - - Zero - - This instance and have the same position in the sort order. - - A positive integer - - This instance follows . - - + A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. + + Value + + + Description + + + + + A negative integer + + + This instance precedes . + + + Zero + + + This instance and have the same position in the sort order. + + + A positive integer + + + This instance follows . + + - instance is cast to an interface. - - This method provides the implementation for the class. Although the method can be called directly, it is most commonly called by the default overloads of collection sorting methods, such as and , to order the members of a collection. - + instance is cast to an interface. + + This method provides the implementation for the class. Although the method can be called directly, it is most commonly called by the default overloads of collection sorting methods, such as and , to order the members of a collection. + > [!CAUTION] -> The method is intended for use in sorting operations. It should not be used when the primary purpose of a comparison is to determine whether two objects are equal. To determine whether two objects are equal, call the method. - - The method uses the default object comparer to compare each component. - - - -## Examples - The following example creates an array of objects that consist of a student's name and test score. It displays the component of each tuple in the array in unsorted order, sorts the array, and then calls to display the value of each tuple in sorted order. The output shows that the array has been sorted by its first component. Note that the example does not directly call the method. This method is called implicitly by the method for each element in the array. - +> The method is intended for use in sorting operations. It should not be used when the primary purpose of a comparison is to determine whether two objects are equal. To determine whether two objects are equal, call the method. + + The method uses the default object comparer to compare each component. + + + +## Examples + The following example creates an array of objects that consist of a student's name and test score. It displays the component of each tuple in the array in unsorted order, sorts the array, and then calls to display the value of each tuple in sorted order. The output shows that the array has been sorted by its first component. Note that the example does not directly call the method. This method is called implicitly by the method for each element in the array. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2/System.Collections.IStructuralComparable.CompareTo/compareto1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2/System.Collections.IStructuralComparable.CompareTo/compareto1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`2.compareto/vb/compareto1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`2.compareto/vb/compareto1.vb" id="Snippet1"::: + ]]> @@ -809,11 +827,11 @@ Gets the value of the specified element. The value of the element at the specified position. - property is an explicit interface implementation. To call it, you must cast or convert the object to an interface object. - + property is an explicit interface implementation. To call it, you must cast or convert the object to an interface object. + ]]> @@ -856,11 +874,11 @@ Gets the number of elements in the . 2, the number of elements in a object. - property is an explicit interface implementation. To call it, you must cast or convert the object to an interface object. - + property is an explicit interface implementation. To call it, you must cast or convert the object to an interface object. + ]]> @@ -905,20 +923,20 @@ Returns a string that represents the value of this instance. The string representation of this object. - and properties. If either property value is `null`, it is represented as . - - - -## Examples - The following example illustrates the method. - + and properties. If either property value is `null`, it is represented as . + + + +## Examples + The following example illustrates the method. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2/ToString/tostring1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2/ToString/tostring1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`2.tostring/vb/tostring1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`2.tostring/vb/tostring1.vb" id="Snippet1"::: + ]]> diff --git a/xml/System/Tuple`3.xml b/xml/System/Tuple`3.xml index 03b892b9cab..8b76e257d75 100644 --- a/xml/System/Tuple`3.xml +++ b/xml/System/Tuple`3.xml @@ -108,27 +108,27 @@ The type of the tuple's third component. Represents a 3-tuple, or triple. - class represents a 3-tuple, or triple, which is a tuple that has three components. - - You can instantiate a object by calling either the constructor or the static method. You can retrieve the values of the tuple's components by using the read-only , , and instance properties. - - Tuples are commonly used in four different ways: - -- To represent a single set of data. For example, a tuple can represent a database record, and its components can represent individual fields of the record. - -- To provide easy access to, and manipulation of, a data set. The following example defines an array of objects that contain the names of students, their average test scores, and the number of tests taken. The array is passed to the `ComputeStatistics` method, which calculates the mean and standard deviation of the test scores. - + class represents a 3-tuple, or triple, which is a tuple that has three components. + + You can instantiate a object by calling either the constructor or the static method. You can retrieve the values of the tuple's components by using the read-only , , and instance properties. + + Tuples are commonly used in four different ways: + +- To represent a single set of data. For example, a tuple can represent a database record, and its components can represent individual fields of the record. + +- To provide easy access to, and manipulation of, a data set. The following example defines an array of objects that contain the names of students, their average test scores, and the number of tests taken. The array is passed to the `ComputeStatistics` method, which calculates the mean and standard deviation of the test scores. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3/Overview/example1.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3/Overview/example1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`3.class/vb/example1.vb" id="Snippet1"::: -- To return multiple values from a method without the use of `out` parameters (in C#) or `ByRef` parameters (in Visual Basic). For example, the previous example returns its summary test score statistics in a object. - -- To pass multiple values to a method through a single parameter. For example, the method has a single parameter that lets you supply one value to the method that the thread executes at startup. If you supply a object as the method argument, you can supply the thread's startup routine with three items of data. - +- To return multiple values from a method without the use of `out` parameters (in C#) or `ByRef` parameters (in Visual Basic). For example, the previous example returns its summary test score statistics in a object. + +- To pass multiple values to a method through a single parameter. For example, the method has a single parameter that lets you supply one value to the method that the thread executes at startup. If you supply a object as the method argument, you can supply the thread's startup routine with three items of data. + ]]> @@ -184,21 +184,21 @@ The value of the tuple's third component. Initializes a new instance of the class. - method to instantiate a 3-tuple object without having to explicitly specify the types of its components. The following example uses the method to instantiate a 3-tuple whose components are of type , , and . - + method to instantiate a 3-tuple object without having to explicitly specify the types of its components. The following example uses the method to instantiate a 3-tuple whose components are of type , , and . + :::code language="csharp" source="~/snippets/csharp/System/Tuple/Overview/create1.cs" id="Snippet5"::: :::code language="fsharp" source="~/snippets/fsharp/System/Tuple/Overview/create1.fs" id="Snippet5"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple.create/vb/create1.vb" id="Snippet5"::: - - This is equivalent to the following call to the class constructor. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple.create/vb/create1.vb" id="Snippet5"::: + + This is equivalent to the following call to the class constructor. + :::code language="csharp" source="~/snippets/csharp/System/Tuple/Overview/create1.cs" id="Snippet6"::: :::code language="fsharp" source="~/snippets/fsharp/System/Tuple/Overview/create1.fs" id="Snippet6"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple.create/vb/create1.vb" id="Snippet6"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple.create/vb/create1.vb" id="Snippet6"::: + ]]> @@ -261,26 +261,26 @@ if the current instance is equal to the specified object; otherwise, . - object. - -- Its three components are of the same types as the current instance. - -- Its three components are equal to those of the current instance. Equality is determined by the default object equality comparer for each component. - - - -## Examples - The following example calls the method to determine whether any of the objects in an array of objects are equal to one another. The output reflects the fact that the method returns `true` when comparing objects whose components have equal values. - + object. + +- Its three components are of the same types as the current instance. + +- Its three components are equal to those of the current instance. Equality is determined by the default object equality comparer for each component. + + + +## Examples + The following example calls the method to determine whether any of the objects in an array of objects are equal to one another. The output reflects the fact that the method returns `true` when comparing objects whose components have equal values. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3/Equals/equals1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3/Equals/equals1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`3.equals/vb/equals1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`3.equals/vb/equals1.vb" id="Snippet1"::: + ]]> @@ -366,24 +366,24 @@ Gets the value of the current object's first component. The value of the current object's first component. - component in one of two ways: - -- By calling the `GetType` method on the value that is returned by the property. - -- By retrieving the object that represents the object, and retrieving the first element from the array that is returned by its method. - - - -## Examples - The following example defines an array of objects that contain the names of students, their average test scores, and the number of tests taken. The array is passed to the `ComputeStatistics` method, which calculates the mean score, standard deviation, and number of cases from which the statistics are calculated. These values are stored in the object that is returned by the `ComputeStatistics` method. The property contains the number of cases. - + component in one of two ways: + +- By calling the `GetType` method on the value that is returned by the property. + +- By retrieving the object that represents the object, and retrieving the first element from the array that is returned by its method. + + + +## Examples + The following example defines an array of objects that contain the names of students, their average test scores, and the number of tests taken. The array is passed to the `ComputeStatistics` method, which calculates the mean score, standard deviation, and number of cases from which the statistics are calculated. These values are stored in the object that is returned by the `ComputeStatistics` method. The property contains the number of cases. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3/Overview/example1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3/Overview/example1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`3.class/vb/example1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`3.class/vb/example1.vb" id="Snippet1"::: + ]]> @@ -427,24 +427,24 @@ Gets the value of the current object's second component. The value of the current object's second component. - component in one of two ways: - -- By calling the `GetType` method on the value that is returned by the property. - -- By retrieving the object that represents the object, and retrieving the second element from the array that is returned by its method. - - - -## Examples - The following example defines an array of objects that contain the names of students, their average test scores, and the number of tests taken. The array is passed to the `ComputeStatistics` method, which calculates the mean score, standard deviation, and number of cases from which the statistics are calculated. These values are stored in the object that is returned by the `ComputeStatistics` method. The property contains the mean test score. - + component in one of two ways: + +- By calling the `GetType` method on the value that is returned by the property. + +- By retrieving the object that represents the object, and retrieving the second element from the array that is returned by its method. + + + +## Examples + The following example defines an array of objects that contain the names of students, their average test scores, and the number of tests taken. The array is passed to the `ComputeStatistics` method, which calculates the mean score, standard deviation, and number of cases from which the statistics are calculated. These values are stored in the object that is returned by the `ComputeStatistics` method. The property contains the mean test score. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3/Overview/example1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3/Overview/example1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`3.class/vb/example1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`3.class/vb/example1.vb" id="Snippet1"::: + ]]> @@ -488,24 +488,24 @@ Gets the value of the current object's third component. The value of the current object's third component. - component in one of two ways: - -- By calling the `GetType` method on the value returned by the property. - -- By retrieving the object that represents the object, and retrieving the third element from the array that is returned by its method. - - - -## Examples - The following example defines an array of objects that contain the names of students, their average test scores, and the number of tests taken. The array is passed to the `ComputeStatistics` method, which calculates the mean score, standard deviation, and number of cases from which the statistics are calculated. These values are stored in the object that is returned by the `ComputeStatistics` method. The property contains the standard deviation. - + component in one of two ways: + +- By calling the `GetType` method on the value returned by the property. + +- By retrieving the object that represents the object, and retrieving the third element from the array that is returned by its method. + + + +## Examples + The following example defines an array of objects that contain the names of students, their average test scores, and the number of tests taken. The array is passed to the `ComputeStatistics` method, which calculates the mean score, standard deviation, and number of cases from which the statistics are calculated. These values are stored in the object that is returned by the `ComputeStatistics` method. The property contains the standard deviation. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3/Overview/example1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3/Overview/example1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`3.class/vb/example1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`3.class/vb/example1.vb" id="Snippet1"::: + ]]> @@ -556,45 +556,54 @@ An object to compare with the current instance. An object that provides custom rules for comparison. Compares the current object to a specified object by using a specified comparer, and returns an integer that indicates whether the current object is before, after, or in the same position as the specified object in the sort order. - A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. - - Value - - Description - - A negative integer - - This instance precedes . - - Zero - - This instance and have the same position in the sort order. - - A positive integer - - This instance follows . - - + A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. + + Value + + + Description + + + + + A negative integer + + + This instance precedes . + + + Zero + + + This instance and have the same position in the sort order. + + + A positive integer + + + This instance follows . + + - instance is cast to an interface. - - Although this method can be called directly, it is most commonly called by collection sorting methods that include parameters to order the members of a collection. For example, it is called by the method and the method of a object that is instantiated by using the constructor. - + instance is cast to an interface. + + Although this method can be called directly, it is most commonly called by collection sorting methods that include parameters to order the members of a collection. For example, it is called by the method and the method of a object that is instantiated by using the constructor. + > [!CAUTION] -> The method is intended for use in sorting operations. It should not be used when the primary purpose of a comparison is to determine whether two objects are equal. To determine whether two objects are equal, call the method. - - - -## Examples - The following example creates an array of objects that consist of a student's name, mean test score, and number of tests. It displays the component of each tuple in the array in unsorted order, sorts the array, and then calls to display the value of each tuple in sorted order. To sort the array, the example defines a generic `ScoreComparer` class that implements the interface and sorts the objects in ascending order by the value of their second component rather than their first component. Note that the example does not directly call the method. This method is called implicitly by the method for each element in the array. - +> The method is intended for use in sorting operations. It should not be used when the primary purpose of a comparison is to determine whether two objects are equal. To determine whether two objects are equal, call the method. + + + +## Examples + The following example creates an array of objects that consist of a student's name, mean test score, and number of tests. It displays the component of each tuple in the array in unsorted order, sorts the array, and then calls to display the value of each tuple in sorted order. To sort the array, the example defines a generic `ScoreComparer` class that implements the interface and sorts the objects in ascending order by the value of their second component rather than their first component. Note that the example does not directly call the method. This method is called implicitly by the method for each element in the array. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3/System.Collections.IStructuralComparable.CompareTo/compareto2.cs" interactive="try-dotnet" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3/System.Collections.IStructuralComparable.CompareTo/compareto2.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`3.compareto/vb/compareto2.vb" id="Snippet2"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`3.compareto/vb/compareto2.vb" id="Snippet2"::: + ]]> @@ -658,22 +667,22 @@ if the current instance is equal to the specified object; otherwise, . - instance is cast to an interface. - - The implementation is called only if `other` is not `null`, and if it can be successfully cast (in C#) or converted (in Visual Basic) to a object whose components are of the same types as the current instance. The method first passes the values of the objects to be compared to the implementation. If this method call returns `true`, the method is called again and passed the values of the two objects. If this method call returns `true` again, the method is called a third time and passed the values of the two objects. - - - -## Examples - The following example defines an `Item2Comparer` class that implements the interface and changes the way in which objects are evaluated for equality. The method always returns `true` when it is passed the property values of two objects, and it calls the method to evaluate their property values. If this method call returns `true`, their property values are passed to the method, which always returns `true`. As a result, the method tests for equality based only on the value of the property. The output illustrates the result for a data set of objects that record the names, mean test score, and number of tests of students in a class. - + instance is cast to an interface. + + The implementation is called only if `other` is not `null`, and if it can be successfully cast (in C#) or converted (in Visual Basic) to a object whose components are of the same types as the current instance. The method first passes the values of the objects to be compared to the implementation. If this method call returns `true`, the method is called again and passed the values of the two objects. If this method call returns `true` again, the method is called a third time and passed the values of the two objects. + + + +## Examples + The following example defines an `Item2Comparer` class that implements the interface and changes the way in which objects are evaluated for equality. The method always returns `true` when it is passed the property values of two objects, and it calls the method to evaluate their property values. If this method call returns `true`, their property values are passed to the method, which always returns `true`. As a result, the method tests for equality based only on the value of the property. The output illustrates the result for a data set of objects that record the names, mean test score, and number of tests of students in a class. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3/Equals/equals2.cs" interactive="try-dotnet" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3/Equals/equals2.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`3.equals/vb/equals2.vb" id="Snippet2"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`3.equals/vb/equals2.vb" id="Snippet2"::: + ]]> @@ -724,15 +733,15 @@ Calculates the hash code for the current object by using a specified computation method. A 32-bit signed integer hash code. - instance is cast to an interface. - - The method simply wraps a call to the `comparer` object's implementation. - - The algorithm used to compute the hash code should return the same hash code for two objects that are considered to be equal. - + instance is cast to an interface. + + The method simply wraps a call to the `comparer` object's implementation. + + The algorithm used to compute the hash code should return the same hash code for two objects that are considered to be equal. + ]]> @@ -781,47 +790,56 @@ An object to compare with the current instance. Compares the current object to a specified object and returns an integer that indicates whether the current object is before, after, or in the same position as the specified object in the sort order. - A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. - - Value - - Description - - A negative integer - - This instance precedes . - - Zero - - This instance and have the same position in the sort order. - - A positive integer - - This instance follows . - - + A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. + + Value + + + Description + + + + + A negative integer + + + This instance precedes . + + + Zero + + + This instance and have the same position in the sort order. + + + A positive integer + + + This instance follows . + + - instance is cast to an interface. - - This method provides the implementation for the class. Although the method can be called directly, it is most commonly called by the default overloads of collection sorting methods, such as and , to order the members of a collection. - + instance is cast to an interface. + + This method provides the implementation for the class. Although the method can be called directly, it is most commonly called by the default overloads of collection sorting methods, such as and , to order the members of a collection. + > [!CAUTION] -> The method is intended for use in sorting operations. It should not be used when the primary purpose of a comparison is to determine whether two objects are equal. To determine whether two objects are equal, call the method. - - The method uses the default object comparer to compare each component. - - - -## Examples - The following example creates an array of objects whose components consist of a student's name, mean test score, and number of tests. It displays the components of each tuple in the array in unsorted order, sorts the array, and then calls to display each tuple in sorted order. The output shows that the array has been sorted by its first component. Note that the example does not directly call the method. This method is called implicitly by the method for each element in the array. - +> The method is intended for use in sorting operations. It should not be used when the primary purpose of a comparison is to determine whether two objects are equal. To determine whether two objects are equal, call the method. + + The method uses the default object comparer to compare each component. + + + +## Examples + The following example creates an array of objects whose components consist of a student's name, mean test score, and number of tests. It displays the components of each tuple in the array in unsorted order, sorts the array, and then calls to display each tuple in sorted order. The output shows that the array has been sorted by its first component. Note that the example does not directly call the method. This method is called implicitly by the method for each element in the array. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3/System.Collections.IStructuralComparable.CompareTo/compareto1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3/System.Collections.IStructuralComparable.CompareTo/compareto1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`3.compareto/vb/compareto1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`3.compareto/vb/compareto1.vb" id="Snippet1"::: + ]]> @@ -876,11 +894,11 @@ Gets the value of the specified element. The value of the element at the specified position. - property is an explicit interface implementation. To call it, you must cast or convert the object to an interface object. - + property is an explicit interface implementation. To call it, you must cast or convert the object to an interface object. + ]]> @@ -923,11 +941,11 @@ Gets the number of elements in the . 3, the number of elements in a object. - property is an explicit interface implementation. To call it, you must cast or convert the object to an interface object. - + property is an explicit interface implementation. To call it, you must cast or convert the object to an interface object. + ]]> @@ -972,20 +990,20 @@ Returns a string that represents the value of this instance. The string representation of this object. - , , and properties, respectively. If any of the property values is `null`, it is represented as . - - - -## Examples - The following example illustrates the method. - + , , and properties, respectively. If any of the property values is `null`, it is represented as . + + + +## Examples + The following example illustrates the method. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3/ToString/tostring1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3/ToString/tostring1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`3.tostring/vb/tostring1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`3.tostring/vb/tostring1.vb" id="Snippet1"::: + ]]> diff --git a/xml/System/Tuple`4.xml b/xml/System/Tuple`4.xml index c94ca34067a..a70f26e4019 100644 --- a/xml/System/Tuple`4.xml +++ b/xml/System/Tuple`4.xml @@ -117,27 +117,27 @@ The type of the tuple's fourth component. Represents a 4-tuple, or quadruple. - class represents a 4-tuple, or quadruple, which is a tuple that has four components. - - You can instantiate a object by calling either the constructor or the static method. You can retrieve the value of the tuple's components by using the read-only , , , and instance properties. - - Tuples are commonly used in four different ways: - -- To represent a single set of data. For example, a tuple can represent a database record, and its components can represent individual fields of the record. - -- To provide easy access to, and manipulation of, a data set. The following example defines an array of objects that contain the names of baseball pitchers, the number of innings they pitched, and the number of earned runs (runs that scored without fielding errors), and hits that they gave up. The array is passed to the `ComputeStatistics` method, which calculates each pitcher's earned run average (the average number of runs given up in a nine-inning game), and the average number of hits given up per inning. The method also uses these two averages to compute a hypothetical effectiveness average. - + class represents a 4-tuple, or quadruple, which is a tuple that has four components. + + You can instantiate a object by calling either the constructor or the static method. You can retrieve the value of the tuple's components by using the read-only , , , and instance properties. + + Tuples are commonly used in four different ways: + +- To represent a single set of data. For example, a tuple can represent a database record, and its components can represent individual fields of the record. + +- To provide easy access to, and manipulation of, a data set. The following example defines an array of objects that contain the names of baseball pitchers, the number of innings they pitched, and the number of earned runs (runs that scored without fielding errors), and hits that they gave up. The array is passed to the `ComputeStatistics` method, which calculates each pitcher's earned run average (the average number of runs given up in a nine-inning game), and the average number of hits given up per inning. The method also uses these two averages to compute a hypothetical effectiveness average. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3,T4/Overview/example1.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3,T4/Overview/example1.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`4.class/vb/example1.vb" id="Snippet1"::: - -- To return multiple values from a method without the use of `out` parameters (in C#) or `ByRef` parameters (in Visual Basic). For example, the previous example returns its computed statistics, along with the name of the pitcher, in an array of objects. - -- To pass multiple values to a method through a single parameter. For example, the method has a single parameter that lets you supply one value to the method that the thread executes at startup. If you supply a object as the method argument, you can supply the thread's startup routine with four items of data. - + +- To return multiple values from a method without the use of `out` parameters (in C#) or `ByRef` parameters (in Visual Basic). For example, the previous example returns its computed statistics, along with the name of the pitcher, in an array of objects. + +- To pass multiple values to a method through a single parameter. For example, the method has a single parameter that lets you supply one value to the method that the thread executes at startup. If you supply a object as the method argument, you can supply the thread's startup routine with four items of data. + ]]> @@ -195,21 +195,21 @@ The value of the tuple's fourth component. Initializes a new instance of the class. - method to instantiate a 4-tuple object without having to explicitly specify the types of its components. The following example uses the method to instantiate a 4-tuple whose components are of type , , , and . - + method to instantiate a 4-tuple object without having to explicitly specify the types of its components. The following example uses the method to instantiate a 4-tuple whose components are of type , , , and . + :::code language="csharp" source="~/snippets/csharp/System/Tuple/Overview/create1.cs" id="Snippet7"::: :::code language="fsharp" source="~/snippets/fsharp/System/Tuple/Overview/create1.fs" id="Snippet7"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple.create/vb/create1.vb" id="Snippet7"::: - - This is equivalent to the following call to the class constructor. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple.create/vb/create1.vb" id="Snippet7"::: + + This is equivalent to the following call to the class constructor. + :::code language="csharp" source="~/snippets/csharp/System/Tuple/Overview/create1.cs" id="Snippet8"::: :::code language="fsharp" source="~/snippets/fsharp/System/Tuple/Overview/create1.fs" id="Snippet8"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple.create/vb/create1.vb" id="Snippet8"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple.create/vb/create1.vb" id="Snippet8"::: + ]]> @@ -272,26 +272,26 @@ if the current instance is equal to the specified object; otherwise, . - object. - -- Its four components are of the same types as the current instance. - -- Its four components are equal to those of the current instance. Equality is determined by the default object equality comparer for each component. - - - -## Examples - The following example defines an array of objects that provide data on temperatures at three times during a particular day. The method is called to compare every object with every other object. The output illustrates that the method returns `true` only when all four components of the objects have equal values. - + object. + +- Its four components are of the same types as the current instance. + +- Its four components are equal to those of the current instance. Equality is determined by the default object equality comparer for each component. + + + +## Examples + The following example defines an array of objects that provide data on temperatures at three times during a particular day. The method is called to compare every object with every other object. The output illustrates that the method returns `true` only when all four components of the objects have equal values. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3,T4/Equals/equals1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3,T4/Equals/equals1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`4.equals/vb/equals1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`4.equals/vb/equals1.vb" id="Snippet1"::: + ]]> @@ -377,24 +377,24 @@ Gets the value of the current object's first component. The value of the current object's first component. - component in one of two ways: - -- By calling the `GetType` method on the value that is returned by the property. - -- By retrieving the object that represents the object, and retrieving the first element from the array that is returned by its method. - - - -## Examples - The following example defines an array of objects whose components contain the name of a city, a month of the year, and the average high and low temperatures for that month. It then retrieves and displays the value of each component. - + component in one of two ways: + +- By calling the `GetType` method on the value that is returned by the property. + +- By retrieving the object that represents the object, and retrieving the first element from the array that is returned by its method. + + + +## Examples + The following example defines an array of objects whose components contain the name of a city, a month of the year, and the average high and low temperatures for that month. It then retrieves and displays the value of each component. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3,T4/Item1/item1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3,T4/Item1/item1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`4.item1/vb/item1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`4.item1/vb/item1.vb" id="Snippet1"::: + ]]> @@ -438,24 +438,24 @@ Gets the value of the current object's second component. The value of the current object's second component. - component in one of two ways: - -- By calling the `GetType` method on the value that is returned by the property. - -- By retrieving the object that represents the object, and retrieving the second element from the array that is returned by its method. - - - -## Examples - The following example defines an array of objects whose components contain the name of a city, a month of the year, and the average high and low temperatures for that month. It then retrieves and displays the value of each component. - + component in one of two ways: + +- By calling the `GetType` method on the value that is returned by the property. + +- By retrieving the object that represents the object, and retrieving the second element from the array that is returned by its method. + + + +## Examples + The following example defines an array of objects whose components contain the name of a city, a month of the year, and the average high and low temperatures for that month. It then retrieves and displays the value of each component. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3,T4/Item1/item1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3,T4/Item1/item1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`4.item1/vb/item1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`4.item1/vb/item1.vb" id="Snippet1"::: + ]]> @@ -499,24 +499,24 @@ Gets the value of the current object's third component. The value of the current object's third component. - component in one of two ways: - -- By calling the `GetType` method on the value that is returned by the property. - -- By retrieving the object that represents the object, and retrieving the third element from the array that is returned by its method. - - - -## Examples - The following example defines an array of objects whose components contain the name of a city, a month of the year, and the average high and low temperatures for that month. It then retrieves and displays the value of each component. - + component in one of two ways: + +- By calling the `GetType` method on the value that is returned by the property. + +- By retrieving the object that represents the object, and retrieving the third element from the array that is returned by its method. + + + +## Examples + The following example defines an array of objects whose components contain the name of a city, a month of the year, and the average high and low temperatures for that month. It then retrieves and displays the value of each component. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3,T4/Item1/item1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3,T4/Item1/item1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`4.item1/vb/item1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`4.item1/vb/item1.vb" id="Snippet1"::: + ]]> @@ -560,24 +560,24 @@ Gets the value of the current object's fourth component. The value of the current object's fourth component. - component in one of two ways: - -- By calling the `GetType` method on the value that is returned by the property. - -- By retrieving the object that represents the object, and retrieving the fourth element from the array that is returned by its method. - - - -## Examples - The following example defines an array of objects whose components contain the name of a city, a month of the year, and the average high and low temperatures for that month. It then retrieves and displays the value of each component. - + component in one of two ways: + +- By calling the `GetType` method on the value that is returned by the property. + +- By retrieving the object that represents the object, and retrieving the fourth element from the array that is returned by its method. + + + +## Examples + The following example defines an array of objects whose components contain the name of a city, a month of the year, and the average high and low temperatures for that month. It then retrieves and displays the value of each component. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3,T4/Item1/item1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3,T4/Item1/item1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`4.item1/vb/item1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`4.item1/vb/item1.vb" id="Snippet1"::: + ]]> @@ -628,45 +628,54 @@ An object to compare with the current instance. An object that provides custom rules for comparison. Compares the current object to a specified object by using a specified comparer and returns an integer that indicates whether the current object is before, after, or in the same position as the specified object in the sort order. - A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. - - Value - - Description - - A negative integer - - This instance precedes . - - Zero - - This instance and have the same position in the sort order. - - A positive integer - - This instance follows . - - + A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. + + Value + + + Description + + + + + A negative integer + + + This instance precedes . + + + Zero + + + This instance and have the same position in the sort order. + + + A positive integer + + + This instance follows . + + - instance is cast to an interface. - - Although this method can be called directly, it is most commonly called by collection sorting methods that include parameters to order the members of a collection. For example, it is called by the method and the method of a object that is instantiated by using the constructor. - + instance is cast to an interface. + + Although this method can be called directly, it is most commonly called by collection sorting methods that include parameters to order the members of a collection. For example, it is called by the method and the method of a object that is instantiated by using the constructor. + > [!CAUTION] -> The method is intended for use in sorting operations. It should not be used when the primary purpose of a comparison is to determine whether two objects are equal. To determine whether two objects are equal, call the method. - - - -## Examples - The following example creates an array of objects that contain statistical data about baseball pitchers. The data items include the name of the pitcher, the number of innings pitched, the pitcher's earned run average (the average number of runs a pitcher allows per game), and the number of hits the pitcher has given up. The example displays the component of each tuple in the array in unsorted order, sorts the array, and then calls to display the value of each tuple in sorted order. To sort the array, the example defines a generic `PitcherComparer` class that implements the interface and sorts the objects in ascending order by the value of their third component (the earned run average) rather than their first component. Note that the example does not directly call the method. This method is called implicitly by the method for each element in the array. - +> The method is intended for use in sorting operations. It should not be used when the primary purpose of a comparison is to determine whether two objects are equal. To determine whether two objects are equal, call the method. + + + +## Examples + The following example creates an array of objects that contain statistical data about baseball pitchers. The data items include the name of the pitcher, the number of innings pitched, the pitcher's earned run average (the average number of runs a pitcher allows per game), and the number of hits the pitcher has given up. The example displays the component of each tuple in the array in unsorted order, sorts the array, and then calls to display the value of each tuple in sorted order. To sort the array, the example defines a generic `PitcherComparer` class that implements the interface and sorts the objects in ascending order by the value of their third component (the earned run average) rather than their first component. Note that the example does not directly call the method. This method is called implicitly by the method for each element in the array. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3,T4/System.Collections.IStructuralComparable.CompareTo/compareto2.cs" interactive="try-dotnet" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3,T4/System.Collections.IStructuralComparable.CompareTo/compareto2.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`4.compareto/vb/compareto2.vb" id="Snippet2"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`4.compareto/vb/compareto2.vb" id="Snippet2"::: + ]]> @@ -729,22 +738,22 @@ if the current instance is equal to the specified object; otherwise, . - instance is cast to an interface. - - The implementation is called only if `other` is not `null`, and if it can be successfully cast (in C#) or converted (in Visual Basic) to a object whose components are of the same types as the current instance. The method first passes the values of the objects to be compared to the implementation. If this method call returns `true`, the method is called again and passed the values of the two objects. If this method call returns `true` again, the method is called a third time and passed the values of the two objects. If this method call returns `true` again, the method is called for the fourth and final time and passed the values of the two objects. - - - -## Examples - The following example defines an `Item3And4Comparer` class that implements the interface and changes the way in which objects are evaluated for equality. The method always returns `true` when it is passed the and property values of two objects, and it calls the `obj.Equals` method to evaluate their property values. It this method call returns true, it also calls the `obj.Equals` method to evaluate the tuples' property values. As a result, the method tests for equality based only on the values of the and properties. The output illustrates the result for a data set of objects that record the name of a U.S. city, the month of a year, and the average high and low temperature for that month. - + instance is cast to an interface. + + The implementation is called only if `other` is not `null`, and if it can be successfully cast (in C#) or converted (in Visual Basic) to a object whose components are of the same types as the current instance. The method first passes the values of the objects to be compared to the implementation. If this method call returns `true`, the method is called again and passed the values of the two objects. If this method call returns `true` again, the method is called a third time and passed the values of the two objects. If this method call returns `true` again, the method is called for the fourth and final time and passed the values of the two objects. + + + +## Examples + The following example defines an `Item3And4Comparer` class that implements the interface and changes the way in which objects are evaluated for equality. The method always returns `true` when it is passed the and property values of two objects, and it calls the `obj.Equals` method to evaluate their property values. It this method call returns true, it also calls the `obj.Equals` method to evaluate the tuples' property values. As a result, the method tests for equality based only on the values of the and properties. The output illustrates the result for a data set of objects that record the name of a U.S. city, the month of a year, and the average high and low temperature for that month. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3,T4/Equals/equals2.cs" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3,T4/Equals/equals2.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`4.equals/vb/equals2.vb" id="Snippet2"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`4.equals/vb/equals2.vb" id="Snippet2"::: + ]]> @@ -795,15 +804,15 @@ Calculates the hash code for the current object by using a specified computation method. A 32-bit signed integer hash code. - instance is cast to an interface. - - The method simply wraps a call to the `comparer` object's implementation. - - The algorithm used to compute the hash code should return the same hash code for two objects that are considered to be equal. - + instance is cast to an interface. + + The method simply wraps a call to the `comparer` object's implementation. + + The algorithm used to compute the hash code should return the same hash code for two objects that are considered to be equal. + ]]> @@ -852,47 +861,56 @@ An object to compare with the current instance. Compares the current object to a specified object and returns an integer that indicates whether the current object is before, after, or in the same position as the specified object in the sort order. - A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. - - Value - - Description - - A negative integer - - This instance precedes . - - Zero - - This instance and have the same position in the sort order. - - A positive integer - - This instance follows . - - + A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. + + Value + + + Description + + + + + A negative integer + + + This instance precedes . + + + Zero + + + This instance and have the same position in the sort order. + + + A positive integer + + + This instance follows . + + - instance is cast to an interface. - - This method provides the implementation for the class. Although the method can be called directly, it is most commonly called by the default overloads of collection sorting methods, such as and , to order the members of a collection. - + instance is cast to an interface. + + This method provides the implementation for the class. Although the method can be called directly, it is most commonly called by the default overloads of collection sorting methods, such as and , to order the members of a collection. + > [!CAUTION] -> The method is intended for use in sorting operations. It should not be used when the primary purpose of a comparison is to determine whether two objects are equal. To determine whether two objects are equal, call the method. - - The method uses the default object comparer to compare each component. - - - -## Examples - The following example creates an array of objects whose components consist of a baseball pitcher's name, number of innings pitched, and number of hits and earned runs given up. It displays the components of each tuple in the array in unsorted order, sorts the array, and then calls to display each tuple in sorted order. The output shows that the array has been sorted by name, which is the first component. Note that the example does not directly call the method. This method is called implicitly by the method for each element in the array. - +> The method is intended for use in sorting operations. It should not be used when the primary purpose of a comparison is to determine whether two objects are equal. To determine whether two objects are equal, call the method. + + The method uses the default object comparer to compare each component. + + + +## Examples + The following example creates an array of objects whose components consist of a baseball pitcher's name, number of innings pitched, and number of hits and earned runs given up. It displays the components of each tuple in the array in unsorted order, sorts the array, and then calls to display each tuple in sorted order. The output shows that the array has been sorted by name, which is the first component. Note that the example does not directly call the method. This method is called implicitly by the method for each element in the array. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3,T4/System.Collections.IStructuralComparable.CompareTo/compareto1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3,T4/System.Collections.IStructuralComparable.CompareTo/compareto1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`4.compareto/vb/compareto1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`4.compareto/vb/compareto1.vb" id="Snippet1"::: + ]]> @@ -947,11 +965,11 @@ Gets the value of the specified element. The value of the element at the specified position. - property is an explicit interface implementation. To call it, you must cast or convert the object to an interface object. - + property is an explicit interface implementation. To call it, you must cast or convert the object to an interface object. + ]]> @@ -994,11 +1012,11 @@ Gets the number of elements in the . 4, the number of elements in a object. - property is an explicit interface implementation. To call it, you must cast or convert the object to an interface object. - + property is an explicit interface implementation. To call it, you must cast or convert the object to an interface object. + ]]> @@ -1043,20 +1061,20 @@ Returns a string that represents the value of this instance. The string representation of this object. - , , , and properties, respectively. If any of the property values is `null`, it is represented as . - - - -## Examples - The following example illustrates the method. It displays the components of an array of 4-tuple objects that contain the name of a city, a month of the year, and the high and low average temperature for that month. - + , , , and properties, respectively. If any of the property values is `null`, it is represented as . + + + +## Examples + The following example illustrates the method. It displays the components of an array of 4-tuple objects that contain the name of a city, a month of the year, and the high and low average temperature for that month. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3,T4/ToString/tostring1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3,T4/ToString/tostring1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`4.tostring/vb/tostring1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`4.tostring/vb/tostring1.vb" id="Snippet1"::: + ]]> diff --git a/xml/System/Tuple`5.xml b/xml/System/Tuple`5.xml index cca7231757f..37b837c20f3 100644 --- a/xml/System/Tuple`5.xml +++ b/xml/System/Tuple`5.xml @@ -126,27 +126,27 @@ The type of the tuple's fifth component. Represents a 5-tuple, or quintuple. - class represents a 5-tuple, or quintuple, which is a tuple that has five components. - - You can instantiate a object by calling either the constructor or the static method. You can retrieve the value of the tuple's components by using the read-only , , , , and instance properties. - - Tuples are commonly used in four different ways: - -- To represent a single set of data. For example, a tuple can represent a database record, and its components can represent individual fields of the record. - -- To provide easy access to, and manipulation of, a data set. The following example defines an array of objects that contain the names of running backs in American football, the number of games in which they played, and the number of carries, total yards gained, and touchdowns scored during those games. The array is passed to the `ComputeStatistics` method, which calculates each running back's number of carries per game, average yards per game, average yards per carry, and average number of touchdowns per attempt. - + class represents a 5-tuple, or quintuple, which is a tuple that has five components. + + You can instantiate a object by calling either the constructor or the static method. You can retrieve the value of the tuple's components by using the read-only , , , , and instance properties. + + Tuples are commonly used in four different ways: + +- To represent a single set of data. For example, a tuple can represent a database record, and its components can represent individual fields of the record. + +- To provide easy access to, and manipulation of, a data set. The following example defines an array of objects that contain the names of running backs in American football, the number of games in which they played, and the number of carries, total yards gained, and touchdowns scored during those games. The array is passed to the `ComputeStatistics` method, which calculates each running back's number of carries per game, average yards per game, average yards per carry, and average number of touchdowns per attempt. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3,T4,T5/Overview/example1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3,T4,T5/Overview/example1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`5.class/vb/example1.vb" id="Snippet1"::: - -- To return multiple values from a method without the use of `out` parameters (in C#) or `ByRef` parameters (in Visual Basic). For example, the previous example returns its computed statistics, along with the name of the player, in an array of objects. - -- To pass multiple values to a method through a single parameter. For example, the method has a single parameter that lets you supply one value to the method that the thread executes at startup. If you supply a object as the method argument, you can supply the thread's startup routine with five items of data. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`5.class/vb/example1.vb" id="Snippet1"::: + +- To return multiple values from a method without the use of `out` parameters (in C#) or `ByRef` parameters (in Visual Basic). For example, the previous example returns its computed statistics, along with the name of the player, in an array of objects. + +- To pass multiple values to a method through a single parameter. For example, the method has a single parameter that lets you supply one value to the method that the thread executes at startup. If you supply a object as the method argument, you can supply the thread's startup routine with five items of data. + ]]> @@ -206,21 +206,21 @@ The value of the tuple's fifth component. Initializes a new instance of the class. - method to instantiate a 5-tuple object without having to explicitly specify the types of its components. The following example uses the method to instantiate a 5-tuple whose first component is of type and its remaining four components are of type . - + method to instantiate a 5-tuple object without having to explicitly specify the types of its components. The following example uses the method to instantiate a 5-tuple whose first component is of type and its remaining four components are of type . + :::code language="csharp" source="~/snippets/csharp/System/Tuple/Overview/create1.cs" id="Snippet9"::: :::code language="fsharp" source="~/snippets/fsharp/System/Tuple/Overview/create1.fs" id="Snippet9"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple.create/vb/create1.vb" id="Snippet9"::: - - This is equivalent to the following call to the class constructor. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple.create/vb/create1.vb" id="Snippet9"::: + + This is equivalent to the following call to the class constructor. + :::code language="csharp" source="~/snippets/csharp/System/Tuple/Overview/create1.cs" id="Snippet10"::: :::code language="fsharp" source="~/snippets/fsharp/System/Tuple/Overview/create1.fs" id="Snippet10"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple.create/vb/create1.vb" id="Snippet10"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple.create/vb/create1.vb" id="Snippet10"::: + ]]> @@ -283,26 +283,26 @@ if the current instance is equal to the specified object; otherwise, . - object. - -- Its five components are of the same types as the current instance. - -- Its five components are equal to those of the current instance. Equality is determined by the default object equality comparer for each component. - - - -## Examples - The following example defines an array of 5-tuple objects that contain data about the temperatures of patients in two test groups. The first component of the array provides the number of the test group, and the second through fifth components provide the temperatures of a patient at hourly intervals. The method is called to compare every object with every other object. The output illustrates that the method returns `true` only when all five components of the objects have equal values. - + object. + +- Its five components are of the same types as the current instance. + +- Its five components are equal to those of the current instance. Equality is determined by the default object equality comparer for each component. + + + +## Examples + The following example defines an array of 5-tuple objects that contain data about the temperatures of patients in two test groups. The first component of the array provides the number of the test group, and the second through fifth components provide the temperatures of a patient at hourly intervals. The method is called to compare every object with every other object. The output illustrates that the method returns `true` only when all five components of the objects have equal values. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3,T4,T5/Equals/equals1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3,T4,T5/Equals/equals1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`5.equals/vb/equals1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`5.equals/vb/equals1.vb" id="Snippet1"::: + ]]> @@ -388,24 +388,24 @@ Gets the value of the current object's first component. The value of the current object's first component. - component in one of two ways: - -- By calling the `GetType` method on the value that is returned by the property. - -- By retrieving the object that represents the object, and retrieving the first element from the array that is returned by its method. - - - -## Examples - The following example defines an array of objects whose components contain the name of a state in the United States, its population in 1990 and 2000, its population change in this 10-year period, and the percentage change in its population. It then iterates through the array and displays the value of each component in a tuple. - + component in one of two ways: + +- By calling the `GetType` method on the value that is returned by the property. + +- By retrieving the object that represents the object, and retrieving the first element from the array that is returned by its method. + + + +## Examples + The following example defines an array of objects whose components contain the name of a state in the United States, its population in 1990 and 2000, its population change in this 10-year period, and the percentage change in its population. It then iterates through the array and displays the value of each component in a tuple. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3,T4,T5/Item1/item1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3,T4,T5/Item1/item1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`5.item1/vb/item1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`5.item1/vb/item1.vb" id="Snippet1"::: + ]]> @@ -449,24 +449,24 @@ Gets the value of the current object's second component. The value of the current object's second component. - component in one of two ways: - -- By calling the `GetType` method on the value that is returned by the property. - -- By retrieving the object that represents the object, and retrieving the second element from the array that is returned by its method. - - - -## Examples - The following example defines an array of objects whose components contain the name of a state in the United States, its population in 1990 and 2000, its population change in this 10-year period, and the percentage change in its population. It then iterates through the array and displays the value of each component in a tuple. - + component in one of two ways: + +- By calling the `GetType` method on the value that is returned by the property. + +- By retrieving the object that represents the object, and retrieving the second element from the array that is returned by its method. + + + +## Examples + The following example defines an array of objects whose components contain the name of a state in the United States, its population in 1990 and 2000, its population change in this 10-year period, and the percentage change in its population. It then iterates through the array and displays the value of each component in a tuple. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3,T4,T5/Item1/item1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3,T4,T5/Item1/item1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`5.item1/vb/item1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`5.item1/vb/item1.vb" id="Snippet1"::: + ]]> @@ -510,24 +510,24 @@ Gets the value of the current object's third component. The value of the current object's third component. - component in one of two ways: - -- By calling the `GetType` method on the value that is returned by the property. - -- By retrieving the object that represents the object, and retrieving the second element from the array that is returned by its method. - - - -## Examples - The following example defines an array of objects whose components contain the name of a state in the United States, its population in 1990 and 2000, its population change in this 10-year period, and the percentage change in its population. It then iterates through the array and displays the value of each component in a tuple. - + component in one of two ways: + +- By calling the `GetType` method on the value that is returned by the property. + +- By retrieving the object that represents the object, and retrieving the second element from the array that is returned by its method. + + + +## Examples + The following example defines an array of objects whose components contain the name of a state in the United States, its population in 1990 and 2000, its population change in this 10-year period, and the percentage change in its population. It then iterates through the array and displays the value of each component in a tuple. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3,T4,T5/Item1/item1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3,T4,T5/Item1/item1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`5.item1/vb/item1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`5.item1/vb/item1.vb" id="Snippet1"::: + ]]> @@ -571,24 +571,24 @@ Gets the value of the current object's fourth component. The value of the current object's fourth component. - component in one of two ways: - -- By calling the `GetType` method on the value that is returned by the property. - -- By retrieving the object that represents the object, and retrieving the second element from the array that is returned by its method. - - - -## Examples - The following example defines an array of objects whose components contain the name of a state in the United States, its population in 1990 and 2000, its population change in this 10-year period, and the percentage change in its population. It then iterates through the array and displays the value of each component in a tuple. - + component in one of two ways: + +- By calling the `GetType` method on the value that is returned by the property. + +- By retrieving the object that represents the object, and retrieving the second element from the array that is returned by its method. + + + +## Examples + The following example defines an array of objects whose components contain the name of a state in the United States, its population in 1990 and 2000, its population change in this 10-year period, and the percentage change in its population. It then iterates through the array and displays the value of each component in a tuple. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3,T4,T5/Item1/item1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3,T4,T5/Item1/item1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`5.item1/vb/item1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`5.item1/vb/item1.vb" id="Snippet1"::: + ]]> @@ -632,24 +632,24 @@ Gets the value of the current object's fifth component. The value of the current object's fifth component. - component in one of two ways: - -- By calling the `GetType` method on the value that is returned by the property. - -- By retrieving the object that represents the object, and retrieving the second element from the array that is returned by its method. - - - -## Examples - The following example defines an array of objects whose components contain the name of a state in the United Dates, its population in 1990 and 2000, its population change in this 10-year period, and the percentage change in its population. It then iterates through the array and displays the value of each component in a tuple. - + component in one of two ways: + +- By calling the `GetType` method on the value that is returned by the property. + +- By retrieving the object that represents the object, and retrieving the second element from the array that is returned by its method. + + + +## Examples + The following example defines an array of objects whose components contain the name of a state in the United Dates, its population in 1990 and 2000, its population change in this 10-year period, and the percentage change in its population. It then iterates through the array and displays the value of each component in a tuple. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3,T4,T5/Item1/item1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3,T4,T5/Item1/item1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`5.item1/vb/item1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`5.item1/vb/item1.vb" id="Snippet1"::: + ]]> @@ -700,43 +700,52 @@ An object to compare with the current instance. An object that provides custom rules for comparison. Compares the current object to a specified object by using a specified comparer and returns an integer that indicates whether the current object is before, after, or in the same position as the specified object in the sort order. - A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. - - Value - - Description - - A negative integer - - This instance precedes . - - Zero - - This instance and have the same position in the sort order. - - A positive integer - - This instance follows . - - + A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. + + Value + + + Description + + + + + A negative integer + + + This instance precedes . + + + Zero + + + This instance and have the same position in the sort order. + + + A positive integer + + + This instance follows . + + - instance is cast to an interface. - - Although this method can be called directly, it is most commonly called by collection-sorting methods that include parameters to order the members of a collection. For example, it is called by the method and the method of a object that is instantiated by using the constructor. - + instance is cast to an interface. + + Although this method can be called directly, it is most commonly called by collection-sorting methods that include parameters to order the members of a collection. For example, it is called by the method and the method of a object that is instantiated by using the constructor. + > [!CAUTION] > The method is intended for use in sorting operations. It should not be used when the primary purpose of a comparison is to determine whether two objects are equal. To determine whether two objects are equal, call the method. - -## Examples - The following example creates an array of objects that contain career statistical data for running backs in American professional football. The 5-tuple's components consist of the player's name, the number of games in which he played, the number of carries or attempts, the total number of yards gained, and the number of touchdowns scored. The example displays the components of each tuple in the array in unsorted order, sorts the array, and then calls to display each tuple in sorted order. To sort the array, the example defines a generic `YardsGained` class that implements the interface and sorts the objects in descending order by the value of their fourth component (yards gained) rather than by their first component. Note that the example does not directly call the method. This method is called implicitly by the method for each element in the array. - + +## Examples + The following example creates an array of objects that contain career statistical data for running backs in American professional football. The 5-tuple's components consist of the player's name, the number of games in which he played, the number of carries or attempts, the total number of yards gained, and the number of touchdowns scored. The example displays the components of each tuple in the array in unsorted order, sorts the array, and then calls to display each tuple in sorted order. To sort the array, the example defines a generic `YardsGained` class that implements the interface and sorts the objects in descending order by the value of their fourth component (yards gained) rather than by their first component. Note that the example does not directly call the method. This method is called implicitly by the method for each element in the array. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3,T4,T5/System.Collections.IStructuralComparable.CompareTo/compareto2.cs" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3,T4,T5/System.Collections.IStructuralComparable.CompareTo/compareto2.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`5.compareto/vb/compareto2.vb" id="Snippet2"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`5.compareto/vb/compareto2.vb" id="Snippet2"::: + ]]> @@ -799,22 +808,22 @@ if the current instance is equal to the specified object; otherwise, . - instance is cast to an interface. - - The implementation is called only if `other` is not `null`, and if it can be successfully cast (in C#) or converted (in Visual Basic) to a object whose components are of the same types as the current instance. The method first passes the values of the objects to be compared to the implementation. If this method call returns `true`, the method is called again and passed the values of the two objects. This continues until the method call returns `false` when it compares a specific pair of `Item` values, or the two values are passed to the method. - - - -## Examples - The following example defines a `DoubleComparer` class that implements the interface. The example instantiates two objects by using a random number generator to populate their second through fifth components, casts the first instance to an interface, and then uses a `DoubleComparer` object to test the two objects for approximate equality. - + instance is cast to an interface. + + The implementation is called only if `other` is not `null`, and if it can be successfully cast (in C#) or converted (in Visual Basic) to a object whose components are of the same types as the current instance. The method first passes the values of the objects to be compared to the implementation. If this method call returns `true`, the method is called again and passed the values of the two objects. This continues until the method call returns `false` when it compares a specific pair of `Item` values, or the two values are passed to the method. + + + +## Examples + The following example defines a `DoubleComparer` class that implements the interface. The example instantiates two objects by using a random number generator to populate their second through fifth components, casts the first instance to an interface, and then uses a `DoubleComparer` object to test the two objects for approximate equality. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3,T4,T5/Equals/equals2.cs" interactive="try-dotnet" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3,T4,T5/Equals/equals2.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`5.equals/vb/equals2.vb" id="Snippet2"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`5.equals/vb/equals2.vb" id="Snippet2"::: + ]]> @@ -865,15 +874,15 @@ Calculates the hash code for the current object by using a specified computation method. A 32-bit signed integer hash code. - instance is cast to an interface. - - The method simply wraps a call to the `comparer` object's implementation. - - The algorithm used to compute the hash code should return the same hash code for two objects that are considered to be equal. - + instance is cast to an interface. + + The method simply wraps a call to the `comparer` object's implementation. + + The algorithm used to compute the hash code should return the same hash code for two objects that are considered to be equal. + ]]> @@ -922,47 +931,56 @@ An object to compare with the current instance. Compares the current object to a specified object and returns an integer that indicates whether the current object is before, after, or in the same position as the specified object in the sort order. - A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. - - Value - - Description - - A negative integer - - This instance precedes . - - Zero - - This instance and have the same position in the sort order. - - A positive integer - - This instance follows . - - + A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. + + Value + + + Description + + + + + A negative integer + + + This instance precedes . + + + Zero + + + This instance and have the same position in the sort order. + + + A positive integer + + + This instance follows . + + - instance is cast to an interface. - - This method provides the implementation for the class. Although the method can be called directly, it is most commonly called by the default overloads of collection-sorting methods, such as and , to order the members of a collection. - + instance is cast to an interface. + + This method provides the implementation for the class. Although the method can be called directly, it is most commonly called by the default overloads of collection-sorting methods, such as and , to order the members of a collection. + > [!CAUTION] -> The method is intended for use in sorting operations. It should not be used when the primary purpose of a comparison is to determine whether two objects are equal. To determine whether two objects are equal, call the method. - - The method uses the default object comparer to compare each component. - - - -## Examples - The following example creates an array of objects that contain career statistics for running backs in American professional football. The five components consist of the player's name, the number of games in which he played, the number of carries or attempts, the total number of yards gained, and the number of touchdowns scored. The example displays the components of each tuple in the array in unsorted order, sorts the array, and then calls to display each tuple in sorted order. The output shows that the array has been sorted by name, which is the first component. Note that the example does not directly call the method. This method is called implicitly by the method for each element in the array. - +> The method is intended for use in sorting operations. It should not be used when the primary purpose of a comparison is to determine whether two objects are equal. To determine whether two objects are equal, call the method. + + The method uses the default object comparer to compare each component. + + + +## Examples + The following example creates an array of objects that contain career statistics for running backs in American professional football. The five components consist of the player's name, the number of games in which he played, the number of carries or attempts, the total number of yards gained, and the number of touchdowns scored. The example displays the components of each tuple in the array in unsorted order, sorts the array, and then calls to display each tuple in sorted order. The output shows that the array has been sorted by name, which is the first component. Note that the example does not directly call the method. This method is called implicitly by the method for each element in the array. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3,T4,T5/System.Collections.IStructuralComparable.CompareTo/compareto1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3,T4,T5/System.Collections.IStructuralComparable.CompareTo/compareto1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`5.compareto/vb/compareto1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`5.compareto/vb/compareto1.vb" id="Snippet1"::: + ]]> @@ -1017,11 +1035,11 @@ Gets the value of the specified element. The value of the element at the specified position. - property is an explicit interface implementation. To call it, you must cast or convert the object to an interface object. - + property is an explicit interface implementation. To call it, you must cast or convert the object to an interface object. + ]]> @@ -1064,11 +1082,11 @@ Gets the number of elements in the . 5, the number of elements in a object. - property is an explicit interface implementation. To call it, you must cast or convert the object to an interface object. - + property is an explicit interface implementation. To call it, you must cast or convert the object to an interface object. + ]]> @@ -1113,20 +1131,20 @@ Returns a string that represents the value of this instance. The string representation of this object. - , , , , and properties, respectively. If any of the property values is `null`, it is represented as . - - - -## Examples - The following example illustrates the method. It displays an array of 5-tuple objects that contain the name of a state in the United States, its population in 1990 and 2000, its population change in this 10-year period, and the annual rate of population change. - + , , , , and properties, respectively. If any of the property values is `null`, it is represented as . + + + +## Examples + The following example illustrates the method. It displays an array of 5-tuple objects that contain the name of a state in the United States, its population in 1990 and 2000, its population change in this 10-year period, and the annual rate of population change. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3,T4,T5/ToString/tostring1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3,T4,T5/ToString/tostring1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`5.tostring/vb/tostring1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`5.tostring/vb/tostring1.vb" id="Snippet1"::: + ]]> diff --git a/xml/System/Tuple`6.xml b/xml/System/Tuple`6.xml index 4e14b17fd3d..ee7e632e7c3 100644 --- a/xml/System/Tuple`6.xml +++ b/xml/System/Tuple`6.xml @@ -135,27 +135,27 @@ The type of the tuple's sixth component. Represents a 6-tuple, or sextuple. - class represents a 6-tuple, or sextuple, which is a tuple that has six components. - - You can instantiate a object by calling either the or the static method. You can retrieve the value of the tuple's components by using the read-only , , , , , and instance properties. - - Tuples are commonly used in four different ways: - -- To represent a single set of data. For example, a tuple can represent a database record, and its components can represent individual fields of the record. - -- To provide easy access to, and manipulation of, a data set. The following example defines a object that contains population data for New York City for each census from 1960 through 2000. The sextuple is passed to the `ComputePopulationChange` method, which calculates the annual rate of change between censuses, as well as the annual rate of change for the entire 50 year period. - + class represents a 6-tuple, or sextuple, which is a tuple that has six components. + + You can instantiate a object by calling either the or the static method. You can retrieve the value of the tuple's components by using the read-only , , , , , and instance properties. + + Tuples are commonly used in four different ways: + +- To represent a single set of data. For example, a tuple can represent a database record, and its components can represent individual fields of the record. + +- To provide easy access to, and manipulation of, a data set. The following example defines a object that contains population data for New York City for each census from 1960 through 2000. The sextuple is passed to the `ComputePopulationChange` method, which calculates the annual rate of change between censuses, as well as the annual rate of change for the entire 50 year period. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3,T4,T5,T6/Overview/example1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3,T4,T5,T6/Overview/example1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`6.class/vb/example1.vb" id="Snippet1"::: - -- To return multiple values from a method without the use of `out` parameters (in C#) or `ByRef` parameters (in Visual Basic). For example, the previous example returns its computed statistics, along with the city name, in a object. - -- To pass multiple values to a method through a single parameter. For example, the method has a single parameter that lets you supply one value to the method that the thread executes at startup. If you supply a object as the method argument, you can supply the thread's startup routine with six items of data. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`6.class/vb/example1.vb" id="Snippet1"::: + +- To return multiple values from a method without the use of `out` parameters (in C#) or `ByRef` parameters (in Visual Basic). For example, the previous example returns its computed statistics, along with the city name, in a object. + +- To pass multiple values to a method through a single parameter. For example, the method has a single parameter that lets you supply one value to the method that the thread executes at startup. If you supply a object as the method argument, you can supply the thread's startup routine with six items of data. + ]]> @@ -217,21 +217,21 @@ The value of the tuple's sixth component. Initializes a new instance of the class. - method to instantiate a 6-tuple object without having to explicitly specify the types of its components. The following example uses the method to instantiate a 6-tuple whose first component is of type and whose remaining components are of type . - + method to instantiate a 6-tuple object without having to explicitly specify the types of its components. The following example uses the method to instantiate a 6-tuple whose first component is of type and whose remaining components are of type . + :::code language="csharp" source="~/snippets/csharp/System/Tuple/Overview/create1.cs" id="Snippet11"::: :::code language="fsharp" source="~/snippets/fsharp/System/Tuple/Overview/create1.fs" id="Snippet11"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple.create/vb/create1.vb" id="Snippet11"::: - - This is equivalent to the following call to the class constructor. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple.create/vb/create1.vb" id="Snippet11"::: + + This is equivalent to the following call to the class constructor. + :::code language="csharp" source="~/snippets/csharp/System/Tuple/Overview/create1.cs" id="Snippet12"::: :::code language="fsharp" source="~/snippets/fsharp/System/Tuple/Overview/create1.fs" id="Snippet12"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple.create/vb/create1.vb" id="Snippet12"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple.create/vb/create1.vb" id="Snippet12"::: + ]]> @@ -294,26 +294,26 @@ if the current instance is equal to the specified object; otherwise, . - object. - -- Its six components are of the same types as the current instance. - -- Its six components are equal to those of the current instance. Equality is determined by the default object equality comparer for each component. - - - -## Examples - The following example defines an array of sextuples that contain population data for Los Angeles and New York from 1960 to 2000. The first component of each sextuple identifies the city. The first, third, and fourth sextuples contain data for New York. The first sextuple is a duplicate of the fourth sextuple. The third sextuple identifies the city as "New York City" instead of "New York". As the example shows, only the fourth sextuple is equal to the first sextuple. - + object. + +- Its six components are of the same types as the current instance. + +- Its six components are equal to those of the current instance. Equality is determined by the default object equality comparer for each component. + + + +## Examples + The following example defines an array of sextuples that contain population data for Los Angeles and New York from 1960 to 2000. The first component of each sextuple identifies the city. The first, third, and fourth sextuples contain data for New York. The first sextuple is a duplicate of the fourth sextuple. The third sextuple identifies the city as "New York City" instead of "New York". As the example shows, only the fourth sextuple is equal to the first sextuple. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3,T4,T5,T6/Equals/equals1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3,T4,T5,T6/Equals/equals1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`6.equals/vb/equals1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`6.equals/vb/equals1.vb" id="Snippet1"::: + ]]> @@ -399,24 +399,24 @@ Gets the value of the current object's first component. The value of the current object's first component. - component in one of two ways: - -- By calling the `GetType` method on the value that is returned by the property. - -- By retrieving the object that represents the object, and retrieving the first element from the array that is returned by its method. - - - -## Examples - The following example defines an array of objects whose components contain population data for three U.S. cities (New York, Chicago, and Los Angeles) from 1960 through 2000. It then displays a table that lists the data. To display the city name, it retrieves the value of the property for each object. - + component in one of two ways: + +- By calling the `GetType` method on the value that is returned by the property. + +- By retrieving the object that represents the object, and retrieving the first element from the array that is returned by its method. + + + +## Examples + The following example defines an array of objects whose components contain population data for three U.S. cities (New York, Chicago, and Los Angeles) from 1960 through 2000. It then displays a table that lists the data. To display the city name, it retrieves the value of the property for each object. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3,T4,T5,T6/Item1/item1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3,T4,T5,T6/Item1/item1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`6.item1/vb/item1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`6.item1/vb/item1.vb" id="Snippet1"::: + ]]> @@ -460,24 +460,24 @@ Gets the value of the current object's second component. The value of the current object's second component. - component in one of two ways: - -- By calling the `GetType` method on the value that is returned by the property. - -- By retrieving the object that represents the object, and retrieving the first element from the array that is returned by its method. - - - -## Examples - The following example defines an array of objects whose components contain population data for three U.S. cities (New York, Chicago, and Los Angeles) from 1960 through 2000. It then displays a table that lists the data. To display the population in 1960, it retrieves the value of the property for each object. - + component in one of two ways: + +- By calling the `GetType` method on the value that is returned by the property. + +- By retrieving the object that represents the object, and retrieving the first element from the array that is returned by its method. + + + +## Examples + The following example defines an array of objects whose components contain population data for three U.S. cities (New York, Chicago, and Los Angeles) from 1960 through 2000. It then displays a table that lists the data. To display the population in 1960, it retrieves the value of the property for each object. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3,T4,T5,T6/Item1/item1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3,T4,T5,T6/Item1/item1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`6.item1/vb/item1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`6.item1/vb/item1.vb" id="Snippet1"::: + ]]> @@ -521,24 +521,24 @@ Gets the value of the current object's third component. The value of the current object's third component. - component in one of two ways: - -- By calling the `GetType` method on the value that is returned by the property. - -- By retrieving the object that represents the object, and retrieving the first element from the array that is returned by its method. - - - -## Examples - The following example defines an array of objects whose components contain population data for three U.S. cities (New York, Chicago, and Los Angeles) from 1960 through 2000. It then displays a table that lists the data. To display the population in 1970, it retrieves the value of the property for each object. - + component in one of two ways: + +- By calling the `GetType` method on the value that is returned by the property. + +- By retrieving the object that represents the object, and retrieving the first element from the array that is returned by its method. + + + +## Examples + The following example defines an array of objects whose components contain population data for three U.S. cities (New York, Chicago, and Los Angeles) from 1960 through 2000. It then displays a table that lists the data. To display the population in 1970, it retrieves the value of the property for each object. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3,T4,T5,T6/Item1/item1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3,T4,T5,T6/Item1/item1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`6.item1/vb/item1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`6.item1/vb/item1.vb" id="Snippet1"::: + ]]> @@ -582,24 +582,24 @@ Gets the value of the current object's fourth component. The value of the current object's fourth component. - component in one of two ways: - -- By calling the `GetType` method on the value that is returned by the property. - -- By retrieving the object that represents the object, and retrieving the first element from the array that is returned by its method. - - - -## Examples - The following example defines an array of objects whose components contain population data for three U.S. cities (New York, Chicago, and Los Angeles) from 1960 through 2000. It then displays a table that lists the data. To display the population in 1980, it retrieves the value of the property for each object. - + component in one of two ways: + +- By calling the `GetType` method on the value that is returned by the property. + +- By retrieving the object that represents the object, and retrieving the first element from the array that is returned by its method. + + + +## Examples + The following example defines an array of objects whose components contain population data for three U.S. cities (New York, Chicago, and Los Angeles) from 1960 through 2000. It then displays a table that lists the data. To display the population in 1980, it retrieves the value of the property for each object. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3,T4,T5,T6/Item1/item1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3,T4,T5,T6/Item1/item1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`6.item1/vb/item1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`6.item1/vb/item1.vb" id="Snippet1"::: + ]]> @@ -641,26 +641,26 @@ Gets the value of the current object's fifth component. - The value of the current object's fifth component. + The value of the current object's fifth component. - component in one of two ways: - -- By calling the `GetType` method on the value that is returned by the property. - -- By retrieving the object that represents the object, and retrieving the first element from the array that is returned by its method. - - - -## Examples - The following example defines an array of objects whose components contain population data for three U.S. cities (New York, Chicago, and Los Angeles) from 1960 through 2000. It then displays a table that lists the data. To display the population in 1990, it retrieves the value of the property for each object. - + component in one of two ways: + +- By calling the `GetType` method on the value that is returned by the property. + +- By retrieving the object that represents the object, and retrieving the first element from the array that is returned by its method. + + + +## Examples + The following example defines an array of objects whose components contain population data for three U.S. cities (New York, Chicago, and Los Angeles) from 1960 through 2000. It then displays a table that lists the data. To display the population in 1990, it retrieves the value of the property for each object. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3,T4,T5,T6/Item1/item1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3,T4,T5,T6/Item1/item1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`6.item1/vb/item1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`6.item1/vb/item1.vb" id="Snippet1"::: + ]]> @@ -704,24 +704,24 @@ Gets the value of the current object's sixth component. The value of the current object's sixth component. - component in one of two ways: - -- By calling the `GetType` method on the value that is returned by the property. - -- By retrieving the object that represents the object, and retrieving the first element from the array that is returned by its method. - - - -## Examples - The following example defines an array of objects whose components contain population data for three U.S. cities (New York, Chicago, and Los Angeles) from 1960 through 2000. It then displays a table that lists the data. To display the population in 2000, it retrieves the value of the property for each object. - + component in one of two ways: + +- By calling the `GetType` method on the value that is returned by the property. + +- By retrieving the object that represents the object, and retrieving the first element from the array that is returned by its method. + + + +## Examples + The following example defines an array of objects whose components contain population data for three U.S. cities (New York, Chicago, and Los Angeles) from 1960 through 2000. It then displays a table that lists the data. To display the population in 2000, it retrieves the value of the property for each object. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3,T4,T5,T6/Item1/item1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3,T4,T5,T6/Item1/item1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`6.item1/vb/item1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`6.item1/vb/item1.vb" id="Snippet1"::: + ]]> @@ -772,51 +772,60 @@ An object to compare with the current instance. An object that provides custom rules for comparison. Compares the current object to a specified object by using a specified comparer and returns an integer that indicates whether the current object is before, after, or in the same position as the specified object in the sort order. - A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. - - Value - - Description - - A negative integer - - This instance precedes . - - Zero - - This instance and have the same position in the sort order. - - A positive integer - - This instance follows . - - + A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. + + Value + + + Description + + + + + A negative integer + + + This instance precedes . + + + Zero + + + This instance and have the same position in the sort order. + + + A positive integer + + + This instance follows . + + - instance is cast to an interface. - - This method lets you define customized comparisons of objects. For example, you can use this method to order objects based on the value of a specific component. - - Although this method can be called directly, it is most commonly called by collection-sorting methods that include parameters to order the members of a collection. For example, it is called by the method and the method of a object that is instantiated by using the constructor. - + instance is cast to an interface. + + This method lets you define customized comparisons of objects. For example, you can use this method to order objects based on the value of a specific component. + + Although this method can be called directly, it is most commonly called by collection-sorting methods that include parameters to order the members of a collection. For example, it is called by the method and the method of a object that is instantiated by using the constructor. + > [!CAUTION] -> The method is intended for use in sorting operations. It should not be used when the primary purpose of a comparison is to determine whether two objects are equal. To determine whether two objects are equal, call the method. - - - -## Examples - The following example creates an array of objects that contains population data for three U.S. cities from 1960 to 2000. The sextuple's first component is the city name. The remaining five components represent the population at 10-year intervals from 1960 to 2000. - - The `PopulationComparer` class provides an implementation that allows the array of sextuples to be sorted by any one of its components. Two values are provided to the `PopulationComparer` class in its constructor: The position of the component that defines the sort order, and a value that indicates whether the tuple objects should be sorted in ascending or descending order. - - The example then displays the elements in the array in unsorted order, sorts them by the third component (the population in 1970) and displays them, and then sorts them by the sixth component (the population in 2000) and displays them. - +> The method is intended for use in sorting operations. It should not be used when the primary purpose of a comparison is to determine whether two objects are equal. To determine whether two objects are equal, call the method. + + + +## Examples + The following example creates an array of objects that contains population data for three U.S. cities from 1960 to 2000. The sextuple's first component is the city name. The remaining five components represent the population at 10-year intervals from 1960 to 2000. + + The `PopulationComparer` class provides an implementation that allows the array of sextuples to be sorted by any one of its components. Two values are provided to the `PopulationComparer` class in its constructor: The position of the component that defines the sort order, and a value that indicates whether the tuple objects should be sorted in ascending or descending order. + + The example then displays the elements in the array in unsorted order, sorts them by the third component (the population in 1970) and displays them, and then sorts them by the sixth component (the population in 2000) and displays them. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3,T4,T5,T6/System.Collections.IStructuralComparable.CompareTo/compareto2.cs" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3,T4,T5,T6/System.Collections.IStructuralComparable.CompareTo/compareto2.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`6.compareto/vb/compareto2.vb" id="Snippet2"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`6.compareto/vb/compareto2.vb" id="Snippet2"::: + ]]> @@ -879,22 +888,22 @@ if the current instance is equal to the specified object; otherwise, . - instance is cast to an interface. - - The implementation is called only if `other` is not `null`, and if it can be successfully cast (in C#) or converted (in Visual Basic) to a object whose components are of the same types as the current instance. The method first passes the values of the objects to be compared to the implementation. If this method call returns `true`, the method is called again and passed the values of the two objects. This continues until the method call returns `false` when it compares a specific pair of `Item` values, or the two values are passed to the method. - - - -## Examples - The following example defines a `RateComparer` class that performs a custom test for equality. If the values that are passed to its method are of type or , the method tests for equality by using only up to three fractional digits. Otherwise, it simply calls the `x` parameter's `Equals` method. The example uses this implementation to determine whether four objects that contain data on the rate of population change between 1960 and 2000 are equal. - + instance is cast to an interface. + + The implementation is called only if `other` is not `null`, and if it can be successfully cast (in C#) or converted (in Visual Basic) to a object whose components are of the same types as the current instance. The method first passes the values of the objects to be compared to the implementation. If this method call returns `true`, the method is called again and passed the values of the two objects. This continues until the method call returns `false` when it compares a specific pair of `Item` values, or the two values are passed to the method. + + + +## Examples + The following example defines a `RateComparer` class that performs a custom test for equality. If the values that are passed to its method are of type or , the method tests for equality by using only up to three fractional digits. Otherwise, it simply calls the `x` parameter's `Equals` method. The example uses this implementation to determine whether four objects that contain data on the rate of population change between 1960 and 2000 are equal. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3,T4,T5,T6/Equals/equals2.cs" interactive="try-dotnet" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3,T4,T5,T6/Equals/equals2.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`6.equals/vb/equals2.vb" id="Snippet2"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`6.equals/vb/equals2.vb" id="Snippet2"::: + ]]> @@ -945,15 +954,15 @@ Calculates the hash code for the current object by using a specified computation method. A 32-bit signed integer hash code. - instance is cast to an interface. - - The method simply wraps a call to the `comparer` object's implementation. - - The algorithm used to compute the hash code should return the same hash code for two objects that are considered to be equal. - + instance is cast to an interface. + + The method simply wraps a call to the `comparer` object's implementation. + + The algorithm used to compute the hash code should return the same hash code for two objects that are considered to be equal. + ]]> @@ -1002,47 +1011,56 @@ An object to compare with the current instance. Compares the current object to a specified object and returns an integer that indicates whether the current object is before, after, or in the same position as the specified object in the sort order. - A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. - - Value - - Description - - A negative integer - - This instance precedes . - - Zero - - This instance and have the same position in the sort order. - - A positive integer - - This instance follows . - - + A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. + + Value + + + Description + + + + + A negative integer + + + This instance precedes . + + + Zero + + + This instance and have the same position in the sort order. + + + A positive integer + + + This instance follows . + + - instance is cast to an interface. - - This method provides the implementation for the class. Although the method can be called directly, it is most commonly called by the default overloads of collection-sorting methods, such as and , to order the members of a collection. - + instance is cast to an interface. + + This method provides the implementation for the class. Although the method can be called directly, it is most commonly called by the default overloads of collection-sorting methods, such as and , to order the members of a collection. + > [!CAUTION] -> The method is intended for use in sorting operations. It should not be used when the primary purpose of a comparison is to determine whether two objects are equal. To determine whether two objects are equal, call the method. - - The method uses the default object comparer to compare each component. - - - -## Examples - The following example creates an array of objects that contain population data for three cities in the United States from 1960 to 2000. The six components consist of the city name followed by the city's population at 10-year intervals from 1960 to 2000. The example displays the components of each tuple in the array in unsorted order, sorts the array, and then calls the method to display each tuple in sorted order. The output shows that the array has been sorted by name, which is the first component. Note that the example does not directly call the method. This method is called implicitly by the method for each element in the array. - +> The method is intended for use in sorting operations. It should not be used when the primary purpose of a comparison is to determine whether two objects are equal. To determine whether two objects are equal, call the method. + + The method uses the default object comparer to compare each component. + + + +## Examples + The following example creates an array of objects that contain population data for three cities in the United States from 1960 to 2000. The six components consist of the city name followed by the city's population at 10-year intervals from 1960 to 2000. The example displays the components of each tuple in the array in unsorted order, sorts the array, and then calls the method to display each tuple in sorted order. The output shows that the array has been sorted by name, which is the first component. Note that the example does not directly call the method. This method is called implicitly by the method for each element in the array. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3,T4,T5,T6/System.Collections.IStructuralComparable.CompareTo/compareto1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3,T4,T5,T6/System.Collections.IStructuralComparable.CompareTo/compareto1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`6.compareto/vb/compareto1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`6.compareto/vb/compareto1.vb" id="Snippet1"::: + ]]> @@ -1096,11 +1114,11 @@ Gets the value of the specified element. The value of the element at the specified position. - property is an explicit interface implementation. To call it, you must cast or convert the object to an interface object. - + property is an explicit interface implementation. To call it, you must cast or convert the object to an interface object. + ]]> @@ -1143,11 +1161,11 @@ Gets the number of elements in the . 6, the number of elements in a object. - property is an explicit interface implementation. To call it, you must cast or convert the object to an interface object. - + property is an explicit interface implementation. To call it, you must cast or convert the object to an interface object. + ]]> @@ -1192,20 +1210,20 @@ Returns a string that represents the value of this instance. The string representation of this object. - , , , , , and properties, respectively. If any of the property values is `null`, it is represented as . - - - -## Examples - The following example defines a object that contains population data for New York City for each census from 1960 through 2000. The components of the sextuple are then displayed by a call to the method. - + , , , , , and properties, respectively. If any of the property values is `null`, it is represented as . + + + +## Examples + The following example defines a object that contains population data for New York City for each census from 1960 through 2000. The components of the sextuple are then displayed by a call to the method. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3,T4,T5,T6/ToString/tostring1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3,T4,T5,T6/ToString/tostring1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`6.tostring/vb/tostring1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`6.tostring/vb/tostring1.vb" id="Snippet1"::: + ]]> diff --git a/xml/System/Tuple`7.xml b/xml/System/Tuple`7.xml index d34c1efeeb9..757f10b3619 100644 --- a/xml/System/Tuple`7.xml +++ b/xml/System/Tuple`7.xml @@ -144,27 +144,27 @@ The type of the tuple's seventh component. Represents a 7-tuple, or septuple. - class represents a 7-tuple, or septuple, which is a tuple that has seven components. - - You can instantiate a object by calling either the or the static method. You can retrieve the value of the tuple's components by using the read-only , , , , , , and instance properties. - - Tuples are commonly used in four different ways: - -- To represent a single set of data. For example, a tuple can represent a database record, and its components can represent individual fields of the record. - -- To provide easy access to, and manipulation of, a data set. The following example defines a object that contains population data for New York City for each census from 1950 through 2000. The septuple is passed to the `ComputePopulationChange` method, which calculates the annual rate of change between censuses, as well as the annual rate of change for the entire 60 year period. - + class represents a 7-tuple, or septuple, which is a tuple that has seven components. + + You can instantiate a object by calling either the or the static method. You can retrieve the value of the tuple's components by using the read-only , , , , , , and instance properties. + + Tuples are commonly used in four different ways: + +- To represent a single set of data. For example, a tuple can represent a database record, and its components can represent individual fields of the record. + +- To provide easy access to, and manipulation of, a data set. The following example defines a object that contains population data for New York City for each census from 1950 through 2000. The septuple is passed to the `ComputePopulationChange` method, which calculates the annual rate of change between censuses, as well as the annual rate of change for the entire 60 year period. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3,T4,T5,T6,T7/Overview/example1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3,T4,T5,T6,T7/Overview/example1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`7.class/vb/example1.vb" id="Snippet1"::: - -- To return multiple values from a method without the use of `out` parameters (in C#) or `ByRef` parameters (in Visual Basic). For example, the previous example returns its computed statistics, along with the city name, in a object. - -- To pass multiple values to a method through a single parameter. For example, the method has a single parameter that lets you supply one value to the method that the thread executes at startup. If you supply a object as the method argument, you can supply the thread's startup routine with seven items of data. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`7.class/vb/example1.vb" id="Snippet1"::: + +- To return multiple values from a method without the use of `out` parameters (in C#) or `ByRef` parameters (in Visual Basic). For example, the previous example returns its computed statistics, along with the city name, in a object. + +- To pass multiple values to a method through a single parameter. For example, the method has a single parameter that lets you supply one value to the method that the thread executes at startup. If you supply a object as the method argument, you can supply the thread's startup routine with seven items of data. + ]]> @@ -228,21 +228,21 @@ The value of the tuple's seventh component. Initializes a new instance of the class. - method to instantiate a 7-tuple object without having to explicitly specify the types of its components. The following example uses the method to instantiate a 7-tuple whose first component is of type and whose remaining components are of type . - + method to instantiate a 7-tuple object without having to explicitly specify the types of its components. The following example uses the method to instantiate a 7-tuple whose first component is of type and whose remaining components are of type . + :::code language="csharp" source="~/snippets/csharp/System/Tuple/Overview/create1.cs" id="Snippet13"::: :::code language="fsharp" source="~/snippets/fsharp/System/Tuple/Overview/create1.fs" id="Snippet13"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple.create/vb/create1.vb" id="Snippet13"::: - - This is equivalent to the following call to the class constructor. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple.create/vb/create1.vb" id="Snippet13"::: + + This is equivalent to the following call to the class constructor. + :::code language="csharp" source="~/snippets/csharp/System/Tuple/Overview/create1.cs" id="Snippet14"::: :::code language="fsharp" source="~/snippets/fsharp/System/Tuple/Overview/create1.fs" id="Snippet14"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple.create/vb/create1.vb" id="Snippet14"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple.create/vb/create1.vb" id="Snippet14"::: + ]]> @@ -305,26 +305,26 @@ if the current instance is equal to the specified object; otherwise, . - object. - -- Its seven components are of the same types as the current instance. - -- Its seven components are equal to those of the current instance. Equality is determined by the default object equality comparer for each component. - - - -## Examples - The following example defines an array of sextuples that contain population data for Los Angeles and New York from 1950 to 2000. The first component of each septuple identifies the city. The first, third, and fourth septuples contain data for New York. The first septuple is a duplicate of the fourth septuple. The third septuple identifies the city as "New York City" instead of "New York". As the example shows, only the fourth septuple is equal to the first septuple. - + object. + +- Its seven components are of the same types as the current instance. + +- Its seven components are equal to those of the current instance. Equality is determined by the default object equality comparer for each component. + + + +## Examples + The following example defines an array of sextuples that contain population data for Los Angeles and New York from 1950 to 2000. The first component of each septuple identifies the city. The first, third, and fourth septuples contain data for New York. The first septuple is a duplicate of the fourth septuple. The third septuple identifies the city as "New York City" instead of "New York". As the example shows, only the fourth septuple is equal to the first septuple. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3,T4,T5,T6,T7/Equals/equals1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3,T4,T5,T6,T7/Equals/equals1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`7.equals/vb/equals1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`7.equals/vb/equals1.vb" id="Snippet1"::: + ]]> @@ -410,24 +410,24 @@ Gets the value of the current object's first component. The value of the current object's first component. - component in one of two ways: - -- By calling the `GetType` method on the value that is returned by the property. - -- By retrieving the object that represents the object, and retrieving the first element from the array that is returned by its method. - - - -## Examples - The following example defines an array of objects whose components contain population data for three U.S. cities (New York, Chicago, and Los Angeles) from 1950 through 2000. It then displays a table that lists the data. To display the city name, it retrieves the value of the property for each object. - + component in one of two ways: + +- By calling the `GetType` method on the value that is returned by the property. + +- By retrieving the object that represents the object, and retrieving the first element from the array that is returned by its method. + + + +## Examples + The following example defines an array of objects whose components contain population data for three U.S. cities (New York, Chicago, and Los Angeles) from 1950 through 2000. It then displays a table that lists the data. To display the city name, it retrieves the value of the property for each object. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3,T4,T5,T6,T7/Item1/item1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3,T4,T5,T6,T7/Item1/item1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`7.item1/vb/item1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`7.item1/vb/item1.vb" id="Snippet1"::: + ]]> @@ -471,24 +471,24 @@ Gets the value of the current object's second component. The value of the current object's second component. - component in one of two ways: - -- By calling the `GetType` method on the value that is returned by the property. - -- By retrieving the object that represents the object, and retrieving the second element from the array that is returned by its method. - - - -## Examples - The following example defines an array of objects whose components contain population data for three U.S. cities (New York, Chicago, and Los Angeles) from 1950 through 2000. It then displays a table that lists the data. To display the population in 1950, it retrieves the value of the property for each object. - + component in one of two ways: + +- By calling the `GetType` method on the value that is returned by the property. + +- By retrieving the object that represents the object, and retrieving the second element from the array that is returned by its method. + + + +## Examples + The following example defines an array of objects whose components contain population data for three U.S. cities (New York, Chicago, and Los Angeles) from 1950 through 2000. It then displays a table that lists the data. To display the population in 1950, it retrieves the value of the property for each object. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3,T4,T5,T6,T7/Item1/item1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3,T4,T5,T6,T7/Item1/item1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`7.item1/vb/item1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`7.item1/vb/item1.vb" id="Snippet1"::: + ]]> @@ -532,24 +532,24 @@ Gets the value of the current object's third component. The value of the current object's third component. - component in one of two ways: - -- By calling the `GetType` method on the value that is returned by the property. - -- By retrieving the object that represents the object, and retrieving the third element from the array that is returned by its method. - - - -## Examples - The following example defines an array of objects whose components contain population data for three U.S. cities (New York, Chicago, and Los Angeles) from 1950 through 2000. It then displays a table that lists the data. To display the population in 1960, it retrieves the value of the property for each object. - + component in one of two ways: + +- By calling the `GetType` method on the value that is returned by the property. + +- By retrieving the object that represents the object, and retrieving the third element from the array that is returned by its method. + + + +## Examples + The following example defines an array of objects whose components contain population data for three U.S. cities (New York, Chicago, and Los Angeles) from 1950 through 2000. It then displays a table that lists the data. To display the population in 1960, it retrieves the value of the property for each object. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3,T4,T5,T6,T7/Item1/item1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3,T4,T5,T6,T7/Item1/item1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`7.item1/vb/item1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`7.item1/vb/item1.vb" id="Snippet1"::: + ]]> @@ -593,24 +593,24 @@ Gets the value of the current object's fourth component. The value of the current object's fourth component. - component in one of two ways: - -- By calling the `GetType` method on the value that is returned by the property. - -- By retrieving the object that represents the object, and retrieving the fourth element from the array that is returned by its method. - - - -## Examples - The following example defines an array of objects whose components contain population data for three U.S. cities (New York, Chicago, and Los Angeles) from 1950 through 2000. It then displays a table that lists the data. To display the population in 1970, it retrieves the value of the property for each object. - + component in one of two ways: + +- By calling the `GetType` method on the value that is returned by the property. + +- By retrieving the object that represents the object, and retrieving the fourth element from the array that is returned by its method. + + + +## Examples + The following example defines an array of objects whose components contain population data for three U.S. cities (New York, Chicago, and Los Angeles) from 1950 through 2000. It then displays a table that lists the data. To display the population in 1970, it retrieves the value of the property for each object. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3,T4,T5,T6,T7/Item1/item1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3,T4,T5,T6,T7/Item1/item1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`7.item1/vb/item1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`7.item1/vb/item1.vb" id="Snippet1"::: + ]]> @@ -654,24 +654,24 @@ Gets the value of the current object's fifth component. The value of the current object's fifth component. - component in one of two ways: - -- By calling the `GetType` method on the value that is returned by the property. - -- By retrieving the object that represents the object, and retrieving the fifth element from the array that is returned by its method. - - - -## Examples - The following example defines an array of objects whose components contain population data for three U.S. cities (New York, Chicago, and Los Angeles) from 1950 through 2000. It then displays a table that lists the data. To display the population in 1980, it retrieves the value of the property for each object. - + component in one of two ways: + +- By calling the `GetType` method on the value that is returned by the property. + +- By retrieving the object that represents the object, and retrieving the fifth element from the array that is returned by its method. + + + +## Examples + The following example defines an array of objects whose components contain population data for three U.S. cities (New York, Chicago, and Los Angeles) from 1950 through 2000. It then displays a table that lists the data. To display the population in 1980, it retrieves the value of the property for each object. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3,T4,T5,T6,T7/Item1/item1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3,T4,T5,T6,T7/Item1/item1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`7.item1/vb/item1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`7.item1/vb/item1.vb" id="Snippet1"::: + ]]> @@ -715,24 +715,24 @@ Gets the value of the current object's sixth component. The value of the current object's sixth component. - component in one of two ways: - -- By calling the `GetType` method on the value that is returned by the property. - -- By retrieving the object that represents the object, and retrieving the sixth element from the array that is returned by its method. - - - -## Examples - The following example defines an array of objects whose components contain population data for three U.S. cities (New York, Chicago, and Los Angeles) from 1950 through 2000. It then displays a table that lists the data. To display the population in 1990, it retrieves the value of the property for each object. - + component in one of two ways: + +- By calling the `GetType` method on the value that is returned by the property. + +- By retrieving the object that represents the object, and retrieving the sixth element from the array that is returned by its method. + + + +## Examples + The following example defines an array of objects whose components contain population data for three U.S. cities (New York, Chicago, and Los Angeles) from 1950 through 2000. It then displays a table that lists the data. To display the population in 1990, it retrieves the value of the property for each object. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3,T4,T5,T6,T7/Item1/item1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3,T4,T5,T6,T7/Item1/item1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`7.item1/vb/item1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`7.item1/vb/item1.vb" id="Snippet1"::: + ]]> @@ -776,24 +776,24 @@ Gets the value of the current object's seventh component. The value of the current object's seventh component. - component in one of two ways: - -- By calling the `GetType` method on the value that is returned by the property. - -- By retrieving the object that represents the object, and retrieving the seventh element from the array that is returned by its method. - - - -## Examples - The following example defines an array of objects whose components contain population data for three U.S. cities (New York, Chicago, and Los Angeles) from 1950 through 2000. It then displays a table that lists the data. To display the population in 2000, it retrieves the value of the property for each object. - + component in one of two ways: + +- By calling the `GetType` method on the value that is returned by the property. + +- By retrieving the object that represents the object, and retrieving the seventh element from the array that is returned by its method. + + + +## Examples + The following example defines an array of objects whose components contain population data for three U.S. cities (New York, Chicago, and Los Angeles) from 1950 through 2000. It then displays a table that lists the data. To display the population in 2000, it retrieves the value of the property for each object. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3,T4,T5,T6,T7/Item1/item1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3,T4,T5,T6,T7/Item1/item1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`7.item1/vb/item1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`7.item1/vb/item1.vb" id="Snippet1"::: + ]]> @@ -844,51 +844,60 @@ An object to compare with the current instance. An object that provides custom rules for comparison. Compares the current object to a specified object by using a specified comparer, and returns an integer that indicates whether the current object is before, after, or in the same position as the specified object in the sort order. - A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. - - Value - - Description - - A negative integer - - This instance precedes . - - Zero - - This instance and have the same position in the sort order. - - A positive integer - - This instance follows . - - + A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. + + Value + + + Description + + + + + A negative integer + + + This instance precedes . + + + Zero + + + This instance and have the same position in the sort order. + + + A positive integer + + + This instance follows . + + - instance is cast to an interface. - - This method lets you define customized comparisons of objects. For example, you can use this method to order objects based on the value of a specific component. - - Although this method can be called directly, it is most commonly called by collection-sorting methods that include parameters to order the members of a collection. For example, it is called by the method and the method of a object that is instantiated by using the constructor. - + instance is cast to an interface. + + This method lets you define customized comparisons of objects. For example, you can use this method to order objects based on the value of a specific component. + + Although this method can be called directly, it is most commonly called by collection-sorting methods that include parameters to order the members of a collection. For example, it is called by the method and the method of a object that is instantiated by using the constructor. + > [!CAUTION] -> The method is intended for use in sorting operations. It should not be used when the primary purpose of a comparison is to determine whether two objects are equal. To determine whether two objects are equal, call the method. - - - -## Examples - The following example creates an array of objects that contains population data for three U.S. cities from 1950 to 2000. The septuple's first component is the city name. The remaining five components represent the population at 10-year intervals from 1950 to 2000. - - The `PopulationComparer` class provides an implementation that allows the array of septuples to be sorted by any one of its components. Two values are provided to the `PopulationComparer` class in its constructor: The position of the component that defines the sort order, and a value that indicates whether the tuple objects should be sorted in ascending or descending order. - - The example then displays the elements in the array in unsorted order, sorts them by the third component (the population in 1960) and displays them, and then sorts them by the sixth component (the population in 1990) and displays them. - +> The method is intended for use in sorting operations. It should not be used when the primary purpose of a comparison is to determine whether two objects are equal. To determine whether two objects are equal, call the method. + + + +## Examples + The following example creates an array of objects that contains population data for three U.S. cities from 1950 to 2000. The septuple's first component is the city name. The remaining five components represent the population at 10-year intervals from 1950 to 2000. + + The `PopulationComparer` class provides an implementation that allows the array of septuples to be sorted by any one of its components. Two values are provided to the `PopulationComparer` class in its constructor: The position of the component that defines the sort order, and a value that indicates whether the tuple objects should be sorted in ascending or descending order. + + The example then displays the elements in the array in unsorted order, sorts them by the third component (the population in 1960) and displays them, and then sorts them by the sixth component (the population in 1990) and displays them. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3,T4,T5,T6,T7/System.Collections.IStructuralComparable.CompareTo/compareto2.cs" interactive="try-dotnet" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3,T4,T5,T6,T7/System.Collections.IStructuralComparable.CompareTo/compareto2.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`7.compareto/vb/compareto2.vb" id="Snippet2"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`7.compareto/vb/compareto2.vb" id="Snippet2"::: + ]]> @@ -952,22 +961,22 @@ if the current instance is equal to the specified object; otherwise, . - instance is cast to an interface. - - The implementation is called only if other is not `null`, and if it can be successfully cast (in C#) or converted (in Visual Basic) to a object whose components are of the same types as the current instance. The method first passes the values of the objects to be compared to the implementation. If this method call returns `true`, the method is called again and passed the values of the two objects. This continues until the method call returns `false` when it compares a specific pair of `Item` values, or the two values are passed to the method. - - - -## Examples - The following example defines a `RateComparer` class that performs a custom test for equality. If the values that are passed to its method are of type or , the method tests for equality by using only up to three fractional digits. Otherwise, it simply calls the `x` parameter's `Equals` method. The example uses this implementation to determine whether four objects that contain data on the rate of population change between 1950 and 2000 are equal. - + instance is cast to an interface. + + The implementation is called only if other is not `null`, and if it can be successfully cast (in C#) or converted (in Visual Basic) to a object whose components are of the same types as the current instance. The method first passes the values of the objects to be compared to the implementation. If this method call returns `true`, the method is called again and passed the values of the two objects. This continues until the method call returns `false` when it compares a specific pair of `Item` values, or the two values are passed to the method. + + + +## Examples + The following example defines a `RateComparer` class that performs a custom test for equality. If the values that are passed to its method are of type or , the method tests for equality by using only up to three fractional digits. Otherwise, it simply calls the `x` parameter's `Equals` method. The example uses this implementation to determine whether four objects that contain data on the rate of population change between 1950 and 2000 are equal. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3,T4,T5,T6,T7/Equals/equals2.cs" interactive="try-dotnet" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3,T4,T5,T6,T7/Equals/equals2.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`7.equals/vb/equals2.vb" id="Snippet2"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`7.equals/vb/equals2.vb" id="Snippet2"::: + ]]> @@ -1018,15 +1027,15 @@ Calculates the hash code for the current object by using a specified computation method. A 32-bit signed integer hash code. - instance is cast to an interface. - - the method simply wraps a call to the comparer object's implementation. - - The algorithm used to compute the hash code should return the same hash code for two objects that are considered to be equal. - + instance is cast to an interface. + + the method simply wraps a call to the comparer object's implementation. + + The algorithm used to compute the hash code should return the same hash code for two objects that are considered to be equal. + ]]> @@ -1075,47 +1084,56 @@ An object to compare with the current instance. Compares the current object to a specified object and returns an integer that indicates whether the current object is before, after, or in the same position as the specified object in the sort order. - A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. - - Value - - Description - - A negative integer - - This instance precedes . - - Zero - - This instance and have the same position in the sort order. - - A positive integer - - This instance follows . - - + A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. + + Value + + + Description + + + + + A negative integer + + + This instance precedes . + + + Zero + + + This instance and have the same position in the sort order. + + + A positive integer + + + This instance follows . + + - instance is cast to an interface. - - This method provides the implementation for the class. Although the method can be called directly, it is most commonly called by the default overloads of collection-sorting methods, such as and , to order the members of a collection. - + instance is cast to an interface. + + This method provides the implementation for the class. Although the method can be called directly, it is most commonly called by the default overloads of collection-sorting methods, such as and , to order the members of a collection. + > [!CAUTION] -> The method is intended for use in sorting operations. It should not be used when the primary purpose of a comparison is to determine whether two objects are equal. To determine whether two objects are equal, call the method. - - This method uses the default object comparer to compare each component. - - - -## Examples - The following example creates an array of objects that contain population data for three cities in the United States from 1950 to 2000. The seven components consist of the city name followed by the city's population at 10-year intervals from 1950 to 2000. The example displays the components of each tuple in the array in unsorted order, sorts the array, and then calls the method to display each tuple in sorted order. The output shows that the array has been sorted by name, which is the first component. Note that the example does not directly call the method. This method is called implicitly by the method for each element in the array. - +> The method is intended for use in sorting operations. It should not be used when the primary purpose of a comparison is to determine whether two objects are equal. To determine whether two objects are equal, call the method. + + This method uses the default object comparer to compare each component. + + + +## Examples + The following example creates an array of objects that contain population data for three cities in the United States from 1950 to 2000. The seven components consist of the city name followed by the city's population at 10-year intervals from 1950 to 2000. The example displays the components of each tuple in the array in unsorted order, sorts the array, and then calls the method to display each tuple in sorted order. The output shows that the array has been sorted by name, which is the first component. Note that the example does not directly call the method. This method is called implicitly by the method for each element in the array. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3,T4,T5,T6,T7/System.Collections.IStructuralComparable.CompareTo/compareto1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3,T4,T5,T6,T7/System.Collections.IStructuralComparable.CompareTo/compareto1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`7.compareto/vb/compareto1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`7.compareto/vb/compareto1.vb" id="Snippet1"::: + ]]> @@ -1169,11 +1187,11 @@ Gets the value of the specified element. The value of the element at the specified position. - property is an explicit interface implementation. To call it, you must cast or convert the object to an interface object. - + property is an explicit interface implementation. To call it, you must cast or convert the object to an interface object. + ]]> @@ -1216,11 +1234,11 @@ Gets the number of elements in the . 7, the number of elements in a object. - property is an explicit interface implementation. To call it, you must cast or convert the object to an interface object. - + property is an explicit interface implementation. To call it, you must cast or convert the object to an interface object. + ]]> @@ -1265,20 +1283,20 @@ Returns a string that represents the value of this instance. The string representation of this object. - , , , , , , and properties, respectively. If any of the property values is `null`, it is represented as . - - - -## Examples - The following example defines a object that contains population data for New York City for each census from 1950 through 2000. The components of the sextuple are then displayed by a call to the method. - + , , , , , , and properties, respectively. If any of the property values is `null`, it is represented as . + + + +## Examples + The following example defines a object that contains population data for New York City for each census from 1950 through 2000. The components of the sextuple are then displayed by a call to the method. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3,T4,T5,T6,T7/ToString/tostring1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3,T4,T5,T6,T7/ToString/tostring1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`7.tostring/vb/tostring1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`7.tostring/vb/tostring1.vb" id="Snippet1"::: + ]]> diff --git a/xml/System/Tuple`8.xml b/xml/System/Tuple`8.xml index 468570589a8..749e1142bce 100644 --- a/xml/System/Tuple`8.xml +++ b/xml/System/Tuple`8.xml @@ -146,46 +146,46 @@ Any generic object that defines the types of the tuple's remaining components. Represents an *n*-tuple, where *n* is 8 or greater. - class represents an *n*-tuple that has eight or more components. - - You can instantiate a object with exactly eight components by calling the static method. The following example creates an 8-tuple (octuple) that contains prime numbers that are less than 20. Note that it uses type inference to determine the type of each component. - + class represents an *n*-tuple that has eight or more components. + + You can instantiate a object with exactly eight components by calling the static method. The following example creates an 8-tuple (octuple) that contains prime numbers that are less than 20. Note that it uses type inference to determine the type of each component. + :::code language="csharp" source="~/snippets/csharp/System/Tuple/Overview/createntuple.cs" interactive="try-dotnet-method" id="Snippet17"::: :::code language="fsharp" source="~/snippets/fsharp/System/Tuple/Overview/createntuple.fs" id="Snippet17"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple.create/vb/createntuple.vb" id="Snippet17"::: - You can also instantiate an n-tuple object with eight or more components by calling the constructor. The following example uses the constructor to create an 8-tuple that is equivalent to the tuple created in the previous example. - + You can also instantiate an n-tuple object with eight or more components by calling the constructor. The following example uses the constructor to create an 8-tuple that is equivalent to the tuple created in the previous example. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3,T4,T5,T6,T7,TRest/Overview/octuple1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3,T4,T5,T6,T7,TRest/Overview/octuple1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`8.class/vb/octuple1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`8.class/vb/octuple1.vb" id="Snippet1"::: + > [!NOTE] -> To create an n-tuple with nine or more components, you must call the constructor. The static factory methods of the class do not support the creation of `Tuple` objects with more than eight components. - - To instantiate an n-tuple that has eight or more components with the constructor, you supply a generic `Tuple` object as the `rest` parameter to define the eighth through *n*th components of the tuple. By nesting generic `Tuple` objects in this way, you can create a tuple that has no practical limitation on the number of its components. - - The following example creates a 17-tuple that contains population data for the city of Detroit, Michigan, for each national census from 1860 to 2000. The first component of the tuple is the city name. The second component is the start date of the data series, and the third component is the population at the start date. Each subsequent component provides the population at decade intervals. The 17-tuple is created by nesting a object inside a object. (That is, the object is supplied as the value of the `rest` parameter in the class constructor.) This object is, in turn, nested in an outer object. (That is, the object is supplied as the value of the `rest` parameter in the outer object's class constructor.) - +> To create an n-tuple with nine or more components, you must call the constructor. The static factory methods of the class do not support the creation of `Tuple` objects with more than eight components. + + To instantiate an n-tuple that has eight or more components with the constructor, you supply a generic `Tuple` object as the `rest` parameter to define the eighth through *n*th components of the tuple. By nesting generic `Tuple` objects in this way, you can create a tuple that has no practical limitation on the number of its components. + + The following example creates a 17-tuple that contains population data for the city of Detroit, Michigan, for each national census from 1860 to 2000. The first component of the tuple is the city name. The second component is the start date of the data series, and the third component is the population at the start date. Each subsequent component provides the population at decade intervals. The 17-tuple is created by nesting a object inside a object. (That is, the object is supplied as the value of the `rest` parameter in the class constructor.) This object is, in turn, nested in an outer object. (That is, the object is supplied as the value of the `rest` parameter in the outer object's class constructor.) + :::code language="csharp" source="~/snippets/csharp/System/Tuple/Overview/example.cs" id="Snippet19"::: :::code language="fsharp" source="~/snippets/fsharp/System/Tuple/Overview/example.fs" id="Snippet19"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple.create/vb/example.vb" id="Snippet19"::: - - You can retrieve the value of the tuple's first seven components by using the read-only , , , , , , and instance properties. Any additional components are nested and can be retrieved from the property. In the previous example, the through properties retrieve the first through seventh components of the tuple. The eighth through fourteenth components are contained in the tuple that is nested at the second level, and are represented by the `Rest.Item1` through `Rest.Item7` properties. The fifteenth through seventeenth components are contained in the tuple that is nested at the third level, and are represented by the `Rest.Rest.Item1` though `Rest.Rest.Item3` properties. - - Tuples are commonly used in four different ways: - -- To represent a single set of data. For example, a tuple can represent a database record, and its components can represent individual fields of the record. - -- To provide easy access to, and manipulation of, a data set. - -- To return multiple values from a method without the use of `out` parameters (in C#) or `ByRef` parameters (in Visual Basic). For example, the previous example returns its computed statistics, along with the city name, in a object. - -- To pass multiple values to a method through a single parameter. For example, the method has a single parameter that lets you supply one value to the method that the thread executes at startup. If you supply a object as the method argument, you can supply the thread's startup routine with seven items of data. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple.create/vb/example.vb" id="Snippet19"::: + + You can retrieve the value of the tuple's first seven components by using the read-only , , , , , , and instance properties. Any additional components are nested and can be retrieved from the property. In the previous example, the through properties retrieve the first through seventh components of the tuple. The eighth through fourteenth components are contained in the tuple that is nested at the second level, and are represented by the `Rest.Item1` through `Rest.Item7` properties. The fifteenth through seventeenth components are contained in the tuple that is nested at the third level, and are represented by the `Rest.Rest.Item1` though `Rest.Rest.Item3` properties. + + Tuples are commonly used in four different ways: + +- To represent a single set of data. For example, a tuple can represent a database record, and its components can represent individual fields of the record. + +- To provide easy access to, and manipulation of, a data set. + +- To return multiple values from a method without the use of `out` parameters (in C#) or `ByRef` parameters (in Visual Basic). For example, the previous example returns its computed statistics, along with the city name, in a object. + +- To pass multiple values to a method through a single parameter. For example, the method has a single parameter that lets you supply one value to the method that the thread executes at startup. If you supply a object as the method argument, you can supply the thread's startup routine with seven items of data. + ]]> @@ -251,42 +251,42 @@ Any generic object that contains the values of the tuple's remaining components. Initializes a new instance of the class. - method to instantiate an 8-tuple (octuple) object without having to explicitly specify the types of its components. The following example uses the method to instantiate an 8-tuple object that contains prime numbers that are less than 20. - + method to instantiate an 8-tuple (octuple) object without having to explicitly specify the types of its components. The following example uses the method to instantiate an 8-tuple object that contains prime numbers that are less than 20. + :::code language="csharp" source="~/snippets/csharp/System/Tuple/Overview/createntuple.cs" id="Snippet17"::: :::code language="fsharp" source="~/snippets/fsharp/System/Tuple/Overview/createntuple.fs" id="Snippet17"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple.create/vb/createntuple.vb" id="Snippet17"::: - - This is equivalent to the following call to the class constructor. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple.create/vb/createntuple.vb" id="Snippet17"::: + + This is equivalent to the following call to the class constructor. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3,T4,T5,T6,T7,TRest/Overview/octuple1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3,T4,T5,T6,T7,TRest/Overview/octuple1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`8.class/vb/octuple1.vb" id="Snippet1"::: - - However, the static method cannot be used to create a tuple object with more than eight components. - - When using the constructor to create an n-tuple with eight or more components, you use the `rest` parameter to create a nested n-tuple that has from one to seven components. By using successive levels of nesting, you can create an n-tuple that has a virtually unlimited number of components. For example, to create a 25-tuple, you instantiate a object with three levels of nesting, as follows: - -- The outermost object contains the first through seventh components. Its property provides access to an object at the first level of nesting. - -- The outermost nested object contains the eighth through fourteenth components, and its property provides access to an object at the second level of nesting. - -- The object at the second level of nesting contains the fifteenth through twenty-first components, and its property provides access to an object at the third level of nesting. - -- The innermost tuple is a object that contains the twenty-second through twenty-fifth components. - - - -## Examples - The following example creates a 17-tuple that contains population data for the city of Detroit, Michigan, for each census from 1860 to 2000. The first component of the tuple is the city name. The second component is the start date of the series of data, and the third component is the population at the start date. Each subsequent component provides the population at decade intervals. The example uses two layers of nesting to create the 17-tuple: It defines a 7-tuple whose third through seventh components contain population data for 1860 through 1900, a nested 7-tuple that contains population data for 1910 through 1970, and an inner nested 3-tuple that contains population data for 1980 through 2000. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`8.class/vb/octuple1.vb" id="Snippet1"::: + + However, the static method cannot be used to create a tuple object with more than eight components. + + When using the constructor to create an n-tuple with eight or more components, you use the `rest` parameter to create a nested n-tuple that has from one to seven components. By using successive levels of nesting, you can create an n-tuple that has a virtually unlimited number of components. For example, to create a 25-tuple, you instantiate a object with three levels of nesting, as follows: + +- The outermost object contains the first through seventh components. Its property provides access to an object at the first level of nesting. + +- The outermost nested object contains the eighth through fourteenth components, and its property provides access to an object at the second level of nesting. + +- The object at the second level of nesting contains the fifteenth through twenty-first components, and its property provides access to an object at the third level of nesting. + +- The innermost tuple is a object that contains the twenty-second through twenty-fifth components. + + + +## Examples + The following example creates a 17-tuple that contains population data for the city of Detroit, Michigan, for each census from 1860 to 2000. The first component of the tuple is the city name. The second component is the start date of the series of data, and the third component is the population at the start date. Each subsequent component provides the population at decade intervals. The example uses two layers of nesting to create the 17-tuple: It defines a 7-tuple whose third through seventh components contain population data for 1860 through 1900, a nested 7-tuple that contains population data for 1910 through 1970, and an inner nested 3-tuple that contains population data for 1980 through 2000. + :::code language="csharp" source="~/snippets/csharp/System/Tuple/Overview/example.cs" id="Snippet19"::: :::code language="fsharp" source="~/snippets/fsharp/System/Tuple/Overview/example.fs" id="Snippet19"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple.create/vb/example.vb" id="Snippet19"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple.create/vb/example.vb" id="Snippet19"::: + ]]> @@ -352,26 +352,26 @@ if the current instance is equal to the specified object; otherwise, . - object. - -- It has the same total number of components that are of the same types as the current instance. - -- Its components (including its nested components) are equal to those of the current instance. Equality is determined by the default equality comparer for each component. - - - -## Examples - The following example defines five objects that contain prime numbers. It then compares the first object with each of the remaining objects. As the output shows, only the first and the last objects are equal, because they have an identical number of components with identical values. - + object. + +- It has the same total number of components that are of the same types as the current instance. + +- Its components (including its nested components) are equal to those of the current instance. Equality is determined by the default equality comparer for each component. + + + +## Examples + The following example defines five objects that contain prime numbers. It then compares the first object with each of the remaining objects. As the output shows, only the first and the last objects are equal, because they have an identical number of components with identical values. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3,T4,T5,T6,T7,TRest/Equals/equals1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3,T4,T5,T6,T7,TRest/Equals/equals1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`8.equals/vb/equals1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`8.equals/vb/equals1.vb" id="Snippet1"::: + ]]> @@ -457,24 +457,24 @@ Gets the value of the current object's first component. The value of the current object's first component. - component in one of two ways: - -- By calling the `GetType` method on the value that is returned by the property. - -- By retrieving the object that represents the object, and retrieving the first element from the array that is returned by its method. - - - -## Examples - The following example creates a 17-tuple object that contains population data for the city of Detroit, Michigan, from 1860 to 2000. The first component of the 17-tuple is the city name. The example uses the property to display the city name in the table header before displaying the population data. - + component in one of two ways: + +- By calling the `GetType` method on the value that is returned by the property. + +- By retrieving the object that represents the object, and retrieving the first element from the array that is returned by its method. + + + +## Examples + The following example creates a 17-tuple object that contains population data for the city of Detroit, Michigan, from 1860 to 2000. The first component of the 17-tuple is the city name. The example uses the property to display the city name in the table header before displaying the population data. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3,T4,T5,T6,T7,TRest/Item1/item1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3,T4,T5,T6,T7,TRest/Item1/item1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`8.item1/vb/item1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`8.item1/vb/item1.vb" id="Snippet1"::: + ]]> @@ -518,24 +518,24 @@ Gets the value of the current object's second component. The value of the current object's second component. - component in one of two ways: - -- By calling the `GetType` method on the value that is returned by the property. - -- By retrieving the object that represents the object, and retrieving the second element from the array that is returned by its method. - - - -## Examples - The following example creates a 17-tuple object that contains population data for the city of Detroit, Michigan, from 1860 to 2000. The second component of the 17-tuple is the first year of the data series. The example assigns the value of the property to a variable, and then uses that variable to represent the year whose data is displayed. - + component in one of two ways: + +- By calling the `GetType` method on the value that is returned by the property. + +- By retrieving the object that represents the object, and retrieving the second element from the array that is returned by its method. + + + +## Examples + The following example creates a 17-tuple object that contains population data for the city of Detroit, Michigan, from 1860 to 2000. The second component of the 17-tuple is the first year of the data series. The example assigns the value of the property to a variable, and then uses that variable to represent the year whose data is displayed. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3,T4,T5,T6,T7,TRest/Item1/item1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3,T4,T5,T6,T7,TRest/Item1/item1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`8.item1/vb/item1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`8.item1/vb/item1.vb" id="Snippet1"::: + ]]> @@ -579,24 +579,24 @@ Gets the value of the current object's third component. The value of the current object's third component. - component in one of two ways: - -- By calling the `GetType` method on the value that is returned by the property. - -- By retrieving the object that represents the object, and retrieving the third element from the array that is returned by its method. - - - -## Examples - The following example creates a 17-tuple object that contains population data for the city of Detroit, Michigan, from 1860 to 2000. The third component of the 17-tuple is the population in 1860. The example uses the property to display the population value and to calculate the annual rate of population change between 1860 and 1870. - + component in one of two ways: + +- By calling the `GetType` method on the value that is returned by the property. + +- By retrieving the object that represents the object, and retrieving the third element from the array that is returned by its method. + + + +## Examples + The following example creates a 17-tuple object that contains population data for the city of Detroit, Michigan, from 1860 to 2000. The third component of the 17-tuple is the population in 1860. The example uses the property to display the population value and to calculate the annual rate of population change between 1860 and 1870. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3,T4,T5,T6,T7,TRest/Item1/item1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3,T4,T5,T6,T7,TRest/Item1/item1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`8.item1/vb/item1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`8.item1/vb/item1.vb" id="Snippet1"::: + ]]> @@ -640,24 +640,24 @@ Gets the value of the current object's fourth component. The value of the current object's fourth component. - component in one of two ways: - -- By calling the `GetType` method on the value that is returned by the property. - -- By retrieving the object that represents the object, and retrieving the fourth element from the array that is returned by its method. - - - -## Examples - The following example creates a 17-tuple object that contains population data for the city of Detroit, Michigan, from 1860 to 2000. The fourth component of the 17-tuple is the population in 1870. The example uses the property to display the population value and to calculate the annual rate of population change between 1870 and 1880. - + component in one of two ways: + +- By calling the `GetType` method on the value that is returned by the property. + +- By retrieving the object that represents the object, and retrieving the fourth element from the array that is returned by its method. + + + +## Examples + The following example creates a 17-tuple object that contains population data for the city of Detroit, Michigan, from 1860 to 2000. The fourth component of the 17-tuple is the population in 1870. The example uses the property to display the population value and to calculate the annual rate of population change between 1870 and 1880. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3,T4,T5,T6,T7,TRest/Item1/item1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3,T4,T5,T6,T7,TRest/Item1/item1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`8.item1/vb/item1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`8.item1/vb/item1.vb" id="Snippet1"::: + ]]> @@ -701,24 +701,24 @@ Gets the value of the current object's fifth component. The value of the current object's fifth component. - component in one of two ways: - -- By calling the `GetType` method on the value that is returned by the property. - -- By retrieving the object that represents the object, and retrieving the fifth element from the array that is returned by its method. - - - -## Examples - The following example creates a 17-tuple object that contains population data for the city of Detroit, Michigan, from 1860 to 2000. The fifth component of the 17-tuple is the population in 1880. The example uses the property to display the population value and to calculate the annual rate of population change between 1880 and 1890. - + component in one of two ways: + +- By calling the `GetType` method on the value that is returned by the property. + +- By retrieving the object that represents the object, and retrieving the fifth element from the array that is returned by its method. + + + +## Examples + The following example creates a 17-tuple object that contains population data for the city of Detroit, Michigan, from 1860 to 2000. The fifth component of the 17-tuple is the population in 1880. The example uses the property to display the population value and to calculate the annual rate of population change between 1880 and 1890. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3,T4,T5,T6,T7,TRest/Item1/item1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3,T4,T5,T6,T7,TRest/Item1/item1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`8.item1/vb/item1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`8.item1/vb/item1.vb" id="Snippet1"::: + ]]> @@ -762,24 +762,24 @@ Gets the value of the current object's sixth component. The value of the current object's sixth component. - component in one of two ways: - -- By calling the `GetType` method on the value that is returned by the property. - -- By retrieving the object that represents the object, and retrieving the sixth element from the array that is returned by its method. - - - -## Examples - The following example creates a 17-tuple object that contains population data for the city of Detroit, Michigan, from 1860 to 2000. The sixth component of the 17-tuple is the population in 1890. The example uses the property to display the population value and to calculate the annual rate of population change between 1890 and 1900. - + component in one of two ways: + +- By calling the `GetType` method on the value that is returned by the property. + +- By retrieving the object that represents the object, and retrieving the sixth element from the array that is returned by its method. + + + +## Examples + The following example creates a 17-tuple object that contains population data for the city of Detroit, Michigan, from 1860 to 2000. The sixth component of the 17-tuple is the population in 1890. The example uses the property to display the population value and to calculate the annual rate of population change between 1890 and 1900. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3,T4,T5,T6,T7,TRest/Item1/item1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3,T4,T5,T6,T7,TRest/Item1/item1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`8.item1/vb/item1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`8.item1/vb/item1.vb" id="Snippet1"::: + ]]> @@ -823,24 +823,24 @@ Gets the value of the current object's seventh component. The value of the current object's seventh component. - component in one of two ways: - -- By calling the `GetType` method on the value that is returned by the property. - -- By retrieving the object that represents the object, and retrieving the seventh element from the array that is returned by its method. - - - -## Examples - The following example creates a 17-tuple object that contains population data for the city of Detroit, Michigan, from 1860 to 2000. The seventh component of the 17-tuple is the population in 1900. The example uses the property to display the population value and to calculate the annual rate of population change between 1900 and 1910. - + component in one of two ways: + +- By calling the `GetType` method on the value that is returned by the property. + +- By retrieving the object that represents the object, and retrieving the seventh element from the array that is returned by its method. + + + +## Examples + The following example creates a 17-tuple object that contains population data for the city of Detroit, Michigan, from 1860 to 2000. The seventh component of the 17-tuple is the population in 1900. The example uses the property to display the population value and to calculate the annual rate of population change between 1900 and 1910. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3,T4,T5,T6,T7,TRest/Item1/item1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3,T4,T5,T6,T7,TRest/Item1/item1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`8.item1/vb/item1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`8.item1/vb/item1.vb" id="Snippet1"::: + ]]> @@ -884,24 +884,24 @@ Gets the current object's remaining components. The value of the current object's remaining components. - property returns a nested `Tuple` object that allows access to the eighth though *n*th components of the tuple. Depending on the total number of components in the tuple, the values of the eighth through fourteenth components can be retrieved from the nested `Tuple` object's through properties. You can then use the property of a nested object to retrieve the `Tuple` object at the next level of nesting. - - You can dynamically determine the number of components in a nested `Tuple` object that is returned by the property by extracting the digit from its type name. The following example provides an illustration. - - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`8.item1/vb/rest.vb" id="Snippet2"::: - - - -## Examples - The following example creates a 17-tuple object that contains population data for the city of Detroit, Michigan, from 1860 to 2000. The seventh component of the 17-tuple is the population in 1900. The example uses the property to retrieve the values of the eighth through fourteenth components, and it uses the property of the nested object to retrieve the values of the remaining components. - + property returns a nested `Tuple` object that allows access to the eighth though *n*th components of the tuple. Depending on the total number of components in the tuple, the values of the eighth through fourteenth components can be retrieved from the nested `Tuple` object's through properties. You can then use the property of a nested object to retrieve the `Tuple` object at the next level of nesting. + + You can dynamically determine the number of components in a nested `Tuple` object that is returned by the property by extracting the digit from its type name. The following example provides an illustration. + + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`8.item1/vb/rest.vb" id="Snippet2"::: + + + +## Examples + The following example creates a 17-tuple object that contains population data for the city of Detroit, Michigan, from 1860 to 2000. The seventh component of the 17-tuple is the population in 1900. The example uses the property to retrieve the values of the eighth through fourteenth components, and it uses the property of the nested object to retrieve the values of the remaining components. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3,T4,T5,T6,T7,TRest/Item1/item1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3,T4,T5,T6,T7,TRest/Item1/item1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`8.item1/vb/item1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`8.item1/vb/item1.vb" id="Snippet1"::: + ]]> @@ -952,51 +952,60 @@ An object to compare with the current instance. An object that provides custom rules for comparison. Compares the current object to a specified object by using a specified comparer and returns an integer that indicates whether the current object is before, after, or in the same position as the specified object in the sort order. - A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. - - Value - - Description - - A negative integer - - This instance precedes . - - Zero - - This instance and have the same position in the sort order. - - A positive integer - - This instance follows . - - + A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. + + Value + + + Description + + + + + A negative integer + + + This instance precedes . + + + Zero + + + This instance and have the same position in the sort order. + + + A positive integer + + + This instance follows . + + - instance is cast to an interface. - - This method lets you define customized comparisons of objects. For example, you can use this method to order objects based on the value of a specific component. - - Although this method can be called directly, it is most commonly called by collection-sorting methods that include parameters to order the members of a collection. For example, it is called by the method and the method of a object that is instantiated by using the constructor. - + instance is cast to an interface. + + This method lets you define customized comparisons of objects. For example, you can use this method to order objects based on the value of a specific component. + + Although this method can be called directly, it is most commonly called by collection-sorting methods that include parameters to order the members of a collection. For example, it is called by the method and the method of a object that is instantiated by using the constructor. + > [!CAUTION] -> The method is intended for use in sorting operations. It should not be used when the primary purpose of a comparison is to determine whether two objects are equal. To determine whether two objects are equal, call the method. - - - -## Examples - The following example creates an array of objects that contains population data for four U.S. cities from 1940 to 2000. The octuple's first component is the city name. The remaining six components represent the population at 10-year intervals from 1940 to 2000. - - The `PopulationComparer` class provides an implementation that allows the array of octuples to be sorted by any one of its components. Two values are provided to the `PopulationComparer` class in its constructor: The position of the component that defines the sort order, and a value that indicates whether the tuple objects should be sorted in ascending or descending order. - - The example then displays the elements in the array in unsorted order, sorts them by the third component (the population in 1950) and displays them, and then sorts them by the eighth component (the population in 2000) and displays them. - +> The method is intended for use in sorting operations. It should not be used when the primary purpose of a comparison is to determine whether two objects are equal. To determine whether two objects are equal, call the method. + + + +## Examples + The following example creates an array of objects that contains population data for four U.S. cities from 1940 to 2000. The octuple's first component is the city name. The remaining six components represent the population at 10-year intervals from 1940 to 2000. + + The `PopulationComparer` class provides an implementation that allows the array of octuples to be sorted by any one of its components. Two values are provided to the `PopulationComparer` class in its constructor: The position of the component that defines the sort order, and a value that indicates whether the tuple objects should be sorted in ascending or descending order. + + The example then displays the elements in the array in unsorted order, sorts them by the third component (the population in 1950) and displays them, and then sorts them by the eighth component (the population in 2000) and displays them. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3,T4,T5,T6,T7,TRest/System.Collections.IStructuralComparable.CompareTo/compareto2.cs" interactive="try-dotnet" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3,T4,T5,T6,T7,TRest/System.Collections.IStructuralComparable.CompareTo/compareto2.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`8.compareto/vb/compareto2.vb" id="Snippet2"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`8.compareto/vb/compareto2.vb" id="Snippet2"::: + ]]> @@ -1059,13 +1068,13 @@ if the current instance is equal to the specified object; otherwise, . - instance is cast to an interface. - - The implementation is called only if `other` is not `null`, and if it can be successfully cast (in C#) or converted (in Visual Basic) to a object that has the same total number of components (including those in nested `Tuple` objects) of the same types as the current instance. The method first passes the values of the objects to be compared to the implementation. If this method call returns `true`, the method is called again and passed the values of the two objects. This continues until the method call returns `false` when it compares a specific pair of values, or the two values are passed to the method. - + instance is cast to an interface. + + The implementation is called only if `other` is not `null`, and if it can be successfully cast (in C#) or converted (in Visual Basic) to a object that has the same total number of components (including those in nested `Tuple` objects) of the same types as the current instance. The method first passes the values of the objects to be compared to the implementation. If this method call returns `true`, the method is called again and passed the values of the two objects. This continues until the method call returns `false` when it compares a specific pair of values, or the two values are passed to the method. + ]]> @@ -1116,15 +1125,15 @@ Calculates the hash code for the current object by using a specified computation method. A 32-bit signed integer hash code. - instance is cast to an interface. - - The method simply wraps a call to the `comparer` object's implementation. - - The algorithm used to compute the hash code should return the same hash code for two objects that are considered to be equal. - + instance is cast to an interface. + + The method simply wraps a call to the `comparer` object's implementation. + + The algorithm used to compute the hash code should return the same hash code for two objects that are considered to be equal. + ]]> @@ -1173,47 +1182,56 @@ An object to compare with the current instance. Compares the current object to a specified object and returns an integer that indicates whether the current object is before, after, or in the same position as the specified object in the sort order. - A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. - - Value - - Description - - A negative integer - - This instance precedes . - - Zero - - This instance and have the same position in the sort order. - - A positive integer - - This instance follows . - - + A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. + + Value + + + Description + + + + + A negative integer + + + This instance precedes . + + + Zero + + + This instance and have the same position in the sort order. + + + A positive integer + + + This instance follows . + + - instance is cast to an interface. - - This method provides the implementation for the class. Although the method can be called directly, it is most commonly called by the default overloads of collection-sorting methods, such as and , to order the members of a collection. - + instance is cast to an interface. + + This method provides the implementation for the class. Although the method can be called directly, it is most commonly called by the default overloads of collection-sorting methods, such as and , to order the members of a collection. + > [!CAUTION] -> The method is intended for use in sorting operations. It should not be used when the primary purpose of a comparison is to determine whether two objects are equal. To determine whether two objects are equal, call the method. - - This method uses the default object comparer to compare each component. - - - -## Examples - The following example creates an array of octuples whose components are integers that contain a range of prime numbers. The example displays the elements of the array in unsorted order, sorts the array, and then displays the array in sorted order. The output shows that the array has been sorted by , or the tuple's first component. Note that the example does not directly call the method. This method is called implicitly by the method for each element in the array. - +> The method is intended for use in sorting operations. It should not be used when the primary purpose of a comparison is to determine whether two objects are equal. To determine whether two objects are equal, call the method. + + This method uses the default object comparer to compare each component. + + + +## Examples + The following example creates an array of octuples whose components are integers that contain a range of prime numbers. The example displays the elements of the array in unsorted order, sorts the array, and then displays the array in sorted order. The output shows that the array has been sorted by , or the tuple's first component. Note that the example does not directly call the method. This method is called implicitly by the method for each element in the array. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3,T4,T5,T6,T7,TRest/System.Collections.IStructuralComparable.CompareTo/compareto1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3,T4,T5,T6,T7,TRest/System.Collections.IStructuralComparable.CompareTo/compareto1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`8.compareto/vb/compareto1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`8.compareto/vb/compareto1.vb" id="Snippet1"::: + ]]> @@ -1267,19 +1285,19 @@ Gets the value of the specified element. The value of the element at the specified position. - property is an explicit interface implementation. To call it, you must cast or convert the object to an interface object. - + property is an explicit interface implementation. To call it, you must cast or convert the object to an interface object. + ]]> - is less than 0. - - -or- - - is greater than or equal to . + is less than 0. + +-or- + + is greater than or equal to . @@ -1318,11 +1336,11 @@ Gets the number of elements in the . The number of elements in the . - property is an explicit interface implementation. To call it, you must cast or convert the type to an interface object. - + property is an explicit interface implementation. To call it, you must cast or convert the type to an interface object. + ]]> @@ -1367,20 +1385,20 @@ Returns a string that represents the value of this instance. The string representation of this object. - , , , , , , and properties. *Item8* represents the value of the object's `Next.Item1` property. The value of any additional nested components follow *Item8*. If any of the property values is `null`, it is represented as . - - - -## Examples - The following example creates a 17-tuple that contains population data for the city of Detroit, Michigan, from 1860 to 1900. It then uses the method to display the tuple's data. - + , , , , , , and properties. *Item8* represents the value of the object's `Next.Item1` property. The value of any additional nested components follow *Item8*. If any of the property values is `null`, it is represented as . + + + +## Examples + The following example creates a 17-tuple that contains population data for the city of Detroit, Michigan, from 1860 to 1900. It then uses the method to display the tuple's data. + :::code language="csharp" source="~/snippets/csharp/System/TupleT1,T2,T3,T4,T5,T6,T7,TRest/ToString/tostring1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TupleT1,T2,T3,T4,T5,T6,T7,TRest/ToString/tostring1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`8.tostring/vb/tostring1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.tuple`8.tostring/vb/tostring1.vb" id="Snippet1"::: + ]]> diff --git a/xml/System/Type.xml b/xml/System/Type.xml index 3f2acfe77a4..5f0c8b2d0f6 100644 --- a/xml/System/Type.xml +++ b/xml/System/Type.xml @@ -201,79 +201,7 @@ This type is thread safe. - When you inherit from , you must override the following members: - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- - -- + When you inherit from , you must override the following members: - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1159,14 +1087,10 @@ TopNamespace.Sub\+Namespace.ContainingClass+NestedClass, MyAssembly, Version=1.3 - The object whose underlying system type is to be compared with the underlying system type of the current . For the comparison to succeed, must be able to be cast or converted to an object of type . + The object whose underlying system type is to be compared with the underlying system type of the current . For the comparison to succeed, must be able to be cast or converted to an object of type . Determines if the underlying system type of the current object is the same as the underlying system type of the specified . - if the underlying system type of is the same as the underlying system type of the current ; otherwise, . This method also returns if: - -- is . - -- cannot be cast or converted to a object. + if the underlying system type of is the same as the underlying system type of the current ; otherwise, . This method also returns if: - is . - cannot be cast or converted to a object. A bitwise combination of the enumeration values that indicates the type of member to search for. A bitwise combination of the enumeration values that specify how the search is conducted. - -or- +-or- - to return . + to return . The delegate that does the comparisons, returning if the member currently being inspected matches the and otherwise. - The search criteria that determines whether a member is returned in the array of objects. - - The fields of , , and can be used in conjunction with the delegate supplied by this class. + The search criteria that determines whether a member is returned in the array of objects. The fields of , , and can be used in conjunction with the delegate supplied by this class. Returns a filtered array of objects of the specified member type. A filtered array of objects of the specified member type. - -or- +-or- - An empty array if the current does not have members of type that match the filter criteria. +An empty array if the current does not have members of type that match the filter criteria. An array of objects representing the number, order, and type of the parameters for the desired constructor. - -or- +-or- - An empty array of objects, to get a constructor that takes no parameters. Such an empty array is provided by the field . +An empty array of objects, to get a constructor that takes no parameters. Such an empty array is provided by the field . Searches for a public instance constructor whose parameters match the types in the specified array. An object representing the public instance constructor whose parameters match the types in the parameter type array, if found; otherwise, . @@ -2204,9 +2126,9 @@ The `filter` argument can be a custom delegate of type is . - -or- +-or- - One of the elements in is . +One of the elements in is . is multidimensional. @@ -2250,10 +2172,19 @@ The `filter` argument can be a custom delegate of type A bitwise combination of the enumeration values that specify how the search is conducted. - -or- Default to return . + +-or- + +Default to return . An array of Type objects representing the number, order, and type of the parameters for the constructor to get. - -or- An empty array of the type (that is, Type[] types = Array.Empty{Type}()) to get a constructor that takes no parameters. - -or- . + +-or- + +An empty array of the type (that is, Type[] types = Array.Empty{Type}()) to get a constructor that takes no parameters. + +-or- + +. Searches for a constructor whose parameters match the specified argument types, using the specified binding constraints. A object representing the constructor that matches the specified requirements, if found; otherwise, . To be added. @@ -2329,23 +2260,23 @@ The `filter` argument can be a custom delegate of type A bitwise combination of the enumeration values that specify how the search is conducted. - -or- +-or- - to return . + to return . An object that defines a set of properties and enables binding, which can involve selection of an overloaded method, coercion of argument types, and invocation of a member through reflection. - -or- +-or- - A null reference ( in Visual Basic), to use the . +A null reference ( in Visual Basic), to use the . An array of objects representing the number, order, and type of the parameters for the constructor to get. - -or- +-or- - An empty array of the type (that is, Type[] types = new Type[0]) to get a constructor that takes no parameters. +An empty array of the type (that is, Type[] types = new Type[0]) to get a constructor that takes no parameters. - -or- +-or- - . +. An array of objects representing the attributes associated with the corresponding element in the parameter type array. The default binder does not process this parameter. Searches for a constructor whose parameters match the specified argument types and modifiers, using the specified binding constraints. A object representing the constructor that matches the specified requirements, if found; otherwise, . @@ -2385,19 +2316,19 @@ The `filter` argument can be a custom delegate of type is . - -or- +-or- - One of the elements in is . +One of the elements in is . is multidimensional. - -or- +-or- - is multidimensional. + is multidimensional. - -or- +-or- - and do not have the same length. + and do not have the same length. @@ -2478,20 +2409,20 @@ The `filter` argument can be a custom delegate of type A bitwise combination of the enumeration values that specify how the search is conducted. - -or- +-or- - to return . + to return . An object that defines a set of properties and enables binding, which can involve selection of an overloaded method, coercion of argument types, and invocation of a member through reflection. - -or- +-or- - A null reference ( in Visual Basic), to use the . +A null reference ( in Visual Basic), to use the . The object that specifies the set of rules to use regarding the order and layout of arguments, how the return value is passed, what registers are used for arguments, and the stack is cleaned up. An array of objects representing the number, order, and type of the parameters for the constructor to get. - -or- +-or- - An empty array of the type (that is, Type[] types = new Type[0]) to get a constructor that takes no parameters. +An empty array of the type (that is, Type[] types = new Type[0]) to get a constructor that takes no parameters. An array of objects representing the attributes associated with the corresponding element in the array. The default binder does not process this parameter. Searches for a constructor whose parameters match the specified argument types and modifiers, using the specified binding constraints and the specified calling convention. An object representing the constructor that matches the specified requirements, if found; otherwise, . @@ -2550,19 +2481,19 @@ The `filter` argument can be a custom delegate of type is . - -or- +-or- - One of the elements in is . +One of the elements in is . is multidimensional. - -or- +-or- - is multidimensional. + is multidimensional. - -or- +-or- - and do not have the same length. + and do not have the same length. @@ -2634,20 +2565,20 @@ The `filter` argument can be a custom delegate of type A bitwise combination of the enumeration values that specify how the search is conducted. - -or- +-or- to return . An object that defines a set of properties and enables binding, which can involve selection of an overloaded method, coercion of argument types, and invocation of a member through reflection. - -or- +-or- - A null reference ( in Visual Basic), to use the . +A null reference ( in Visual Basic), to use the . The object that specifies the set of rules to use regarding the order and layout of arguments, how the return value is passed, what registers are used for arguments, and the stack is cleaned up. An array of objects representing the number, order, and type of the parameters for the constructor to get. - -or- +-or- - An empty array of the type (that is, Type[] types = new Type[0]) to get a constructor that takes no parameters. +An empty array of the type (that is, Type[] types = new Type[0]) to get a constructor that takes no parameters. An array of objects representing the attributes associated with the corresponding element in the array. The default binder does not process this parameter. When overridden in a derived class, searches for a constructor whose parameters match the specified argument types and modifiers, using the specified binding constraints and the specified calling convention. A object representing the constructor that matches the specified requirements, if found; otherwise, . @@ -2676,19 +2607,19 @@ The `filter` argument can be a custom delegate of type is . - -or- +-or- - One of the elements in is . +One of the elements in is . is multidimensional. - -or- +-or- - is multidimensional. + is multidimensional. - -or- +-or- - and do not have the same length. + and do not have the same length. The current type is a or . @@ -2975,9 +2906,9 @@ If the current represents a generic type parameter, the Searches for the members defined for the current whose is set. An array of objects representing all default members of the current . - -or- +-or- - An empty array of type , if the current does not have default members. +An empty array of type , if the current does not have default members. represents a generic type parameter, the To be added. The current type is not an enumeration. - -or- +-or- - is neither of the current type nor does it have the same underlying type as the current type. + is neither of the current type nor does it have the same underlying type as the current type. is . @@ -3240,9 +3171,9 @@ If the current represents a generic type parameter, the The current type is not an enumeration. - -or- + -or- - The enumeration type is not valid, because it contains more than one instance field. + The enumeration type is not valid, because it contains more than one instance field. @@ -3320,10 +3251,7 @@ If the current represents a generic type parameter, the Retrieves an array of the values of the underlying type constants of this enumeration type. An array that contains the values of the underlying type constants in this enumeration type. - - You can use this method to get enumeration values when it's hard to create an array of the enumeration type. - For example, you might use this method for the enumeration or on a platform where run-time code generation is not available. - + You can use this method to get enumeration values when it's hard to create an array of the enumeration type. For example, you might use this method for the enumeration or on a platform where run-time code generation is not available. This type is not an enumeration type. @@ -3490,9 +3418,9 @@ If the current represents a generic type parameter, the The string containing the name of an event which is declared or inherited by the current . A bitwise combination of the enumeration values that specify how the search is conducted. - -or- +-or- - to return . + to return . When overridden in a derived class, returns the object representing the specified event, using the specified binding constraints. The object representing the specified event that is declared or inherited by the current , if found; otherwise, . @@ -3601,9 +3529,9 @@ If the current represents a generic type parameter, the Returns all the public events that are declared or inherited by the current . An array of objects representing all the public events which are declared or inherited by the current . - -or- +-or- - An empty array of type , if the current does not have public events. +An empty array of type , if the current does not have public events. represents a generic type parameter, the to return an empty array. + to return an empty array. When overridden in a derived class, searches for events that are declared or inherited by the current , using the specified binding constraints. An array of objects representing all events that are declared or inherited by the current that match the specified binding constraints. - -or- +-or- - An empty array of type , if the current does not have events, or if none of the events match the binding constraints. +An empty array of type , if the current does not have events, or if none of the events match the binding constraints. represents a generic type parameter, the The string containing the name of the data field to get. A bitwise combination of the enumeration values that specify how the search is conducted. - -or- +-or- - to return . + to return . Searches for the specified field, using the specified binding constraints. An object representing the field that matches the specified requirements, if found; otherwise, . @@ -4033,9 +3961,9 @@ If the current represents a generic type parameter, the Returns all the public fields of the current . An array of objects representing all the public fields defined for the current . - -or- +-or- - An empty array of type , if no public fields are defined for the current . +An empty array of type , if no public fields are defined for the current . represents a generic type parameter, the to return an empty array. + to return an empty array. When overridden in a derived class, searches for the fields defined for the current , using the specified binding constraints. An array of objects representing all fields defined for the current that match the specified binding constraints. - -or- +-or- - An empty array of type , if no fields are defined for the current , or if none of the defined fields match the binding constraints. +An empty array of type , if no fields are defined for the current , or if none of the defined fields match the binding constraints. method does ]]> - The current type is not a generic type. That is, returns . + The current type is not a generic type. That is, returns . The invoked method is not supported in the base class. Derived classes must provide an implementation. @@ -4723,9 +4651,9 @@ In .NET 6 and earlier versions, the method does to ignore the case of that part of that specifies the simple interface name (the part that specifies the namespace must be correctly cased). - -or- +-or- - to perform a case-sensitive search for all parts of . + to perform a case-sensitive search for all parts of . When overridden in a derived class, searches for the specified interface, specifying whether to do a case-insensitive search for the interface name. An object representing the interface with the specified name, implemented or inherited by the current , if found; otherwise, . @@ -4851,8 +4779,7 @@ The current instance or argument is an open ge -or- - - is a generic interface, and the current type is an array type. + is a generic interface, and the current type is an array type. is . The current represents a generic type parameter; that is, is . @@ -4907,9 +4834,9 @@ The current instance or argument is an open ge When overridden in a derived class, gets all the interfaces implemented or inherited by the current . An array of objects representing all the interfaces implemented or inherited by the current . - -or- +-or- - An empty array of type , if no interfaces are implemented or inherited by the current . +An empty array of type , if no interfaces are implemented or inherited by the current . argument is an open ge The string containing the name of the members to get. A bitwise combination of the enumeration values that specify how the search is conducted. - -or- +-or- - to return an empty array. + to return an empty array. Searches for the specified members, using the specified binding constraints. An array of objects representing the public members with the specified name, if found; otherwise, an empty array. @@ -5235,9 +5162,9 @@ The current instance or argument is an open ge The value to search for. A bitwise combination of the enumeration values that specify how the search is conducted. - -or- +-or- - to return an empty array. + to return an empty array. Searches for the specified members of the specified member type, using the specified binding constraints. An array of objects representing the public members with the specified name, if found; otherwise, an empty array. @@ -5363,9 +5290,9 @@ The current instance or argument is an open ge Returns all the public members of the current . An array of objects representing all the public members of the current . - -or- +-or- - An empty array of type , if the current does not have public members. +An empty array of type , if the current does not have public members. A bitwise combination of the enumeration values that specify how the search is conducted. - -or- +-or- - to return an empty array. + to return an empty array. When overridden in a derived class, searches for the members defined for the current , using the specified binding constraints. An array of objects representing all members defined for the current that match the specified binding constraints. - -or- +-or- - An empty array if no members are defined for the current , or if none of the defined members match the binding constraints. +An empty array if no members are defined for the current , or if none of the defined members match the binding constraints. The string containing the name of the method to get. A bitwise combination of the enumeration values that specify how the search is conducted. - -or- +-or- - to return . + to return . Searches for the specified method, using the specified binding constraints. An object representing the method that matches the specified requirements, if found; otherwise, . @@ -5869,9 +5796,9 @@ This method can be used to find a constructed generic member given a member from The string containing the name of the public method to get. An array of objects representing the number, order, and type of the parameters for the method to get. - -or- +-or- - An empty array of objects (as provided by the field) to get a method that takes no parameters. +An empty array of objects (as provided by the field) to get a method that takes no parameters. Searches for the specified public method whose parameters match the specified argument types. An object representing the public method whose parameters match the specified argument types, if found; otherwise, . @@ -5917,13 +5844,13 @@ This method can be used to find a constructed generic member given a member from is . - -or- +-or- - is . + is . - -or- +-or- - One of the elements in is . +One of the elements in is . is multidimensional. @@ -5991,8 +5918,7 @@ An empty array of objects (as provided by the array is . - +One of the elements in the array is . is negative. @@ -6034,9 +5960,15 @@ One of the elements in the array is The string containing the name of the method to get. A bitwise combination of the enumeration values that specify how the search is conducted. - -or- Default to return . + +-or- + +Default to return . An array of objects representing the number, order, and type of the parameters for the method to get. - -or- An empty array of objects (as provided by the field) to get a method that takes no parameters. + +-or- + +An empty array of objects (as provided by the field) to get a method that takes no parameters. Searches for the specified method whose parameters match the specified argument types, using the specified binding constraints. An object representing the method that matches the specified requirements, if found; otherwise, . To be added. @@ -6104,9 +6036,9 @@ One of the elements in the array is The string containing the name of the public method to get. An array of objects representing the number, order, and type of the parameters for the method to get. - -or- +-or- - An empty array of objects (as provided by the field) to get a method that takes no parameters. +An empty array of objects (as provided by the field) to get a method that takes no parameters. An array of objects representing the attributes associated with the corresponding element in the array. To be only used when calling through COM interop, and only parameters that are passed by reference are handled. The default binder does not process this parameter. Searches for the specified public method whose parameters match the specified argument types and modifiers. An object representing the public method that matches the specified requirements, if found; otherwise, . @@ -6134,19 +6066,19 @@ One of the elements in the array is is . - -or- +-or- - is . + is . - -or- +-or- - One of the elements in is . +One of the elements in is . is multidimensional. - -or- +-or- - is multidimensional. + is multidimensional. @@ -6223,8 +6155,7 @@ An empty array of objects (as provided by the array is . - +One of the elements in the array is . is negative. @@ -6302,19 +6233,19 @@ One of the elements in the array is The string containing the name of the method to get. A bitwise combination of the enumeration values that specify how the search is conducted. - -or- +-or- - to return . + to return . An object that defines a set of properties and enables binding, which can involve selection of an overloaded method, coercion of argument types, and invocation of a member through reflection. - -or- +-or- - A null reference ( in Visual Basic), to use the . +A null reference ( in Visual Basic), to use the . An array of objects representing the number, order, and type of the parameters for the method to get. - -or- +-or- - An empty array of objects (as provided by the field) to get a method that takes no parameters. +An empty array of objects (as provided by the field) to get a method that takes no parameters. An array of objects representing the attributes associated with the corresponding element in the array. To be only used when calling through COM interop, and only parameters that are passed by reference are handled. The default binder does not process this parameter. Searches for the specified method whose parameters match the specified argument types and modifiers, using the specified binding constraints. An object representing the method that matches the specified requirements, if found; otherwise, . @@ -6371,19 +6302,19 @@ One of the elements in the array is is . - -or- +-or- - is . + is . - -or- +-or- - One of the elements in is . +One of the elements in is . is multidimensional. - -or- +-or- - is multidimensional. + is multidimensional. @@ -6485,8 +6416,7 @@ An empty array of objects (as provided by the array is . - +One of the elements in the array is . is negative. @@ -6567,20 +6497,20 @@ One of the elements in the array is The string containing the name of the method to get. A bitwise combination of the enumeration values that specify how the search is conducted. - -or- +-or- - to return . + to return . An object that defines a set of properties and enables binding, which can involve selection of an overloaded method, coercion of argument types, and invocation of a member through reflection. - -or- +-or- - A null reference ( in Visual Basic), to use the . +A null reference ( in Visual Basic), to use the . The object that specifies the set of rules to use regarding the order and layout of arguments, how the return value is passed, what registers are used for arguments, and how the stack is cleaned up. An array of objects representing the number, order, and type of the parameters for the method to get. - -or- +-or- - An empty array of objects (as provided by the field) to get a method that takes no parameters. +An empty array of objects (as provided by the field) to get a method that takes no parameters. An array of objects representing the attributes associated with the corresponding element in the array. To be only used when calling through COM interop, and only parameters that are passed by reference are handled. The default binder does not process this parameter. Searches for the specified method whose parameters match the specified argument types and modifiers, using the specified binding constraints and the specified calling convention. An object representing the method that matches the specified requirements, if found; otherwise, . @@ -6654,19 +6584,19 @@ One of the elements in the array is is . - -or- +-or- - is . + is . - -or- +-or- - One of the elements in is . +One of the elements in is . is multidimensional. - -or- +-or- - is multidimensional. + is multidimensional. @@ -6771,8 +6701,7 @@ An empty array of objects (as provided by the array is . - +One of the elements in the array is . is negative. @@ -6847,24 +6776,24 @@ One of the elements in the array is The string containing the name of the method to get. A bitwise combination of the enumeration values that specify how the search is conducted. - -or- +-or- - to return . + to return . An object that defines a set of properties and enables binding, which can involve selection of an overloaded method, coercion of argument types, and invocation of a member through reflection. - -or- +-or- - A null reference ( in Visual Basic), to use the . +A null reference ( in Visual Basic), to use the . The object that specifies the set of rules to use regarding the order and layout of arguments, how the return value is passed, what registers are used for arguments, and what process cleans up the stack. An array of objects representing the number, order, and type of the parameters for the method to get. - -or- +-or- - An empty array of the type (that is, Type[] types = new Type[0]) to get a method that takes no parameters. +An empty array of the type (that is, Type[] types = new Type[0]) to get a method that takes no parameters. - -or- +-or- - . If is , arguments are not matched. +. If is , arguments are not matched. An array of objects representing the attributes associated with the corresponding element in the array. The default binder does not process this parameter. When overridden in a derived class, searches for the specified method whose parameters match the specified argument types and modifiers, using the specified binding constraints and the specified calling convention. An object representing the method that matches the specified requirements, if found; otherwise, . @@ -6902,13 +6831,13 @@ One of the elements in the array is is multidimensional. - -or- +-or- - is multidimensional. + is multidimensional. - -or- +-or- - and do not have the same length. + and do not have the same length. The current type is a or . @@ -7072,9 +7001,9 @@ An empty array of the type (that is, Type[] types = Returns all the public methods of the current . An array of objects representing all the public methods defined for the current . - -or- +-or- - An empty array of type , if no public methods are defined for the current . +An empty array of type , if no public methods are defined for the current . method does -or- - to return an empty array. + to return an empty array. When overridden in a derived class, searches for the methods defined for the current , using the specified binding constraints. An array of objects representing all methods defined for the current that match the specified binding constraints. - -or- +-or- - An empty array of type , if no methods are defined for the current , or if none of the defined methods match the binding constraints. +An empty array of type , if no methods are defined for the current , or if none of the defined methods match the binding constraints. represents a type parameter in the definition The string containing the name of the nested type to get. A bitwise combination of the enumeration values that specify how the search is conducted. - -or- +-or- - to return . + to return . When overridden in a derived class, searches for the specified nested type, using the specified binding constraints. An object representing the nested type that matches the specified requirements, if found; otherwise, . @@ -7578,9 +7507,9 @@ If the current represents a type parameter in the definition A bitwise combination of the enumeration values that specify how the search is conducted. - -or- +-or- - to return . + to return . When overridden in a derived class, searches for the types nested in the current , using the specified binding constraints. An array of objects representing all the types nested in the current that match the specified binding constraints (the search is not recursive), or an empty array of type , if no nested types are found that match the binding constraints. @@ -7658,13 +7587,13 @@ If the current represents a type parameter in the definition When overridden in a derived class, returns the optional custom modifiers of the current . An array of objects that identify the optional custom modifiers of the current . - -or- +-or- - An empty array of type , if the current has no custom modifiers. +An empty array of type , if the current has no custom modifiers. - -or- +-or- - An empty array of type , if the current is not a modified . A modified is obtained from , , or . +An empty array of type , if the current is not a modified . A modified is obtained from , , or . represents a type parameter in the definition Returns all the public properties of the current . An array of objects representing all public properties of the current . - -or- +-or- - An empty array of type , if the current does not have public properties. +An empty array of type , if the current does not have public properties. represents a type parameter in the definition -or- - to return an empty array. + to return an empty array. When overridden in a derived class, searches for the properties of the current , using the specified binding constraints. An array of objects representing all properties of the current that match the specified binding constraints. - -or- +-or- - An empty array of type , if the current does not have properties, or if none of the properties match the binding constraints. +An empty array of type , if the current does not have properties, or if none of the properties match the binding constraints. method d The string containing the name of the property to get. A bitwise combination of the enumeration values that specify how the search is conducted. - -or- +-or- to return . Searches for the specified property, using the specified binding constraints. @@ -8296,9 +8225,9 @@ In .NET 6 and earlier versions, the method d The string containing the name of the public property to get. An array of objects representing the number, order, and type of the parameters for the indexed property to get. - -or- +-or- - An empty array of the type (that is, Type[] types = new Type[0]) to get a property that is not indexed. +An empty array of the type (that is, Type[] types = new Type[0]) to get a property that is not indexed. Searches for the specified public property whose parameters match the specified argument types. An object representing the public property whose parameters match the specified argument types, if found; otherwise, . @@ -8336,9 +8265,9 @@ In .NET 6 and earlier versions, the method d is . - -or- +-or- - is . + is . is multidimensional. An element of is . @@ -8412,9 +8341,9 @@ In .NET 6 and earlier versions, the method d The return type of the property. An array of objects representing the number, order, and type of the parameters for the indexed property to get. - -or- +-or- - An empty array of the type (that is, Type[] types = new Type[0]) to get a property that is not indexed. +An empty array of the type (that is, Type[] types = new Type[0]) to get a property that is not indexed. Searches for the specified public property whose parameters match the specified argument types. An object representing the public property whose parameters match the specified argument types, if found; otherwise, . @@ -8442,9 +8371,9 @@ In .NET 6 and earlier versions, the method d is . - -or- +-or- - is . + is . is multidimensional. An element of is . @@ -8530,9 +8459,9 @@ In .NET 6 and earlier versions, the method d The return type of the property. An array of objects representing the number, order, and type of the parameters for the indexed property to get. - -or- +-or- - An empty array of the type (that is, Type[] types = new Type[0]) to get a property that is not indexed. +An empty array of the type (that is, Type[] types = new Type[0]) to get a property that is not indexed. An array of objects representing the attributes associated with the corresponding element in the array. The default binder does not process this parameter. Searches for the specified public property whose parameters match the specified argument types and modifiers. An object representing the public property that matches the specified requirements, if found; otherwise, . @@ -8573,19 +8502,19 @@ In .NET 6 and earlier versions, the method d is . - -or- +-or- - is . + is . is multidimensional. - -or- +-or- - is multidimensional. + is multidimensional. - -or- +-or- - and do not have the same length. + and do not have the same length. An element of is . @@ -8669,20 +8598,20 @@ In .NET 6 and earlier versions, the method d The string containing the name of the property to get. A bitwise combination of the enumeration values that specify how the search is conducted. - -or- +-or- - to return . + to return . An object that defines a set of properties and enables binding, which can involve selection of an overloaded method, coercion of argument types, and invocation of a member through reflection. - -or- +-or- - A null reference ( in Visual Basic), to use the . +A null reference ( in Visual Basic), to use the . The return type of the property. An array of objects representing the number, order, and type of the parameters for the indexed property to get. - -or- +-or- - An empty array of the type (that is, Type[] types = new Type[0]) to get a property that is not indexed. +An empty array of the type (that is, Type[] types = new Type[0]) to get a property that is not indexed. An array of objects representing the attributes associated with the corresponding element in the array. The default binder does not process this parameter. Searches for the specified property whose parameters match the specified argument types and modifiers, using the specified binding constraints. An object representing the property that matches the specified requirements, if found; otherwise, . @@ -8746,19 +8675,19 @@ In .NET 6 and earlier versions, the method d is . - -or- +-or- - is . + is . is multidimensional. - -or- +-or- - is multidimensional. + is multidimensional. - -or- +-or- - and do not have the same length. + and do not have the same length. An element of is . @@ -8840,20 +8769,20 @@ In .NET 6 and earlier versions, the method d The string containing the name of the property to get. A bitwise combination of the enumeration values that specify how the search is conducted. - -or- +-or- - to return . + to return . An object that defines a set of properties and enables binding, which can involve selection of an overloaded member, coercion of argument types, and invocation of a member through reflection. - -or- +-or- - A null reference ( in Visual Basic), to use the . +A null reference ( in Visual Basic), to use the . The return type of the property. An array of objects representing the number, order, and type of the parameters for the indexed property to get. - -or- +-or- - An empty array of the type (that is, Type[] types = new Type[0]) to get a property that is not indexed. +An empty array of the type (that is, Type[] types = new Type[0]) to get a property that is not indexed. An array of objects representing the attributes associated with the corresponding element in the array. The default binder does not process this parameter. When overridden in a derived class, searches for the specified property whose parameters match the specified argument types and modifiers, using the specified binding constraints. An object representing the property that matches the specified requirements, if found; otherwise, . @@ -8887,23 +8816,23 @@ In .NET 6 and earlier versions, the method d is . - -or- +-or- - is . + is . - -or- +-or- - One of the elements in is . +One of the elements in is . is multidimensional. - -or- +-or- - is multidimensional. + is multidimensional. - -or- +-or- - and do not have the same length. + and do not have the same length. The current type is a , , or . @@ -8941,13 +8870,13 @@ In .NET 6 and earlier versions, the method d When overridden in a derived class, returns the required custom modifiers of the current . An array of objects that identify the required custom modifiers of the current . - -or- +-or- - An empty array of type , if the current has no custom modifiers. +An empty array of type , if the current has no custom modifiers. - -or- +-or- - An empty array of type , if the current is not a modified . A modified is obtained from , , or . +An empty array of type , if the current is not a modified . A modified is obtained from , , or . represents a generic type that has a pointer type, a type, or as one of its type arguments. - -or- +-or- - represents a generic type that has an incorrect number of type arguments. + represents a generic type that has an incorrect number of type arguments. - -or- +-or- - represents a generic type, and one of its type arguments does not satisfy the constraints for the corresponding type parameter. + represents a generic type, and one of its type arguments does not satisfy the constraints for the corresponding type parameter. represents an array of . - The assembly or one of its dependencies was found, but could not be loaded. - -Note: In .NET for Windows Store apps or the Portable Class Library, catch the base class exception, , instead. - + The assembly or one of its dependencies was found, but could not be loaded. Note: In .NET for Windows Store apps or the Portable Class Library, catch the base class exception, , instead. The assembly or one of its dependencies is not valid. - -or- + -or- - Version 2.0 or later of the common language runtime is currently loaded, and the assembly was compiled with a later version. + Version 2.0 or later of the common language runtime is currently loaded, and the assembly was compiled with a later version. @@ -9416,46 +9342,43 @@ Type.GetType("System.Collections.Generic.Dictionary`2[System.String,[MyType,MyAs is and the type is not found. - -or- +-or- - is and contains invalid characters, such as an embedded tab. + is and contains invalid characters, such as an embedded tab. - -or- +-or- - is and is an empty string. + is and is an empty string. - -or- +-or- - is and represents an array type with an invalid size. + is and represents an array type with an invalid size. - -or- +-or- - represents an array of . + represents an array of . is and contains invalid syntax. For example, "MyType[,*,]". - -or- +-or- - represents a generic type that has a pointer type, a type, or as one of its type arguments. + represents a generic type that has a pointer type, a type, or as one of its type arguments. - -or- +-or- - represents a generic type that has an incorrect number of type arguments. + represents a generic type that has an incorrect number of type arguments. - -or- +-or- - represents a generic type, and one of its type arguments does not satisfy the constraints for the corresponding type parameter. + represents a generic type, and one of its type arguments does not satisfy the constraints for the corresponding type parameter. is and the assembly or one of its dependencies was not found. - The assembly or one of its dependencies was found, but could not be loaded. - -Note: In .NET for Windows Store apps or the Portable Class Library, catch the base class exception, , instead. - + The assembly or one of its dependencies was found, but could not be loaded. Note: In .NET for Windows Store apps or the Portable Class Library, catch the base class exception, , instead. The assembly or one of its dependencies is not valid. - -or- + -or- - Version 2.0 or later of the common language runtime is currently loaded, and the assembly was compiled with a later version. + Version 2.0 or later of the common language runtime is currently loaded, and the assembly was compiled with a later version. @@ -9643,43 +9566,43 @@ Type.GetType("System.Collections.Generic.Dictionary`2[System.String,[MyType,MyAs is and the type is not found. - -or- +-or- - is and contains invalid characters, such as an embedded tab. + is and contains invalid characters, such as an embedded tab. - -or- +-or- - is and is an empty string. + is and is an empty string. - -or- +-or- - is and represents an array type with an invalid size. + is and represents an array type with an invalid size. - -or- +-or- - represents an array of . + represents an array of . is and contains invalid syntax. For example, "MyType[,*,]". - -or- +-or- - represents a generic type that has a pointer type, a type, or as one of its type arguments. + represents a generic type that has a pointer type, a type, or as one of its type arguments. - -or- +-or- - represents a generic type that has an incorrect number of type arguments. + represents a generic type that has an incorrect number of type arguments. - -or- +-or- - represents a generic type, and one of its type arguments does not satisfy the constraints for the corresponding type parameter. + represents a generic type, and one of its type arguments does not satisfy the constraints for the corresponding type parameter. is and the assembly or one of its dependencies was not found. The assembly or one of its dependencies was found, but could not be loaded. The assembly or one of its dependencies is not valid. - -or- + -or- - Version 2.0 or later of the common language runtime is currently loaded, and the assembly was compiled with a later version. + Version 2.0 or later of the common language runtime is currently loaded, and the assembly was compiled with a later version. @@ -9748,12 +9671,8 @@ Type.GetType("System.Collections.Generic.Dictionary`2[System.String,[MyType,MyAs The name of the type to get. If the parameter is provided, the type name can be any string that is capable of resolving. If the parameter is provided or if standard type resolution is used, must be an assembly-qualified name (see ), unless the type is in the currently executing assembly or in mscorlib.dll/System.Private.CoreLib.dll, in which case it is sufficient to supply the type name qualified by its namespace. - A method that locates and returns the assembly that is specified in . The assembly name is passed to as an object. If does not contain the name of an assembly, is not called. If is not supplied, standard assembly resolution is performed. - - Caution Do not pass methods from unknown or untrusted callers. Doing so could result in elevation of privilege for malicious code. Use only methods that you provide or that you are familiar with. - A method that locates and returns the type that is specified by from the assembly that is returned by or by standard assembly resolution. If no assembly is provided, the method can provide one. The method also takes a parameter that specifies whether to perform a case-insensitive search; is passed to that parameter. - - Caution Do not pass methods from unknown or untrusted callers. + A method that locates and returns the assembly that is specified in . The assembly name is passed to as an object. If does not contain the name of an assembly, is not called. If is not supplied, standard assembly resolution is performed. Caution Do not pass methods from unknown or untrusted callers. Doing so could result in elevation of privilege for malicious code. Use only methods that you provide or that you are familiar with. + A method that locates and returns the type that is specified by from the assembly that is returned by or by standard assembly resolution. If no assembly is provided, the method can provide one. The method also takes a parameter that specifies whether to perform a case-insensitive search; is passed to that parameter. Caution Do not pass methods from unknown or untrusted callers. Gets the type with the specified name, optionally providing custom methods to resolve the assembly and the type. The type with the specified name, or if the type is not found. @@ -9774,33 +9693,33 @@ Type.GetType("System.Collections.Generic.Dictionary`2[System.String,[MyType,MyAs A class initializer is invoked and throws an exception. An error occurs when is parsed into a type name and an assembly name (for example, when the simple type name includes an unescaped special character). - -or- +-or- - represents a generic type that has a pointer type, a type, or as one of its type arguments. + represents a generic type that has a pointer type, a type, or as one of its type arguments. - -or- +-or- - represents a generic type that has an incorrect number of type arguments. + represents a generic type that has an incorrect number of type arguments. - -or- +-or- - represents a generic type, and one of its type arguments does not satisfy the constraints for the corresponding type parameter. + represents a generic type, and one of its type arguments does not satisfy the constraints for the corresponding type parameter. represents an array of . The assembly or one of its dependencies was found, but could not be loaded. - -or- +-or- - contains an invalid assembly name. + contains an invalid assembly name. - -or- +-or- - is a valid assembly name without a type name. + is a valid assembly name without a type name. The assembly or one of its dependencies is not valid. - -or- + -or- - The assembly was compiled with a later version of the common language runtime than the version that is currently loaded. + The assembly was compiled with a later version of the common language runtime than the version that is currently loaded. @@ -9863,12 +9782,8 @@ Type.GetType("System.Collections.Generic.Dictionary`2[System.String,[MyType,MyAs The name of the type to get. If the parameter is provided, the type name can be any string that is capable of resolving. If the parameter is provided or if standard type resolution is used, must be an assembly-qualified name (see ), unless the type is in the currently executing assembly or in mscorlib.dll/System.Private.CoreLib.dll, in which case it is sufficient to supply the type name qualified by its namespace. - A method that locates and returns the assembly that is specified in . The assembly name is passed to as an object. If does not contain the name of an assembly, is not called. If is not supplied, standard assembly resolution is performed. - - Caution Do not pass methods from unknown or untrusted callers. Doing so could result in elevation of privilege for malicious code. Use only methods that you provide or that you are familiar with. - A method that locates and returns the type that is specified by from the assembly that is returned by or by standard assembly resolution. If no assembly is provided, the method can provide one. The method also takes a parameter that specifies whether to perform a case-insensitive search; is passed to that parameter. - - Caution Do not pass methods from unknown or untrusted callers. + A method that locates and returns the assembly that is specified in . The assembly name is passed to as an object. If does not contain the name of an assembly, is not called. If is not supplied, standard assembly resolution is performed. Caution Do not pass methods from unknown or untrusted callers. Doing so could result in elevation of privilege for malicious code. Use only methods that you provide or that you are familiar with. + A method that locates and returns the type that is specified by from the assembly that is returned by or by standard assembly resolution. If no assembly is provided, the method can provide one. The method also takes a parameter that specifies whether to perform a case-insensitive search; is passed to that parameter. Caution Do not pass methods from unknown or untrusted callers. to throw an exception if the type cannot be found; to return . Specifying also suppresses some other exception conditions, but not all of them. See the Exceptions section. Gets the type with the specified name, specifying whether to throw an exception if the type is not found, and optionally providing custom methods to resolve the assembly and the type. @@ -9889,54 +9804,54 @@ Type.GetType("System.Collections.Generic.Dictionary`2[System.String,[MyType,MyAs is and the type is not found. - -or- +-or- - is and contains invalid characters, such as an embedded tab. + is and contains invalid characters, such as an embedded tab. - -or- +-or- - is and is an empty string. + is and is an empty string. - -or- +-or- - is and represents an array type with an invalid size. + is and represents an array type with an invalid size. - -or- +-or- - represents an array of . + represents an array of . An error occurs when is parsed into a type name and an assembly name (for example, when the simple type name includes an unescaped special character). - -or- +-or- - is and contains invalid syntax (for example, "MyType[,*,]"). + is and contains invalid syntax (for example, "MyType[,*,]"). - -or- +-or- - represents a generic type that has a pointer type, a type, or as one of its type arguments. + represents a generic type that has a pointer type, a type, or as one of its type arguments. - -or- +-or- - represents a generic type that has an incorrect number of type arguments. + represents a generic type that has an incorrect number of type arguments. - -or- +-or- - represents a generic type, and one of its type arguments does not satisfy the constraints for the corresponding type parameter. + represents a generic type, and one of its type arguments does not satisfy the constraints for the corresponding type parameter. is and the assembly or one of its dependencies was not found. - -or- +-or- - contains an invalid assembly name. + contains an invalid assembly name. - -or- +-or- - is a valid assembly name without a type name. + is a valid assembly name without a type name. The assembly or one of its dependencies was found, but could not be loaded. The assembly or one of its dependencies is not valid. - -or- + -or- - The assembly was compiled with a later version of the common language runtime than the version that is currently loaded. + The assembly was compiled with a later version of the common language runtime than the version that is currently loaded. @@ -10000,12 +9915,8 @@ Type.GetType("System.Collections.Generic.Dictionary`2[System.String,[MyType,MyAs The name of the type to get. If the parameter is provided, the type name can be any string that is capable of resolving. If the parameter is provided or if standard type resolution is used, must be an assembly-qualified name (see ), unless the type is in the currently executing assembly or in mscorlib.dll/System.Private.CoreLib.dll, in which case it is sufficient to supply the type name qualified by its namespace. - A method that locates and returns the assembly that is specified in . The assembly name is passed to as an object. If does not contain the name of an assembly, is not called. If is not supplied, standard assembly resolution is performed. - - Caution Do not pass methods from unknown or untrusted callers. Doing so could result in elevation of privilege for malicious code. Use only methods that you provide or that you are familiar with. - A method that locates and returns the type that is specified by from the assembly that is returned by or by standard assembly resolution. If no assembly is provided, the method can provide one. The method also takes a parameter that specifies whether to perform a case-insensitive search; the value of is passed to that parameter. - - Caution Do not pass methods from unknown or untrusted callers. + A method that locates and returns the assembly that is specified in . The assembly name is passed to as an object. If does not contain the name of an assembly, is not called. If is not supplied, standard assembly resolution is performed. Caution Do not pass methods from unknown or untrusted callers. Doing so could result in elevation of privilege for malicious code. Use only methods that you provide or that you are familiar with. + A method that locates and returns the type that is specified by from the assembly that is returned by or by standard assembly resolution. If no assembly is provided, the method can provide one. The method also takes a parameter that specifies whether to perform a case-insensitive search; the value of is passed to that parameter. Caution Do not pass methods from unknown or untrusted callers. to throw an exception if the type cannot be found; to return . Specifying also suppresses some other exception conditions, but not all of them. See the Exceptions section. @@ -10157,54 +10068,54 @@ Type.GetType("System.Collections.Generic.Dictionary`2[System.String,[MyType,MyAs is and the type is not found. - -or- +-or- - is and contains invalid characters, such as an embedded tab. + is and contains invalid characters, such as an embedded tab. - -or- +-or- - is and is an empty string. + is and is an empty string. - -or- +-or- - is and represents an array type with an invalid size. + is and represents an array type with an invalid size. - -or- +-or- - represents an array of . + represents an array of . An error occurs when is parsed into a type name and an assembly name (for example, when the simple type name includes an unescaped special character). - -or- +-or- - is and contains invalid syntax (for example, "MyType[,*,]"). + is and contains invalid syntax (for example, "MyType[,*,]"). - -or- +-or- - represents a generic type that has a pointer type, a type, or as one of its type arguments. + represents a generic type that has a pointer type, a type, or as one of its type arguments. - -or- +-or- - represents a generic type that has an incorrect number of type arguments. + represents a generic type that has an incorrect number of type arguments. - -or- +-or- - represents a generic type, and one of its type arguments does not satisfy the constraints for the corresponding type parameter. + represents a generic type, and one of its type arguments does not satisfy the constraints for the corresponding type parameter. is and the assembly or one of its dependencies was not found. The assembly or one of its dependencies was found, but could not be loaded. - -or- +-or- - contains an invalid assembly name. + contains an invalid assembly name. - -or- +-or- - is a valid assembly name without a type name. + is a valid assembly name without a type name. The assembly or one of its dependencies is not valid. - -or- + -or- - The assembly was compiled with a later version of the common language runtime than the version that is currently loaded. + The assembly was compiled with a later version of the common language runtime than the version that is currently loaded. @@ -10263,9 +10174,9 @@ Type.GetType("System.Collections.Generic.Dictionary`2[System.String,[MyType,MyAs is . - -or- +-or- - One or more of the elements in is . +One or more of the elements in is . The class initializers are invoked and at least one throws an exception. @@ -10483,13 +10394,7 @@ Type.GetType("System.Collections.Generic.Dictionary`2[System.String,[MyType,MyAs ]]> - This method is intended for use when working with COM objects, not with .NET Framework objects. All managed objects, including those that are visible to COM (that is, their attribute is ) have a GUID that is returned by the property. Although the method returns a object that corresponds to the GUID for .NET Framework objects, you can't use that object to create a type instance by calling the method, as the following example shows. - - :::code language="csharp" source="~/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid11.cs" id="Snippet11"::: - :::code language="fsharp" source="~/snippets/fsharp/System/Type/GetTypeFromCLSID/gettypefromclsid11.fs" id="Snippet11"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.type.gettypefromclsid/vb/gettypefromclsid11.vb" id="Snippet11"::: - - Instead, the should only be used to retrieve the GUID of an unmanaged COM object, and the resulting object that is passed to the method must represent an unmanaged COM object. + This method is intended for use when working with COM objects, not with .NET Framework objects. All managed objects, including those that are visible to COM (that is, their attribute is ) have a GUID that is returned by the property. Although the method returns a object that corresponds to the GUID for .NET Framework objects, you can't use that object to create a type instance by calling the method, as the following example shows. :::code language="csharp" source="~/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid11.cs" id="Snippet11"::: :::code language="fsharp" source="~/snippets/fsharp/System/Type/GetTypeFromCLSID/gettypefromclsid11.fs" id="Snippet11"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.type.gettypefromclsid/vb/gettypefromclsid11.vb" id="Snippet11"::: Instead, the should only be used to retrieve the GUID of an unmanaged COM object, and the resulting object that is passed to the method must represent an unmanaged COM object. @@ -10550,9 +10455,9 @@ Type.GetType("System.Collections.Generic.Dictionary`2[System.String,[MyType,MyAs to throw any exception that occurs. - -or- +-or- - to ignore any exception that occurs. + to ignore any exception that occurs. Gets the type associated with the specified class identifier (CLSID), specifying whether to throw an exception if an error occurs while loading the type. regardless of whether the CLSID is valid. @@ -10587,13 +10492,7 @@ Type.GetType("System.Collections.Generic.Dictionary`2[System.String,[MyType,MyAs ]]> - This method is intended for use when working with COM objects, not with .NET Framework objects. All managed objects, including those that are visible to COM (that is, their attribute is ) have a GUID that is returned by the property. Although the method returns a object that corresponds to the GUID for .NET Framework objects, you can't use that object to create a type instance by calling the method, as the following example shows. - - :::code language="csharp" source="~/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid11.cs" id="Snippet11"::: - :::code language="fsharp" source="~/snippets/fsharp/System/Type/GetTypeFromCLSID/gettypefromclsid11.fs" id="Snippet11"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.type.gettypefromclsid/vb/gettypefromclsid11.vb" id="Snippet11"::: - - Instead, the should only be used to retrieve the GUID of an unmanaged COM object, and the resulting object that is passed to the method must represent an unmanaged COM object. + This method is intended for use when working with COM objects, not with .NET Framework objects. All managed objects, including those that are visible to COM (that is, their attribute is ) have a GUID that is returned by the property. Although the method returns a object that corresponds to the GUID for .NET Framework objects, you can't use that object to create a type instance by calling the method, as the following example shows. :::code language="csharp" source="~/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid11.cs" id="Snippet11"::: :::code language="fsharp" source="~/snippets/fsharp/System/Type/GetTypeFromCLSID/gettypefromclsid11.fs" id="Snippet11"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.type.gettypefromclsid/vb/gettypefromclsid11.vb" id="Snippet11"::: Instead, the should only be used to retrieve the GUID of an unmanaged COM object, and the resulting object that is passed to the method must represent an unmanaged COM object. @@ -10682,13 +10581,7 @@ Type.GetType("System.Collections.Generic.Dictionary`2[System.String,[MyType,MyAs ]]> - This method is intended for use when working with COM objects, not with .NET Framework objects. All managed objects, including those that are visible to COM (that is, their attribute is ) have a GUID that is returned by the property. Although the method returns a object that corresponds to the GUID for .NET Framework objects, you can't use that object to create a type instance by calling the method, as the following example shows. - - :::code language="csharp" source="~/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid11.cs" id="Snippet11"::: - :::code language="fsharp" source="~/snippets/fsharp/System/Type/GetTypeFromCLSID/gettypefromclsid11.fs" id="Snippet11"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.type.gettypefromclsid/vb/gettypefromclsid11.vb" id="Snippet11"::: - - Instead, the should only be used to retrieve the GUID of an unmanaged COM object, and the resulting object that is passed to the method must represent an unmanaged COM object. + This method is intended for use when working with COM objects, not with .NET Framework objects. All managed objects, including those that are visible to COM (that is, their attribute is ) have a GUID that is returned by the property. Although the method returns a object that corresponds to the GUID for .NET Framework objects, you can't use that object to create a type instance by calling the method, as the following example shows. :::code language="csharp" source="~/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid11.cs" id="Snippet11"::: :::code language="fsharp" source="~/snippets/fsharp/System/Type/GetTypeFromCLSID/gettypefromclsid11.fs" id="Snippet11"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.type.gettypefromclsid/vb/gettypefromclsid11.vb" id="Snippet11"::: Instead, the should only be used to retrieve the GUID of an unmanaged COM object, and the resulting object that is passed to the method must represent an unmanaged COM object. @@ -10751,9 +10644,9 @@ Type.GetType("System.Collections.Generic.Dictionary`2[System.String,[MyType,MyAs to throw any exception that occurs. - -or- +-or- - to ignore any exception that occurs. + to ignore any exception that occurs. Gets the type associated with the specified class identifier (CLSID) from the specified server, specifying whether to throw an exception if an error occurs while loading the type. regardless of whether the CLSID is valid. @@ -10786,13 +10679,7 @@ Type.GetType("System.Collections.Generic.Dictionary`2[System.String,[MyType,MyAs ]]> - This method is intended for use when working with COM objects, not with .NET Framework objects. All managed objects, including those that are visible to COM (that is, their attribute is ) have a GUID that is returned by the property. Although the method returns a object that corresponds to the GUID for a particular managed object, you can't use that object to create a type instance by calling the method, as the following example shows. - - :::code language="csharp" source="~/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid11.cs" id="Snippet11"::: - :::code language="fsharp" source="~/snippets/fsharp/System/Type/GetTypeFromCLSID/gettypefromclsid11.fs" id="Snippet11"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.type.gettypefromclsid/vb/gettypefromclsid11.vb" id="Snippet11"::: - - Instead, the should only be used to retrieve the GUID of an unmanaged COM object, and the resulting object that is passed to the method must represent an unmanaged COM object. + This method is intended for use when working with COM objects, not with .NET Framework objects. All managed objects, including those that are visible to COM (that is, their attribute is ) have a GUID that is returned by the property. Although the method returns a object that corresponds to the GUID for a particular managed object, you can't use that object to create a type instance by calling the method, as the following example shows. :::code language="csharp" source="~/snippets/csharp/System/Type/GetTypeFromCLSID/gettypefromclsid11.cs" id="Snippet11"::: :::code language="fsharp" source="~/snippets/fsharp/System/Type/GetTypeFromCLSID/gettypefromclsid11.fs" id="Snippet11"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.type.gettypefromclsid/vb/gettypefromclsid11.vb" id="Snippet11"::: Instead, the should only be used to retrieve the GUID of an unmanaged COM object, and the resulting object that is passed to the method must represent an unmanaged COM object. @@ -11002,9 +10889,9 @@ Type.GetType("System.Collections.Generic.Dictionary`2[System.String,[MyType,MyAs to throw any exception that occurs. - -or- +-or- - to ignore any exception that occurs. + to ignore any exception that occurs. Gets the type associated with the specified program identifier (ProgID), specifying whether to throw an exception if an error occurs while loading the type. The type associated with the specified program identifier (ProgID), if is a valid entry in the registry and a type is associated with it; otherwise, . @@ -11184,9 +11071,9 @@ Type.GetType("System.Collections.Generic.Dictionary`2[System.String,[MyType,MyAs to throw any exception that occurs. - -or- +-or- - to ignore any exception that occurs. + to ignore any exception that occurs. Gets the type associated with the specified program identifier (progID) from the specified server, specifying whether to throw an exception if an error occurs while loading the type. The type associated with the specified program identifier (progID), if is a valid entry in the registry and a type is associated with it; otherwise, . @@ -11556,19 +11443,19 @@ Type.GetType("System.Collections.Generic.Dictionary`2[System.String,[MyType,MyAs The string containing the name of the constructor, method, property, or field member to invoke. - -or- +-or- - An empty string ("") to invoke the default member. +An empty string ("") to invoke the default member. - -or- +-or- - For members, a string representing the DispID, for example "[DispID=3]". +For members, a string representing the DispID, for example "[DispID=3]". A bitwise combination of the enumeration values that specify how the search is conducted. The access can be one of the such as , , , , , and so on. The type of lookup need not be specified. If the type of lookup is omitted, | | are used. An object that defines a set of properties and enables binding, which can involve selection of an overloaded method, coercion of argument types, and invocation of a member through reflection. - -or- +-or- - A null reference ( in Visual Basic), to use the . Note that explicitly defining a object may be required for successfully invoking method overloads with variable arguments. +A null reference ( in Visual Basic), to use the . Note that explicitly defining a object may be required for successfully invoking method overloads with variable arguments. The object on which to invoke the specified member. An array containing the arguments to pass to the member to invoke. Invokes the specified member, using the specified binding constraints and matching the specified argument list. @@ -11661,44 +11548,44 @@ Type.GetType("System.Collections.Generic.Dictionary`2[System.String,[MyType,MyAs is not a valid attribute. - -or- +-or- - does not contain one of the following binding flags: , , , , , or . + does not contain one of the following binding flags: , , , , , or . - -or- +-or- - contains combined with , , , , or . + contains combined with , , , , or . - -or- +-or- - contains both and . + contains both and . - -or- +-or- - contains both and . + contains both and . - -or- +-or- - contains combined with or . + contains combined with or . - -or- +-or- - contains and has more than one element. + contains and has more than one element. - -or- +-or- - This method is called on a COM object and one of the following binding flags was not passed in: , , , , or . +This method is called on a COM object and one of the following binding flags was not passed in: , , , , or . - -or- +-or- - One of the named parameter arrays contains a string that is . +One of the named parameter arrays contains a string that is . The specified member is a class initializer. The field or property cannot be found. No method can be found that matches the arguments in . - -or- +-or- - The current object represents a type that contains open type parameters, that is, returns . +The current object represents a type that contains open type parameters, that is, returns . The specified member cannot be invoked on . More than one method matches the binding criteria. The .NET Compact Framework does not currently support this method. @@ -11785,26 +11672,26 @@ Type.GetType("System.Collections.Generic.Dictionary`2[System.String,[MyType,MyAs The string containing the name of the constructor, method, property, or field member to invoke. - -or- +-or- - An empty string ("") to invoke the default member. +An empty string ("") to invoke the default member. - -or- +-or- - For members, a string representing the DispID, for example "[DispID=3]". +For members, a string representing the DispID, for example "[DispID=3]". A bitwise combination of the enumeration values that specify how the search is conducted. The access can be one of the such as , , , , , and so on. The type of lookup need not be specified. If the type of lookup is omitted, | | are used. An object that defines a set of properties and enables binding, which can involve selection of an overloaded method, coercion of argument types, and invocation of a member through reflection. - -or- +-or- - A null reference ( in Visual Basic), to use the . Note that explicitly defining a object may be required for successfully invoking method overloads with variable arguments. +A null reference ( in Visual Basic), to use the . Note that explicitly defining a object may be required for successfully invoking method overloads with variable arguments. The object on which to invoke the specified member. An array containing the arguments to pass to the member to invoke. The object representing the globalization locale to use, which may be necessary for locale-specific conversions, such as converting a numeric to a . - -or- +-or- - A null reference ( in Visual Basic) to use the current thread's . +A null reference ( in Visual Basic) to use the current thread's . Invokes the specified member, using the specified binding constraints and matching the specified argument list and culture. An object representing the return value of the invoked member. @@ -11886,44 +11773,44 @@ Type.GetType("System.Collections.Generic.Dictionary`2[System.String,[MyType,MyAs is not a valid attribute. - -or- +-or- - does not contain one of the following binding flags: , , , , , or . + does not contain one of the following binding flags: , , , , , or . - -or- +-or- - contains combined with , , , , or . + contains combined with , , , , or . - -or- +-or- - contains both and . + contains both and . - -or- +-or- - contains both and . + contains both and . - -or- +-or- - contains combined with or . + contains combined with or . - -or- +-or- - contains and has more than one element. + contains and has more than one element. - -or- +-or- - This method is called on a COM object and one of the following binding flags was not passed in: , , , , or . +This method is called on a COM object and one of the following binding flags was not passed in: , , , , or . - -or- +-or- - One of the named parameter arrays contains a string that is . +One of the named parameter arrays contains a string that is . The specified member is a class initializer. The field or property cannot be found. No method can be found that matches the arguments in . - -or- +-or- - The current object represents a type that contains open type parameters, that is, returns . +The current object represents a type that contains open type parameters, that is, returns . The specified member cannot be invoked on . More than one method matches the binding criteria. The method represented by has one or more unspecified generic type parameters. That is, the method's property returns . @@ -12012,29 +11899,27 @@ Type.GetType("System.Collections.Generic.Dictionary`2[System.String,[MyType,MyAs The string containing the name of the constructor, method, property, or field member to invoke. - -or- +-or- - An empty string ("") to invoke the default member. +An empty string ("") to invoke the default member. - -or- +-or- - For members, a string representing the DispID, for example "[DispID=3]". +For members, a string representing the DispID, for example "[DispID=3]". A bitwise combination of the enumeration values that specify how the search is conducted. The access can be one of the such as , , , , , and so on. The type of lookup need not be specified. If the type of lookup is omitted, | | are used. An object that defines a set of properties and enables binding, which can involve selection of an overloaded method, coercion of argument types, and invocation of a member through reflection. - -or- +-or- - A null reference (Nothing in Visual Basic), to use the . Note that explicitly defining a object may be required for successfully invoking method overloads with variable arguments. +A null reference (Nothing in Visual Basic), to use the . Note that explicitly defining a object may be required for successfully invoking method overloads with variable arguments. The object on which to invoke the specified member. An array containing the arguments to pass to the member to invoke. - An array of objects representing the attributes associated with the corresponding element in the array. A parameter's associated attributes are stored in the member's signature. - - The default binder processes this parameter only when calling a COM component. + An array of objects representing the attributes associated with the corresponding element in the array. A parameter's associated attributes are stored in the member's signature. The default binder processes this parameter only when calling a COM component. The object representing the globalization locale to use, which may be necessary for locale-specific conversions, such as converting a numeric String to a Double. - -or- +-or- - A null reference ( in Visual Basic) to use the current thread's . +A null reference ( in Visual Basic) to use the current thread's . An array containing the names of the parameters to which the values in the array are passed. When overridden in a derived class, invokes the specified member, using the specified binding constraints and matching the specified argument list, modifiers and culture. An object representing the return value of the invoked member. @@ -12127,56 +12012,56 @@ Type.GetType("System.Collections.Generic.Dictionary`2[System.String,[MyType,MyAs and do not have the same length. - -or- +-or- - is not a valid attribute. + is not a valid attribute. - -or- +-or- - does not contain one of the following binding flags: , , , , , or . + does not contain one of the following binding flags: , , , , , or . - -or- +-or- - contains combined with , , , , or . + contains combined with , , , , or . - -or- +-or- - contains both and . + contains both and . - -or- +-or- - contains both and . + contains both and . - -or- +-or- - contains combined with or . + contains combined with or . - -or- +-or- - contains and has more than one element. + contains and has more than one element. - -or- +-or- - The named parameter array is larger than the argument array. +The named parameter array is larger than the argument array. - -or- +-or- - This method is called on a COM object and one of the following binding flags was not passed in: , , , , or . +This method is called on a COM object and one of the following binding flags was not passed in: , , , , or . - -or- +-or- - One of the named parameter arrays contains a string that is . +One of the named parameter arrays contains a string that is . The specified member is a class initializer. The field or property cannot be found. No method can be found that matches the arguments in . - -or- +-or- - No member can be found that has the argument names supplied in . +No member can be found that has the argument names supplied in . - -or- +-or- - The current object represents a type that contains open type parameters, that is, returns . +The current object represents a type that contains open type parameters, that is, returns . The specified member cannot be invoked on . More than one method matches the binding criteria. The method represented by has one or more unspecified generic type parameters. That is, the method's property returns . @@ -12542,19 +12427,7 @@ GetType(Array).IsAssignableFrom(type) The type to compare with the current type. Determines whether an instance of a specified type can be assigned to a variable of the current type. - if any of the following conditions is true: - -- and the current instance represent the same type. - -- is derived either directly or indirectly from the current instance. is derived directly from the current instance if it inherits from the current instance; is derived indirectly from the current instance if it inherits from a succession of one or more classes that inherit from the current instance. - -- The current instance is an interface that implements. - -- is a generic type parameter, and the current instance represents one of the constraints of . - -- represents a value type, and the current instance represents Nullable<c> (Nullable(Of c) in Visual Basic). - - if none of these conditions are true, or if is . + if any of the following conditions is true: - and the current instance represent the same type. - is derived either directly or indirectly from the current instance. is derived directly from the current instance if it inherits from the current instance; is derived indirectly from the current instance if it inherits from a succession of one or more classes that inherit from the current instance. - The current instance is an interface that implements. - is a generic type parameter, and the current instance represents one of the constraints of . - represents a value type, and the current instance represents Nullable<c> (Nullable(Of c) in Visual Basic). if none of these conditions are true, or if is . The type to compare with the current type. Determines whether the current type can be assigned to a variable of the specified . - if any of the following conditions is true: - -- The current instance and represent the same type. - -- The current type is derived either directly or indirectly from . The current type is derived directly from if it inherits from ; the current type is derived indirectly from if it inherits from a succession of one or more classes that inherit from . - -- is an interface that the current type implements. - -- The current type is a generic type parameter, and represents one of the constraints of the current type. - -- The current type represents a value type, and represents Nullable<c> (Nullable(Of c) in Visual Basic). - - if none of these conditions are true, or if is . + if any of the following conditions is true: - The current instance and represent the same type. - The current type is derived either directly or indirectly from . The current type is derived directly from if it inherits from ; the current type is derived indirectly from if it inherits from a succession of one or more classes that inherit from . - is an interface that the current type implements. - The current type is a generic type parameter, and represents one of the constraints of the current type. - The current type represents a value type, and represents Nullable<c> (Nullable(Of c) in Visual Basic). if none of these conditions are true, or if is . To be added. @@ -16147,9 +16008,9 @@ If the value of this property is `true` for an array type, it can be used to cre The invoked method is not supported in the base class. Derived classes must provide an implementation. The current type is . - -or- +-or- - The current type is a type. That is, returns . +The current type is a type. That is, returns . @@ -16223,13 +16084,13 @@ If the value of this property is `true` for an array type, it can be used to cre The invoked method is not supported in the base class. The current type is . - -or- +-or- - The current type is a type. That is, returns . +The current type is a type. That is, returns . - -or- +-or- - is greater than 32. + is greater than 32. @@ -16301,9 +16162,9 @@ If the value of this property is `true` for an array type, it can be used to cre The invoked method is not supported in the base class. The current type is . - -or- +-or- - The current type is a type. That is, returns . +The current type is a type. That is, returns . @@ -16534,18 +16395,18 @@ If the value of this property is `true` for an array type, it can be used to cre is . - -or- +-or- - Any element of is . +Any element of is . The number of elements in is not the same as the number of type parameters in the current generic type definition. - -or- +-or- - Any element of does not satisfy the constraints specified for the corresponding type parameter of the current generic type. +Any element of does not satisfy the constraints specified for the corresponding type parameter of the current generic type. - -or- +-or- - contains an element that is a pointer type ( returns ), a by-ref type ( returns ), or . + contains an element that is a pointer type ( returns ), a by-ref type ( returns ), or . The invoked method is not supported in the base class. Derived classes must provide an implementation. @@ -16620,9 +16481,9 @@ If the value of this property is `true` for an array type, it can be used to cre The invoked method is not supported in the base class. The current type is . - -or- +-or- - The current type is a type. That is, returns . +The current type is a type. That is, returns . @@ -17187,47 +17048,47 @@ If the value of this property is `true` for an array type, it can be used to cre is and the type is not found. - -or- +-or- - is and contains invalid characters, such as an embedded tab. + is and contains invalid characters, such as an embedded tab. - -or- +-or- - is and is an empty string. + is and is an empty string. - -or- +-or- - is and represents an array type with an invalid size. + is and represents an array type with an invalid size. - -or- +-or- - represents an array of objects. + represents an array of objects. does not include the assembly name. - -or- +-or- - is and contains invalid syntax; for example, "MyType[,*,]". + is and contains invalid syntax; for example, "MyType[,*,]". - -or- +-or- - represents a generic type that has a pointer type, a type, or as one of its type arguments. + represents a generic type that has a pointer type, a type, or as one of its type arguments. - -or- +-or- - represents a generic type that has an incorrect number of type arguments. + represents a generic type that has an incorrect number of type arguments. - -or- +-or- - represents a generic type, and one of its type arguments does not satisfy the constraints for the corresponding type parameter. + represents a generic type, and one of its type arguments does not satisfy the constraints for the corresponding type parameter. is and the assembly or one of its dependencies was not found. The assembly or one of its dependencies was found, but could not be loaded. The assembly or one of its dependencies is not valid. - -or- + -or- - The assembly was compiled with a later version of the common language runtime than the version that is currently loaded. + The assembly was compiled with a later version of the common language runtime than the version that is currently loaded. .NET Core and .NET 5+ only: In all cases. diff --git a/xml/System/TypeAccessException.xml b/xml/System/TypeAccessException.xml index c1e7fbd116f..9786f74be56 100644 --- a/xml/System/TypeAccessException.xml +++ b/xml/System/TypeAccessException.xml @@ -58,15 +58,15 @@ The exception that is thrown when a method attempts to use a type that it does not have access to. - is thrown when a method attempts to cast an object to a type that is not accessible from the method. For example, an anonymously hosted dynamic method cannot access a security-critical type because the method is [transparent](/dotnet/framework/misc/security-transparent-code). If the method contains a instruction that casts an object to a security-critical type, or to a generic type that has a security-critical type as one of its type parameters, is thrown by the JIT compiler. - - Similarly, is thrown for a dynamic method that uses an internal type from another assembly. A method might not have access to its containing type, its return type, or one of its parameter types. - - Apps compiled by using the .NET Native tool chain may throw a [MissingMetadataException](/windows/uwp/dotnet-native/missingmetadataexception-class-net-native) exception at run time. `MissingMetadataException` is an internal-only exception type derived from . The exception indicates that metadata needed for the successful execution of an app is not present at run time. You should not use a `try`/`catch` block to handle the exception. Instead, you should determine what metadata is missing and modify your app's runtime directives file to ensure that it is present at run time. - + is thrown when a method attempts to cast an object to a type that is not accessible from the method. For example, an anonymously hosted dynamic method cannot access a security-critical type because the method is [transparent](/dotnet/framework/misc/security-transparent-code). If the method contains a instruction that casts an object to a security-critical type, or to a generic type that has a security-critical type as one of its type parameters, is thrown by the JIT compiler. + + Similarly, is thrown for a dynamic method that uses an internal type from another assembly. A method might not have access to its containing type, its return type, or one of its parameter types. + + Apps compiled by using the .NET Native tool chain may throw a [MissingMetadataException](/windows/uwp/dotnet-native/missingmetadataexception-class-net-native) exception at run time. `MissingMetadataException` is an internal-only exception type derived from . The exception indicates that metadata needed for the successful execution of an app is not present at run time. You should not use a `try`/`catch` block to handle the exception. Instead, you should determine what metadata is missing and modify your app's runtime directives file to ensure that it is present at run time. + ]]> @@ -119,18 +119,18 @@ Initializes a new instance of the class with a system-supplied message that describes the error. - property of the new instance to a system-supplied message that describes the error, such as "Attempt to access the type failed." This message takes the current system culture into account. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The localized error message string.| - + property of the new instance to a system-supplied message that describes the error, such as "Attempt to access the type failed." This message takes the current system culture into account. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The localized error message string.| + ]]> Handling and Throwing Exceptions @@ -176,16 +176,16 @@ The message that describes the exception. The caller of this constructor must ensure that this string has been localized for the current system culture. Initializes a new instance of the class with a specified message that describes the error. - . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The error message string specified in `message`.| - + . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The error message string specified in `message`.| + ]]> Handling and Throwing Exceptions @@ -242,11 +242,11 @@ The contextual information about the source or destination. Initializes a new instance of the class with serialized data. - XML and SOAP Serialization @@ -294,18 +294,18 @@ The exception that is the cause of the current exception. If the parameter is not , the current exception is raised in a block that handles the inner exception. Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception. - property. The property returns the same value that is passed into the constructor, or `null` if the property does not supply the inner exception value to the constructor. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The error message string specified in `message`.| - + property. The property returns the same value that is passed into the constructor, or `null` if the property does not supply the inner exception value to the constructor. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The error message string specified in `message`.| + ]]> Handling and Throwing Exceptions diff --git a/xml/System/TypeCode.xml b/xml/System/TypeCode.xml index d664986871f..a8eb5de2c6b 100644 --- a/xml/System/TypeCode.xml +++ b/xml/System/TypeCode.xml @@ -53,22 +53,22 @@ Specifies the type of an object. - method on classes that implement the interface to obtain the type code for an instance of that class. - - Otherwise, call an object's method to obtain its object, then call the `Type` object's method to obtain the object's type code. - - - -## Examples - The following code example demonstrates how the enumeration can be used. In a decision block inside the WriteObjectInfo method, the of an parameter is examined, and an appropriate message is written to the console. - + method on classes that implement the interface to obtain the type code for an instance of that class. + + Otherwise, call an object's method to obtain its object, then call the `Type` object's method to obtain the object's type code. + + + +## Examples + The following code example demonstrates how the enumeration can be used. In a decision block inside the WriteObjectInfo method, the of an parameter is examined, and an appropriate message is written to the console. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR_System/system.TypeCode/CPP/iconvertible.cpp" id="Snippet2"::: :::code language="csharp" source="~/snippets/csharp/System/Type/GetTypeCode/iconvertible.cs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TypeCode/VB/iconvertible.vb" id="Snippet2"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.TypeCode/VB/iconvertible.vb" id="Snippet2"::: + ]]> diff --git a/xml/System/TypeInitializationException.xml b/xml/System/TypeInitializationException.xml index d8f33c60a0a..56b84f1943e 100644 --- a/xml/System/TypeInitializationException.xml +++ b/xml/System/TypeInitializationException.xml @@ -70,121 +70,121 @@ The exception that is thrown as a wrapper around the exception thrown by the class initializer. This class cannot be inherited. - is created and passed a reference to the exception thrown by the type's class initializer. The property of holds the underlying exception. - - Typically, the exception reflects a catastrophic condition (the runtime is unable to instantiate a type) that prevents an application from continuing. Most commonly, the is thrown in response to some change in the executing environment of the application. Consequently, other than possibly for troubleshooting debug code, the exception should not be handled in a `try`/`catch` block. Instead, the cause of the exception should be investigated and eliminated. - - uses the HRESULT COR_E_TYPEINITIALIZATION, which has the value 0x80131534. - - For a list of initial property values for an instance of , see the constructors. - - The following sections describe some of the situations in which a exception is thrown. - -- [Static constructors and the TypeInitializationException exception](#Static) -- [Regular expression match timeout values](#Timeout) -- [Calendars and cultural data](#Calendars) - - + is created and passed a reference to the exception thrown by the type's class initializer. The property of holds the underlying exception. + + Typically, the exception reflects a catastrophic condition (the runtime is unable to instantiate a type) that prevents an application from continuing. Most commonly, the is thrown in response to some change in the executing environment of the application. Consequently, other than possibly for troubleshooting debug code, the exception should not be handled in a `try`/`catch` block. Instead, the cause of the exception should be investigated and eliminated. + + uses the HRESULT COR_E_TYPEINITIALIZATION, which has the value 0x80131534. + + For a list of initial property values for an instance of , see the constructors. + + The following sections describe some of the situations in which a exception is thrown. + +- [Static constructors and the TypeInitializationException exception](#Static) +- [Regular expression match timeout values](#Timeout) +- [Calendars and cultural data](#Calendars) + + ## Static constructors and the TypeInitializationException - A static constructor, if one exists, is called automatically by the runtime before creating a new instance of a type. Static constructors can be explicitly defined by a developer. If a static constructor is not explicitly defined, compilers automatically create one to initialize any `static` (in C# or F#) or `Shared` (in Visual Basic) members of the type. For more information on static constructors, see [Static Constructors](/dotnet/csharp/programming-guide/classes-and-structs/static-constructors). - - Most commonly, a exception is thrown when a static constructor is unable to instantiate a type. The property indicates why the static constructor was unable to instantiate the type. Some of the more common causes of a exception are: - -- An unhandled exception in a static constructor - - If an exception is thrown in a static constructor, that exception is wrapped in a exception, and the type cannot be instantiated. - - What often makes this exception difficult to troubleshoot is that static constructors are not always explicitly defined in source code. A static constructor exists in a type if: - - - It has been explicitly defined as a member of a type. - - - The type has `static` (in C# or F#) or `Shared` (in Visual Basic) variables that are declared and initialized in a single statement. In this case, the language compiler generates a static constructor for the type. You can inspect it by using a utility such as [IL Disassembler](/dotnet/framework/tools/ildasm-exe-il-disassembler). For instance, when the C# and VB compilers compile the following example, they generate the IL for a static constructor that is similar to this: - - ``` - .method private specialname rtspecialname static - void .cctor() cil managed - { - // Code size 12 (0xc) - .maxstack 8 - IL_0000: ldc.i4.3 - IL_0001: newobj instance void TestClass::.ctor(int32) - IL_0006: stsfld class TestClass Example::test - IL_000b: ret - } // end of method Example::.cctor - ``` - - The following example shows a exception thrown by a compiler-generated static constructor. The `Example` class includes a `static` (in C#) or `Shared` (in Visual Basic) field of type `TestClass` that is instantiated by passing a value of 3 to its class constructor. That value, however, is illegal; only values of 0 or 1 are permitted. As a result, the `TestClass` class constructor throws an . Since this exception is not handled, it is wrapped in a exception. - + A static constructor, if one exists, is called automatically by the runtime before creating a new instance of a type. Static constructors can be explicitly defined by a developer. If a static constructor is not explicitly defined, compilers automatically create one to initialize any `static` (in C# or F#) or `Shared` (in Visual Basic) members of the type. For more information on static constructors, see [Static Constructors](/dotnet/csharp/programming-guide/classes-and-structs/static-constructors). + + Most commonly, a exception is thrown when a static constructor is unable to instantiate a type. The property indicates why the static constructor was unable to instantiate the type. Some of the more common causes of a exception are: + +- An unhandled exception in a static constructor + + If an exception is thrown in a static constructor, that exception is wrapped in a exception, and the type cannot be instantiated. + + What often makes this exception difficult to troubleshoot is that static constructors are not always explicitly defined in source code. A static constructor exists in a type if: + + - It has been explicitly defined as a member of a type. + + - The type has `static` (in C# or F#) or `Shared` (in Visual Basic) variables that are declared and initialized in a single statement. In this case, the language compiler generates a static constructor for the type. You can inspect it by using a utility such as [IL Disassembler](/dotnet/framework/tools/ildasm-exe-il-disassembler). For instance, when the C# and VB compilers compile the following example, they generate the IL for a static constructor that is similar to this: + + ``` + .method private specialname rtspecialname static + void .cctor() cil managed + { + // Code size 12 (0xc) + .maxstack 8 + IL_0000: ldc.i4.3 + IL_0001: newobj instance void TestClass::.ctor(int32) + IL_0006: stsfld class TestClass Example::test + IL_000b: ret + } // end of method Example::.cctor + ``` + + The following example shows a exception thrown by a compiler-generated static constructor. The `Example` class includes a `static` (in C#) or `Shared` (in Visual Basic) field of type `TestClass` that is instantiated by passing a value of 3 to its class constructor. That value, however, is illegal; only values of 0 or 1 are permitted. As a result, the `TestClass` class constructor throws an . Since this exception is not handled, it is wrapped in a exception. + :::code language="csharp" source="~/snippets/csharp/System/TypeInitializationException/Overview/ctorException1.cs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.TypeInitializationException/vb/CtorException1.vb" id="Snippet3"::: - - Note that the exception message displays information about the property. - -- A missing assembly or data file - - A common cause of a exception is that an assembly or data file that was present in an application's development and test environments is missing from its runtime environment. For example, you can compile the following example to an assembly named Missing1a.dll by using this command-line syntax: - - ```csharp - csc -t:library Missing1a.cs - ``` - - ```fsharp - fsc --target:library Missing1a.fs - ``` - - ```vb - vbc Missing1a.vb -t:library - ``` - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.TypeInitializationException/vb/CtorException1.vb" id="Snippet3"::: + + Note that the exception message displays information about the property. + +- A missing assembly or data file + + A common cause of a exception is that an assembly or data file that was present in an application's development and test environments is missing from its runtime environment. For example, you can compile the following example to an assembly named Missing1a.dll by using this command-line syntax: + + ```csharp + csc -t:library Missing1a.cs + ``` + + ```fsharp + fsc --target:library Missing1a.fs + ``` + + ```vb + vbc Missing1a.vb -t:library + ``` + :::code language="csharp" source="~/snippets/csharp/System/TypeInitializationException/Overview/Missing1a.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/TypeInitializationException/Overview/Missing1a.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.TypeInitializationException/vb/Missing1a.vb" id="Snippet1"::: - - You can then compile the following example to an executable named Missing1.exe by including a reference to Missing1a.dll: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.TypeInitializationException/vb/Missing1a.vb" id="Snippet1"::: + + You can then compile the following example to an executable named Missing1.exe by including a reference to Missing1a.dll: + ```csharp - csc Missing1.cs /r:Missing1a.dll - ``` - + csc Missing1.cs /r:Missing1a.dll + ``` + ```vb - vbc Missing1.vb /r:Missing1a.dll - ``` - - However, if you rename, move, or delete Missing1a.dll and run the example, it throws a exception and displays the output shown in the example. Note that the exception message includes information about the property. In this case, the inner exception is a that is thrown because the runtime cannot find the dependent assembly. - + vbc Missing1.vb /r:Missing1a.dll + ``` + + However, if you rename, move, or delete Missing1a.dll and run the example, it throws a exception and displays the output shown in the example. Note that the exception message includes information about the property. In this case, the inner exception is a that is thrown because the runtime cannot find the dependent assembly. + :::code language="csharp" source="~/snippets/csharp/System/TypeInitializationException/Overview/Missing1.cs" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/TypeInitializationException/Overview/Missing1.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.TypeInitializationException/vb/Missing1.vb" id="Snippet2"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.TypeInitializationException/vb/Missing1.vb" id="Snippet2"::: + > [!NOTE] - > In this example, a exception was thrown because an assembly could not be loaded. The exception can also be thrown if a static constructor attempts to open a data file, such as a configuration file, an XML file, or a file containing serialized data, that it cannot find. - - -## Regular expression match timeout values - You can set the default timeout value for a regular expression pattern matching operation on a per-application domain basis. The timeout is defined by a specifying a value for the "REGEX_DEFAULT_MATCH_TIMEOUT" property to the method. The time interval must be a valid object that is greater than zero and less than approximately 24 days. If these requirements are not met, the attempt to set the default timeout value throws an , which in turn is wrapped in a exception. - - The following example shows the that is thrown when the value assigned to the "REGEX_DEFAULT_MATCH_TIMEOUT" property is invalid. To eliminate the exception, set the"REGEX_DEFAULT_MATCH_TIMEOUT" property to a value that is greater than zero and less than approximately 24 days. - + > In this example, a exception was thrown because an assembly could not be loaded. The exception can also be thrown if a static constructor attempts to open a data file, such as a configuration file, an XML file, or a file containing serialized data, that it cannot find. + + +## Regular expression match timeout values + You can set the default timeout value for a regular expression pattern matching operation on a per-application domain basis. The timeout is defined by a specifying a value for the "REGEX_DEFAULT_MATCH_TIMEOUT" property to the method. The time interval must be a valid object that is greater than zero and less than approximately 24 days. If these requirements are not met, the attempt to set the default timeout value throws an , which in turn is wrapped in a exception. + + The following example shows the that is thrown when the value assigned to the "REGEX_DEFAULT_MATCH_TIMEOUT" property is invalid. To eliminate the exception, set the"REGEX_DEFAULT_MATCH_TIMEOUT" property to a value that is greater than zero and less than approximately 24 days. + :::code language="csharp" source="~/snippets/csharp/System/TypeInitializationException/Overview/Regex1.cs" id="Snippet4"::: :::code language="fsharp" source="~/snippets/fsharp/System/TypeInitializationException/Overview/Regex1.fs" id="Snippet4"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.TypeInitializationException/vb/Regex1.vb" id="Snippet4"::: - - -## Calendars and cultural data - If you attempt to instantiate a calendar but the runtime is unable to instantiate the object that corresponds to that calendar, it throws a exception. This exception can be thrown by the following calendar class constructors: - -- The parameterless constructor of the class. - -- The parameterless constructor of the class. - -- The parameterless constructor of the class. - - Since cultural data for these cultures should be available on all systems, you should rarely, if ever, encounter this exception. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.TypeInitializationException/vb/Regex1.vb" id="Snippet4"::: + + +## Calendars and cultural data + If you attempt to instantiate a calendar but the runtime is unable to instantiate the object that corresponds to that calendar, it throws a exception. This exception can be thrown by the following calendar class constructors: + +- The parameterless constructor of the class. + +- The parameterless constructor of the class. + +- The parameterless constructor of the class. + + Since cultural data for these cultures should be available on all systems, you should rarely, if ever, encounter this exception. + ]]> @@ -241,19 +241,19 @@ The exception that is the cause of the current exception. If the parameter is not a null reference ( in Visual Basic), the current exception is raised in a block that handles the inner exception. Initializes a new instance of the class with the default error message, the specified type name, and a reference to the inner exception that is the root cause of this exception. - property. The property returns the same value that is passed into the constructor, or a null reference (`Nothing` in Visual Basic) if the property does not supply the inner exception value to the constructor. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||The inner exception reference.| -||The localized error message string.| -||The name of the type.| - + property. The property returns the same value that is passed into the constructor, or a null reference (`Nothing` in Visual Basic) if the property does not supply the inner exception value to the constructor. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||The inner exception reference.| +||The localized error message string.| +||The name of the type.| + ]]> diff --git a/xml/System/TypeLoadException.xml b/xml/System/TypeLoadException.xml index ccfc6381567..3c82b0ba284 100644 --- a/xml/System/TypeLoadException.xml +++ b/xml/System/TypeLoadException.xml @@ -76,17 +76,17 @@ The exception that is thrown when type-loading failures occur. - is thrown when the common language runtime cannot find the assembly, the type within the assembly, or cannot load the type. The property contains more detailed information that can help you identify the cause of the exception. - - uses the HRESULT COR_E_TYPELOAD, that has the value 0x80131522. - - For a list of initial property values for an instance of , see the constructors. - + is thrown when the common language runtime cannot find the assembly, the type within the assembly, or cannot load the type. The property contains more detailed information that can help you identify the cause of the exception. + + uses the HRESULT COR_E_TYPELOAD, that has the value 0x80131522. + + For a list of initial property values for an instance of , see the constructors. + The exact timing of when statically referenced types are loaded is unspecified. This exception may be thrown before the method that references the missing type starts executing. - + ]]> @@ -143,18 +143,18 @@ The exact timing of when statically referenced types are loaded is unspecified. Initializes a new instance of the class. - property of the new instance to a system-supplied message that describes the error, such as "A failure has occurred while loading a type." This message takes into account the current system culture. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The localized error message string.| - + property of the new instance to a system-supplied message that describes the error, such as "A failure has occurred while loading a type." This message takes into account the current system culture. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The localized error message string.| + ]]> @@ -207,27 +207,27 @@ The exact timing of when statically referenced types are loaded is unspecified. The message that describes the error. Initializes a new instance of the class with a specified error message. - . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The error message string.| - - - -## Examples - The following code example demonstrates the constructor. It contains a method that generates a with a custom message, and displays the error message to the console. - + . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The error message string.| + + + +## Examples + The following code example demonstrates the constructor. It contains a method that generates a with a custom message, and displays the error message to the console. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/TypeLoadException_Constructor2/CPP/typeloadexception_constructor2.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/TypeLoadException/.ctor/typeloadexception_constructor2.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/TypeLoadException_Constructor2/VB/typeloadexception_constructor2.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/TypeLoadException_Constructor2/VB/typeloadexception_constructor2.vb" id="Snippet1"::: + ]]> @@ -285,20 +285,20 @@ The exact timing of when statically referenced types are loaded is unspecified. The contextual information about the source or destination. Initializes a new instance of the class with serialized data. - The object is . @@ -355,27 +355,27 @@ The exact timing of when statically referenced types are loaded is unspecified. The exception that is the cause of the current exception. If the parameter is not , the current exception is raised in a block that handles the inner exception. Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception. - property. The property returns the same value that is passed into the constructor, or `null` if the property does not supply the inner exception value to the constructor. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||The inner exception reference.| -||The error message string.| - - - -## Examples - The following code example demonstrates the constructor. It contains a method that generates a , catches that exception, and throws a new with a custom message, including the original as the inner exception. - + property. The property returns the same value that is passed into the constructor, or `null` if the property does not supply the inner exception value to the constructor. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||The inner exception reference.| +||The error message string.| + + + +## Examples + The following code example demonstrates the constructor. It contains a method that generates a , catches that exception, and throws a new with a custom message, including the original as the inner exception. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/TypeLoadException_Constructor3/CPP/typeloadexception_constructor3.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/TypeLoadException/.ctor/typeloadexception_constructor3.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/TypeLoadException_Constructor3/VB/typeloadexception_constructor3.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/TypeLoadException_Constructor3/VB/typeloadexception_constructor3.vb" id="Snippet1"::: + ]]> @@ -441,23 +441,23 @@ The exact timing of when statically referenced types are loaded is unspecified. The contextual information about the source or destination. Sets the object with the class name, method name, resource ID, and additional exception information. - sets a with all the exception object data targeted for serialization. During deserialization, the exception object is reconstituted from the transmitted over the stream. - - For more information, see [XML and SOAP Serialization](/dotnet/standard/serialization/xml-and-soap-serialization). - - - -## Examples - - The following example generates an exception, and serializes the exception data to a file, and then reconstitutes the exception. For this code example to run, you must provide the fully qualified assembly name. For information about how to obtain the fully qualified assembly name, see [Assembly Names](/dotnet/standard/assembly/names). - + sets a with all the exception object data targeted for serialization. During deserialization, the exception object is reconstituted from the transmitted over the stream. + + For more information, see [XML and SOAP Serialization](/dotnet/standard/serialization/xml-and-soap-serialization). + + + +## Examples + + The following example generates an exception, and serializes the exception data to a file, and then reconstitutes the exception. For this code example to run, you must provide the fully qualified assembly name. For information about how to obtain the fully qualified assembly name, see [Assembly Names](/dotnet/standard/assembly/names). + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/TypeLoadException_GetObjectData/CPP/typeloadexception_getobjectdata.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/TypeLoadException/.ctor/typeloadexception_getobjectdata.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/TypeLoadException_GetObjectData/VB/typeloadexception_getobjectdata.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/TypeLoadException_GetObjectData/VB/typeloadexception_getobjectdata.vb" id="Snippet1"::: + ]]> The object is . @@ -512,22 +512,22 @@ The exact timing of when statically referenced types are loaded is unspecified. Gets the error message for this exception. The error message string. - . The error message should be localized. - - This property is read-only. - - - -## Examples - The following example attempts to load a non-existent type from the mscorlib assembly. The resulting exception is caught, and the and values are displayed. For this code example to run, you must provide the fully qualified assembly name. For information about how to obtain the fully qualified assembly name, see [Assembly Names](/dotnet/standard/assembly/names). - + . The error message should be localized. + + This property is read-only. + + + +## Examples + The following example attempts to load a non-existent type from the mscorlib assembly. The resulting exception is caught, and the and values are displayed. For this code example to run, you must provide the fully qualified assembly name. For information about how to obtain the fully qualified assembly name, see [Assembly Names](/dotnet/standard/assembly/names). + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/TypeLoadException_TypeName/CPP/typeloadexception_typename.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/TypeLoadException/Message/typeloadexception_typename.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/TypeLoadException_TypeName/VB/typeloadexception_typename.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/TypeLoadException_TypeName/VB/typeloadexception_typename.vb" id="Snippet1"::: + ]]> @@ -573,21 +573,19 @@ The exact timing of when statically referenced types are loaded is unspecified. Gets the fully qualified name of the type that causes the exception. The fully qualified type name. - and values are displayed. For this code example to run, you must provide the fully qualified assembly name. For information about how to obtain the fully qualified assembly name, see [Assembly Names](/dotnet/standard/assembly/names). - + and values are displayed. For this code example to run, you must provide the fully qualified assembly name. For information about how to obtain the fully qualified assembly name, see [Assembly Names](/dotnet/standard/assembly/names). + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/TypeLoadException_TypeName/CPP/typeloadexception_typename.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/TypeLoadException/Message/typeloadexception_typename.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/TypeLoadException_TypeName/VB/typeloadexception_typename.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/TypeLoadException_TypeName/VB/typeloadexception_typename.vb" id="Snippet1"::: + ]]> - When overriding in a derived class, be sure to call the base class's property. - - This property is read-only. + When overriding in a derived class, be sure to call the base class's property. This property is read-only. diff --git a/xml/System/TypeUnloadedException.xml b/xml/System/TypeUnloadedException.xml index 7761696fafe..ce1ea03fc80 100644 --- a/xml/System/TypeUnloadedException.xml +++ b/xml/System/TypeUnloadedException.xml @@ -65,13 +65,13 @@ The exception that is thrown when there is an attempt to access an unloaded class. - uses the HRESULT COR_E_TYPEUNLOADED, that has the value 0x80131013. - - For a list of initial property values for an instance of , see the constructors. - + uses the HRESULT COR_E_TYPEUNLOADED, that has the value 0x80131013. + + For a list of initial property values for an instance of , see the constructors. + ]]> @@ -121,18 +121,18 @@ Initializes a new instance of the class. - property of the new instance to a system-supplied message that describes the error, such as "Type has been unloaded." This message takes into account the current system culture. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The localized error message string.| - + property of the new instance to a system-supplied message that describes the error, such as "Type has been unloaded." This message takes into account the current system culture. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The localized error message string.| + ]]> @@ -175,18 +175,18 @@ The message that describes the error. Initializes a new instance of the class with a specified error message. - . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The error message string.| - + . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The error message string.| + ]]> @@ -248,11 +248,11 @@ The contextual information about the source or destination. Initializes a new instance of the class with serialized data. - XML and SOAP Serialization @@ -298,18 +298,18 @@ The exception that is the cause of the current exception. If the parameter is not a null reference ( in Visual Basic), the current exception is raised in a block that handles the inner exception. Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception. - property. The property returns the same value that is passed into the constructor, or a null reference (`Nothing` in Visual Basic) if the property does not supply the inner exception value to the constructor. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||The inner exception reference.| -||The error message string.| - + property. The property returns the same value that is passed into the constructor, or a null reference (`Nothing` in Visual Basic) if the property does not supply the inner exception value to the constructor. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||The inner exception reference.| +||The error message string.| + ]]> diff --git a/xml/System/TypedReference.xml b/xml/System/TypedReference.xml index 244a810e740..217b25370cb 100644 --- a/xml/System/TypedReference.xml +++ b/xml/System/TypedReference.xml @@ -63,18 +63,18 @@ Describes objects that contain both a managed pointer to a location and a runtime representation of the type that may be stored at that location. - @@ -267,38 +267,38 @@ Makes a for a field identified by a specified object and list of field descriptions. A for the field described by the last element of . - method returns a typed reference to some terminal field, where the `target` parameter contains the field described by the first element of `flds`, the field described by the first element of `flds` contains the field described by the second element of `flds`, and so on until the terminal field is reached. - + method returns a typed reference to some terminal field, where the `target` parameter contains the field described by the first element of `flds`, the field described by the first element of `flds` contains the field described by the second element of `flds`, and so on until the terminal field is reached. + > [!NOTE] -> Starting with the .NET Framework 2.0 Service Pack 1, this method can be used to access non-public members if the caller has been granted with the flag and if the grant set of the non-public members is restricted to the caller's grant set, or a subset thereof. (See [Security Considerations for Reflection](/dotnet/framework/reflection-and-codedom/security-considerations-for-reflection).) -> -> To use this functionality, your application should target the .NET Framework 3.5 or later. - +> Starting with the .NET Framework 2.0 Service Pack 1, this method can be used to access non-public members if the caller has been granted with the flag and if the grant set of the non-public members is restricted to the caller's grant set, or a subset thereof. (See [Security Considerations for Reflection](/dotnet/framework/reflection-and-codedom/security-considerations-for-reflection).) +> +> To use this functionality, your application should target the .NET Framework 3.5 or later. + ]]> - or is . - - -or- - - An element of is . - The array has no elements. - - -or- - - An element of is not a object. - - -or- - - The or property of an element of is . - Parameter does not contain the field described by the first element of , or an element of describes a field that is not contained in the field described by the succeeding element of . - - -or- - - The field described by an element of is not a value type. + or is . + +-or- + +An element of is . + The array has no elements. + +-or- + +An element of is not a object. + +-or- + +The or property of an element of is . + Parameter does not contain the field described by the first element of , or an element of describes a field that is not contained in the field described by the succeeding element of . + +-or- + +The field described by an element of is not a value type. @@ -358,11 +358,11 @@ The value to be converted. Converts the specified value to a . This method is not supported. - . - + . + ]]> In all cases. @@ -458,11 +458,11 @@ Converts the specified to an . An converted from a . - diff --git a/xml/System/UInt16.xml b/xml/System/UInt16.xml index 3305a38d0d6..b8f65a9214a 100644 --- a/xml/System/UInt16.xml +++ b/xml/System/UInt16.xml @@ -375,25 +375,34 @@ An object to compare, or . Compares this instance to a specified object and returns an indication of their relative values. - A signed number indicating the relative values of this instance and . - - Return Value - - Description - - Less than zero - - This instance is less than . - - Zero - - This instance is equal to . - - Greater than zero - - This instance is greater than , or is . - - + A signed number indicating the relative values of this instance and . + + Return Value + + + Description + + + + + Less than zero + + + This instance is less than . + + + Zero + + + This instance is equal to . + + + Greater than zero + + + This instance is greater than , or is . + + An unsigned integer to compare. Compares this instance to a specified 16-bit unsigned integer and returns an indication of their relative values. - A signed number indicating the relative values of this instance and . - - Return Value - - Description - - Less than zero - - This instance is less than . - - Zero - - This instance is equal to . - - Greater than zero - - This instance is greater than . - - + A signed number indicating the relative values of this instance and . + + Return Value + + + Description + + + + + Less than zero + + + This instance is less than . + + + Zero + + + This instance is equal to . + + + Greater than zero + + + This instance is greater than . + + - 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 a 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 a value. The following example illustrates the difference in behavior between the two method overloads. In the case of a value, 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 language="csharp" source="~/snippets/csharp/System/UInt16/Equals/equalsoverl.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/UInt16/Equals/equalsoverl.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.uint16.equals/vb/equalsoverl.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 a 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 a value. The following example illustrates the difference in behavior between the two method overloads. In the case of a value, 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 language="csharp" source="~/snippets/csharp/System/UInt16/Equals/equalsoverl.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/UInt16/Equals/equalsoverl.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.uint16.equals/vb/equalsoverl.vb" id="Snippet1"::: @@ -872,11 +886,7 @@ ]]> - 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 a 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 a value. The following example illustrates the difference in behavior between the two method overloads. In the case of a value, 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 language="csharp" source="~/snippets/csharp/System/UInt16/Equals/equalsoverl.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/UInt16/Equals/equalsoverl.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.uint16.equals/vb/equalsoverl.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 a 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 a value. The following example illustrates the difference in behavior between the two method overloads. In the case of a value, 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 language="csharp" source="~/snippets/csharp/System/UInt16/Equals/equalsoverl.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/UInt16/Equals/equalsoverl.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.uint16.equals/vb/equalsoverl.vb" id="Snippet1"::: @@ -1640,9 +1650,7 @@ For this method matches the IEEE 754:2 A string that represents the number to convert. The string is interpreted by using the style specified by the parameter. A bitwise combination of the enumeration values that specify the permitted format of . A typical value to specify is . - Converts the string representation of a number in a specified style to its 16-bit unsigned integer equivalent. - - This method is not CLS-compliant. The CLS-compliant alternative is . + Converts the string representation of a number in a specified style to its 16-bit unsigned integer equivalent. This method is not CLS-compliant. The CLS-compliant alternative is . A 16-bit unsigned integer equivalent to the number specified in . this method matches the IEEE 754:2 is not a value. - -or- +-or- - is not a combination of and values. + is not a combination of and values. is not in a format compliant with . represents a number less than UInt16.MinValue or greater than UInt16.MaxValue. - -or- +-or- - includes non-zero, fractional digits. + includes non-zero, fractional digits. Parsing Numeric Strings in .NET @@ -2101,17 +2109,17 @@ For this method matches the IEEE 754:2 is not a value. - -or- +-or- - is not a combination of and values. + is not a combination of and values. is not in a format compliant with . represents a number that is less than UInt16.MinValue or greater than UInt16.MaxValue. - -or- +-or- - includes non-zero, fractional digits. + includes non-zero, fractional digits. Parsing Numeric Strings in .NET @@ -2306,8 +2314,24 @@ It is recommended that a function return `1`, `0`, and `-1`, respectively. An object to compare, or . Compares this instance to a specified object and returns an indication of their relative values. - A signed number indicating the relative values of this instance and . - Return ValueDescriptionLess than zeroThis instance is less than .ZeroThis instance is equal to .Greater than zeroThis instance is greater than , or is . + A signed number indicating the relative values of this instance and . + + Return Value + Description + + + Less than zero + This instance is less than . + + + Zero + This instance is equal to . + + + Greater than zero + This instance is greater than , or is . + + is not a value. - -or- +-or- - is not a combination of and values. + is not a combination of and values. Parsing Numeric Strings in .NET diff --git a/xml/System/UInt32.xml b/xml/System/UInt32.xml index b4a3b579702..05995164456 100644 --- a/xml/System/UInt32.xml +++ b/xml/System/UInt32.xml @@ -375,25 +375,34 @@ An object to compare, or . Compares this instance to a specified object and returns an indication of their relative values. - A signed number indicating the relative values of this instance and . - - Return Value - - Description - - Less than zero - - This instance is less than . - - Zero - - This instance is equal to . - - Greater than zero - - This instance is greater than , or is . - - + A signed number indicating the relative values of this instance and . + + Return Value + + + Description + + + + + Less than zero + + + This instance is less than . + + + Zero + + + This instance is equal to . + + + Greater than zero + + + This instance is greater than , or is . + + An unsigned integer to compare. Compares this instance to a specified 32-bit unsigned integer and returns an indication of their relative values. - A signed number indicating the relative values of this instance and . - - Return value - - Description - - Less than zero - - This instance is less than . - - Zero - - This instance is equal to . - - Greater than zero - - This instance is greater than . - - + A signed number indicating the relative values of this instance and . + + Return value + + + Description + + + + + Less than zero + + + This instance is less than . + + + Zero + + + This instance is equal to . + + + Greater than zero + + + This instance is greater than . + + - 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 a 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 a value. The following example illustrates the difference in behavior between the two method overloads. In the case of 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 language="csharp" source="~/snippets/csharp/System/UInt32/Equals/equalsoverl.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/UInt32/Equals/equalsoverl.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.uint32.equals/vb/equalsoverl.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 a 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 a value. The following example illustrates the difference in behavior between the two method overloads. In the case of 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 language="csharp" source="~/snippets/csharp/System/UInt32/Equals/equalsoverl.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/UInt32/Equals/equalsoverl.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.uint32.equals/vb/equalsoverl.vb" id="Snippet1"::: @@ -877,11 +891,7 @@ ]]> - 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 a 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 a value. The following example illustrates the difference in behavior between the two method overloads. In the case of 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 language="csharp" source="~/snippets/csharp/System/UInt32/Equals/equalsoverl.cs" id="Snippet1"::: - :::code language="fsharp" source="~/snippets/fsharp/System/UInt32/Equals/equalsoverl.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.uint32.equals/vb/equalsoverl.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 a 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 a value. The following example illustrates the difference in behavior between the two method overloads. In the case of 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 language="csharp" source="~/snippets/csharp/System/UInt32/Equals/equalsoverl.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/UInt32/Equals/equalsoverl.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.uint32.equals/vb/equalsoverl.vb" id="Snippet1"::: @@ -1731,17 +1741,17 @@ For this method matches the IEEE 754:2 is not a value. - -or- +-or- - is not a combination of and values. + is not a combination of and values. is not in a format compliant with . represents a number that is less than UInt32.MinValue or greater than UInt32.MaxValue. - -or- +-or- - includes non-zero, fractional digits. + includes non-zero, fractional digits. Parsing Numeric Strings in .NET @@ -2115,17 +2125,17 @@ For this method matches the IEEE 754:2 is not a value. - -or- +-or- - is not a combination of and values. + is not a combination of and values. is not in a format compliant with . represents a number that is less than UInt32.MinValue or greater than UInt32.MaxValue. - -or- +-or- - includes non-zero, fractional digits. + includes non-zero, fractional digits. Parsing Numeric Strings in .NET @@ -2319,8 +2329,24 @@ It is recommended that a function return `1`, `0`, and `-1`, respectively. An object to compare, or . Compares this instance to a specified object and returns an indication of their relative values. - A signed number indicating the relative values of this instance and . - Return ValueDescriptionLess than zeroThis instance is less than .ZeroThis instance is equal to .Greater than zeroThis instance is greater than , or is . + A signed number indicating the relative values of this instance and . + + Return Value + Description + + + Less than zero + This instance is less than . + + + Zero + This instance is equal to . + + + Greater than zero + This instance is greater than , or is . + + is not a value. - -or- +-or- - is not a combination of and values. + is not a combination of and values. Parsing Numeric Strings in .NET diff --git a/xml/System/UInt64.xml b/xml/System/UInt64.xml index 7bcf1eed0e8..3a035f2c2bd 100644 --- a/xml/System/UInt64.xml +++ b/xml/System/UInt64.xml @@ -373,25 +373,34 @@ An object to compare, or . Compares this instance to a specified object and returns an indication of their relative values. - A signed number indicating the relative values of this instance and . - - Return Value - - Description - - Less than zero - - This instance is less than . - - Zero - - This instance is equal to . - - Greater than zero - - This instance is greater than , or is . - - + A signed number indicating the relative values of this instance and . + + Return Value + + + Description + + + + + Less than zero + + + This instance is less than . + + + Zero + + + This instance is equal to . + + + Greater than zero + + + This instance is greater than , or is . + + An unsigned integer to compare. Compares this instance to a specified 64-bit unsigned integer and returns an indication of their relative values. - A signed number indicating the relative values of this instance and . - - Return Value - - Description - - Less than zero - - This instance is less than . - - Zero - - This instance is equal to . - - Greater than zero - - This instance is greater than . - - + A signed number indicating the relative values of this instance and . + + Return Value + + + Description + + + + + Less than zero + + + This instance is less than . + + + Zero + + + This instance is equal to . + + + Greater than zero + + + This instance is greater than . + + - 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 a 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 a 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 language="csharp" source="~/snippets/csharp/System/UInt64/Equals/equalsoverl.cs" id="Snippet2"::: - :::code language="fsharp" source="~/snippets/fsharp/System/UInt64/Equals/equalsoverl.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.uint64.equals/vb/equalsoverl.vb" id="Snippet2"::: + 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 a 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 a 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 language="csharp" source="~/snippets/csharp/System/UInt64/Equals/equalsoverl.cs" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/UInt64/Equals/equalsoverl.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.uint64.equals/vb/equalsoverl.vb" id="Snippet2"::: @@ -880,11 +894,7 @@ ]]> - 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 a 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 a 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 language="csharp" source="~/snippets/csharp/System/UInt64/Equals/equalsoverl.cs" id="Snippet2"::: - :::code language="fsharp" source="~/snippets/fsharp/System/UInt64/Equals/equalsoverl.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.uint64.equals/vb/equalsoverl.vb" id="Snippet2"::: + 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 a 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 a 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 language="csharp" source="~/snippets/csharp/System/UInt64/Equals/equalsoverl.cs" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/UInt64/Equals/equalsoverl.fs" id="Snippet2"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.uint64.equals/vb/equalsoverl.vb" id="Snippet2"::: @@ -1718,15 +1728,15 @@ For this method matches the IEEE 754:2 is not a value. - -or- +-or- - is not a combination of and values. + is not a combination of and values. The parameter is not in a format compliant with . The parameter represents a number less than UInt64.MinValue or greater than UInt64.MaxValue. - -or- +-or- - includes non-zero, fractional digits. + includes non-zero, fractional digits. Parsing Numeric Strings in .NET @@ -2098,15 +2108,15 @@ For this method matches the IEEE 754:2 is not a value. - -or- +-or- - is not a combination of and values. + is not a combination of and values. The parameter is not in a format compliant with . The parameter represents a number less than UInt64.MinValue or greater than UInt64.MaxValue. - -or- +-or- - includes non-zero, fractional digits. + includes non-zero, fractional digits. Parsing Numeric Strings in .NET @@ -2300,8 +2310,24 @@ It is recommended that a function return `1`, `0`, and `-1`, respectively. An object to compare, or . Compares this instance to a specified object and returns an indication of their relative values. - A signed number indicating the relative values of this instance and . - Return ValueDescriptionLess than zeroThis instance is less than .ZeroThis instance is equal to .Greater than zeroThis instance is greater than , or is . + A signed number indicating the relative values of this instance and . + + Return Value + Description + + + Less than zero + This instance is less than . + + + Zero + This instance is equal to . + + + Greater than zero + This instance is greater than , or is . + + is not a value. - -or- +-or- - is not a combination of and values. + is not a combination of and values. diff --git a/xml/System/UIntPtr.xml b/xml/System/UIntPtr.xml index 63432f75585..fab41039bb4 100644 --- a/xml/System/UIntPtr.xml +++ b/xml/System/UIntPtr.xml @@ -604,16 +604,29 @@ An object to compare, or . Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object. - A value that indicates the relative order of the objects being compared. The return value has these meanings: - Value - Meaning - Less than zero - This instance precedes in the sort order. - Zero - This instance occurs in the same position in the sort order as . - Greater than zero - This instance follows in the sort order. - + A value that indicates the relative order of the objects being compared. The return value has these meanings: + + Value + + Meaning + + + + Less than zero + + This instance precedes in the sort order. + + + Zero + + This instance occurs in the same position in the sort order as . + + + Greater than zero + + This instance follows in the sort order. + + To be added. @@ -650,16 +663,29 @@ An unsigned native integer to compare. Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object. - A value that indicates the relative order of the objects being compared. The return value has these meanings: - Value - Meaning - Less than zero - This instance precedes in the sort order. - Zero - This instance occurs in the same position in the sort order as . - Greater than zero - This instance follows in the sort order. - + A value that indicates the relative order of the objects being compared. The return value has these meanings: + + Value + + Meaning + + + + Less than zero + + This instance precedes in the sort order. + + + Zero + + This instance occurs in the same position in the sort order as . + + + Greater than zero + + This instance follows in the sort order. + + To be added. @@ -1792,9 +1818,7 @@ For this method matches the IEEE 754:2 The unsigned integer to convert. - Converts the value of the specified to a pointer to an unspecified type. - - This API is not CLS-compliant. + Converts the value of the specified to a pointer to an unspecified type. This API is not CLS-compliant. The contents of . To be added. @@ -1851,9 +1875,7 @@ For this method matches the IEEE 754:2 A pointer to an unspecified type. - Converts the specified pointer to an unspecified type to an . - - This API is not CLS-compliant. + Converts the specified pointer to an unspecified type to an . This API is not CLS-compliant. A new instance of initialized to . To be added. @@ -5571,8 +5593,10 @@ This member is an explicit interface member implementation. It can be used only The format to use. - -or- - A reference ( in Visual Basic) to use the default format defined for the type of the implementation. + +-or- + +A reference ( in Visual Basic) to use the default format defined for the type of the implementation. An object that supplies culture-specific formatting information. Formats the value of the current instance using the specified format. The value of the current instance in the specified format. diff --git a/xml/System/UnauthorizedAccessException.xml b/xml/System/UnauthorizedAccessException.xml index 455ef06d34c..6317d3787b1 100644 --- a/xml/System/UnauthorizedAccessException.xml +++ b/xml/System/UnauthorizedAccessException.xml @@ -70,22 +70,22 @@ The exception that is thrown when the operating system denies access because of an I/O error or a specific type of security error. - exception is typically thrown by a method that wraps a Windows API call. To find the reasons for the exception, examine the text of the exception object's property. - - uses the `HRESULT` `COR_E_UNAUTHORIZEDACCESS`, which has the value 0x80070005. - - - -## Examples - The following example illustrates the exception that is thrown when attempting to write to a read-only file. - + exception is typically thrown by a method that wraps a Windows API call. To find the reasons for the exception, examine the text of the exception object's property. + + uses the `HRESULT` `COR_E_UNAUTHORIZEDACCESS`, which has the value 0x80070005. + + + +## Examples + The following example illustrates the exception that is thrown when attempting to write to a read-only file. + :::code language="csharp" source="~/snippets/csharp/System/UnauthorizedAccessException/Overview/withio.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/UnauthorizedAccessException/Overview/withio.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.unauthorizedaccessexception/vb/withio.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.unauthorizedaccessexception/vb/withio.vb" id="Snippet1"::: + ]]> @@ -142,18 +142,18 @@ Initializes a new instance of the class. - property of the new instance to a system-supplied message that describes the error, such as "Attempted to perform an unauthorized operation." This message takes into account the current system culture. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The localized error message string.| - + property of the new instance to a system-supplied message that describes the error, such as "Attempted to perform an unauthorized operation." This message takes into account the current system culture. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The localized error message string.| + ]]> @@ -200,18 +200,18 @@ The message that describes the error. Initializes a new instance of the class with a specified error message. - . - -|Property|Value| -|--------------|-----------| -||A null reference (`Nothing` in Visual Basic).| -||The error message string.| - + . + +|Property|Value| +|--------------|-----------| +||A null reference (`Nothing` in Visual Basic).| +||The error message string.| + ]]> @@ -319,18 +319,18 @@ The exception that is the cause of the current exception. If the parameter is not a null reference ( in Visual Basic), the current exception is raised in a block that handles the inner exception. Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception. - property. The property returns the same value that is passed into the constructor, or a null reference (`Nothing` in Visual Basic) if the property does not supply the inner exception value to the constructor. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||The inner exception reference.| -||The error message string.| - + property. The property returns the same value that is passed into the constructor, or a null reference (`Nothing` in Visual Basic) if the property does not supply the inner exception value to the constructor. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||The inner exception reference.| +||The error message string.| + ]]> diff --git a/xml/System/UnhandledExceptionEventArgs.xml b/xml/System/UnhandledExceptionEventArgs.xml index d17e46b83b5..7b30213adb3 100644 --- a/xml/System/UnhandledExceptionEventArgs.xml +++ b/xml/System/UnhandledExceptionEventArgs.xml @@ -59,13 +59,13 @@ Provides data for the event that is raised when there is an exception that is not handled in any application domain. - provides access to the exception object and a flag indicating whether the common language runtime is terminating. The is one of the parameters passed into for the event. - - For more information about event handler delegates, see [Handling and Raising Events](/dotnet/standard/events/). - + provides access to the exception object and a flag indicating whether the common language runtime is terminating. The is one of the parameters passed into for the event. + + For more information about event handler delegates, see [Handling and Raising Events](/dotnet/standard/events/). + ]]> @@ -157,25 +157,25 @@ Gets the unhandled exception object. The unhandled exception object. - rather than one derived from . Although the Common Language Specification requires that all exception types derive from , it is possible for methods to throw exceptions with objects not derived from . You can do the following to work with this exception: - -- Apply the attribute with a value of `true` to the assembly that contains the event handler. This wraps all exceptions not derived from the class in a object. You can then safely cast (in C#) or convert (in Visual Basic) the object returned by this property to an object, and retrieve the original exception object from the property. Note that some compilers, such as the C# and Visual Basic compilers, automatically apply this attribute. - -- Cast the object returned by this property to an object. - - - -## Examples - The following example demonstrates the event. It defines an event handler, `MyHandler`, that is invoked whenever an unhandled exception is thrown in the default application domain. It then throws two exceptions. The first is handled by a **try/catch** block. The second is unhandled and invokes the `MyHandle` routine before the application terminates. - + rather than one derived from . Although the Common Language Specification requires that all exception types derive from , it is possible for methods to throw exceptions with objects not derived from . You can do the following to work with this exception: + +- Apply the attribute with a value of `true` to the assembly that contains the event handler. This wraps all exceptions not derived from the class in a object. You can then safely cast (in C#) or convert (in Visual Basic) the object returned by this property to an object, and retrieve the original exception object from the property. Note that some compilers, such as the C# and Visual Basic compilers, automatically apply this attribute. + +- Cast the object returned by this property to an object. + + + +## Examples + The following example demonstrates the event. It defines an event handler, `MyHandler`, that is invoked whenever an unhandled exception is thrown in the default application domain. It then throws two exceptions. The first is handled by a **try/catch** block. The second is unhandled and invokes the `MyHandle` routine before the application terminates. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/AppDomain_UnhandledException/CPP/unhandledexception.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/AppDomain/UnhandledException/unhandledexception.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/AppDomain/UnhandledException/unhandledexception.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AppDomain_UnhandledException/VB/unhandledexception.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/AppDomain_UnhandledException/VB/unhandledexception.vb" id="Snippet1"::: + ]]> @@ -226,14 +226,14 @@ if the runtime is terminating; otherwise, . - diff --git a/xml/System/UnhandledExceptionEventHandler.xml b/xml/System/UnhandledExceptionEventHandler.xml index 85ed5130061..bd397644e0d 100644 --- a/xml/System/UnhandledExceptionEventHandler.xml +++ b/xml/System/UnhandledExceptionEventHandler.xml @@ -59,13 +59,13 @@ An UnhandledExceptionEventArgs that contains the event data. Represents the method that will handle the event raised by an exception that is not handled by the application domain. - can only be specified for the default application domain that is created by the system to execute an application. Specifying an for an created by an application has no effect. - - When you create an delegate, you identify the method that will handle the event. To associate the event handler with your event, add an instance of the delegate to the event. The event handler is called whenever the event occurs, unless you remove the delegate. For more information about event handler delegates, see [Handling and Raising Events](/dotnet/standard/events/). - + can only be specified for the default application domain that is created by the system to execute an application. Specifying an for an created by an application has no effect. + + When you create an delegate, you identify the method that will handle the event. To associate the event handler with your event, add an instance of the delegate to the event. The event handler is called whenever the event occurs, unless you remove the delegate. For more information about event handler delegates, see [Handling and Raising Events](/dotnet/standard/events/). + ]]> diff --git a/xml/System/Uri.xml b/xml/System/Uri.xml index a91e80086ac..aa8edcb9559 100644 --- a/xml/System/Uri.xml +++ b/xml/System/Uri.xml @@ -359,57 +359,55 @@ The following code snippet shows example values of the various properties on the is . - Note: In the .NET for Windows Store apps or the Portable Class Library, catch the base class exception, , instead. + Note: In the .NET for Windows Store apps or the Portable Class Library, catch the base class exception, , instead. is empty. - is empty. +-or- - -or- +The scheme specified in is not correctly formed. See . - The scheme specified in is not correctly formed. See . +-or- - -or- + contains too many slashes. - contains too many slashes. +-or- - -or- +The password specified in is not valid. - The password specified in is not valid. +-or- - -or- +The host name specified in is not valid. - The host name specified in is not valid. +-or- - -or- +The file name specified in is not valid. - The file name specified in is not valid. +-or- - -or- +The user name specified in is not valid. - The user name specified in is not valid. +-or- - -or- +The host or authority name specified in cannot be terminated by backslashes. - The host or authority name specified in cannot be terminated by backslashes. +-or- - -or- +The port number specified in is not valid or cannot be parsed. - The port number specified in is not valid or cannot be parsed. +-or- - -or- +The length of exceeds 65519 characters. - The length of exceeds 65519 characters. +-or- - -or- +The length of the scheme specified in exceeds 1023 characters. - The length of the scheme specified in exceeds 1023 characters. +-or- - -or- +There is an invalid character sequence in . - There is an invalid character sequence in . +-or- - -or- - - The MS-DOS path specified in must start with c:\\\\. +The MS-DOS path specified in must start with c:\\\\. @@ -471,53 +469,53 @@ The following code snippet shows example values of the various properties on the The parameter contains a URI. The parameter contains a URI that is empty. - -or- +-or- - The scheme specified is not correctly formed. See . +The scheme specified is not correctly formed. See . - -or- +-or- - The URI contains too many slashes. +The URI contains too many slashes. - -or- +-or- - The password specified in the URI is not valid. +The password specified in the URI is not valid. - -or- +-or- - The host name specified in URI is not valid. +The host name specified in URI is not valid. - -or- +-or- - The file name specified in the URI is not valid. +The file name specified in the URI is not valid. - -or- +-or- - The user name specified in the URI is not valid. +The user name specified in the URI is not valid. - -or- +-or- - The host or authority name specified in the URI cannot be terminated by backslashes. +The host or authority name specified in the URI cannot be terminated by backslashes. - -or- +-or- - The port number specified in the URI is not valid or cannot be parsed. +The port number specified in the URI is not valid or cannot be parsed. - -or- +-or- - The length of URI exceeds 65519 characters. +The length of URI exceeds 65519 characters. - -or- +-or- - The length of the scheme specified in the URI exceeds 1023 characters. +The length of the scheme specified in the URI exceeds 1023 characters. - -or- +-or- - There is an invalid character sequence in the URI. +There is an invalid character sequence in the URI. - -or- +-or- - The MS-DOS path specified in the URI must start with c:\\\\. +The MS-DOS path specified in the URI must start with c:\\\\. XML and SOAP Serialization @@ -608,53 +606,53 @@ The following code snippet shows example values of the various properties on the is empty or contains only spaces. - -or- +-or- - The scheme specified in is not valid. +The scheme specified in is not valid. - -or- +-or- - contains too many slashes. + contains too many slashes. - -or- +-or- - The password specified in is not valid. +The password specified in is not valid. - -or- +-or- - The host name specified in is not valid. +The host name specified in is not valid. - -or- +-or- - The file name specified in is not valid. +The file name specified in is not valid. - -or- +-or- - The user name specified in is not valid. +The user name specified in is not valid. - -or- +-or- - The host or authority name specified in cannot be terminated by backslashes. +The host or authority name specified in cannot be terminated by backslashes. - -or- +-or- - The port number specified in is not valid or cannot be parsed. +The port number specified in is not valid or cannot be parsed. - -or- +-or- - The length of exceeds 65519 characters. +The length of exceeds 65519 characters. - -or- +-or- - The length of the scheme specified in exceeds 1023 characters. +The length of the scheme specified in exceeds 1023 characters. - -or- +-or- - There is an invalid character sequence in . +There is an invalid character sequence in . - -or- +-or- - The MS-DOS path specified in must start with c:\\\\. +The MS-DOS path specified in must start with c:\\\\. @@ -762,65 +760,55 @@ The following code snippet shows example values of the various properties on the is invalid. is . - Note: In the .NET for Windows Store apps or the Portable Class Library, catch the base class exception, , instead. - - contains a relative URI and is . - - or - - contains an absolute URI and is . + Note: In the .NET for Windows Store apps or the Portable Class Library, catch the base class exception, , instead. contains a relative URI and is . or contains an absolute URI and is . or is empty. - or +-or- - is empty. +The scheme specified in is not correctly formed. See . - -or- +-or- - The scheme specified in is not correctly formed. See . + contains too many slashes. - -or- +-or- - contains too many slashes. +The password specified in is not valid. - -or- +-or- - The password specified in is not valid. +The host name specified in is not valid. - -or- +-or- - The host name specified in is not valid. +The file name specified in is not valid. - -or- +-or- - The file name specified in is not valid. +The user name specified in is not valid. - -or- +-or- - The user name specified in is not valid. +The host or authority name specified in cannot be terminated by backslashes. - -or- +-or- - The host or authority name specified in cannot be terminated by backslashes. +The port number specified in is not valid or cannot be parsed. - -or- +-or- - The port number specified in is not valid or cannot be parsed. +The length of exceeds 65519 characters. - -or- +-or- - The length of exceeds 65519 characters. +The length of the scheme specified in exceeds 1023 characters. - -or- +-or- - The length of the scheme specified in exceeds 1023 characters. +There is an invalid character sequence in . - -or- +-or- - There is an invalid character sequence in . - - -or- - - The MS-DOS path specified in must start with c:\\\\. +The MS-DOS path specified in must start with c:\\\\. @@ -899,57 +887,55 @@ The following code snippet shows example values of the various properties on the is . is not an absolute instance. - Note: In the .NET for Windows Store apps or the Portable Class Library, catch the base class exception, , instead. - - The URI formed by combining and is empty or contains only spaces. + Note: In the .NET for Windows Store apps or the Portable Class Library, catch the base class exception, , instead. The URI formed by combining and is empty or contains only spaces. - -or- +-or- - The scheme specified in the URI formed by combining and is not valid. +The scheme specified in the URI formed by combining and is not valid. - -or- +-or- - The URI formed by combining and contains too many slashes. +The URI formed by combining and contains too many slashes. - -or- +-or- - The password specified in the URI formed by combining and is not valid. +The password specified in the URI formed by combining and is not valid. - -or- +-or- - The host name specified in the URI formed by combining and is not valid. +The host name specified in the URI formed by combining and is not valid. - -or- +-or- - The file name specified in the URI formed by combining and is not valid. +The file name specified in the URI formed by combining and is not valid. - -or- +-or- - The user name specified in the URI formed by combining and is not valid. +The user name specified in the URI formed by combining and is not valid. - -or- +-or- - The host or authority name specified in the URI formed by combining and cannot be terminated by backslashes. +The host or authority name specified in the URI formed by combining and cannot be terminated by backslashes. - -or- +-or- - The port number specified in the URI formed by combining and is not valid or cannot be parsed. +The port number specified in the URI formed by combining and is not valid or cannot be parsed. - -or- +-or- - The length of the URI formed by combining and exceeds 65519 characters. +The length of the URI formed by combining and exceeds 65519 characters. - -or- +-or- - The length of the scheme specified in the URI formed by combining and exceeds 1023 characters. +The length of the scheme specified in the URI formed by combining and exceeds 1023 characters. - -or- +-or- - There is an invalid character sequence in the URI formed by combining and . +There is an invalid character sequence in the URI formed by combining and . - -or- +-or- - The MS-DOS path specified in must start with c:\\\\. +The MS-DOS path specified in must start with c:\\\\. @@ -1021,57 +1007,55 @@ The following code snippet shows example values of the various properties on the is . is not an absolute instance. - Note: In the .NET for Windows Store apps or the Portable Class Library, catch the base class exception, , instead. + Note: In the .NET for Windows Store apps or the Portable Class Library, catch the base class exception, , instead. The URI formed by combining and is empty or contains only spaces. -The URI formed by combining and is empty or contains only spaces. +-or- - -or- +The scheme specified in the URI formed by combining and is not valid. - The scheme specified in the URI formed by combining and is not valid. +-or- - -or- +The URI formed by combining and contains too many slashes. - The URI formed by combining and contains too many slashes. +-or- - -or- +The password specified in the URI formed by combining and is not valid. - The password specified in the URI formed by combining and is not valid. +-or- - -or- +The host name specified in the URI formed by combining and is not valid. - The host name specified in the URI formed by combining and is not valid. +-or- - -or- +The file name specified in the URI formed by combining and is not valid. - The file name specified in the URI formed by combining and is not valid. +-or- - -or- +The user name specified in the URI formed by combining and is not valid. - The user name specified in the URI formed by combining and is not valid. +-or- - -or- +The host or authority name specified in the URI formed by combining and cannot be terminated by backslashes. - The host or authority name specified in the URI formed by combining and cannot be terminated by backslashes. +-or- - -or- +The port number specified in the URI formed by combining and is not valid or cannot be parsed. - The port number specified in the URI formed by combining and is not valid or cannot be parsed. +-or- - -or- +The length of the URI formed by combining and exceeds 65519 characters. - The length of the URI formed by combining and exceeds 65519 characters. +-or- - -or- +The length of the scheme specified in the URI formed by combining and exceeds 1023 characters. - The length of the scheme specified in the URI formed by combining and exceeds 1023 characters. +-or- - -or- +There is an invalid character sequence in the URI formed by combining and . - There is an invalid character sequence in the URI formed by combining and . +-or- - -or- - - The MS-DOS path specified in must start with c:\\\\. +The MS-DOS path specified in must start with c:\\\\. @@ -1163,53 +1147,53 @@ The URI formed by combining and is not an absolute instance. The URI formed by combining and is empty or contains only spaces. - -or- +-or- - The scheme specified in the URI formed by combining and is not valid. +The scheme specified in the URI formed by combining and is not valid. - -or- +-or- - The URI formed by combining and contains too many slashes. +The URI formed by combining and contains too many slashes. - -or- +-or- - The password specified in the URI formed by combining and is not valid. +The password specified in the URI formed by combining and is not valid. - -or- +-or- - The host name specified in the URI formed by combining and is not valid. +The host name specified in the URI formed by combining and is not valid. - -or- +-or- - The file name specified in the URI formed by combining and is not valid. +The file name specified in the URI formed by combining and is not valid. - -or- +-or- - The user name specified in the URI formed by combining and is not valid. +The user name specified in the URI formed by combining and is not valid. - -or- +-or- - The host or authority name specified in the URI formed by combining and cannot be terminated by backslashes. +The host or authority name specified in the URI formed by combining and cannot be terminated by backslashes. - -or- +-or- - The port number specified in the URI formed by combining and is not valid or cannot be parsed. +The port number specified in the URI formed by combining and is not valid or cannot be parsed. - -or- +-or- - The length of the URI formed by combining and exceeds 65519 characters. +The length of the URI formed by combining and exceeds 65519 characters. - -or- +-or- - The length of the scheme specified in the URI formed by combining and exceeds 1023 characters. +The length of the scheme specified in the URI formed by combining and exceeds 1023 characters. - -or- +-or- - There is an invalid character sequence in the URI formed by combining and . +There is an invalid character sequence in the URI formed by combining and . - -or- +-or- - The MS-DOS path specified in must start with c:\\\\. +The MS-DOS path specified in must start with c:\\\\. Because of security concerns, your application should not call this constructor with URI strings from untrusted sources and with set to . Alternately, you can check a URI string for validity by calling the method prior to calling this constructor. @@ -1714,25 +1698,34 @@ The URI formed by combining and One of the enumeration values that specifies the character escaping used when the URI components are compared. One of the enumeration values that specifies the culture, case, and sort rules for the comparison. Compares the specified parts of two URIs using the specified comparison rules. - A value that indicates the lexical relationship between the compared components. - - Value - - Meaning - - Less than zero - - is less than . - - Zero - - equals . - - Greater than zero - - is greater than . - - + A value that indicates the lexical relationship between the compared components. + + Value + + + Meaning + + + + + Less than zero + + + is less than . + + + Zero + + + equals . + + + Greater than zero + + + is greater than . + + is . - Note: In the .NET for Windows Store apps or the Portable Class Library, catch the base class exception, , instead. - - The length of exceeds 32766 characters. + Note: In the .NET for Windows Store apps or the Portable Class Library, catch the base class exception, , instead. The length of exceeds 32766 characters. @@ -2204,9 +2195,7 @@ If you used an escaped string to construct this instance (for example, `"http:// is . - The length of exceeds 32766 characters. - - Note: In .NET for Windows Store apps or the Portable Class Library, catch the base class exception, , instead. + The length of exceeds 32766 characters. Note: In .NET for Windows Store apps or the Portable Class Library, catch the base class exception, , instead. @@ -3802,9 +3791,7 @@ The following examples show a URI and the results of calling The URI to compare to the current URI. Determines the difference between two instances. - If the hostname and scheme of this URI instance and are the same, then this method returns a that represents a relative URI that, when appended to the current URI instance, yields the parameter. - - If the hostname or scheme is different, then this method returns a that represents the parameter. + If the hostname and scheme of this URI instance and are the same, then this method returns a that represents a relative URI that, when appended to the current URI instance, yields the parameter. If the hostname or scheme is different, then this method returns a that represents the parameter. The URI to compare to the current URI. Determines the difference between two instances. - If the hostname and scheme of this URI instance and are the same, then this method returns a relative that, when appended to the current URI instance, yields . - - If the hostname or scheme is different, then this method returns a that represents the parameter. + If the hostname and scheme of this URI instance and are the same, then this method returns a relative that, when appended to the current URI instance, yields . If the hostname or scheme is different, then this method returns a that represents the parameter. - The format to use. - -or- - A reference ( in Visual Basic) to use the default format defined for the type of the implementation. - The provider to use to format the value. - -or- - A reference ( in Visual Basic) to obtain the numeric format information from the current locale setting of the operating system. + The format to use. + +-or- + +A reference ( in Visual Basic) to use the default format defined for the type of the implementation. + The provider to use to format the value. + +-or- + +A reference ( in Visual Basic) to obtain the numeric format information from the current locale setting of the operating system. Formats the value of the current instance using the specified format. The value of the current instance in the specified format. To be added. diff --git a/xml/System/UriBuilder.xml b/xml/System/UriBuilder.xml index 787ecacbb76..191fde86f22 100644 --- a/xml/System/UriBuilder.xml +++ b/xml/System/UriBuilder.xml @@ -61,13 +61,13 @@ Provides a custom constructor for uniform resource identifiers (URIs) and modifies URIs for the class. - class provides a convenient way to modify the contents of a instance without creating a new instance for each modification. - - The properties provide read/write access to the read-only properties so that they can be modified. - + class provides a convenient way to modify the contents of a instance without creating a new instance for each modification. + + The properties provide read/write access to the read-only properties so that they can be modified. + ]]> @@ -124,22 +124,22 @@ Initializes a new instance of the class. - class with its properties initialized as follows. - -|Property|Initial Value| -|--------------|-------------------| -|Fragment|| -|Host|"loopback"| -|Password|| -|Path|"/"| -|Port|-1| -|Query|| -|Scheme|"http"| -|UserName|| - + class with its properties initialized as follows. + +|Property|Initial Value| +|--------------|-------------------| +|Fragment|| +|Host|"loopback"| +|Password|| +|Path|"/"| +|Port|-1| +|Query|| +|Scheme|"http"| +|UserName|| + ]]> @@ -194,34 +194,31 @@ A URI string. Initializes a new instance of the class with the specified URI. - class with the , , , , , , and properties set as specified in `uri`. - - If `uri` does not specify a scheme, the scheme defaults to "http:". - + class with the , , , , , , and properties set as specified in `uri`. + + If `uri` does not specify a scheme, the scheme defaults to "http:". + ]]> is . - is a zero-length string or contains only spaces. - - -or- - - The parsing routine detected a scheme in an invalid form. - - -or- - - The parser detected more than two consecutive slashes in a URI that does not use the "file" scheme. - - -or- - - is not a valid URI. - -Note: In .NET for Windows Store apps or the Portable Class Library, catch the base class exception, , instead. - + is a zero-length string or contains only spaces. + +-or- + +The parsing routine detected a scheme in an invalid form. + +-or- + +The parser detected more than two consecutive slashes in a URI that does not use the "file" scheme. + +-or- + + is not a valid URI. Note: In .NET for Windows Store apps or the Portable Class Library, catch the base class exception, , instead. @@ -267,11 +264,11 @@ Note: In An instance of the class. Initializes a new instance of the class with the specified instance. - class with the , , , , , , and properties set as specified in `uri`. - + class with the , , , , , , and properties set as specified in `uri`. + ]]> @@ -330,19 +327,19 @@ Note: In A DNS-style domain name or IP address. Initializes a new instance of the class with the specified scheme and host. - instance is initialized with the property set to `schemeName` and the property set to `hostName`. is initialized to the value -1 to indicate the default port for the scheme should be used, and the property is set to the slash character (/). - -## Examples - The following example creates a instance that contains the URI `http://www.contoso.com/`. - + +## Examples + The following example creates a instance that contains the URI `http://www.contoso.com/`. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_Remoting/Classic UriBuilder.UriBuilder3 Example/CPP/source.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/UriBuilder/.ctor/source.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/UriBuilder/.ctor/source.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_Remoting/Classic UriBuilder.UriBuilder3 Example/VB/source.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_Remoting/Classic UriBuilder.UriBuilder3 Example/VB/source.vb" id="Snippet1"::: + ]]> @@ -401,21 +398,21 @@ Note: In An IP port number for the service. Initializes a new instance of the class with the specified scheme, host, and port. - instance is initialized with the property set to `schemeName`, the property set to `hostName`, and the property set to `portNumber`. The property is set to the slash character (/). - + instance is initialized with the property set to `schemeName`, the property set to `hostName`, and the property set to `portNumber`. The property is set to the slash character (/). + If the `portNumber` is set to a value of -1, this indicates that the default port value for the scheme will be used to connect to the host. - -## Examples - The following example creates a instance that contains the URI `http://www.contoso.com:8080/`. - + +## Examples + The following example creates a instance that contains the URI `http://www.contoso.com:8080/`. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_Remoting/Classic UriBuilder.UriBuilder4 Example/CPP/source.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/UriBuilder/.ctor/source1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/UriBuilder/.ctor/source1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_Remoting/Classic UriBuilder.UriBuilder4 Example/VB/source.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_Remoting/Classic UriBuilder.UriBuilder4 Example/VB/source.vb" id="Snippet1"::: + ]]> @@ -478,21 +475,21 @@ Note: In The path to the Internet resource. Initializes a new instance of the class with the specified scheme, host, port number, and path. - instance is initialized with the property set to `schemeName`, the property set to `hostName`, the property set to `portNumber`, and the property set to `pathValue`. - + instance is initialized with the property set to `schemeName`, the property set to `hostName`, the property set to `portNumber`, and the property set to `pathValue`. + If the `portNumber` is set to a value of -1, this indicates that the default port value for the scheme will be used to connect to the host. - -## Examples - The following example creates a instance that contains the URI `http://www.contoso.com:8080/index.htm`. - + +## Examples + The following example creates a instance that contains the URI `http://www.contoso.com:8080/index.htm`. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_Remoting/Classic UriBuilder.UriBuilder5 Example/CPP/source.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/UriBuilder/.ctor/source2.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/UriBuilder/.ctor/source2.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_Remoting/Classic UriBuilder.UriBuilder5 Example/VB/source.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_Remoting/Classic UriBuilder.UriBuilder5 Example/VB/source.vb" id="Snippet1"::: + ]]> @@ -557,21 +554,21 @@ Note: In A query string or fragment identifier. Initializes a new instance of the class with the specified scheme, host, port number, path, and query string or fragment identifier. - instance is initialized with the property set to `schemeName`, the property set to `hostName`, the property set to `portNumber`, and the property set to `pathValue`. If `extraValue` begins with a number sign (#), then is set to `extraValue`. If `extraValue` begins with a question mark (?), then is set to `extraValue`. - + instance is initialized with the property set to `schemeName`, the property set to `hostName`, the property set to `portNumber`, and the property set to `pathValue`. If `extraValue` begins with a number sign (#), then is set to `extraValue`. If `extraValue` begins with a question mark (?), then is set to `extraValue`. + If the `portNumber` is set to a value of -1, this indicates that the default port value for the scheme will be used to connect to the host. - -## Examples - The following example creates a instance that contains the URI `http://www.contoso.com:8080/index.htm#top`. - + +## Examples + The following example creates a instance that contains the URI `http://www.contoso.com:8080/index.htm#top`. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_Remoting/Classic UriBuilder.UriBuilder6 Example/CPP/source.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/UriBuilder/.ctor/source3.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/UriBuilder/.ctor/source3.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_Remoting/Classic UriBuilder.UriBuilder6 Example/VB/source.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_Remoting/Classic UriBuilder.UriBuilder6 Example/VB/source.vb" id="Snippet1"::: + ]]> @@ -642,11 +639,11 @@ Note: In if represents the same as the constructed by this instance; otherwise, . - method compares a specified instance with the instance built by the instance. If the two are the same, the method returns `true`. - + method compares a specified instance with the instance built by the instance. If the two are the same, the method returns `true`. + ]]> @@ -700,8 +697,8 @@ Note: In property contains any text following a fragment marker (#) in the URI, including the marker itself. When setting the property: @@ -712,14 +709,14 @@ The property contains any text following a fra > [!NOTE] > To append a value to an existing fragment in .NET Framework, you must remove the leading fragment marker before setting the property with the new value. This is because .NET Framework always prepends the fragment marker when setting the property. .NET 5 (and .NET Core) and later versions are tolerant to a leading fragment marker, and will only prepend one if necessary. -## Examples - The following example creates the URI `"http://www.contoso.com/index.htm#main"`. - +## Examples + The following example creates the URI `"http://www.contoso.com/index.htm#main"`. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_Remoting/Classic UriBuilder.Fragment Example/CPP/source.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/UriBuilder/Fragment/source.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/UriBuilder/Fragment/source.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_Remoting/Classic UriBuilder.Fragment Example/VB/source.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_Remoting/Classic UriBuilder.Fragment Example/VB/source.vb" id="Snippet1"::: + ]]> @@ -768,15 +765,15 @@ The property contains any text following a fra Returns the hash code for the URI. The hash code generated for the URI. - A and B are guaranteed to be the same when A.Equals(B) is `true`. - - This method implements . - + A and B are guaranteed to be the same when A.Equals(B) is `true`. + + This method implements . + ]]> @@ -830,11 +827,11 @@ The property contains any text following a fra Gets or sets the Domain Name System (DNS) host name or IP address of a server. The DNS host name or IP address of the server. - property contains the fully qualified DNS host name or IP address of the server. - + property contains the fully qualified DNS host name or IP address of the server. + ]]> @@ -939,13 +936,13 @@ The property contains any text following a fra Gets or sets the path to the resource referenced by the URI. The path to the resource referenced by the URI. - property contains the path information that the server uses to resolve requests for information. Typically, this is the path to the desired information on the server's file system. It can also indicate the application or script that the server must run to provide the information. - - The path information does not include the scheme, host name, or query portion of the URI. The property always returns at least a slash (/). - + property contains the path information that the server uses to resolve requests for information. Typically, this is the path to the desired information on the server's file system. It can also indicate the application or script that the server must run to provide the information. + + The path information does not include the scheme, host name, or query portion of the URI. The property always returns at least a slash (/). + ]]> @@ -999,11 +996,11 @@ The property contains any text following a fra Gets or sets the port number of the URI. The port number of the URI. - property returns the value of -1 to indicate that the default port value for the protocol scheme will be used to connect to the host. If the property is set to a value of -1, this indicates that the default port value for the protocol scheme will be used to connect to the host. - + property returns the value of -1 to indicate that the default port value for the protocol scheme will be used to connect to the host. If the property is set to a value of -1, this indicates that the default port value for the protocol scheme will be used to connect to the host. + ]]> The port cannot be set to a value less than -1 or greater than 65,535. @@ -1060,8 +1057,8 @@ The property contains any text following a fra Gets or sets any query information included in the URI, including the leading '?' character if not empty. The query information included in the URI. - property contains any query information included in the URI. Query information is separated from the path information by a question mark (?) and continues to the end of the URI. The query information that's returned includes the leading question mark. When setting the property: @@ -1069,7 +1066,7 @@ The property contains any query information included in - In .NET Framework, a question mark is always prepended to the string, even if the string already starts with a question mark. - In .NET 5 (and .NET Core) and later versions, a question mark is prepended to the string if it's not already present. -The query information is escaped according to RFC 2396. +The query information is escaped according to RFC 2396. > [!NOTE] > To append a value to existing query information in .NET Framework, you must remove the leading question mark before setting the property with the new value. This is because .NET Framework always prepends the question mark when setting the property. .NET 5 (and .NET Core) and later versions are tolerant to a leading question mark, and will only prepend one if necessary. @@ -1081,7 +1078,7 @@ The following example sets the property. :::code language="cpp" source="~/snippets/cpp/VS_Snippets_Remoting/UriBuilderSample/cpp/main.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/UriBuilder/Query/main.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/UriBuilder/Query/main.fs" id="Snippet1"::: - + ]]> @@ -1137,21 +1134,21 @@ The following example sets the property. Gets or sets the scheme name of the URI. The scheme of the URI. - property. - -|Scheme|Description| -|------------|-----------------| -|file|The resource is a file on the local computer.| -|ftp|The resource is accessed through FTP.| -|gopher|The resource is accessed through the Gopher protocol.| -|http|The resource is accessed through HTTP.| -|https|The resource is accessed through SSL-encrypted HTTP.| -|mailto|The resource is an email address and is accessed through SMTP.| -|news|The resource is accessed through NNTP.| - + property. + +|Scheme|Description| +|------------|-----------------| +|file|The resource is a file on the local computer.| +|ftp|The resource is accessed through FTP.| +|gopher|The resource is accessed through the Gopher protocol.| +|http|The resource is accessed through HTTP.| +|https|The resource is accessed through SSL-encrypted HTTP.| +|mailto|The resource is an email address and is accessed through SMTP.| +|news|The resource is accessed through NNTP.| + ]]> The scheme cannot be set to an invalid scheme name. @@ -1203,8 +1200,8 @@ The following example sets the property. Returns the display string for the specified instance. The string that contains the unescaped display string of the . - property value if one of the following conditions is true: @@ -1213,13 +1210,10 @@ The display string contains the property value if - The port was specified when the was constructed using one of the constructors that accept a port number parameter. In either case, the display string does not contain the property value if the port number was set to a value of -1 (for the default port). - + ]]> - The instance has a bad password. - -Note: In .NET for Windows Store apps or the Portable Class Library, catch the base class exception, , instead. - + The instance has a bad password. Note: In .NET for Windows Store apps or the Portable Class Library, catch the base class exception, , instead. @@ -1265,17 +1259,14 @@ Note: In instance constructed by the specified instance. The URI constructed by the . - property contains the created by the . Any changes made to the properties are reflected in the property. - + property contains the created by the . Any changes made to the properties are reflected in the property. + ]]> - The URI constructed by the properties is invalid. - -Note: In .NET for Windows Store apps or the Portable Class Library, catch the base class exception, , instead. - + The URI constructed by the properties is invalid. Note: In .NET for Windows Store apps or the Portable Class Library, catch the base class exception, , instead. diff --git a/xml/System/UriComponents.xml b/xml/System/UriComponents.xml index 9d0fbbdc0bb..79038d2a8d1 100644 --- a/xml/System/UriComponents.xml +++ b/xml/System/UriComponents.xml @@ -49,11 +49,11 @@ Specifies the parts of a . - . This enumeration is used with the method. - + . This enumeration is used with the method. + ]]> diff --git a/xml/System/UriFormat.xml b/xml/System/UriFormat.xml index 3387d1c8cd3..849f887d051 100644 --- a/xml/System/UriFormat.xml +++ b/xml/System/UriFormat.xml @@ -43,15 +43,15 @@ Controls how URI information is escaped. - method to specify the level of character escaping in the returned URI. - - RFC 2396 defines the standard escaping for URIs, and is available at [https://rfc-editor.org](https://rfc-editor.org). - - SafeUnescaped leaves the following characters escaped if the character has a reserved meaning in the requested : "%", "#", "?", "/", "\\", and "@". - + method to specify the level of character escaping in the returned URI. + + RFC 2396 defines the standard escaping for URIs, and is available at [https://rfc-editor.org](https://rfc-editor.org). + + SafeUnescaped leaves the following characters escaped if the character has a reserved meaning in the requested : "%", "#", "?", "/", "\\", and "@". + ]]> diff --git a/xml/System/UriFormatException.xml b/xml/System/UriFormatException.xml index 0abd6bd27d1..344ef8e86e9 100644 --- a/xml/System/UriFormatException.xml +++ b/xml/System/UriFormatException.xml @@ -56,16 +56,16 @@ The exception that is thrown when an invalid Uniform Resource Identifier (URI) is detected. - is thrown by the Uri class constructor if the supplied URI could not be correctly parsed. The format for a valid URI is defined in RFC 2396. - - The text of the property indicates the reason that the exception was thrown. - + is thrown by the Uri class constructor if the supplied URI could not be correctly parsed. The format for a valid URI is defined in RFC 2396. + + The text of the property indicates the reason that the exception was thrown. + > [!NOTE] -> This exception is not included in the [.NET for Windows Store apps](https://go.microsoft.com/fwlink/?LinkID=247912) or the [Portable Class Library](/dotnet/standard/cross-platform/cross-platform-development-with-the-portable-class-library), but it is thrown by some members that are. To catch the exception in that case, write a `catch` statement for instead. - +> This exception is not included in the [.NET for Windows Store apps](https://go.microsoft.com/fwlink/?LinkID=247912) or the [Portable Class Library](/dotnet/standard/cross-platform/cross-platform-development-with-the-portable-class-library), but it is thrown by some members that are. To catch the exception in that case, write a `catch` statement for instead. + ]]> @@ -122,11 +122,11 @@ Initializes a new instance of the class. - class with all fields set to `null`. - + class with all fields set to `null`. + ]]> @@ -181,11 +181,11 @@ The error message string. Initializes a new instance of the class with the specified message. - instance with the property set to the value of `textString`. - + instance with the property set to the value of `textString`. + ]]> @@ -247,11 +247,11 @@ A that contains the source of the serialized stream that is associated with the new . Initializes a new instance of the class from the specified and instances. - interface for the class. - + interface for the class. + ]]> @@ -307,18 +307,18 @@ The exception that is the cause of the current exception. If the innerException parameter is not , the current exception is raised in a block that handles the inner exception. Initializes a new instance of the class with a specified error message and a reference to the inner exception that is the cause of this exception. - property. The property returns the same value that is passed into the constructor, or `null` if the property does not supply the inner exception value to the constructor. - - The following table shows the initial property values for an instance of . - -|Property|Value| -|--------------|-----------| -||`null`.| -||The error message string specified in `message`.| - + property. The property returns the same value that is passed into the constructor, or `null` if the property does not supply the inner exception value to the constructor. + + The following table shows the initial property values for an instance of . + +|Property|Value| +|--------------|-----------| +||`null`.| +||The error message string specified in `message`.| + ]]> Handling and Throwing Exceptions diff --git a/xml/System/UriHostNameType.xml b/xml/System/UriHostNameType.xml index 14d541e7735..ef1e0afa1e9 100644 --- a/xml/System/UriHostNameType.xml +++ b/xml/System/UriHostNameType.xml @@ -44,11 +44,11 @@ Defines host name types for the method. - enumeration defines the values that the method can return. - + enumeration defines the values that the method can return. + ]]> diff --git a/xml/System/UriIdnScope.xml b/xml/System/UriIdnScope.xml index 2fa2d39d3f5..74b12a619f6 100644 --- a/xml/System/UriIdnScope.xml +++ b/xml/System/UriIdnScope.xml @@ -27,17 +27,17 @@ Provides the possible values for the configuration setting of the in the namespace. - class has been extended to provide support for International Resource Identifiers (IR) based on RFC 3987. - - The Internationalized Domain Name (IDN) attribute only controls IDN processing. All other IRI processing (character normalization, for example) is always performed by default. - - The configuration setting for the will be read once when the first class is constructed. Changes to configuration settings after that time are ignored. - - For more information on IRI support, see the Remarks section for the class. - + + The Internationalized Domain Name (IDN) attribute only controls IDN processing. All other IRI processing (character normalization, for example) is always performed by default. + + The configuration setting for the will be read once when the first class is constructed. Changes to configuration settings after that time are ignored. + + For more information on IRI support, see the Remarks section for the class. + ]]> diff --git a/xml/System/UriKind.xml b/xml/System/UriKind.xml index 44ec88fff34..f1ee7199c06 100644 --- a/xml/System/UriKind.xml +++ b/xml/System/UriKind.xml @@ -43,8 +43,8 @@ Defines the different kinds of URIs. - * * - + ]]> diff --git a/xml/System/UriParser.xml b/xml/System/UriParser.xml index f1e11f0be65..19e36e4b3a1 100644 --- a/xml/System/UriParser.xml +++ b/xml/System/UriParser.xml @@ -50,13 +50,13 @@ Parses a new URI scheme. This is an abstract class. - . If you want to create a parser that extends a well-known URI scheme, inherit from , , , , or . - - Microsoft strongly recommends that you use a parser shipped with .NET. Building your own parser increases the complexity of your application, and will not perform as well as the shipped parsers. - + . If you want to create a parser that extends a well-known URI scheme, inherit from , , , , or . + + Microsoft strongly recommends that you use a parser shipped with .NET. Building your own parser increases the complexity of your application, and will not perform as well as the shipped parsers. + ]]> @@ -145,27 +145,27 @@ Gets the components from a URI. A string that contains the components. - method to determine the value of various parts of the URI, such as the , , or . - - The components are returned in the order that they appear in the URI. For example, if is specified, it appears first. - + method to determine the value of various parts of the URI, such as the , , or . + + The components are returned in the order that they appear in the URI. For example, if is specified, it appears first. + ]]> - is invalid. - + is invalid. + -or- - - is not a combination of valid values. + + is not a combination of valid values. - requires user-driven parsing - + requires user-driven parsing + -or- - - is not an absolute URI. Relative URIs cannot be used with this method. + + is not an absolute URI. Relative URIs cannot be used with this method. @@ -223,11 +223,11 @@ When this method returns, contains the validation errors, if any. Initialize the state of the parser and validate the URI. - method is called every time a is instantiated. - + method is called every time a is instantiated. + ]]> @@ -363,19 +363,19 @@ if is well-formed; otherwise, . - method will return false if: - -- The string is not correctly escaped per RFC 2396. - -- The string represents an absolute URI that references an implicit file URI. - -- The string represents an absolute URI that is missing a forward slash before the path component. - -- The string contains unescaped backslashes, even if they will be treated as forward slashes. - + method will return false if: + +- The string is not correctly escaped per RFC 2396. + +- The string represents an absolute URI that references an implicit file URI. + +- The string represents an absolute URI that is missing a forward slash before the path component. + +- The string contains unescaped backslashes, even if they will be treated as forward slashes. + ]]> @@ -417,11 +417,11 @@ Invoked by a constructor to get a instance. A for the constructed . - instance. You may need to override this method and return a different for each invocation if you are operating in a multithreaded environment. - + instance. You may need to override this method and return a different for each invocation if you are operating in a multithreaded environment. + ]]> @@ -512,25 +512,25 @@ The default port number for the specified scheme. Associates a scheme and port number with a . - method registers no default value for the port number. - + method registers no default value for the port number. + ]]> - parameter is null - + parameter is null + -or- - - parameter is null. + + parameter is null. - parameter is not valid - + parameter is not valid + -or- - - parameter is not valid. The parameter is less than -1 or greater than 65,534. + + parameter is not valid. The parameter is less than -1 or greater than 65,534. @@ -591,21 +591,21 @@ Called by constructors and to resolve a relative URI. The string of the resolved relative . - constructors and use to construct a URI from `baseUri` and `relativeUri`. - - If a parsing error occurs, the returned string for the resolved relative is null. - + constructors and use to construct a URI from `baseUri` and `relativeUri`. + + If a parsing error occurs, the returned string for the resolved relative is null. + ]]> - parameter is not an absolute - + parameter is not an absolute + -or- - - parameter requires user-driven parsing. + + parameter requires user-driven parsing. diff --git a/xml/System/UriPartial.xml b/xml/System/UriPartial.xml index afbf8c312e4..5c9bf73186b 100644 --- a/xml/System/UriPartial.xml +++ b/xml/System/UriPartial.xml @@ -39,11 +39,11 @@ Defines the parts of a URI for the method. - enumeration defines the values that can be passed to the method. - + enumeration defines the values that can be passed to the method. + ]]> diff --git a/xml/System/UriTemplate.xml b/xml/System/UriTemplate.xml index 6cf2f8792b7..9a5f5dac369 100644 --- a/xml/System/UriTemplate.xml +++ b/xml/System/UriTemplate.xml @@ -31,31 +31,31 @@ A class that represents a Uniform Resource Identifier (URI) template. - instance into a by replacing variables with actual values. For example, taking the template "weather/{state}/{city}" and putting in values for the variables "{state}" and "{city}" gives you "weather/WA/Seattle". Given a candidate URI, you can test whether it matches a given URI template by calling . You can also use instances to create a from a set of variable values by calling or . - - - -## Examples - The following code demonstrates how to create a instance, and bind and match it to a candidate URI. - + instance into a by replacing variables with actual values. For example, taking the template "weather/{state}/{city}" and putting in values for the variables "{state}" and "{city}" gives you "weather/WA/Seattle". Given a candidate URI, you can test whether it matches a given URI template by calling . You can also use instances to create a from a set of variable values by calling or . + + + +## Examples + The following code demonstrates how to create a instance, and bind and match it to a candidate URI. + :::code language="csharp" source="~/snippets/csharp/VS_Snippets_CFX/uritemplate/cs/snippets.cs" id="Snippet0"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CFX/uritemplate/vb/snippets.vb" id="Snippet0"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CFX/uritemplate/vb/snippets.vb" id="Snippet0"::: + ]]> @@ -100,14 +100,14 @@ The template. Initializes a new instance of the class with the specified template string. - @@ -145,16 +145,16 @@ A value that specifies whether trailing slash "/" characters should be ignored. Initializes a new instance of the class. - @@ -272,17 +272,17 @@ Creates a new URI from the template and the collection of parameters. A URI. - ](xref:System.Collections.Generic.IDictionary%602) parameter contains a collection of parameter name and value pairs. The parameters are matched up against the variables within the template by a case-insensitive comparison. - + ](xref:System.Collections.Generic.IDictionary%602) parameter contains a collection of parameter name and value pairs. The parameters are matched up against the variables within the template by a case-insensitive comparison. + > [!NOTE] -> The name/value collection passed to this method must contain a key for every template variable. Extra name/value pairs that do not match template variables are appended to the query string of the final URI. - +> The name/value collection passed to this method must contain a key for every template variable. Extra name/value pairs that do not match template variables are appended to the query string of the final URI. + > [!IMPORTANT] -> It is possible to pass in text within the name/value pairs that prevent the generated URI from matching the template that is used to generate it. Examples of such text includes: '/', '..', '*', '{', and '}'. - +> It is possible to pass in text within the name/value pairs that prevent the generated URI from matching the template that is used to generate it. Examples of such text includes: '/', '..', '*', '{', and '}'. + ]]> @@ -324,25 +324,25 @@ Creates a new URI from the template and the collection of parameters. A new instance. - parameter contains a collection of parameter name/value pairs. The parameters are matched up against the variables within the template by a case-insensitive comparison. Values passed in this collection are escaped. - + parameter contains a collection of parameter name/value pairs. The parameters are matched up against the variables within the template by a case-insensitive comparison. Values passed in this collection are escaped. + > [!NOTE] -> The name/value collection passed to must contain a key for every template variable. Extra name/value pairs that do not match template variables are appended to the query string of the final URI. - +> The name/value collection passed to must contain a key for every template variable. Extra name/value pairs that do not match template variables are appended to the query string of the final URI. + > [!NOTE] -> It is possible to pass in text within the name/value pairs that prevent the generated URI from matching the template that is used to generate it. Examples of such text includes: '/', '..', '*', '{', and '}'. - - - -## Examples - The following example shows how to call the method. - +> It is possible to pass in text within the name/value pairs that prevent the generated URI from matching the template that is used to generate it. Examples of such text includes: '/', '..', '*', '{', and '}'. + + + +## Examples + The following example shows how to call the method. + :::code language="csharp" source="~/snippets/csharp/VS_Snippets_CFX/uritemplate/cs/snippets.cs" id="Snippet4"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CFX/uritemplate/vb/snippets.vb" id="Snippet4"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CFX/uritemplate/vb/snippets.vb" id="Snippet4"::: + ]]> @@ -457,39 +457,39 @@ Creates a new URI from the template and an array of parameter values. A new instance. - [!NOTE] -> The number of parameters passed in the values parameter must match the number of variables in the template. If not, a is thrown. - +> The number of parameters passed in the values parameter must match the number of variables in the template. If not, a is thrown. + > [!NOTE] -> It is possible to pass in text within the parameter values array that prevents the generated URI from matching the template that is used to generate it. Examples of such text includes: '/', '.','..', '*', '{', and '}'. The following code demonstrates this. - - `UriTemplate template = new UriTemplate("far/{bat}/baz");` - - `Uri uri = new Uri("http://localhost/Base");` - - `Uri result = template.BindByPosition(uri, "."); // returns Base/form/baz` - - `Uri result = template.BindByPosition(uri, ".."); // returns Base/baz` - - `Uri result = template.BindByPosition(uri, "x/y"); // returns Base/form/x/y/baz` - - `Uri result = template.BindByPosition(uri, "{x}"); // returns Base/form/{x}/baz` - - `Uri result = template.BindByPosition(uri, "*"); // returns Base/form/*/baz` - - - -## Examples - The following example shows how to call the . - +> It is possible to pass in text within the parameter values array that prevents the generated URI from matching the template that is used to generate it. Examples of such text includes: '/', '.','..', '*', '{', and '}'. The following code demonstrates this. + + `UriTemplate template = new UriTemplate("far/{bat}/baz");` + + `Uri uri = new Uri("http://localhost/Base");` + + `Uri result = template.BindByPosition(uri, "."); // returns Base/form/baz` + + `Uri result = template.BindByPosition(uri, ".."); // returns Base/baz` + + `Uri result = template.BindByPosition(uri, "x/y"); // returns Base/form/x/y/baz` + + `Uri result = template.BindByPosition(uri, "{x}"); // returns Base/form/{x}/baz` + + `Uri result = template.BindByPosition(uri, "*"); // returns Base/form/*/baz` + + + +## Examples + The following example shows how to call the . + :::code language="csharp" source="~/snippets/csharp/VS_Snippets_CFX/uritemplate/cs/snippets.cs" id="Snippet5"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CFX/uritemplate/vb/snippets.vb" id="Snippet5"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CFX/uritemplate/vb/snippets.vb" id="Snippet5"::: + ]]> @@ -585,19 +585,19 @@ if the is structurally equivalent to another; otherwise . - instances are equivalent if their literal strings are identical and the variables appear in the same segments. For example "weather/{state}/{city}" is equivalent to "weather/{country}/{village}". - - - -## Examples - The following example shows how to call the . - + instances are equivalent if their literal strings are identical and the variables appear in the same segments. For example "weather/{state}/{city}" is equivalent to "weather/{country}/{village}". + + + +## Examples + The following example shows how to call the . + :::code language="csharp" source="~/snippets/csharp/VS_Snippets_CFX/uritemplate/cs/snippets.cs" id="Snippet6"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CFX/uritemplate/vb/snippets.vb" id="Snippet6"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CFX/uritemplate/vb/snippets.vb" id="Snippet6"::: + ]]> @@ -633,19 +633,19 @@ Attempts to match a to a . An instance. - is populated with the URI segments, variable values, query string values, and wildcard segments from the candidate URI. If the match is unsuccessful, `null` is returned. - - - -## Examples - The following example shows how to call the method. - + is populated with the URI segments, variable values, query string values, and wildcard segments from the candidate URI. If the match is unsuccessful, `null` is returned. + + + +## Examples + The following example shows how to call the method. + :::code language="csharp" source="~/snippets/csharp/VS_Snippets_CFX/uritemplate/cs/snippets.cs" id="Snippet7"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CFX/uritemplate/vb/snippets.vb" id="Snippet7"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CFX/uritemplate/vb/snippets.vb" id="Snippet7"::: + ]]> @@ -675,19 +675,19 @@ Gets a collection of variable names used within path segments in the template. A collection of variable names that appear within the template's path segment. - property. - + property. + :::code language="csharp" source="~/snippets/csharp/VS_Snippets_CFX/uritemplate/cs/snippets.cs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CFX/uritemplate/vb/snippets.vb" id="Snippet2"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CFX/uritemplate/vb/snippets.vb" id="Snippet2"::: + ]]> @@ -717,19 +717,19 @@ Gets a collection of variable names used within the query string in the template. A collection of template variable names that appear in the query portion of the template string. - property. - + property. + :::code language="csharp" source="~/snippets/csharp/VS_Snippets_CFX/uritemplate/cs/snippets.cs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CFX/uritemplate/vb/snippets.vb" id="Snippet3"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CFX/uritemplate/vb/snippets.vb" id="Snippet3"::: + ]]> @@ -760,14 +760,14 @@ Returns a string representation of the instance. The representation of the instance. - method. - + method. + :::code language="csharp" source="~/snippets/csharp/VS_Snippets_CFX/uritemplate/cs/snippets.cs" id="Snippet8"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CFX/uritemplate/vb/snippets.vb" id="Snippet8"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CFX/uritemplate/vb/snippets.vb" id="Snippet8"::: + ]]> diff --git a/xml/System/UriTemplateEquivalenceComparer.xml b/xml/System/UriTemplateEquivalenceComparer.xml index e4a3504db07..0824988c22f 100644 --- a/xml/System/UriTemplateEquivalenceComparer.xml +++ b/xml/System/UriTemplateEquivalenceComparer.xml @@ -35,19 +35,19 @@ A class used to compare instances for structural (instead of reference) equivalence. - instances are compared using reference equality by default. The class evaluates equivalence using instead of the default reference equality check. This class is useful when you wish to compare two instances based on the URIs they match instead of strict reference equality. - - - -## Examples - The following example shows the difference between reference equality and structural equality. It also shows how to use the as a comparer in a dictionary. - + instances are compared using reference equality by default. The class evaluates equivalence using instead of the default reference equality check. This class is useful when you wish to compare two instances based on the URIs they match instead of strict reference equality. + + + +## Examples + The following example shows the difference between reference equality and structural equality. It also shows how to use the as a comparer in a dictionary. + :::code language="csharp" source="~/snippets/csharp/VS_Snippets_CFX/uritemplateequivalencecomparer/cs/program.cs" id="Snippet0"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CFX/uritemplateequivalencecomparer/vb/program.vb" id="Snippet0"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CFX/uritemplateequivalencecomparer/vb/program.vb" id="Snippet0"::: + ]]> @@ -79,14 +79,14 @@ Initializes a new instance of the class. - @@ -125,18 +125,18 @@ Compares two instances for equivalence. A value that indicates whether the two instances are equivalent. - instances. - - - -## Examples - The following code shows how to call the method. - - :::code language="csharp" source="~/snippets/csharp/VS_Snippets_CFX/uritemplateequivalencecomparer/cs/snippets.cs" id="Snippet2"::: - + instances. + + + +## Examples + The following code shows how to call the method. + + :::code language="csharp" source="~/snippets/csharp/VS_Snippets_CFX/uritemplateequivalencecomparer/cs/snippets.cs" id="Snippet2"::: + ]]> @@ -173,11 +173,11 @@ Gets a hash code for the specified instance. The hash code. - instance. - + instance. + ]]> diff --git a/xml/System/UriTemplateMatch.xml b/xml/System/UriTemplateMatch.xml index 6f69275900c..28fc8373502 100644 --- a/xml/System/UriTemplateMatch.xml +++ b/xml/System/UriTemplateMatch.xml @@ -31,19 +31,19 @@ A class that represents the results of a match operation on a instance. - class represents the results of calling the method. This class is not thread safe. - - - -## Examples - The following code shows how to use the class. - + class represents the results of calling the method. This class is not thread safe. + + + +## Examples + The following code shows how to use the class. + :::code language="csharp" source="~/snippets/csharp/VS_Snippets_CFX/uritemplatematch/cs/program.cs" id="Snippet0"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CFX/uritemplatematch/vb/program.vb" id="Snippet0"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CFX/uritemplatematch/vb/program.vb" id="Snippet0"::: + ]]> @@ -69,11 +69,11 @@ Initializes a new instance of the class. - instance is returned from the or method. The method returns a collection of as well. - + instance is returned from the or method. The method returns a collection of as well. + ]]> @@ -103,14 +103,14 @@ Gets or sets the base URI for the template match. A instance that represents the base URI for the template match. - property. - + property. + :::code language="csharp" source="~/snippets/csharp/VS_Snippets_CFX/uritemplatematch/cs/snippets.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CFX/uritemplatematch/vb/snippets.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CFX/uritemplatematch/vb/snippets.vb" id="Snippet1"::: + ]]> @@ -140,19 +140,19 @@ Gets the collection for the template match. A instance that contains template variable values extracted from the URI during the match. - property. - + property. + :::code language="csharp" source="~/snippets/csharp/VS_Snippets_CFX/uritemplatematch/cs/snippets.cs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CFX/uritemplatematch/vb/snippets.vb" id="Snippet2"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CFX/uritemplatematch/vb/snippets.vb" id="Snippet2"::: + ]]> @@ -192,19 +192,19 @@ Gets or sets the object associated with the instance. An instance. - to a you associate data with the template. This value is application specific; no particular semantics are associated with this value. When is called and a match is found the data associated with the matching template is returned in the property. - - - -## Examples - The following code shows how to access the property. - + to a you associate data with the template. This value is application specific; no particular semantics are associated with this value. When is called and a match is found the data associated with the matching template is returned in the property. + + + +## Examples + The following code shows how to access the property. + :::code language="csharp" source="~/snippets/csharp/VS_Snippets_CFX/uritemplatematch/cs/snippets.cs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CFX/uritemplatematch/vb/snippets.vb" id="Snippet3"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CFX/uritemplatematch/vb/snippets.vb" id="Snippet3"::: + ]]> @@ -234,19 +234,19 @@ Gets a collection of query string parameters and their values. A instance that contains the query string parameters and their values. - property. - + property. + :::code language="csharp" source="~/snippets/csharp/VS_Snippets_CFX/uritemplatematch/cs/snippets.cs" id="Snippet4"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CFX/uritemplatematch/vb/snippets.vb" id="Snippet4"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CFX/uritemplatematch/vb/snippets.vb" id="Snippet4"::: + ]]> @@ -276,19 +276,19 @@ Gets a collection of relative path segments. A collection of relative path segments. - property. - - - -## Examples - The following code shows how to access the property. - + property. + + + +## Examples + The following code shows how to access the property. + :::code language="csharp" source="~/snippets/csharp/VS_Snippets_CFX/uritemplatematch/cs/snippets.cs" id="Snippet5"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CFX/uritemplatematch/vb/snippets.vb" id="Snippet5"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CFX/uritemplatematch/vb/snippets.vb" id="Snippet5"::: + ]]> @@ -328,14 +328,14 @@ Gets or sets the matched URI. A instance. - property. - + property. + :::code language="csharp" source="~/snippets/csharp/VS_Snippets_CFX/uritemplatematch/cs/snippets.cs" id="Snippet6"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CFX/uritemplatematch/vb/snippets.vb" id="Snippet6"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CFX/uritemplatematch/vb/snippets.vb" id="Snippet6"::: + ]]> @@ -375,19 +375,19 @@ Gets or sets the instance associated with this instance. A instance. - that the candidate URI matched. - - - -## Examples - The following code shows how to access the property. - + that the candidate URI matched. + + + +## Examples + The following code shows how to access the property. + :::code language="csharp" source="~/snippets/csharp/VS_Snippets_CFX/uritemplatematch/cs/snippets.cs" id="Snippet7"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CFX/uritemplatematch/vb/snippets.vb" id="Snippet7"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CFX/uritemplatematch/vb/snippets.vb" id="Snippet7"::: + ]]> @@ -417,13 +417,13 @@ Gets a collection of path segments that are matched by a wildcard in the URI template. A collection of path segments that are matched by a wildcard in the URI template. - property. - - :::code language="csharp" source="~/snippets/csharp/VS_Snippets_CFX/uritemplatematch/cs/snippets.cs" id="Snippet8"::: - + property. + + :::code language="csharp" source="~/snippets/csharp/VS_Snippets_CFX/uritemplatematch/cs/snippets.cs" id="Snippet8"::: + ]]> diff --git a/xml/System/UriTemplateTable.xml b/xml/System/UriTemplateTable.xml index 293e5c3578f..99f6361bda3 100644 --- a/xml/System/UriTemplateTable.xml +++ b/xml/System/UriTemplateTable.xml @@ -31,23 +31,23 @@ A class that represents an associative set of objects. - is an associative set of objects bound to an object of the developer's choosing. It allows you to match candidate Uniform Resource Identifiers (URIs) against the templates in the set and retrieve the data associated with the matching templates. The contents of can be changed until the method is called, at which time one of following types of validation occurs: - -- When is called passing in `false`, the checks to make sure the table contains no multiple structurally-equivalent templates. If it finds such templates, it throws an exception. This type of validation is used in conjunction with when you want to ensure only one template matches an incoming URI. - -- When is called passing in `true`, multiple structurally-equivalent templates can be contained within a . However, any query strings in the templates must not be ambiguous; identical query strings are allowed. For more information about ambiguous query strings, see [UriTemplate and UriTemplateTable](/dotnet/framework/wcf/feature-details/uritemplate-and-uritemplatetable). - - - -## Examples - The following code shows how to create a , populate it, and use it to match against a candidate . - + is an associative set of objects bound to an object of the developer's choosing. It allows you to match candidate Uniform Resource Identifiers (URIs) against the templates in the set and retrieve the data associated with the matching templates. The contents of can be changed until the method is called, at which time one of following types of validation occurs: + +- When is called passing in `false`, the checks to make sure the table contains no multiple structurally-equivalent templates. If it finds such templates, it throws an exception. This type of validation is used in conjunction with when you want to ensure only one template matches an incoming URI. + +- When is called passing in `true`, multiple structurally-equivalent templates can be contained within a . However, any query strings in the templates must not be ambiguous; identical query strings are allowed. For more information about ambiguous query strings, see [UriTemplate and UriTemplateTable](/dotnet/framework/wcf/feature-details/uritemplate-and-uritemplatetable). + + + +## Examples + The following code shows how to create a , populate it, and use it to match against a candidate . + :::code language="csharp" source="~/snippets/csharp/VS_Snippets_CFX/uritemplatetable/cs/program.cs" id="Snippet0"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CFX/uritemplatetable/vb/program1.vb" id="Snippet0"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CFX/uritemplatetable/vb/program1.vb" id="Snippet0"::: + ]]> @@ -88,14 +88,14 @@ Initializes a new instance of the class. - class. - + class. + :::code language="csharp" source="~/snippets/csharp/VS_Snippets_CFX/uritemplatetable/cs/program.cs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CFX/uritemplatetable/vb/program1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CFX/uritemplatetable/vb/program1.vb" id="Snippet1"::: + ]]> @@ -131,14 +131,14 @@ A collection of key/value pairs that consist of URI templates and associated data. Initializes a new instance of the class with the specified collection of key/value pairs. - class. - + class. + :::code language="csharp" source="~/snippets/csharp/VS_Snippets_CFX/uritemplatetable/cs/snippets.cs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CFX/uritemplatetable/vb/snippets.vb" id="Snippet2"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CFX/uritemplatetable/vb/snippets.vb" id="Snippet2"::: + ]]> @@ -174,14 +174,14 @@ A instance that contains the base address. Initializes a new instance of the class with the specified base address. - @@ -213,14 +213,14 @@ A collection of key/value pairs that consist of URI templates and associated data. Initializes a new instance of the class with the specified base address and collection of key/value pairs. - @@ -256,19 +256,19 @@ Gets or sets the base address for the instance. A that contains the base address. - property can only be set prior to calling or or otherwise an is thrown. - - - -## Examples - The following example shows how to access the property. - + property can only be set prior to calling or or otherwise an is thrown. + + + +## Examples + The following example shows how to access the property. + :::code language="csharp" source="~/snippets/csharp/VS_Snippets_CFX/uritemplatetable/cs/snippets.cs" id="Snippet5"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CFX/uritemplatetable/vb/snippets.vb" id="Snippet5"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CFX/uritemplatetable/vb/snippets.vb" id="Snippet5"::: + ]]> @@ -299,19 +299,19 @@ if the property is read only; otherwise . - is read only after the method is called. - - - -## Examples - The following example shows how to access the property. - + is read only after the method is called. + + + +## Examples + The following example shows how to access the property. + :::code language="csharp" source="~/snippets/csharp/VS_Snippets_CFX/uritemplatetable/cs/snippets.cs" id="Snippet6"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CFX/uritemplatetable/vb/snippets.vb" id="Snippet6"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CFX/uritemplatetable/vb/snippets.vb" id="Snippet6"::: + ]]> @@ -347,19 +347,19 @@ Gets a collection of key/value pairs that consist of objects and their associated data. A collection of key/value pairs that consist of objects and their associated data. - instance in the table has data associated with it. The property contains a collection of key value pairs where the key is a instance and the value is the data associated with the . Values can only be added to property prior to calling or or otherwise a is thrown. - - - -## Examples - The following example shows how to access the property. - + instance in the table has data associated with it. The property contains a collection of key value pairs where the key is a instance and the value is the data associated with the . Values can only be added to property prior to calling or or otherwise a is thrown. + + + +## Examples + The following example shows how to access the property. + :::code language="csharp" source="~/snippets/csharp/VS_Snippets_CFX/uritemplatetable/cs/snippets.cs" id="Snippet7"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CFX/uritemplatetable/vb/snippets.vb" id="Snippet7"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CFX/uritemplatetable/vb/snippets.vb" id="Snippet7"::: + ]]> @@ -392,17 +392,17 @@ Specifies whether to allow duplicate equivalent instances in the . Makes the read only. - method is called, one of the following types of validation occurs: - -- When is called passing in `false`, the checks to make sure the table contains no multiple structurally-equivalent templates. If it finds such templates, an exception is thrown. This type of validation is used in conjunction with when you want to ensure only one template matches an incoming URI. - -- When is called passing in `true`, multiple structurally-equivalent templates can be contained within a . However, any query strings in the templates must not be ambiguous; identical query strings are allowed. This type of validation is used in conjunction with when multiple template matches are allowed on the candidate URI. - - Only the first call to is honored, subsequent calls are ignored without any exception being thrown. - + method is called, one of the following types of validation occurs: + +- When is called passing in `false`, the checks to make sure the table contains no multiple structurally-equivalent templates. If it finds such templates, an exception is thrown. This type of validation is used in conjunction with when you want to ensure only one template matches an incoming URI. + +- When is called passing in `true`, multiple structurally-equivalent templates can be contained within a . However, any query strings in the templates must not be ambiguous; identical query strings are allowed. This type of validation is used in conjunction with when multiple template matches are allowed on the candidate URI. + + Only the first call to is honored, subsequent calls are ignored without any exception being thrown. + ]]> @@ -436,19 +436,19 @@ Attempts to match a candidate to the . A collection of instances. - method. - + method. + :::code language="csharp" source="~/snippets/csharp/VS_Snippets_CFX/uritemplatetable/cs/snippets.cs" id="Snippet9"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CFX/uritemplatetable/vb/snippets.vb" id="Snippet9"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CFX/uritemplatetable/vb/snippets.vb" id="Snippet9"::: + ]]> @@ -482,19 +482,19 @@ Attempts to match a candidate to the . A single instance. - is thrown. - - - -## Examples - The following example shows how to call the method. - + is thrown. + + + +## Examples + The following example shows how to call the method. + :::code language="csharp" source="~/snippets/csharp/VS_Snippets_CFX/uritemplatetable/cs/snippets.cs" id="Snippet10"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CFX/uritemplatetable/vb/snippets.vb" id="Snippet10"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CFX/uritemplatetable/vb/snippets.vb" id="Snippet10"::: + ]]> diff --git a/xml/System/ValueTuple.xml b/xml/System/ValueTuple.xml index ae9b32d9672..6ef771519b2 100644 --- a/xml/System/ValueTuple.xml +++ b/xml/System/ValueTuple.xml @@ -88,20 +88,20 @@ Provides static methods for creating value tuples. - , , etc., as follows: - -- They are structures (value types) rather than classes (reference types). - -- They are mutable rather than read-only. That is, the value of tuple components can change. - -- Their data members, such as `Item1`, `Item2`, etc., are fields rather than properties. - -The structure represents a tuple that has no elements. It is useful primarily for its static methods that let you create and compare instances of value tuple types. Its helper methods let you instantiate value tuples without having to explicitly specify the type of each value tuple component. By calling its static methods, you can create value tuples that have from zero to eight components. For value tuples with more than eight components, you must call the constructor. + , , etc., as follows: + +- They are structures (value types) rather than classes (reference types). + +- They are mutable rather than read-only. That is, the value of tuple components can change. + +- Their data members, such as `Item1`, `Item2`, etc., are fields rather than properties. + +The structure represents a tuple that has no elements. It is useful primarily for its static methods that let you create and compare instances of value tuple types. Its helper methods let you instantiate value tuples without having to explicitly specify the type of each value tuple component. By calling its static methods, you can create value tuples that have from zero to eight components. For value tuples with more than eight components, you must call the constructor. ### Serialization and value tuples @@ -157,7 +157,7 @@ The type is not serializable in .NET Core 1.x or in the Compares the current instance to a specified instance. This method always returns 0. - instance has no elements, any two instances are considered to be equivalent. ]]> @@ -271,11 +271,11 @@ The type is not serializable in .NET Core 1.x or in the Creates a new value tuple with 1 component (a singleton). A value tuple with 1 component. - is a helper method that you can call to instantiate a 1-component value tuple without having to explicitly specify the type of its component. - + is a helper method that you can call to instantiate a 1-component value tuple without having to explicitly specify the type of its component. + ]]> @@ -345,11 +345,11 @@ The type is not serializable in .NET Core 1.x or in the Creates a new value tuple with 2 components (a pair). A value tuple with 2 components. - is a helper method that you can call to instantiate an 2-component value tuple without having to explicitly specify the types of its components. - + is a helper method that you can call to instantiate an 2-component value tuple without having to explicitly specify the types of its components. + ]]> @@ -430,11 +430,11 @@ The type is not serializable in .NET Core 1.x or in the Creates a new value tuple with 3 components (a triple). A value tuple with 3 components. - is a helper method that you can call to instantiate an 3-component value tuple without having to explicitly specify the types of its components. - + is a helper method that you can call to instantiate an 3-component value tuple without having to explicitly specify the types of its components. + ]]> @@ -526,11 +526,11 @@ The type is not serializable in .NET Core 1.x or in the Creates a new value tuple with 4 components (a quadruple). A value tuple with 4 components. - is a helper method that you can call to instantiate an 4-component value tuple without having to explicitly specify the types of its components. - + is a helper method that you can call to instantiate an 4-component value tuple without having to explicitly specify the types of its components. + ]]> @@ -633,11 +633,11 @@ The type is not serializable in .NET Core 1.x or in the Creates a new value tuple with 5 components (a quintuple). A value tuple with 5 components. - is a helper method that you can call to instantiate a 5-component value tuple without having to explicitly specify the types of its components. - + is a helper method that you can call to instantiate a 5-component value tuple without having to explicitly specify the types of its components. + ]]> @@ -751,11 +751,11 @@ The type is not serializable in .NET Core 1.x or in the Creates a new value tuple with 6 components (a sexuple). A value tuple with 6 components. - is a helper method that you can call to instantiate a 6-component value tuple without having to explicitly specify the types of its components. - + is a helper method that you can call to instantiate a 6-component value tuple without having to explicitly specify the types of its components. + ]]> @@ -880,11 +880,11 @@ The type is not serializable in .NET Core 1.x or in the Creates a new value tuple with 7 components (a septuple). A value tuple with 7 components. - is a helper method that you can call to instantiate an 7-component value tuple without having to explicitly specify the types of its components. - + is a helper method that you can call to instantiate an 7-component value tuple without having to explicitly specify the types of its components. + ]]> @@ -1020,14 +1020,14 @@ The type is not serializable in .NET Core 1.x or in the Creates a new value tuple with 8 components (an octuple). A value tuple with 8 components. - is a helper method that you can call to instantiate an 8-component value tuple without having to explicitly specify the types of its components. - + is a helper method that you can call to instantiate an 8-component value tuple without having to explicitly specify the types of its components. + > [!NOTE] -> You must call the constructor to create a tuple with nine or more components unless your language provides a special syntax for this purpose. The static methods of the structure cannot be used to create a tuple with nine or more components. - +> You must call the constructor to create a tuple with nine or more components unless your language provides a special syntax for this purpose. The static methods of the structure cannot be used to create a tuple with nine or more components. + ]]> @@ -1293,11 +1293,11 @@ The type is not serializable in .NET Core 1.x or in the if the current instance is equal to the specified object; otherwise, . - t> instance is cast to an interface. The implementation is called only if `other` is not `null`, and if it can be successfully cast to a object. - + t> instance is cast to an interface. The implementation is called only if `other` is not `null`, and if it can be successfully cast to a object. + ]]> diff --git a/xml/System/ValueTuple`1.xml b/xml/System/ValueTuple`1.xml index 5ea0d9acb2b..6144ec16cf6 100644 --- a/xml/System/ValueTuple`1.xml +++ b/xml/System/ValueTuple`1.xml @@ -91,25 +91,25 @@ The type of the value tuple's only element. Represents a value tuple with a single component. - structure represents a value tuple that has one element. - - The value tuple types differ from the tuple types (such as as follows: - -- They are structures (value types) rather than classes (reference types). - -- Its member is a field rather than a property. - -- Its field is mutable rather than read-only. - - The value tuple types provide the runtime implementation that supports [tuples in C#](/dotnet/csharp/tuples) and struct tuples in F#. In addition to creating a instance by using language syntax, you can call the factory method. - + structure represents a value tuple that has one element. + + The value tuple types differ from the tuple types (such as as follows: + +- They are structures (value types) rather than classes (reference types). + +- Its member is a field rather than a property. + +- Its field is mutable rather than read-only. + + The value tuple types provide the runtime implementation that supports [tuples in C#](/dotnet/csharp/tuples) and struct tuples in F#. In addition to creating a instance by using language syntax, you can call the factory method. + ### Serialization and value tuples The type is not serializable in .NET Core 1.x or in the .NET Framework 4.7 and earlier versions. In addition, .NET Standard, including .NET Standard 2.0, does not mandate serialization of instances; whether or not a instance is serializable depends on the individual .NET Standard implementation. To determine whether a type is serializable on a particular .NET implementation, get a object that represents the type and retrieve the value of its property. For a list of serializable types in .NET Core and the .NET Framework, see [Binary Serialization](/dotnet/standard/serialization/binary-serialization). - + ]]> @@ -212,25 +212,34 @@ The type is not serializable in .NET Core 1.x or in The tuple to compare with this instance. Compares the current instance to a specified instance. - A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. - - Value - - Description - - A negative integer - - This instance precedes . - - Zero - - This instance and have the same position in the sort order. - - A positive integer - - This instance follows . - - + A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. + + Value + + + Description + + + + + A negative integer + + + This instance precedes . + + + Zero + + + This instance and have the same position in the sort order. + + + A positive integer + + + This instance follows . + + To be added. @@ -302,17 +311,17 @@ The type is not serializable in .NET Core 1.x or in if the current instance is equal to the specified object; otherwise, . - value type. - -- It component is of the same types as that of the current instance. - -- Its component is equal to that of the current instance. Equality is determined by the default equality comparer for the component. - + value type. + +- It component is of the same types as that of the current instance. + +- Its component is equal to that of the current instance. Equality is determined by the default equality comparer for the component. + ]]> @@ -371,15 +380,15 @@ The type is not serializable in .NET Core 1.x or in if the current instance is equal to the specified tuple; otherwise, . - @@ -518,25 +527,34 @@ The type is not serializable in .NET Core 1.x or in The object to compare with the current instance. An object that provides custom rules for comparison. Compares the current instance to a specified object by using a specified comparer and returns an integer that indicates whether the current object is before, after, or in the same position as the specified object in the sort order. - A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. - - Value - - Description - - A negative integer - - This instance precedes . - - Zero - - This instance and have the same position in the sort order. - - A positive integer - - This instance follows . - - + A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. + + Value + + + Description + + + + + A negative integer + + + This instance precedes . + + + Zero + + + This instance and have the same position in the sort order. + + + A positive integer + + + This instance follows . + + To be added. @@ -683,25 +701,34 @@ The type is not serializable in .NET Core 1.x or in The object to compare with the current instance. Compares the current instance to a specified object by using a specified comparer and returns an integer that indicates whether the current object is before, after, or in the same position as the specified object in the sort order. - A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. - - Value - - Description - - A negative integer - - This instance precedes . - - Zero - - This instance and have the same position in the sort order. - - A positive integer - - This instance follows . - - + A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. + + Value + + + Description + + + + + A negative integer + + + This instance precedes . + + + Zero + + + This instance and have the same position in the sort order. + + + A positive integer + + + This instance follows . + + To be added. @@ -755,11 +782,11 @@ The type is not serializable in .NET Core 1.x or in Gets the value of the element. The value of the element. - property is an explicit interface implementation. To call it, you must cast or convert the object to a interface object. - + property is an explicit interface implementation. To call it, you must cast or convert the object to a interface object. + ]]> @@ -805,11 +832,11 @@ The type is not serializable in .NET Core 1.x or in Gets the number of elements in the . 1, the number of elements in a object. - property is an explicit interface implementation. To call it, you must cast or convert the object to an interface object. - + property is an explicit interface implementation. To call it, you must cast or convert the object to an interface object. + ]]> @@ -860,11 +887,11 @@ The type is not serializable in .NET Core 1.x or in Returns a string that represents the value of this instance. The string representation of this instance. - field. If the field value is `null`, it is represented as . - + field. If the field value is `null`, it is represented as . + ]]> diff --git a/xml/System/ValueTuple`2.xml b/xml/System/ValueTuple`2.xml index 1d5d777408a..f4f2dd109f2 100644 --- a/xml/System/ValueTuple`2.xml +++ b/xml/System/ValueTuple`2.xml @@ -102,25 +102,25 @@ The type of the value tuple's second element. Represents a value tuple with 2 components. - structure represents a value tuple that has two elements. - - The value tuple types differ from the tuple types (such as ) as follows: - -- They are structures (value types) rather than classes (reference types). - -- Members such as and are fields rather than properties. - -- Their fields are mutable rather than read-only. - - The value tuple types provide the runtime implementation that supports [tuples in C#](/dotnet/csharp/tuples) and struct tuples in F#. In addition to creating a instance by using language syntax, you can call the factory method. + structure represents a value tuple that has two elements. + + The value tuple types differ from the tuple types (such as ) as follows: + +- They are structures (value types) rather than classes (reference types). + +- Members such as and are fields rather than properties. + +- Their fields are mutable rather than read-only. + + The value tuple types provide the runtime implementation that supports [tuples in C#](/dotnet/csharp/tuples) and struct tuples in F#. In addition to creating a instance by using language syntax, you can call the factory method. ### Serialization and value tuples The type is not serializable in .NET Core 1.x or in the .NET Framework 4.7 and earlier versions. In addition, .NET Standard, including .NET Standard 2.0, does not mandate serialization of instances; whether or not a instance is serializable depends on the individual .NET Standard implementation. To determine whether a type is serializable on a particular .NET implementation, get a object that represents the type and retrieve the value of its property. For a list of serializable types in .NET Core and the .NET Framework, see [Binary Serialization](/dotnet/standard/serialization/binary-serialization). - + ]]> @@ -225,25 +225,34 @@ The type is not serializable in .NET Core 1.x or in The tuple to compare with this instance. Compares the current instance to a specified instance. - A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. - - Value - - Description - - A negative integer - - This instance precedes . - - Zero - - This instance and have the same position in the sort order. - - A positive integer - - This instance follows . - - + A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. + + Value + + + Description + + + + + A negative integer + + + This instance precedes . + + + Zero + + + This instance and have the same position in the sort order. + + + A positive integer + + + This instance follows . + + To be added. @@ -315,17 +324,17 @@ The type is not serializable in .NET Core 1.x or in if the current instance is equal to the specified object; otherwise, . - value type. - -- Its components are of the same types as those of the current instance. - -- Its components are equal to those of the current instance. Equality is determined by the default equality comparer for each component. - + value type. + +- Its components are of the same types as those of the current instance. + +- Its components are equal to those of the current instance. Equality is determined by the default equality comparer for each component. + ]]> @@ -384,15 +393,15 @@ The type is not serializable in .NET Core 1.x or in if the current instance is equal to the specified tuple; otherwise, . - @@ -577,25 +586,34 @@ The type is not serializable in .NET Core 1.x or in The object to compare with the current instance. An object that provides custom rules for comparison. Compares the current instance to a specified object by using a specified comparer and returns an integer that indicates whether the current object is before, after, or in the same position as the specified object in the sort order. - A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. - - Value - - Description - - A negative integer - - This instance precedes . - - Zero - - This instance and have the same position in the sort order. - - A positive integer - - This instance follows . - - + A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. + + Value + + + Description + + + + + A negative integer + + + This instance precedes . + + + Zero + + + This instance and have the same position in the sort order. + + + A positive integer + + + This instance follows . + + To be added. @@ -653,7 +671,7 @@ The type is not serializable in .NET Core 1.x or in ### Remarks This member is an explicit interface member implementation. It can be used only when the instance is cast to an interface. - + The implementation is called only if `other` is not `null`, and if it can be successfully cast to a whose components are of the same types as those of the current instance. The method first passes the values of the objects to be compared to the implementation. If this method call returns `true`, the method is called again and passed the values of the two instances. ]]> @@ -752,25 +770,34 @@ The The object to compare with the current instance. Compares the current instance to a specified object by using a specified comparer and returns an integer that indicates whether the current object is before, after, or in the same position as the specified object in the sort order. - A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. - - Value - - Description - - A negative integer - - This instance precedes . - - Zero - - This instance and have the same position in the sort order. - - A positive integer - - This instance follows . - - + A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. + + Value + + + Description + + + + + A negative integer + + + This instance precedes . + + + Zero + + + This instance and have the same position in the sort order. + + + A positive integer + + + This instance follows . + + To be added. @@ -824,11 +851,11 @@ The Gets the value of the specified element. The value of the element at the specified position. - property is an explicit interface implementation. To call it, you must cast or convert the object to an interface object. - + property is an explicit interface implementation. To call it, you must cast or convert the object to an interface object. + ]]> @@ -874,11 +901,11 @@ The Gets the number of elements in the . 2, the number of elements in a object. - property is an explicit interface implementation. To call it, you must cast or convert the object to an interface object. - + property is an explicit interface implementation. To call it, you must cast or convert the object to an interface object. + ]]> @@ -929,11 +956,11 @@ The Returns a string that represents the value of this instance. The string representation of this instance. - and fields. If any of the field values is `null`, it is represented as . - + and fields. If any of the field values is `null`, it is represented as . + ]]> diff --git a/xml/System/ValueTuple`3.xml b/xml/System/ValueTuple`3.xml index e79f7b9953b..fcfd4246e69 100644 --- a/xml/System/ValueTuple`3.xml +++ b/xml/System/ValueTuple`3.xml @@ -111,25 +111,25 @@ The type of the value tuple's third element. Represents a value tuple with 3 components. - structure represents a value tuple that has three elements. - - The value tuple types differ from the tuple types (such as ) as follows: - -- They are structures (value types) rather than classes (reference types). - -- Members such as and are fields rather than properties. - -- Their fields are mutable rather than read-only. - - The value tuple types provide the runtime implementation that supports [tuples in C#](/dotnet/csharp/tuples) and struct tuples in F#. In addition to creating a instance by using language syntax, you can call the factory method. - + structure represents a value tuple that has three elements. + + The value tuple types differ from the tuple types (such as ) as follows: + +- They are structures (value types) rather than classes (reference types). + +- Members such as and are fields rather than properties. + +- Their fields are mutable rather than read-only. + + The value tuple types provide the runtime implementation that supports [tuples in C#](/dotnet/csharp/tuples) and struct tuples in F#. In addition to creating a instance by using language syntax, you can call the factory method. + ### Serialization and value tuples The type is not serializable in .NET Core 1.x or in the .NET Framework 4.7 and earlier versions. In addition, .NET Standard, including .NET Standard 2.0, does not mandate serialization of instances; whether or not a instance is serializable depends on the individual .NET Standard implementation. To determine whether a type is serializable on a particular .NET implementation, get a object that represents the type and retrieve the value of its property. For a list of serializable types in .NET Core and the .NET Framework, see [Binary Serialization](/dotnet/standard/serialization/binary-serialization). - + ]]> @@ -236,25 +236,34 @@ The type is not serializable in .NET Core 1.x or in The tuple to compare with this instance. Compares the current instance to a specified instance. - A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. - - Value - - Description - - A negative integer - - This instance precedes . - - Zero - - This instance and have the same position in the sort order. - - A positive integer - - This instance follows . - - + A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. + + Value + + + Description + + + + + A negative integer + + + This instance precedes . + + + Zero + + + This instance and have the same position in the sort order. + + + A positive integer + + + This instance follows . + + To be added. @@ -326,17 +335,17 @@ The type is not serializable in .NET Core 1.x or in if the current instance is equal to the specified object; otherwise, . - value type. - -- Its components are of the same types as those of the current instance. - -- Its components are equal to those of the current instance. Equality is determined by the default equality comparer for each component. - + value type. + +- Its components are of the same types as those of the current instance. + +- Its components are equal to those of the current instance. Equality is determined by the default equality comparer for each component. + ]]> @@ -395,15 +404,15 @@ The type is not serializable in .NET Core 1.x or in if the current instance is equal to the specified tuple; otherwise, . - @@ -634,25 +643,34 @@ The type is not serializable in .NET Core 1.x or in The object to compare with the current instance. An object that provides custom rules for comparison. Compares the current instance to a specified object by using a specified comparer and returns an integer that indicates whether the current object is before, after, or in the same position as the specified object in the sort order. - A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. - - Value - - Description - - A negative integer - - This instance precedes . - - Zero - - This instance and have the same position in the sort order. - - A positive integer - - This instance follows . - - + A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. + + Value + + + Description + + + + + A negative integer + + + This instance precedes . + + + Zero + + + This instance and have the same position in the sort order. + + + A positive integer + + + This instance follows . + + To be added. @@ -799,25 +817,34 @@ The type is not serializable in .NET Core 1.x or in The object to compare with the current instance. Compares the current instance to a specified object by using a specified comparer and returns an integer that indicates whether the current object is before, after, or in the same position as the specified object in the sort order. - A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. - - Value - - Description - - A negative integer - - This instance precedes . - - Zero - - This instance and have the same position in the sort order. - - A positive integer - - This instance follows . - - + A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. + + Value + + + Description + + + + + A negative integer + + + This instance precedes . + + + Zero + + + This instance and have the same position in the sort order. + + + A positive integer + + + This instance follows . + + To be added. @@ -871,11 +898,11 @@ The type is not serializable in .NET Core 1.x or in Gets the value of the specified element. The value of the element at the specified position. - property is an explicit interface implementation. To call it, you must cast or convert the object to an interface object. - + property is an explicit interface implementation. To call it, you must cast or convert the object to an interface object. + ]]> @@ -921,11 +948,11 @@ The type is not serializable in .NET Core 1.x or in Gets the number of elements in the . 3, the number of elements in a object. - property is an explicit interface implementation. To call it, you must cast or convert the object to an interface object. - + property is an explicit interface implementation. To call it, you must cast or convert the object to an interface object. + ]]> @@ -976,11 +1003,11 @@ The type is not serializable in .NET Core 1.x or in Returns a string that represents the value of this instance. The string representation of this instance. - , , and fields. If any of the field values is `null`, it is represented as . - + , , and fields. If any of the field values is `null`, it is represented as . + ]]> diff --git a/xml/System/ValueTuple`4.xml b/xml/System/ValueTuple`4.xml index 3cd528d6749..3b2e158b0df 100644 --- a/xml/System/ValueTuple`4.xml +++ b/xml/System/ValueTuple`4.xml @@ -128,25 +128,25 @@ The type of the value tuple's fourth element. Represents a value tuple with 4 components. - structure represents a value tuple that has four elements. - - The value tuple types differ from the tuple types (such as ) as follows: - -- They are structures (value types) rather than classes (reference types). - -- Members such as and are fields rather than properties. - -- Their fields are mutable rather than read-only. - - The value tuple types provide the runtime implementation that supports [tuples in C#](/dotnet/csharp/tuples) and struct tuples in F#. In addition to creating a instance by using language syntax, you can call the factory method. + structure represents a value tuple that has four elements. + + The value tuple types differ from the tuple types (such as ) as follows: + +- They are structures (value types) rather than classes (reference types). + +- Members such as and are fields rather than properties. + +- Their fields are mutable rather than read-only. + + The value tuple types provide the runtime implementation that supports [tuples in C#](/dotnet/csharp/tuples) and struct tuples in F#. In addition to creating a instance by using language syntax, you can call the factory method. ### Serialization and value tuples The type is not serializable in .NET Core 1.x or in the .NET Framework 4.7 and earlier versions. In addition, .NET Standard, including .NET Standard 2.0, does not mandate serialization of instances; whether or not a instance is serializable depends on the individual .NET Standard implementation. To determine whether a type is serializable on a particular .NET implementation, get a object that represents the type and retrieve the value of its property. For a list of serializable types in .NET Core and the .NET Framework, see [Binary Serialization](/dotnet/standard/serialization/binary-serialization). - + ]]> @@ -249,25 +249,34 @@ The type is not serializable in .NET Core 1.x or in The tuple to compare with this instance. Compares the current instance to a specified instance. - A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. - - Value - - Description - - A negative integer - - This instance precedes . - - Zero - - This instance and have the same position in the sort order. - - A positive integer - - This instance follows . - - + A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. + + Value + + + Description + + + + + A negative integer + + + This instance precedes . + + + Zero + + + This instance and have the same position in the sort order. + + + A positive integer + + + This instance follows . + + To be added. @@ -339,17 +348,17 @@ The type is not serializable in .NET Core 1.x or in if the current instance is equal to the specified object; otherwise, . - value type. - -- Its components are of the same types as those of the current instance. - -- Its components are equal to those of the current instance. Equality is determined by the default equality comparer for each component. - + value type. + +- Its components are of the same types as those of the current instance. + +- Its components are equal to those of the current instance. Equality is determined by the default equality comparer for each component. + ]]> @@ -408,15 +417,15 @@ The type is not serializable in .NET Core 1.x or in if the current instance is equal to the specified tuple; otherwise, . - @@ -669,25 +678,34 @@ The type is not serializable in .NET Core 1.x or in The object to compare with the current instance. An object that provides custom rules for comparison. Compares the current instance to a specified object by using a specified comparer and returns an integer that indicates whether the current object is before, after, or in the same position as the specified object in the sort order. - A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. - - Value - - Description - - A negative integer - - This instance precedes . - - Zero - - This instance and have the same position in the sort order. - - A positive integer - - This instance follows . - - + A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. + + Value + + + Description + + + + + A negative integer + + + This instance precedes . + + + Zero + + + This instance and have the same position in the sort order. + + + A positive integer + + + This instance follows . + + To be added. @@ -834,25 +852,34 @@ The type is not serializable in .NET Core 1.x or in The object to compare with the current instance. Compares the current instance to a specified object by using a specified comparer and returns an integer that indicates whether the current object is before, after, or in the same position as the specified object in the sort order. - A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. - - Value - - Description - - A negative integer - - This instance precedes . - - Zero - - This instance and have the same position in the sort order. - - A positive integer - - This instance follows . - - + A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. + + Value + + + Description + + + + + A negative integer + + + This instance precedes . + + + Zero + + + This instance and have the same position in the sort order. + + + A positive integer + + + This instance follows . + + To be added. @@ -906,11 +933,11 @@ The type is not serializable in .NET Core 1.x or in Gets the value of the specified element. The value of the element at the specified position. - property is an explicit interface implementation. To call it, you must cast or convert the object to an interface object. - + property is an explicit interface implementation. To call it, you must cast or convert the object to an interface object. + ]]> @@ -956,11 +983,11 @@ The type is not serializable in .NET Core 1.x or in Gets the number of elements in the . 4, the number of elements in a object. - property is an explicit interface implementation. To call it, you must cast or convert the object to an interface object. - + property is an explicit interface implementation. To call it, you must cast or convert the object to an interface object. + ]]> @@ -1005,11 +1032,11 @@ The type is not serializable in .NET Core 1.x or in Returns a string that represents the value of this instance. The string representation of this instance. - , , , and fields. If any of the field values is `null`, it is represented as . - + , , , and fields. If any of the field values is `null`, it is represented as . + ]]> diff --git a/xml/System/ValueTuple`5.xml b/xml/System/ValueTuple`5.xml index e2bc96d1fac..e9bd751dfe0 100644 --- a/xml/System/ValueTuple`5.xml +++ b/xml/System/ValueTuple`5.xml @@ -137,25 +137,25 @@ The type of the value tuple's fifth element. Represents a value tuple with 5 components. - structure represents a value tuple that has five elements. - - The value tuple types differ from the tuple types (such as ) as follows: - -- They are structures (value types) rather than classes (reference types). - -- Members such as and are fields rather than properties. - -- Their fields are mutable rather than read-only. - - The value tuple types provide the runtime implementation that supports [tuples in C#](/dotnet/csharp/tuples) and struct tuples in F#. In addition to creating a instance by using language syntax, you can call the factory method. - + structure represents a value tuple that has five elements. + + The value tuple types differ from the tuple types (such as ) as follows: + +- They are structures (value types) rather than classes (reference types). + +- Members such as and are fields rather than properties. + +- Their fields are mutable rather than read-only. + + The value tuple types provide the runtime implementation that supports [tuples in C#](/dotnet/csharp/tuples) and struct tuples in F#. In addition to creating a instance by using language syntax, you can call the factory method. + ### Serialization and value tuples The type is not serializable in .NET Core 1.x or in the .NET Framework 4.7 and earlier versions. In addition, .NET Standard, including .NET Standard 2.0, does not mandate serialization of instances; whether or not a instance is serializable depends on the individual .NET Standard implementation. To determine whether a type is serializable on a particular .NET implementation, get a object that represents the type and retrieve the value of its property. For a list of serializable types in .NET Core and the .NET Framework, see [Binary Serialization](/dotnet/standard/serialization/binary-serialization). - + ]]> @@ -260,25 +260,34 @@ The type is not serializable in .NET Core 1.x or in The tuple to compare with this instance. Compares the current instance to a specified instance. - A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. - - Value - - Description - - A negative integer - - This instance precedes . - - Zero - - This instance and have the same position in the sort order. - - A positive integer - - This instance follows . - - + A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. + + Value + + + Description + + + + + A negative integer + + + This instance precedes . + + + Zero + + + This instance and have the same position in the sort order. + + + A positive integer + + + This instance follows . + + To be added. @@ -350,17 +359,17 @@ The type is not serializable in .NET Core 1.x or in if the current instance is equal to the specified object; otherwise, . - value type. - -- Its components are of the same types as those of the current instance. - -- Its components are equal to those of the current instance. Equality is determined by the default equality comparer for each component. - + value type. + +- Its components are of the same types as those of the current instance. + +- Its components are equal to those of the current instance. Equality is determined by the default equality comparer for each component. + ]]> @@ -419,15 +428,15 @@ The type is not serializable in .NET Core 1.x or in if the current instance is equal to the specified tuple; otherwise, . - @@ -720,25 +729,34 @@ The type is not serializable in .NET Core 1.x or in The object to compare with the current instance. An object that provides custom rules for comparison. Compares the current instance to a specified object by using a specified comparer and returns an integer that indicates whether the current object is before, after, or in the same position as the specified object in the sort order. - A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. - - Value - - Description - - A negative integer - - This instance precedes . - - Zero - - This instance and have the same position in the sort order. - - A positive integer - - This instance follows . - - + A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. + + Value + + + Description + + + + + A negative integer + + + This instance precedes . + + + Zero + + + This instance and have the same position in the sort order. + + + A positive integer + + + This instance follows . + + To be added. @@ -885,25 +903,34 @@ The type is not serializable in .NET Core 1.x or in The object to compare with the current instance. Compares the current instance to a specified object by using a specified comparer and returns an integer that indicates whether the current object is before, after, or in the same position as the specified object in the sort order. - A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. - - Value - - Description - - A negative integer - - This instance precedes . - - Zero - - This instance and have the same position in the sort order. - - A positive integer - - This instance follows . - - + A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. + + Value + + + Description + + + + + A negative integer + + + This instance precedes . + + + Zero + + + This instance and have the same position in the sort order. + + + A positive integer + + + This instance follows . + + To be added. @@ -957,11 +984,11 @@ The type is not serializable in .NET Core 1.x or in Gets the value of the specified element. The value of the element at the specified position. - property is an explicit interface implementation. To call it, you must cast or convert the object to an interface object. - + property is an explicit interface implementation. To call it, you must cast or convert the object to an interface object. + ]]> @@ -1007,11 +1034,11 @@ The type is not serializable in .NET Core 1.x or in Gets the number of elements in the . 5, the number of elements in a object. - property is an explicit interface implementation. To call it, you must cast or convert the object to an interface object. - + property is an explicit interface implementation. To call it, you must cast or convert the object to an interface object. + ]]> @@ -1056,11 +1083,11 @@ The type is not serializable in .NET Core 1.x or in Returns a string that represents the value of this instance. The string representation of this instance. - , , , , and fields. If any of the field values is `null`, it is represented as . - + , , , , and fields. If any of the field values is `null`, it is represented as . + ]]> diff --git a/xml/System/ValueTuple`6.xml b/xml/System/ValueTuple`6.xml index f9dad6d34d9..cd67dac1a86 100644 --- a/xml/System/ValueTuple`6.xml +++ b/xml/System/ValueTuple`6.xml @@ -146,25 +146,25 @@ The type of the value tuple's sixth element. Represents a value tuple with 6 components. - structure represents a value tuple that has six elements. - - The value tuple types differ from the tuple types (such as ) as follows: - -- They are structures (value types) rather than classes (reference types). - -- Members such as and are fields rather than properties. - -- Their fields are mutable rather than read-only. - - The value tuple types provide the runtime implementation that supports [tuples in C#](/dotnet/csharp/tuples) and struct tuples in F#. In addition to creating a instance by using language syntax, you can call the factory method. + structure represents a value tuple that has six elements. + + The value tuple types differ from the tuple types (such as ) as follows: + +- They are structures (value types) rather than classes (reference types). + +- Members such as and are fields rather than properties. + +- Their fields are mutable rather than read-only. + + The value tuple types provide the runtime implementation that supports [tuples in C#](/dotnet/csharp/tuples) and struct tuples in F#. In addition to creating a instance by using language syntax, you can call the factory method. ### Serialization and value tuples The type is not serializable in .NET Core 1.x or in the .NET Framework 4.7 and earlier versions. In addition, .NET Standard, including .NET Standard 2.0, does not mandate serialization of instances; whether or not a instance is serializable depends on the individual .NET Standard implementation. To determine whether a type is serializable on a particular .NET implementation, get a object that represents the type and retrieve the value of its property. For a list of serializable types in .NET Core and the .NET Framework, see [Binary Serialization](/dotnet/standard/serialization/binary-serialization). - + ]]> @@ -271,25 +271,34 @@ The type is not serializable in .NET Core 1.x or in The tuple to compare with this instance. Compares the current instance to a specified instance. - A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. - - Value - - Description - - A negative integer - - This instance precedes . - - Zero - - This instance and have the same position in the sort order. - - A positive integer - - This instance follows . - - + A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. + + Value + + + Description + + + + + A negative integer + + + This instance precedes . + + + Zero + + + This instance and have the same position in the sort order. + + + A positive integer + + + This instance follows . + + To be added. @@ -361,17 +370,17 @@ The type is not serializable in .NET Core 1.x or in if the current instance is equal to the specified object; otherwise, . - value type. - -- Its components are of the same types as those of the current instance. - -- Its components are equal to those of the current instance. Equality is determined by the default equality comparer for each component. - + value type. + +- Its components are of the same types as those of the current instance. + +- Its components are equal to those of the current instance. Equality is determined by the default equality comparer for each component. + ]]> @@ -430,15 +439,15 @@ The type is not serializable in .NET Core 1.x or in if the current instance is equal to the specified tuple; otherwise, . - @@ -771,25 +780,34 @@ The type is not serializable in .NET Core 1.x or in The object to compare with the current instance. An object that provides custom rules for comparison. Compares the current instance to a specified object by using a specified comparer and returns an integer that indicates whether the current object is before, after, or in the same position as the specified object in the sort order. - A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. - - Value - - Description - - A negative integer - - This instance precedes . - - Zero - - This instance and have the same position in the sort order. - - A positive integer - - This instance follows . - - + A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. + + Value + + + Description + + + + + A negative integer + + + This instance precedes . + + + Zero + + + This instance and have the same position in the sort order. + + + A positive integer + + + This instance follows . + + To be added. @@ -936,25 +954,34 @@ The type is not serializable in .NET Core 1.x or in The object to compare with the current instance. Compares the current instance to a specified object by using a specified comparer and returns an integer that indicates whether the current object is before, after, or in the same position as the specified object in the sort order. - A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. - - Value - - Description - - A negative integer - - This instance precedes . - - Zero - - This instance and have the same position in the sort order. - - A positive integer - - This instance follows . - - + A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. + + Value + + + Description + + + + + A negative integer + + + This instance precedes . + + + Zero + + + This instance and have the same position in the sort order. + + + A positive integer + + + This instance follows . + + To be added. @@ -1008,11 +1035,11 @@ The type is not serializable in .NET Core 1.x or in Gets the value of the specified element. The value of the element at the specified position. - property is an explicit interface implementation. To call it, you must cast or convert the object to an interface object. - + property is an explicit interface implementation. To call it, you must cast or convert the object to an interface object. + ]]> @@ -1058,11 +1085,11 @@ The type is not serializable in .NET Core 1.x or in Gets the number of elements in the . 6, the number of elements in a object. - property is an explicit interface implementation. To call it, you must cast or convert the object to an interface object. - + property is an explicit interface implementation. To call it, you must cast or convert the object to an interface object. + ]]> @@ -1107,11 +1134,11 @@ The type is not serializable in .NET Core 1.x or in Returns a string that represents the value of this instance. The string representation of this instance. - , , , , , and fields. If any of the field values is `null`, it is represented as . - + , , , , , and fields. If any of the field values is `null`, it is represented as . + ]]> diff --git a/xml/System/ValueTuple`7.xml b/xml/System/ValueTuple`7.xml index 1d43753ea0f..c796e1fd9a5 100644 --- a/xml/System/ValueTuple`7.xml +++ b/xml/System/ValueTuple`7.xml @@ -155,25 +155,25 @@ The type of the value tuple's seventh element. Represents a value tuple with 7 components. - structure represents a value tuple that has seven elements. - - The value tuple types differ from the tuple types (such as ) as follows: - -- They are structures (value types) rather than classes (reference types). - -- Members such as and are fields rather than properties. - -- Their fields are mutable rather than read-only. - - The value tuple types provide the runtime implementation that supports [tuples in C#](/dotnet/csharp/tuples) and struct tuples in F#. In addition to creating a instance by using language syntax, you can call the factory method. - + structure represents a value tuple that has seven elements. + + The value tuple types differ from the tuple types (such as ) as follows: + +- They are structures (value types) rather than classes (reference types). + +- Members such as and are fields rather than properties. + +- Their fields are mutable rather than read-only. + + The value tuple types provide the runtime implementation that supports [tuples in C#](/dotnet/csharp/tuples) and struct tuples in F#. In addition to creating a instance by using language syntax, you can call the factory method. + ### Serialization and value tuples The type is not serializable in .NET Core 1.x or in the .NET Framework 4.7 and earlier versions. In addition, .NET Standard, including .NET Standard 2.0, does not mandate serialization of instances; whether or not a instance is serializable depends on the individual .NET Standard implementation. To determine whether a type is serializable on a particular .NET implementation, get a object that represents the type and retrieve the value of its property. For a list of serializable types in .NET Core and the .NET Framework, see [Binary Serialization](/dotnet/standard/serialization/binary-serialization). - + ]]> @@ -282,25 +282,34 @@ The type is not serializable in .NET Core 1.x or in The tuple to compare with this instance. Compares the current instance to a specified instance. - A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. - - Value - - Description - - A negative integer - - This instance precedes . - - Zero - - This instance and have the same position in the sort order. - - A positive integer - - This instance follows . - - + A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. + + Value + + + Description + + + + + A negative integer + + + This instance precedes . + + + Zero + + + This instance and have the same position in the sort order. + + + A positive integer + + + This instance follows . + + To be added. @@ -372,17 +381,17 @@ The type is not serializable in .NET Core 1.x or in if the current instance is equal to the specified object; otherwise, . - value type. - -- Its components are of the same types as those of the current instance. - -- Its components are equal to those of the current instance. Equality is determined by the default equality comparer for each component. - + value type. + +- Its components are of the same types as those of the current instance. + +- Its components are equal to those of the current instance. Equality is determined by the default equality comparer for each component. + ]]> @@ -441,15 +450,15 @@ The type is not serializable in .NET Core 1.x or in if the current instance is equal to the specified tuple; otherwise, . - @@ -822,25 +831,34 @@ The type is not serializable in .NET Core 1.x or in The object to compare with the current instance. An object that provides custom rules for comparison. Compares the current instance to a specified object by using a specified comparer and returns an integer that indicates whether the current object is before, after, or in the same position as the specified object in the sort order. - A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. - - Value - - Description - - A negative integer - - This instance precedes . - - Zero - - This instance and have the same position in the sort order. - - A positive integer - - This instance follows . - - + A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. + + Value + + + Description + + + + + A negative integer + + + This instance precedes . + + + Zero + + + This instance and have the same position in the sort order. + + + A positive integer + + + This instance follows . + + To be added. @@ -987,25 +1005,34 @@ The type is not serializable in .NET Core 1.x or in The object to compare with the current instance. Compares the current instance to a specified object by using a specified comparer and returns an integer that indicates whether the current object is before, after, or in the same position as the specified object in the sort order. - A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. - - Value - - Description - - A negative integer - - This instance precedes . - - Zero - - This instance and have the same position in the sort order. - - A positive integer - - This instance follows . - - + A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. + + Value + + + Description + + + + + A negative integer + + + This instance precedes . + + + Zero + + + This instance and have the same position in the sort order. + + + A positive integer + + + This instance follows . + + To be added. @@ -1055,15 +1082,15 @@ The type is not serializable in .NET Core 1.x or in - The index of the specified element. can range from 0 (the index of ) to 6 (the index of ). + The index of the specified element. can range from 0 (the index of ) to 6 (the index of ). Gets the value of the specified element. The value of the element at the specified position. - property is an explicit interface implementation. To call it, you must cast or convert the object to an interface object. - + property is an explicit interface implementation. To call it, you must cast or convert the object to an interface object. + ]]> @@ -1109,11 +1136,11 @@ The type is not serializable in .NET Core 1.x or in Gets the number of elements in the . 7, the number of elements in a object. - property is an explicit interface implementation. To call it, you must cast or convert the object to an interface object. - + property is an explicit interface implementation. To call it, you must cast or convert the object to an interface object. + ]]> @@ -1158,11 +1185,11 @@ The type is not serializable in .NET Core 1.x or in Returns a string that represents the value of this instance. The string representation of this instance. - , , , , , , and fields. If any of the field values is `null`, it is represented as . - + , , , , , , and fields. If any of the field values is `null`, it is represented as . + ]]> diff --git a/xml/System/ValueTuple`8.xml b/xml/System/ValueTuple`8.xml index 704339db563..6e0427def74 100644 --- a/xml/System/ValueTuple`8.xml +++ b/xml/System/ValueTuple`8.xml @@ -169,25 +169,25 @@ Any generic value tuple instance that defines the types of the tuple's remaining elements. Represents an *n*-value tuple, where *n* is 8 or greater. - structure represents a value tuple that has eight or more elements. - - The value tuple types differ from the tuple types (such as ) as follows: - -- They are structures (value types) rather than classes (reference types). - -- Members such as and are fields rather than properties. - -- Their fields are mutable rather than read-only. - - The value tuple types provide the runtime implementation that supports [tuples in C#](/dotnet/csharp/tuples) and struct tuples in F#. In addition to creating a instance by using language syntax, you can call the factory method. + structure represents a value tuple that has eight or more elements. + + The value tuple types differ from the tuple types (such as ) as follows: + +- They are structures (value types) rather than classes (reference types). + +- Members such as and are fields rather than properties. + +- Their fields are mutable rather than read-only. + + The value tuple types provide the runtime implementation that supports [tuples in C#](/dotnet/csharp/tuples) and struct tuples in F#. In addition to creating a instance by using language syntax, you can call the factory method. ### Serialization and value tuples The type is not serializable in .NET Core 1.x or in the .NET Framework 4.7 and earlier versions. In addition, .NET Standard, including .NET Standard 2.0, does not mandate serialization of instances; whether or not a instance is serializable depends on the individual .NET Standard implementation. To determine whether a type is serializable on a particular .NET implementation, get a object that represents the type and retrieve the value of its property. For a list of serializable types in .NET Core and the .NET Framework, see [Binary Serialization](/dotnet/standard/serialization/binary-serialization). - + ]]> @@ -253,11 +253,11 @@ The type is not serializable in .NET Core 1.x or in An instance of any value tuple type that contains the values of the value's tuple's remaining elements. Initializes a new instance. - method without having to explicitly specify the types of its elements. - + method without having to explicitly specify the types of its elements. + ]]> @@ -316,25 +316,34 @@ The type is not serializable in .NET Core 1.x or in The tuple to compare with this instance. Compares the current instance to a specified instance. - A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. - - Value - - Description - - A negative integer - - This instance precedes . - - Zero - - This instance and have the same position in the sort order. - - A positive integer - - This instance follows . - - + A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. + + Value + + + Description + + + + + A negative integer + + + This instance precedes . + + + Zero + + + This instance and have the same position in the sort order. + + + A positive integer + + + This instance follows . + + To be added. @@ -406,17 +415,17 @@ The type is not serializable in .NET Core 1.x or in if the current instance is equal to the specified object; otherwise, . - value type. - -- Its components are of the same types as those of the current instance. - -- Its components are equal to those of the current instance. Equality is determined by the default equality comparer for each component. - + value type. + +- Its components are of the same types as those of the current instance. + +- Its components are equal to those of the current instance. Equality is determined by the default equality comparer for each component. + ]]> @@ -475,15 +484,15 @@ The type is not serializable in .NET Core 1.x or in if the current instance is equal to the specified tuple; otherwise, . - @@ -854,11 +863,11 @@ The type is not serializable in .NET Core 1.x or in Gets the current instance's remaining elements. - field returns a nested value tuple that allows access to the eighth though *n*th elements of the tuple. Depending on the total number of elements in the tuple, the values of the eighth through fourteenth components can be retrieved from the nested value tuple's `Item1` through `Item7` properties. You can then use the property of a nested object to retrieve the value tuple at the next level of nesting. - + field returns a nested value tuple that allows access to the eighth though *n*th elements of the tuple. Depending on the total number of elements in the tuple, the values of the eighth through fourteenth components can be retrieved from the nested value tuple's `Item1` through `Item7` properties. You can then use the property of a nested object to retrieve the value tuple at the next level of nesting. + ]]> @@ -909,38 +918,47 @@ The type is not serializable in .NET Core 1.x or in The object to compare with the current instance. An object that provides custom rules for comparison. Compares the current instance to a specified object by using a specified comparer and returns an integer that indicates whether the current object is before, after, or in the same position as the specified object in the sort order. - A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. - - Value - - Description - - A negative integer - - This instance precedes . - - Zero - - This instance and have the same position in the sort order. - - A positive integer - - This instance follows . - - + A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. + + Value + + + Description + + + + + A negative integer + + + This instance precedes . + + + Zero + + + This instance and have the same position in the sort order. + + + A positive integer + + + This instance follows . + + - instance is cast to an interface. - - This method lets you define customized comparisons of objects. For example, you can use this method to order objects based on the value of a specific component. - - Although this method can be called directly, it is most commonly called by collection-sorting methods that include parameters to order the members of a collection. For example, it is called by the method and the method of a object that is instantiated by using the constructor. - + instance is cast to an interface. + + This method lets you define customized comparisons of objects. For example, you can use this method to order objects based on the value of a specific component. + + Although this method can be called directly, it is most commonly called by collection-sorting methods that include parameters to order the members of a collection. For example, it is called by the method and the method of a object that is instantiated by using the constructor. + > [!CAUTION] -> The method is intended for use in sorting operations. It should not be used when the primary purpose of a comparison is to determine whether two objects are equal. To determine whether two objects are equal, call the method. - +> The method is intended for use in sorting operations. It should not be used when the primary purpose of a comparison is to determine whether two objects are equal. To determine whether two objects are equal, call the method. + ]]> @@ -996,13 +1014,13 @@ The type is not serializable in .NET Core 1.x or in if the current instance is equal to the specified objects; otherwise, . - instance is cast to an interface. - - The implementation is called only if `other` is not `null`, and if it can be successfully cast to a object that has the same total number of components (including those in nested tuple objects) of the same types as the current instance. The method first passes the values of the objects to be compared to the implementation. If this method call returns `true`, the method is called again and passed the values of the two objects. This continues until the method call returns `false` when it compares a specific pair of values, or the two values are passed to the method. - + instance is cast to an interface. + + The implementation is called only if `other` is not `null`, and if it can be successfully cast to a object that has the same total number of components (including those in nested tuple objects) of the same types as the current instance. The method first passes the values of the objects to be compared to the implementation. If this method call returns `true`, the method is called again and passed the values of the two objects. This continues until the method call returns `false` when it compares a specific pair of values, or the two values are passed to the method. + ]]> @@ -1053,13 +1071,13 @@ The type is not serializable in .NET Core 1.x or in Calculates the hash code for the current instance by using a specified computation method. A 32-bit signed integer hash code. - instance is cast to an interface. The method simply wraps a call to the `comparer` object's implementation. - - The algorithm used to compute the hash code should return the same hash code for two objects that are considered to be equal. - + instance is cast to an interface. The method simply wraps a call to the `comparer` object's implementation. + + The algorithm used to compute the hash code should return the same hash code for two objects that are considered to be equal. + ]]> @@ -1108,38 +1126,47 @@ The type is not serializable in .NET Core 1.x or in An object to compare with the current instance. Compares the current object to a specified object and returns an integer that indicates whether the current object is before, after, or in the same position as the specified object in the sort order. - A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. - - Value - - Description - - A negative integer - - This instance precedes . - - Zero - - This instance and have the same position in the sort order. - - A positive integer - - This instance follows . - - + A signed integer that indicates the relative position of this instance and in the sort order, as shown in the following table. + + Value + + + Description + + + + + A negative integer + + + This instance precedes . + + + Zero + + + This instance and have the same position in the sort order. + + + A positive integer + + + This instance follows . + + - instance is cast to an interface. - - This method provides the implementation for the structure. Although the method can be called directly, it is most commonly called by the default overloads of collection-sorting methods, such as and , to order the members of a collection. - + instance is cast to an interface. + + This method provides the implementation for the structure. Although the method can be called directly, it is most commonly called by the default overloads of collection-sorting methods, such as and , to order the members of a collection. + > [!CAUTION] -> The method is intended for use in sorting operations. It should not be used when the primary purpose of a comparison is to determine whether two objects are equal. To determine whether two objects are equal, call the method. - - This method uses the default object comparer to compare each component. - +> The method is intended for use in sorting operations. It should not be used when the primary purpose of a comparison is to determine whether two objects are equal. To determine whether two objects are equal, call the method. + + This method uses the default object comparer to compare each component. + ]]> @@ -1196,19 +1223,19 @@ The type is not serializable in .NET Core 1.x or in Gets the value of the specified element. The value of the element at the specified position. - property is an explicit interface implementation. To call it, you must cast or convert the object to an interface object. - + property is an explicit interface implementation. To call it, you must cast or convert the object to an interface object. + ]]> - is less than 0. - - -or- - - is greater than or equal to . + is less than 0. + +-or- + + is greater than or equal to . @@ -1250,11 +1277,11 @@ The type is not serializable in .NET Core 1.x or in Gets the number of elements in the . The number of elements in the . - property is an explicit interface implementation. To call it, you must cast or convert the object to an interface object. - + property is an explicit interface implementation. To call it, you must cast or convert the object to an interface object. + ]]> @@ -1299,11 +1326,11 @@ The type is not serializable in .NET Core 1.x or in Returns a string that represents the value of this instance. The string representation of this instance. - , , , , , , and fields. *Item8* represents the value of the instance's `Next.Item1` field. The value of any additional nested elements follows *Item8*. If any of the field values is `null`, it is represented as . - + , , , , , , and fields. *Item8* represents the value of the instance's `Next.Item1` field. The value of any additional nested elements follows *Item8*. If any of the field values is `null`, it is represented as . + ]]> diff --git a/xml/System/ValueType.xml b/xml/System/ValueType.xml index e2457eba728..ddbbf29df8d 100644 --- a/xml/System/ValueType.xml +++ b/xml/System/ValueType.xml @@ -64,27 +64,27 @@ Provides the base class for value types. - overrides the virtual methods from with more appropriate implementations for value types. See also , which inherits from . - - Data types are separated into value types and reference types. Value types are either stack-allocated or allocated inline in a structure. Reference types are heap-allocated. Both reference and value types are derived from the ultimate base class . In cases where it is necessary for a value type to behave like an object, a wrapper that makes the value type look like a reference object is allocated on the heap, and the value type's value is copied into it. The wrapper is marked so the system knows that it contains a value type. This process is known as boxing, and the reverse process is known as unboxing. Boxing and unboxing allow any type to be treated as an object. - - Although is the implicit base class for value types, you cannot create a class that inherits from directly. Instead, individual compilers provide a language keyword or construct (such as `struct` in C# and `Structure`…`End Structure` in Visual Basic) to support the creation of value types. - - Aside from serving as the base class for value types in the .NET Framework, the structure is generally not used directly in code. However, it can be used as a parameter in method calls to restrict possible arguments to value types instead of all objects, or to permit a method to handle a number of different value types. The following example illustrates how prevents reference types from being passed to methods. It defines a class named `Utility` that contains four methods: `IsNumeric`, which indicates whether its argument is a number; `IsInteger`, which indicates whether its argument is an integer; `IsFloat`, which indicates whether its argument is a floating-point number; and `Compare`, which indicates the relationship between two numeric values. In each case, the method parameters are of type , and reference types are prevented from being passed to the methods. - + overrides the virtual methods from with more appropriate implementations for value types. See also , which inherits from . + + Data types are separated into value types and reference types. Value types are either stack-allocated or allocated inline in a structure. Reference types are heap-allocated. Both reference and value types are derived from the ultimate base class . In cases where it is necessary for a value type to behave like an object, a wrapper that makes the value type look like a reference object is allocated on the heap, and the value type's value is copied into it. The wrapper is marked so the system knows that it contains a value type. This process is known as boxing, and the reverse process is known as unboxing. Boxing and unboxing allow any type to be treated as an object. + + Although is the implicit base class for value types, you cannot create a class that inherits from directly. Instead, individual compilers provide a language keyword or construct (such as `struct` in C# and `Structure`…`End Structure` in Visual Basic) to support the creation of value types. + + Aside from serving as the base class for value types in the .NET Framework, the structure is generally not used directly in code. However, it can be used as a parameter in method calls to restrict possible arguments to value types instead of all objects, or to permit a method to handle a number of different value types. The following example illustrates how prevents reference types from being passed to methods. It defines a class named `Utility` that contains four methods: `IsNumeric`, which indicates whether its argument is a number; `IsInteger`, which indicates whether its argument is an integer; `IsFloat`, which indicates whether its argument is a floating-point number; and `Compare`, which indicates the relationship between two numeric values. In each case, the method parameters are of type , and reference types are prevented from being passed to the methods. + :::code language="csharp" source="~/snippets/csharp/System/ValueType/Overview/example1.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/ValueType/Overview/example1.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.valuetype.structure/vb/example1.vb" id="Snippet1"::: - - The following example illustrates calls to the methods of the `Utility` class. - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.valuetype.structure/vb/example1.vb" id="Snippet1"::: + + The following example illustrates calls to the methods of the `Utility` class. + :::code language="csharp" source="~/snippets/csharp/System/ValueType/Overview/example1.cs" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/ValueType/Overview/example1.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.valuetype.structure/vb/example1.vb" id="Snippet2"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/system.valuetype.structure/vb/example1.vb" id="Snippet2"::: + ]]> @@ -190,29 +190,29 @@ if and this instance are the same type and represent the same value; otherwise, . - method overrides and provides the default implementation of value equality for all value types in the .NET Framework. - + method overrides and provides the default implementation of value equality for all value types in the .NET Framework. + The default implementation calls on each field of the current instance and `obj` and returns `true` if all fields are equal. - + > [!TIP] -> Particularly if your value type contains fields that are reference types, you should override the method. This can improve performance and enable you to more closely represent the meaning of equality for the type. - -## Notes for the Windows Runtime - When you call the method on a Windows Runtime structure, it provides the default behavior for value types that don't override . This is part of the support that the .NET Framework provides for the Windows Runtime (see [.NET Framework Support for Windows Store Apps and Windows Runtime](/dotnet/standard/cross-platform/support-for-windows-store-apps-and-windows-runtime)). Windows Runtime structures can't override , even if they're written with C# or Visual Basic, because they can't have methods. (In addition, structures in the Windows Runtime itself don't inherit .) However, they appear to have , , and methods when you use them in your C# or Visual Basic code, and the .NET Framework provides the default behavior for these methods. - - - -## Examples - The following example demonstrates how the method can be overridden by a derived value type. - +> Particularly if your value type contains fields that are reference types, you should override the method. This can improve performance and enable you to more closely represent the meaning of equality for the type. + +## Notes for the Windows Runtime + When you call the method on a Windows Runtime structure, it provides the default behavior for value types that don't override . This is part of the support that the .NET Framework provides for the Windows Runtime (see [.NET Framework Support for Windows Store Apps and Windows Runtime](/dotnet/standard/cross-platform/support-for-windows-store-apps-and-windows-runtime)). Windows Runtime structures can't override , even if they're written with C# or Visual Basic, because they can't have methods. (In addition, structures in the Windows Runtime itself don't inherit .) However, they appear to have , , and methods when you use them in your C# or Visual Basic code, and the .NET Framework provides the default behavior for these methods. + + + +## Examples + The following example demonstrates how the method can be overridden by a derived value type. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/ValueType.Equals Example/CPP/source.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/ValueType/Equals/source.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/ValueType/Equals/source.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ValueType.Equals Example/VB/source.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ValueType.Equals Example/VB/source.vb" id="Snippet1"::: + ]]> @@ -265,26 +265,26 @@ Returns the hash code for this instance. A 32-bit signed integer that is the hash code for this instance. - method applies to types derived from . One or more fields of the derived type is used to calculate the return value. If you call the derived type's `GetHashCode` method, the return value is not likely to be suitable for use as a key in a hash table. Additionally, if the value of one or more of those fields changes, the return value might become unsuitable for use as a key in a hash table. In either case, consider writing your own implementation of the method that more closely represents the concept of a hash code for the type. - - For more information, see , and . - -## Notes for the Windows Runtime - When you call the method on a Windows Runtime structure, it provides the default behavior for value types that don't override . This is part of the support that the .NET Framework provides for the Windows Runtime (see [.NET Framework Support for Windows Store Apps and Windows Runtime](/dotnet/standard/cross-platform/support-for-windows-store-apps-and-windows-runtime)). Windows Runtime structures can't override , even if they're written with C# or Visual Basic, because they can't have methods. (In addition, structures in the Windows Runtime itself don't inherit .) However, they appear to have , , and methods when you use them in your C# or Visual Basic code, and the .NET Framework provides the default behavior for these methods. - - - -## Examples - The following example demonstrates how the method can be overridden by a derived value type. - + method applies to types derived from . One or more fields of the derived type is used to calculate the return value. If you call the derived type's `GetHashCode` method, the return value is not likely to be suitable for use as a key in a hash table. Additionally, if the value of one or more of those fields changes, the return value might become unsuitable for use as a key in a hash table. In either case, consider writing your own implementation of the method that more closely represents the concept of a hash code for the type. + + For more information, see , and . + +## Notes for the Windows Runtime + When you call the method on a Windows Runtime structure, it provides the default behavior for value types that don't override . This is part of the support that the .NET Framework provides for the Windows Runtime (see [.NET Framework Support for Windows Store Apps and Windows Runtime](/dotnet/standard/cross-platform/support-for-windows-store-apps-and-windows-runtime)). Windows Runtime structures can't override , even if they're written with C# or Visual Basic, because they can't have methods. (In addition, structures in the Windows Runtime itself don't inherit .) However, they appear to have , , and methods when you use them in your C# or Visual Basic code, and the .NET Framework provides the default behavior for these methods. + + + +## Examples + The following example demonstrates how the method can be overridden by a derived value type. + :::code language="cpp" source="~/snippets/cpp/VS_Snippets_CLR/ValueType.Equals Example/CPP/source.cpp" id="Snippet1"::: :::code language="csharp" source="~/snippets/csharp/System/ValueType/Equals/source.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/ValueType/Equals/source.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ValueType.Equals Example/VB/source.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/ValueType.Equals Example/VB/source.vb" id="Snippet1"::: + ]]> @@ -332,22 +332,22 @@ Returns the fully qualified type name of this instance. The fully qualified type name. - method overrides the method and provides the default implementation of the `ToString` method for value types. (Value types are types defined by the `struct` keyword in C#, and by the `Structure`...`End Structure` construct in Visual Basic.) Functionally, however, the implementation is that same as that of : the method returns the fully qualified type name. - - Value types defined by the `struct` keyword in C# and the `Structure`...`End Structure` construct in Visual Basic typically override the method to provide a more meaningful string representation of the value type. The following example illustrates the difference. It defines two value types, `EmployeeA` and `EmployeeB`, creates an instance of each, and calls its `ToString` method. Because the `EmployeeA` structure does not override the method, it displays only the fully qualified type name. The `EmployeeB.ToString` method, on the other hand, provides meaningful information about the object. - + method overrides the method and provides the default implementation of the `ToString` method for value types. (Value types are types defined by the `struct` keyword in C#, and by the `Structure`...`End Structure` construct in Visual Basic.) Functionally, however, the implementation is that same as that of : the method returns the fully qualified type name. + + Value types defined by the `struct` keyword in C# and the `Structure`...`End Structure` construct in Visual Basic typically override the method to provide a more meaningful string representation of the value type. The following example illustrates the difference. It defines two value types, `EmployeeA` and `EmployeeB`, creates an instance of each, and calls its `ToString` method. Because the `EmployeeA` structure does not override the method, it displays only the fully qualified type name. The `EmployeeB.ToString` method, on the other hand, provides meaningful information about the object. + :::code language="csharp" source="~/snippets/csharp/System/ValueType/ToString/ToString2.cs" interactive="try-dotnet" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/ValueType/ToString/ToString2.fs" id="Snippet1"::: :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR_System/System.ValueType.ToString/vb/ToString2.vb" id="Snippet1"::: - Note that, although enumeration types are also value types, they derive from the class, which overrides . - -## Notes for the Windows Runtime - When you call the method on a Windows Runtime structure, it provides the default behavior for value types that don't override . This is part of the support that the .NET Framework provides for the Windows Runtime (see [.NET Framework Support for Windows Store Apps and Windows Runtime](/dotnet/standard/cross-platform/support-for-windows-store-apps-and-windows-runtime)). Windows Runtime structures can't override , even if they're written with C# or Visual Basic, because they can't have methods. (In addition, structures in the Windows Runtime itself don't inherit .) However, they appear to have , , and methods when you use them in your C# or Visual Basic code, and the .NET Framework provides the default behavior for these methods. - + Note that, although enumeration types are also value types, they derive from the class, which overrides . + +## Notes for the Windows Runtime + When you call the method on a Windows Runtime structure, it provides the default behavior for value types that don't override . This is part of the support that the .NET Framework provides for the Windows Runtime (see [.NET Framework Support for Windows Store Apps and Windows Runtime](/dotnet/standard/cross-platform/support-for-windows-store-apps-and-windows-runtime)). Windows Runtime structures can't override , even if they're written with C# or Visual Basic, because they can't have methods. (In addition, structures in the Windows Runtime itself don't inherit .) However, they appear to have , , and methods when you use them in your C# or Visual Basic code, and the .NET Framework provides the default behavior for these methods. + ]]> diff --git a/xml/System/Version.xml b/xml/System/Version.xml index f9aa9e67e07..576264c88c9 100644 --- a/xml/System/Version.xml +++ b/xml/System/Version.xml @@ -696,25 +696,34 @@ An object to compare, or . Compares the current object to a specified object and returns an indication of their relative values. - A signed integer that indicates the relative values of the two objects, as shown in the following table. - - Return value - - Meaning - - Less than zero - - The current object is a version before . - - Zero - - The current object is the same version as . - - Greater than zero - - The current object is a version subsequent to , or is . - - + A signed integer that indicates the relative values of the two objects, as shown in the following table. + + Return value + + + Meaning + + + + + Less than zero + + + The current object is a version before . + + + Zero + + + The current object is the same version as . + + + Greater than zero + + + The current object is a version subsequent to , or is . + + A object to compare to the current object, or . Compares the current object to a specified object and returns an indication of their relative values. - A signed integer that indicates the relative values of the two objects, as shown in the following table. - - Return value - - Meaning - - Less than zero - - The current object is a version before . - - Zero - - The current object is the same version as . - - Greater than zero - - The current object is a version subsequent to , or is . - - + A signed integer that indicates the relative values of the two objects, as shown in the following table. + + Return value + + + Meaning + + + + + Less than zero + + + The current object is a version before . + + + Zero + + + The current object is the same version as . + + + Greater than zero + + + The current object is a version subsequent to , or is . + + An object to compare, or . Compares the current object to a specified object and returns an indication of their relative values. - A signed integer that indicates the relative values of the two objects, as shown in the following table: - Return valueMeaningLess than zeroThe current object is a version before .ZeroThe current object is the same version as .Greater than zeroThe current object is a version subsequent to , or is . + A signed integer that indicates the relative values of the two objects, as shown in the following table: + + Return value + Meaning + + + Less than zero + The current object is a version before . + + + Zero + The current object is the same version as . + + + Greater than zero + The current object is a version subsequent to , or is . + + - The format to use. - -or- - A reference ( in Visual Basic) to use the default format defined for the type of the implementation. - The provider to use to format the value. - -or- - A reference ( in Visual Basic) to obtain the numeric format information from the current locale setting of the operating system. + The format to use. + +-or- + +A reference ( in Visual Basic) to use the default format defined for the type of the implementation. + The provider to use to format the value. + +-or- + +A reference ( in Visual Basic) to obtain the numeric format information from the current locale setting of the operating system. Formats the value of the current instance using the specified format. The value of the current instance in the specified format. To be added. @@ -2079,11 +2117,7 @@ This member is an explicit interface member implementation. Converts the value of the current object to its equivalent representation. - The representation of the values of the major, minor, build, and revision components of the current object, as depicted in the following format. Each component is separated by a period character ('.'). Square brackets ('[' and ']') indicate a component that will not appear in the return value if the component is not defined: - - major.minor[.build[.revision]] - - For example, if you create a object using the constructor Version(1,1), the returned string is "1.1". If you create a object using the constructor Version(1,3,4,2), the returned string is "1.3.4.2". + The representation of the values of the major, minor, build, and revision components of the current object, as depicted in the following format. Each component is separated by a period character ('.'). Square brackets ('[' and ']') indicate a component that will not appear in the return value if the component is not defined: major.minor[.build[.revision]] For example, if you create a object using the constructor Version(1,1), the returned string is "1.1". If you create a object using the constructor Version(1,3,4,2), the returned string is "1.3.4.2". To be added. @@ -2136,42 +2170,63 @@ This member is an explicit interface member implementation. The number of components to return. The ranges from 0 to 4. Converts the value of the current object to its equivalent representation. A specified count indicates the number of components to return. - The representation of the values of the major, minor, build, and revision components of the current object, each separated by a period character ('.'). The parameter determines how many components are returned. - - fieldCount - - Return Value + The representation of the values of the major, minor, build, and revision components of the current object, each separated by a period character ('.'). The parameter determines how many components are returned. + + fieldCount - 0 + + Return Value - An empty string (""). + + + + 0 - 1 + + An empty string (""). - major + + + + 1 - 2 + + major - major.minor + + + + 2 - 3 + + major.minor - major.minor.build + + + + 3 - 4 + + major.minor.build - major.minor.build.revision + + + + 4 - + + major.minor.build.revision - For example, if you create object using the constructor Version(1,3,5), ToString(2) returns "1.3" and ToString(4) throws an exception. + + + For example, if you create object using the constructor Version(1,3,5), ToString(2) returns "1.3" and ToString(4) throws an exception. To be added. is less than 0, or more than 4. - -or- +-or- - is more than the number of components defined in the current object. + is more than the number of components defined in the current object. diff --git a/xml/System/Void.xml b/xml/System/Void.xml index d3b43ef931f..6d0ac75c0ba 100644 --- a/xml/System/Void.xml +++ b/xml/System/Void.xml @@ -56,11 +56,11 @@ Specifies a return value type for a method that does not return a value. - structure is used in the namespace, but is rarely useful in a typical application. The structure has no members other than the ones all types inherit from the class. - + structure is used in the namespace, but is rarely useful in a typical application. The structure has no members other than the ones all types inherit from the class. + ]]> diff --git a/xml/System/WeakReference.xml b/xml/System/WeakReference.xml index 072116bdf3d..c01d3dfc4a9 100644 --- a/xml/System/WeakReference.xml +++ b/xml/System/WeakReference.xml @@ -73,22 +73,22 @@ Represents a weak reference, which references an object while still allowing that object to be reclaimed by garbage collection. - of objects keyed by an index value. The property for the objects is an object in a byte array that represents data. - - The example randomly accesses objects in the cache. If an object is reclaimed for garbage collection, a new data object is regenerated; otherwise, the object is available to access because of the weak reference. - + of objects keyed by an index value. The property for the objects is an object in a byte array that represents data. + + The example randomly accesses objects in the cache. If an object is reclaimed for garbage collection, a new data object is regenerated; otherwise, the object is available to access because of the weak reference. + :::code language="csharp" source="~/snippets/csharp/System/WeakReference/Overview/program.cs" id="Snippet1"::: :::code language="fsharp" source="~/snippets/fsharp/System/WeakReference/Overview/program.fs" id="Snippet1"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/WeakReference/vb/Module1.vb" id="Snippet1"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/WeakReference/vb/Module1.vb" id="Snippet1"::: + ]]> @@ -169,11 +169,11 @@ The object to track or . Initializes a new instance of the class, referencing the specified object. - @@ -229,20 +229,20 @@ Indicates when to stop tracking the object. If , the object is tracked after finalization; if , the object is only tracked until finalization. Initializes a new instance of the class, referencing the specified object and using the specified resurrection tracking. - class. - + class. + :::code language="csharp" source="~/snippets/csharp/System/WeakReference/Overview/program.cs" id="Snippet2"::: :::code language="fsharp" source="~/snippets/fsharp/System/WeakReference/Overview/program.fs" id="Snippet2"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/WeakReference/vb/Module1.vb" id="Snippet2"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/WeakReference/vb/Module1.vb" id="Snippet2"::: + ]]> @@ -308,11 +308,11 @@ (Reserved) Describes the source and destination of the serialized stream specified by . Initializes a new instance of the class, using deserialized data from the specified serialization and stream objects. - @@ -433,13 +433,13 @@ (Reserved) The location where serialized data is stored and retrieved. Populates a object with all the data needed to serialize the current object. - object. - - The `context` parameter is reserved and is not currently used in the execution of this method. - + object. + + The `context` parameter is reserved and is not currently used in the execution of this method. + ]]> @@ -496,11 +496,11 @@ if the object referenced by the current object has not been garbage collected and is still accessible; otherwise, . - property returns `true`, using this property is not recommended unless you are testing only for a `false` return value. - + property returns `true`, using this property is not recommended unless you are testing only for a `false` return value. + ]]> @@ -561,20 +561,20 @@ if the object referenced by the current object has been garbage collected; otherwise, a reference to the object referenced by the current object. - class. - + class. + :::code language="csharp" source="~/snippets/csharp/System/WeakReference/Overview/program.cs" id="Snippet3"::: :::code language="fsharp" source="~/snippets/fsharp/System/WeakReference/Overview/program.fs" id="Snippet3"::: - :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/WeakReference/vb/Module1.vb" id="Snippet3"::: - + :::code language="vb" source="~/snippets/visualbasic/VS_Snippets_CLR/WeakReference/vb/Module1.vb" id="Snippet3"::: + ]]> The reference to the target object is invalid. This exception can be thrown while setting this property if the value is a null reference or if the object has been finalized during the set operation. @@ -625,11 +625,11 @@ if the object the current object refers to is tracked after finalization; or if the object is only tracked until finalization. - constructor. - + constructor. + ]]> diff --git a/xml/System/WeakReference`1.xml b/xml/System/WeakReference`1.xml index 9150de65f6c..05fa4ed0441 100644 --- a/xml/System/WeakReference`1.xml +++ b/xml/System/WeakReference`1.xml @@ -81,11 +81,11 @@ The type of the object referenced. Represents a typed weak reference, which references an object while still allowing that object to be reclaimed by garbage collection. - diff --git a/xml/System/WindowsRuntimeSystemExtensions.xml b/xml/System/WindowsRuntimeSystemExtensions.xml index 1358c97af85..ac23ad0ac75 100644 --- a/xml/System/WindowsRuntimeSystemExtensions.xml +++ b/xml/System/WindowsRuntimeSystemExtensions.xml @@ -76,7 +76,7 @@ The methods are used Use this method when you want to pass a task to a Windows Runtime method that takes an asynchronous action. -The class provides static methods (`Shared` methods in Visual Basic) that create and start Windows Runtime asynchronous actions that represent tasks that can respond to cancellation requests and report progress. +The class provides static methods (`Shared` methods in Visual Basic) that create and start Windows Runtime asynchronous actions that represent tasks that can respond to cancellation requests and report progress. ]]> @@ -526,7 +526,7 @@ Use this method to get a object for a Win > [!NOTE] > In Visual Basic and C#, you can call this method as an instance method on any object of type . When you use instance method syntax to call this method, omit the first parameter. For more information, see [Extension Methods (Visual Basic)](/dotnet/visual-basic/programming-guide/language-features/procedures/extension-methods) or [Extension Methods (C# Programming Guide)](/dotnet/csharp/programming-guide/classes-and-structs/extension-methods). -Use this method to get a object for a Windows Runtime asynchronous operation. objects simplify the coordination of asynchronous operations. +Use this method to get a object for a Windows Runtime asynchronous operation. objects simplify the coordination of asynchronous operations. Calling this method overload is equivalent to calling the extension method overload and specifying `null` for the `progress` parameter. This is useful when you don't want to get progress reports from an action that reports progress. diff --git a/xml/System/_AppDomain.xml b/xml/System/_AppDomain.xml index e2d6e323e2b..c3bb7e2773b 100644 --- a/xml/System/_AppDomain.xml +++ b/xml/System/_AppDomain.xml @@ -34,11 +34,11 @@ Exposes the public members of the class to unmanaged code. - class members that can be accessed by unmanaged COM objects. - + class members that can be accessed by unmanaged COM objects. + ]]> @@ -74,11 +74,11 @@ The name of the directory to be appended to the private path. Provides COM objects with version-independent access to the method. - method. - + method. + ]]> @@ -114,11 +114,11 @@ Provides COM objects with version-independent access to the event. - event. - + event. + ]]> @@ -154,11 +154,11 @@ Provides COM objects with version-independent access to the event. - event. - + event. + ]]> @@ -185,11 +185,11 @@ Provides COM objects with version-independent access to the property. The base directory that the assembly resolver uses to probe for assemblies. - property. - + property. + ]]> @@ -222,11 +222,11 @@ Provides COM objects with version-independent access to the method. - method. - + method. + ]]> @@ -259,11 +259,11 @@ Provides COM objects with version-independent access to the method. - method. - + method. + ]]> @@ -306,11 +306,11 @@ Provides COM objects with version-independent access to the method. An object that is a wrapper for the new instance specified by . The return value needs to be unwrapped to access the real object. - method. - + method. + ]]> @@ -345,13 +345,13 @@ Provides COM objects with version-independent access to the method overload. An object that is a wrapper for the new instance specified by . The return value needs to be unwrapped to access the real object. - method overload. - - The `activationAttributes` parameter is related to client-activated objects, a legacy technology. - + method overload. + + The `activationAttributes` parameter is related to client-activated objects, a legacy technology. + ]]> @@ -398,13 +398,13 @@ Provides COM objects with version-independent access to the method overload. An object that is a wrapper for the new instance specified by . The return value needs to be unwrapped to access the real object. - method overload. - - The `activationAttributes` parameter is related to client-activated objects, a legacy technology. - + method overload. + + The `activationAttributes` parameter is related to client-activated objects, a legacy technology. + ]]> @@ -447,11 +447,11 @@ Provides COM objects with version-independent access to the method overload. An object that is a wrapper for the new instance, or if is not found. The return value needs to be unwrapped to access the real object. - method overload. - + method overload. + ]]> @@ -486,13 +486,13 @@ Provides COM objects with version-independent access to the method overload. An object that is a wrapper for the new instance, or if is not found. The return value needs to be unwrapped to access the real object. - method overload. - - The `activationAttributes` parameter is related to client-activated objects, a legacy technology. - + method overload. + + The `activationAttributes` parameter is related to client-activated objects, a legacy technology. + ]]> @@ -539,13 +539,13 @@ Provides COM objects with version-independent access to the method overload. An object that is a wrapper for the new instance, or if is not found. The return value needs to be unwrapped to access the real object. - method overload. - - The `activationAttributes` parameter is related to client-activated objects, a legacy technology. - + method overload. + + The `activationAttributes` parameter is related to client-activated objects, a legacy technology. + ]]> @@ -588,11 +588,11 @@ Provides COM objects with version-independent access to the method overload. Represents the dynamic assembly created. - method overload. - + method overload. + ]]> @@ -627,11 +627,11 @@ Provides COM objects with version-independent access to the method overload. Represents the dynamic assembly created. - method overload. - + method overload. + ]]> @@ -666,11 +666,11 @@ Provides COM objects with version-independent access to the method overload. Represents the dynamic assembly created. - method overload. - + method overload. + ]]> @@ -707,11 +707,11 @@ Provides COM objects with version-independent access to the method overload. Represents the dynamic assembly created. - method overload. - + method overload. + ]]> @@ -750,11 +750,11 @@ Provides COM objects with version-independent access to the method overload. Represents the dynamic assembly created. - method overload. - + method overload. + ]]> @@ -795,11 +795,11 @@ Provides COM objects with version-independent access to the method overload. Represents the dynamic assembly created. - method overload. - + method overload. + ]]> @@ -840,11 +840,11 @@ Provides COM objects with version-independent access to the method overload. Represents the dynamic assembly created. - method overload. - + method overload. + ]]> @@ -887,11 +887,11 @@ Provides COM objects with version-independent access to the method overload. Represents the dynamic assembly created. - method overload. - + method overload. + ]]> @@ -937,11 +937,11 @@ Provides COM objects with version-independent access to the method overload. Represents the dynamic assembly created. - method overload. - + method overload. + ]]> @@ -971,11 +971,11 @@ A delegate that specifies a method to call. Provides COM objects with version-independent access to the method. - method. - + method. + ]]> @@ -1011,11 +1011,11 @@ Provides COM objects with version-independent access to the event. - event. - + event. + ]]> @@ -1042,11 +1042,11 @@ Provides COM objects with version-independent access to the property. Get the directory that the assembly resolver uses to probe for dynamically-created assemblies. - property. - + property. + ]]> @@ -1078,11 +1078,11 @@ if the specified is equal to the current ; otherwise, . - method. - + method. + ]]> @@ -1109,11 +1109,11 @@ Provides COM objects with version-independent access to the property. Gets the associated with this application domain that is used as input to the security policy. - property. - + property. + ]]> @@ -1154,11 +1154,11 @@ Provides COM objects with version-independent access to the method overload. The value returned by the entry point of the assembly. - method overload. - + method overload. + ]]> @@ -1191,11 +1191,11 @@ Provides COM objects with version-independent access to the method overload. The value returned by the entry point of the assembly. - method overload. - + method overload. + ]]> @@ -1230,11 +1230,11 @@ Provides COM objects with version-independent access to the method overload. The value returned by the entry point of the assembly. - method overload. - + method overload. + ]]> @@ -1261,11 +1261,11 @@ Provides COM objects with version-independent access to the property. The friendly name of this application domain. - property. - + property. + ]]> @@ -1293,11 +1293,11 @@ Provides COM objects with version-independent access to the method. An array of assemblies in this application domain. - method. - + method. + ]]> @@ -1328,11 +1328,11 @@ Provides COM objects with version-independent access to the method. The value of the property. - method. - + method. + ]]> @@ -1360,11 +1360,11 @@ Provides COM objects with version-independent access to the inherited method. A hash code for the current . - method. - + method. + ]]> @@ -1402,11 +1402,11 @@ Caller-allocated array which receives the IDs corresponding to the names. Maps a set of names to a corresponding set of dispatch identifiers. - The method is called late-bound using the COM IDispatch interface. @@ -1441,11 +1441,11 @@ Provides COM objects with version-independent access to the inherited method. An object of type used to control the lifetime policy for this instance. - method. - + method. + ]]> @@ -1473,11 +1473,11 @@ Provides COM objects with version-independent access to the method. A representing the type of the current instance. - method. - + method. + ]]> @@ -1511,11 +1511,11 @@ Receives a pointer to the requested type information object. Retrieves the type information for an object, which can then be used to get the type information for an interface. - The method is called late-bound using the COM IDispatch interface. @@ -1546,11 +1546,11 @@ Points to a location that receives the number of type information interfaces provided by the object. Retrieves the number of type information interfaces that an object provides (either 0 or 1). - The method is called late-bound using the COM IDispatch interface. @@ -1585,11 +1585,11 @@ Provides COM objects with version-independent access to the method. Always . - method. - + method. + ]]> @@ -1633,11 +1633,11 @@ The index of the first argument that has an error. Provides access to properties and methods exposed by an object. - The method is called late-bound using the COM IDispatch interface. @@ -1679,11 +1679,11 @@ Provides COM objects with version-independent access to the method overload. The loaded assembly. - method overload. - + method overload. + ]]> @@ -1714,11 +1714,11 @@ Provides COM objects with version-independent access to the method overload. The loaded assembly. - method overload. - + method overload. + ]]> @@ -1749,11 +1749,11 @@ Provides COM objects with version-independent access to the method overload. The loaded assembly. - method overload. - + method overload. + ]]> @@ -1816,11 +1816,11 @@ Provides COM objects with version-independent access to the method overload. The loaded assembly. - method overload. - + method overload. + ]]> @@ -1853,11 +1853,11 @@ Provides COM objects with version-independent access to the method overload. The loaded assembly. - method overload. - + method overload. + ]]> @@ -1925,11 +1925,11 @@ Provides COM objects with version-independent access to the event. - event. - + event. + ]]> @@ -1956,11 +1956,11 @@ Provides COM objects with version-independent access to the property. The path under the base directory where the assembly resolver should probe for private assemblies. - property. - + property. + ]]> @@ -1996,11 +1996,11 @@ Provides COM objects with version-independent access to the event. - event. - + event. + ]]> @@ -2036,11 +2036,11 @@ The security policy level. Provides COM objects with version-independent access to the method. - method. - + method. + ]]> @@ -2076,11 +2076,11 @@ The fully qualified path to the shadow copy location. Provides COM objects with version-independent access to the method. - method. - + method. + ]]> @@ -2118,11 +2118,11 @@ The value of the property. Provides COM objects with version-independent access to the method. - method. - + method. + ]]> @@ -2152,11 +2152,11 @@ One of the values that specifies the type of the principal object to attach to threads. Provides COM objects with version-independent access to the method. - method. - + method. + ]]> @@ -2192,11 +2192,11 @@ A list of directory names, where each name is separated by a semicolon. Provides COM objects with version-independent access to the method. - method. - + method. + ]]> @@ -2226,11 +2226,11 @@ The principal object to attach to threads. Provides COM objects with version-independent access to the method. - method. - + method. + ]]> @@ -2258,11 +2258,11 @@ if the application domain is configured to shadow copy files; otherwise, . - property. - + property. + ]]> @@ -2290,11 +2290,11 @@ Provides COM objects with version-independent access to the method. A string formed by concatenating the literal string "Name:", the friendly name of the application domain, and either string representations of the context policies or the string "There are no context policies." - method. - + method. + ]]> @@ -2330,11 +2330,11 @@ Provides COM objects with version-independent access to the event. - event. - + event. + ]]> @@ -2370,11 +2370,11 @@ Provides COM objects with version-independent access to the event. - event. - + event. + ]]>