diff --git a/.openpublishing.redirection.csharp.json b/.openpublishing.redirection.csharp.json index 557373cce2323..643dee94558de 100644 --- a/.openpublishing.redirection.csharp.json +++ b/.openpublishing.redirection.csharp.json @@ -379,6 +379,10 @@ "source_path_from_root": "/docs/csharp/language-reference/compiler-messages/cs1742.md", "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/parameter-argument-mismatch" }, + { + "source_path_from_root": "/docs/csharp/language-reference/compiler-messages/cs1751.md", + "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/params-arrays" + }, { "source_path_from_root": "/docs/csharp/language-reference/compiler-messages/cs1921.md", "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/array-declaration-errors" @@ -1456,6 +1460,14 @@ "source_path_from_root": "/docs/csharp/misc/cs0206.md", "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/ref-modifiers-errors" }, + { + "source_path_from_root": "/docs/csharp/misc/cs0225.md", + "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/params-arrays" + }, + { + "source_path_from_root": "/docs/csharp/misc/cs0231.md", + "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/params-arrays" + }, { "source_path_from_root": "/docs/csharp/misc/cs0248.md", "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/feature-version-errors" @@ -1480,6 +1492,10 @@ "source_path_from_root": "/docs/csharp/misc/cs0440.md", "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/using-directive-errors" }, + { + "source_path_from_root": "/docs/csharp/misc/cs0466.md", + "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/params-arrays" + }, { "source_path_from_root": "/docs/csharp/misc/cs0514.md", "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/constructor-errors#static-constructors" @@ -1552,6 +1568,10 @@ "source_path_from_root": "/docs/csharp/misc/cs0655.md", "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/parameter-argument-mismatch" }, + { + "source_path_from_root": "/docs/csharp/misc/cs0674.md", + "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/params-arrays" + }, { "source_path_from_root": "/docs/csharp/misc/cs0687.md", "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/using-directive-errors" @@ -1572,6 +1592,10 @@ "source_path_from_root": "/docs/csharp/misc/cs0748.md", "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/lambda-expression-errors#lambda-expression-parameters-and-returns" }, + { + "source_path_from_root": "/docs/csharp/misc/cs0758.md", + "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/params-arrays" + }, { "source_path_from_root": "/docs/csharp/misc/cs0765.md", "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/expression-tree-restrictions" @@ -1608,6 +1632,10 @@ "source_path_from_root": "/docs/csharp/misc/cs1016.md", "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/parameter-argument-mismatch" }, + { + "source_path_from_root": "/docs/csharp/misc/cs1104.md", + "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/params-arrays" + }, { "source_path_from_root": "/docs/csharp/misc/cs1510.md", "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/ref-modifiers-errors" @@ -1632,6 +1660,10 @@ "source_path_from_root": "/docs/csharp/misc/cs1605.md", "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/ref-modifiers-errors" }, + { + "source_path_from_root": "/docs/csharp/misc/cs1611.md", + "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/params-arrays" + }, { "source_path_from_root": "/docs/csharp/misc/cs1621.md", "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/lambda-expression-errors#syntax-limitations-in-lambda-expressions" @@ -1664,6 +1696,10 @@ "source_path_from_root": "/docs/csharp/misc/cs1657.md", "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/ref-modifiers-errors" }, + { + "source_path_from_root": "/docs/csharp/misc/cs1670.md", + "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/params-arrays" + }, { "source_path_from_root": "/docs/csharp/misc/cs1673.md", "redirect_url": "/dotnet/csharp/language-reference/compiler-messages/lambda-expression-errors#syntax-limitations-in-lambda-expressions" diff --git a/docs/csharp/language-reference/compiler-messages/cs1751.md b/docs/csharp/language-reference/compiler-messages/cs1751.md deleted file mode 100644 index 337752564df13..0000000000000 --- a/docs/csharp/language-reference/compiler-messages/cs1751.md +++ /dev/null @@ -1,41 +0,0 @@ ---- -description: "Compiler Error CS1751" -title: "Compiler Error CS1751" -ms.date: 10/25/2022 -f1_keywords: - - "CS1751" -helpviewer_keywords: - - "CS1751" ---- -# Compiler Error CS1751 - -Cannot specify a default value for a parameter array. - -## Example - -The following sample generates CS1751: - -```csharp -// CS1751.cs -void Method(params object[] values = null) -{ -} -``` - -## Solution - -```csharp -// Explicitly passing null -object[] values = null; -Method(values); - -void Method(params object[] values) -{ - if (values == null) - { - - } -} -``` - -For more information, see [Params](../keywords/method-parameters.md#params-modifier). diff --git a/docs/csharp/language-reference/compiler-messages/expression-tree-restrictions.md b/docs/csharp/language-reference/compiler-messages/expression-tree-restrictions.md index 88f04a903efd1..9ea1d47aa9c6d 100644 --- a/docs/csharp/language-reference/compiler-messages/expression-tree-restrictions.md +++ b/docs/csharp/language-reference/compiler-messages/expression-tree-restrictions.md @@ -46,6 +46,7 @@ f1_keywords: - "CS8952" - "CS9170" - "CS9175" + - "CS9226" helpviewer_keywords: - "CS0765" - "CS0831" @@ -92,6 +93,7 @@ helpviewer_keywords: - "CS8952" - "CS9170" - "CS9175" + - "CS9226" ms.date: 09/06/2023 --- # Resolve errors and warnings generated from expressions prohibited in expression trees @@ -146,6 +148,7 @@ That's by design. The text closely matches the text of the compiler error / warn - **CS8972** - *A lambda expression with attributes cannot be converted to an expression tree.* - **CS9170** - *An expression tree may not contain an inline array access or conversion.* - **CS9175** - *An expression tree may not contain a collection expression.* +- **CS9226** - *An expression tree may not contain an expanded form of non-array params collection parameter.* ## Expression tree restrictions @@ -177,6 +180,7 @@ The following expressions are prohibited: - Calls to methods that return by `ref` aren't allowed. - [static abstract interface members](../keywords/interface.md#static-abstract-and-virtual-members) can't be accessed. - [Inline arrays](../builtin-types/struct.md#inline-arrays). +- The `params` modifier is allowed only on single-dimensional arrays. Other collection types aren't allowed. Other restrictions are: diff --git a/docs/csharp/language-reference/compiler-messages/index.md b/docs/csharp/language-reference/compiler-messages/index.md index f8817bb4774e6..0328ceaab8659 100644 --- a/docs/csharp/language-reference/compiler-messages/index.md +++ b/docs/csharp/language-reference/compiler-messages/index.md @@ -1,7 +1,7 @@ --- description: "C# Compiler Errors" title: "Compiler messages" -ms.date: 04/27/2021 +ms.date: 05/21/2024 helpviewer_keywords: - "C# language, compiler errors" - "Visual C# compiler, errors" diff --git a/docs/csharp/language-reference/compiler-messages/params-arrays.md b/docs/csharp/language-reference/compiler-messages/params-arrays.md new file mode 100644 index 0000000000000..4c629ff1b2390 --- /dev/null +++ b/docs/csharp/language-reference/compiler-messages/params-arrays.md @@ -0,0 +1,142 @@ +--- +title: Errors and warnings related to `params` arrays +description: This article helps you diagnose and correct compiler errors and warnings when you use the `params` modifier on method parameters. +f1_keywords: + - "CS0225" + - "CS0231" + - "CS0466" + - "CS0674" + - "CS0758" + - "CS1104" + - "CS1611" + - "CS1670" + - "CS1751" + - "CS9218" + - "CS9219" + - "CS9220" + - "CS9221" + - "CS9222" + - "CS9223" + - "CS9224" + - "CS9225" + - "CS9227" + - "CS9228" +helpviewer_keywords: + - "CS0225" + - "CS0231" + - "CS0466" + - "CS0674" + - "CS0758" + - "CS1104" + - "CS1611" + - "CS1670" + - "CS1751" + - "CS9218" + - "CS9219" + - "CS9220" + - "CS9221" + - "CS9222" + - "CS9223" + - "CS9224" + - "CS9225" + - "CS9227" + - "CS9228" +ms.date: 05/20/2024 +--- +# Errors and warnings related to the `params` modifier on method parameters + +There are a few *errors* related to the `lock` statement and thread synchronization: + + +- [**CS0225**](#parameter-and-argument-type-rules): *The params parameter must be a single-dimensional array or have a valid collection type* +- [**CS0231**](#method-declaration-rules): *A params parameter must be the last parameter in a formal parameter list.* +- [**CS0466**](#other-params-errors): *'method1' should not have a params parameter since 'method2' does not* +- [**CS0674**](#other-params-errors): *Do not use `System.ParamArrayAttribute` or `System.ParamArrayAttribute`/`System.Runtime.CompilerServices.ParamCollectionAttribute`. Use the `params` keyword instead.* +- [**CS0758**](#other-params-errors): *Both partial method declarations must use a `params` parameter or neither may use a `params` parameter* +- [**CS1104**](#method-declaration-rules): *A parameter array cannot be used with `this` modifier on an extension method.* +- [**CS1611**](#method-declaration-rules): *The params parameter cannot be declared as in `ref` or `out`* +- [**CS1670**](#method-declaration-rules): *`params` is not valid in this context* +- [**CS1751**](#method-declaration-rules): *Cannot specify a default value for a parameter array.* +- [**CS9218**](#parameter-and-argument-type-rules): *The type arguments for method cannot be inferred from the usage because an argument with dynamic type is used and the method has a non-array params collection parameter. Try specifying the type arguments explicitly.* +- [**CS9219**](#parameter-and-argument-type-rules): *Ambiguity between expanded and normal forms of non-array params collection parameter of, the only corresponding argument has the type `dynamic`. Consider casting the dynamic argument.* +- [**CS9223**](#other-params-errors): *Creation of params collection results in an infinite chain of invocation of constructor.* +- [**CS9224**](#other-params-errors): *Method cannot be less visible than the member with params collection.* +- [**CS9225**](#other-params-errors): *Constructor leaves required member uninitialized.* +- [**CS9227**](#parameter-and-argument-type-rules): *Type does not contain a definition for a suitable instance `Add` method.* +- [**CS9228**](#parameter-and-argument-type-rules): *Non-array params collection type must have an applicable constructor that can be called with no arguments.* + +In addition, the compiler might produce the following *warning* related to the `params` modifier on method parameters: + +- [**CS9220**](#parameter-and-argument-type-rules): *One or more overloads of method having non-array params collection parameter might be applicable only in expanded form which is not supported during dynamic dispatch.* +- [**CS9221**](#parameter-and-argument-type-rules): *One or more indexer overloads having non-array params collection parameter might be applicable only in expanded form which is not supported during dynamic dispatch.* +- [**CS9222**](#parameter-and-argument-type-rules): *One or more constructor overloads having non-array params collection parameter might be applicable only in expanded form which is not supported during dynamic dispatch.* + +## Method declaration rules + +The following errors indicate using a `params` modifier on a parameter when the `params` modifier isn't allowed in that context: + +- **CS0231**: *A params parameter must be the last parameter in a formal parameter list.* +- **CS1104**: *A parameter array cannot be used with `this` modifier on an extension method.* +- **CS1611**: *The params parameter cannot be declared as in `ref` or `out`* +- **CS1670**: *`params` is not valid in this context* +- **CS1751**: *Cannot specify a default value for a parameter array.* + +The compiler enforces the following rules on your use of the `params` modifier on a method parameter: + +- The `params` modifier is allowed only on the last parameter in a formal parameter list. This includes any parameters with a default value. +- You can't include a default argument for the parameter when the `params` modifier is used. +- The `params` modifier can't be applied to reference parameter. A reference parameter is one with the `in`, `ref readonly`, `ref` or `out` modifier. +- The `params` modifier can't be combined with the `this` modifier on an extension method. +- The `params` modifier can't be used on an overloaded operator. + +In versions before C# 12, the `params` modifier can't be used on the parameter of an anonymous method or lambda expression. + +## Parameter and argument type rules + +The following errors indicate that the type of the parameter used with `params` is invalid: + +- **CS9218**: *The type arguments for method cannot be inferred from the usage because an argument with dynamic type is used and the method has a non-array params collection parameter. Try specifying the type arguments explicitly.* +- **CS9219**: *Ambiguity between expanded and normal forms of non-array params collection parameter of, the only corresponding argument has the type 'dynamic'. Consider casting the dynamic argument.* +- **CS0225**: *The params parameter must be a single-dimensional array or have a valid collection type* +- **CS9227**: *Type does not contain a definition for a suitable instance `Add` method.* +- **CS9228**: *Non-array params collection type must have an applicable constructor that can be called with no arguments.* + +The following warnings indicate that the one of the possible overloads might involve dynamic dispatch. The dynamic nature of the argument doesn't participate in overload resolution. + +- **CS9220**: *One or more overloads of method having non-array params collection parameter might be applicable only in expanded form which is not supported during dynamic dispatch.* +- **CS9221**: *One or more indexer overloads having non-array params collection parameter might be applicable only in expanded form which is not supported during dynamic dispatch.* +- **CS9222**: *One or more constructor overloads having non-array params collection parameter might be applicable only in expanded form which is not supported during dynamic dispatch.* + +In versions before C# 13, the `params` modifier is allowed on single-dimensional arrays only. No other types were valid. + +Starting with C# 13 any valid collection type can be used. However, some restrictions remain. The collection type must follow the same rules as the target of a [collection expression](../operators/collection-expressions.md#conversions). + +## Other params errors + +The following errors indicate other issues with using the `params` modifier: + +- **CS0466**: *'method1' should not have a params parameter since 'method2' does not* +- **CS0674**: *Do not use `System.ParamArrayAttribute` or `System.Runtime.CompilerServices.ParamCollectionAttribute`. Use the `params` keyword instead.* +- **CS0758**: *Both partial method declarations must use a `params` parameter or neither may use a `params` parameter* +- **CS9223**: *Creation of params collection results in an infinite chain of invocation of constructor.* +- **CS9224**: *Method cannot be less visible than the member with params collection.* +- **CS9225**: *Constructor leaves required member uninitialized.* + +A method that implements an interface must include the `params` modifier if and only if the interface member has the `params` modifier. Similarly, either both declarations of a `partial` method must include the `params` modifier, or none can include the `params` modifier. + +You must use the `params` modifier. You can't apply the equivalent attributes, either or . + +The compiler generates one of the final three errors in the preceding list when the code generated to create the collection type is invalid: + +- The compiler emits **CS9223** when the code emitted to create the collection also contains a params collection of the same type. Typically, the `Add` method takes a `params` collection of the same type. +- The compiler emits **CS9224** when the `Create` method for the collection type is less accessible than the method that takes the `params` parameter of the collection type. +- The compiler emits **CS9225** when the collection type has a required member and the parameterless constructor doesn't initialize that member and have the on the parameterless constructor. + +## See also + +- [Extension Methods](../../programming-guide/classes-and-structs/extension-methods.md) +- [Partial Classes and Methods](../../programming-guide/classes-and-structs/partial-classes-and-methods.md) +- [Collection expressions](../operators/collection-expressions.md) +- [params](../keywords/method-parameters.md#params-modifier) diff --git a/docs/csharp/language-reference/toc.yml b/docs/csharp/language-reference/toc.yml index 24ef9b1ba57ba..11e712f02b954 100644 --- a/docs/csharp/language-reference/toc.yml +++ b/docs/csharp/language-reference/toc.yml @@ -464,6 +464,11 @@ items: CS8351, CS8373, CS8374, CS8388, CS8977, CS9072, CS9077, CS9078, CS9079, CS9085, CS9086, CS9087, CS9089, CS9091, CS9092, CS9093, CS9094, CS9095, CS9096, CS9097, CS9101, CS9102, CS9104, CS9190, CS9191, CS9192, CS9193, CS9195, CS9196, CS9197, CS9198, CS9199, CS9200, CS9201 + - name: Params modifier + href: ./compiler-messages/params-arrays.md + displayName: > + CS0225, CS0231, CS0466, CS0674, CS0758, CS1104, CS1611, CS1670, CS1751, CS9218, CS9219, CS9220, CS9221, CS9222, CS9223, + CS9224, CS9225, CS9227, CS9228 - name: Nullable warnings href: ./compiler-messages/nullable-warnings.md displayName: > @@ -813,8 +818,6 @@ items: href: ../misc/cs0220.md - name: CS0221 href: ../misc/cs0221.md - - name: CS0225 - href: ../misc/cs0225.md - name: CS0226 href: ../misc/cs0226.md - name: CS0227 @@ -825,8 +828,6 @@ items: href: ./compiler-messages/cs0229.md - name: CS0230 href: ../misc/cs0230.md - - name: CS0231 - href: ../misc/cs0231.md - name: CS0233 href: ./compiler-messages/cs0233.md - name: CS0236 @@ -1007,8 +1008,6 @@ items: href: ../misc/cs0462.md - name: CS0463 href: ../misc/cs0463.md - - name: CS0466 - href: ../misc/cs0466.md - name: CS0468 href: ../misc/cs0468.md - name: CS0470 @@ -1221,8 +1220,6 @@ items: href: ../misc/cs0670.md - name: CS0673 href: ../misc/cs0673.md - - name: CS0674 - href: ../misc/cs0674.md - name: CS0677 href: ../misc/cs0677.md - name: CS0678 @@ -1341,8 +1338,6 @@ items: href: ../misc/cs0756.md - name: CS0757 href: ../misc/cs0757.md - - name: CS0758 - href: ../misc/cs0758.md - name: CS0759 href: ../misc/cs0759.md - name: CS0761 @@ -1487,8 +1482,6 @@ items: href: ../misc/cs1102.md - name: CS1103 href: ../misc/cs1103.md - - name: CS1104 - href: ../misc/cs1104.md - name: CS1105 href: ../misc/cs1105.md - name: CS1106 @@ -1641,8 +1634,6 @@ items: href: ../misc/cs1608.md - name: CS1609 href: ../misc/cs1609.md - - name: CS1611 - href: ../misc/cs1611.md - name: CS1612 href: ./compiler-messages/cs1612.md - name: CS1613 @@ -1719,8 +1710,6 @@ items: href: ../misc/cs1666.md - name: CS1667 href: ../misc/cs1667.md - - name: CS1670 - href: ../misc/cs1670.md - name: CS1671 href: ../misc/cs1671.md - name: CS1672 @@ -1789,8 +1778,6 @@ items: href: ./compiler-messages/cs1737.md - name: CS1750 href: ./compiler-messages/cs1750.md - - name: CS1751 - href: ./compiler-messages/cs1751.md - name: CS1763 href: ./compiler-messages/cs1763.md - name: CS1900 diff --git a/docs/csharp/misc/cs0225.md b/docs/csharp/misc/cs0225.md deleted file mode 100644 index 861e2da59d592..0000000000000 --- a/docs/csharp/misc/cs0225.md +++ /dev/null @@ -1,36 +0,0 @@ ---- -description: "Compiler Error CS0225" -title: "Compiler Error CS0225" -ms.date: 07/20/2015 -f1_keywords: - - "CS0225" -helpviewer_keywords: - - "CS0225" -ms.assetid: 0b0cd72b-c47a-44d1-9b27-d1a1fad06807 ---- -# Compiler Error CS0225 - -The params parameter must be a single-dimensional array or collection - - When using the [params](../language-reference/keywords/method-parameters.md#params-modifier) keyword, you must specify a single-dimensional array or collection of the data type. For more information, see [Methods](../programming-guide/classes-and-structs/methods.md). - -## Example - - The following sample generates CS0225: - -```csharp -// CS0225.cs -public class MyClass -{ - public static void TestParams(params int a) // CS0225 - // try the following line instead - // public static void TestParams(params int[] a) - { - } - - public static void Main() - { - TestParams(1); - } -} -``` diff --git a/docs/csharp/misc/cs0231.md b/docs/csharp/misc/cs0231.md deleted file mode 100644 index 8fac462824607..0000000000000 --- a/docs/csharp/misc/cs0231.md +++ /dev/null @@ -1,31 +0,0 @@ ---- -description: "Compiler Error CS0231" -title: "Compiler Error CS0231" -ms.date: 07/20/2015 -f1_keywords: - - "CS0231" -helpviewer_keywords: - - "CS0231" -ms.assetid: e5e6a8e1-6c9f-4a88-8935-7bedfba88f8c ---- -# Compiler Error CS0231 - -A params parameter must be the last parameter in a formal parameter list. - - The [params](../language-reference/keywords/method-parameters.md#params-modifier) parameter supports a variable number of arguments and must be after all other parameters. For more information, see [Methods](../programming-guide/classes-and-structs/methods.md). - - The following sample generates CS0231: - -```csharp -// CS0231.cs -class Test -{ - public void TestMethod(params int[] p, int i) {} // CS0231 - // To resolve the error, use the following line instead: - // public void TestMethod(int i, params int[] p) {} - - static void Main() - { - } -} -``` diff --git a/docs/csharp/misc/cs0466.md b/docs/csharp/misc/cs0466.md deleted file mode 100644 index 9f018db144728..0000000000000 --- a/docs/csharp/misc/cs0466.md +++ /dev/null @@ -1,43 +0,0 @@ ---- -description: "Compiler Error CS0466" -title: "Compiler Error CS0466" -ms.date: 07/20/2015 -f1_keywords: - - "CS0466" -helpviewer_keywords: - - "CS0466" -ms.assetid: db6be72b-120a-4b48-b41c-a738d02adae0 ---- -# Compiler Error CS0466 - -'method1' should not have a params parameter since 'method2' does not - - You cannot use `params` parameter on a class member if the implemented interface doesn't use it. - -## Example - - The following sample generates CS0466. - -```csharp -// CS0466.cs -interface I -{ - void F1(params int[] a); - void F2(int[] a); -} - -class C : I -{ - void I.F1(params int[] a) {} - void I.F2(params int[] a) {} // CS0466 - void I.F2(int[] a) {} // OK - - public static void Main() - { - I i = (I) new C(); - - i.F1(new int[] {1, 2} ); - i.F2(new int[] {1, 2} ); - } -} -``` diff --git a/docs/csharp/misc/cs0674.md b/docs/csharp/misc/cs0674.md deleted file mode 100644 index a906ee62c0591..0000000000000 --- a/docs/csharp/misc/cs0674.md +++ /dev/null @@ -1,39 +0,0 @@ ---- -description: "Compiler Error CS0674" -title: "Compiler Error CS0674" -ms.date: 07/20/2015 -f1_keywords: - - "CS0674" -helpviewer_keywords: - - "CS0674" -ms.assetid: 9ebfac30-6de8-4503-b4f0-d79f7398e3d5 ---- -# Compiler Error CS0674 - -Do not use 'System.ParamArrayAttribute'. Use the 'params' keyword instead. - - The C# compiler does not allow for the use of ; use [params](../language-reference/keywords/method-parameters.md#params-modifier) instead. - - The following sample generates CS0674: - -```csharp -// CS0674.cs -using System; -public class MyClass -{ - - public static void UseParams([ParamArray] int[] list) // CS0674 - // try the following line instead - // public static void UseParams(params int[] list) - { - for ( int i = 0 ; i < list.Length ; i++ ) - Console.WriteLine(list[i]); - Console.WriteLine(); - } - - public static void Main() - { - UseParams(1, 2, 3); - } -} -``` diff --git a/docs/csharp/misc/cs0758.md b/docs/csharp/misc/cs0758.md deleted file mode 100644 index 509543eed73c5..0000000000000 --- a/docs/csharp/misc/cs0758.md +++ /dev/null @@ -1,46 +0,0 @@ ---- -description: "Compiler Error CS0758" -title: "Compiler Error CS0758" -ms.date: 07/20/2015 -f1_keywords: - - "CS0758" -helpviewer_keywords: - - "CS0758" -ms.assetid: 06ddd548-1311-40db-9078-8a18107b8346 ---- -# Compiler Error CS0758 - -Both partial method declarations must use a params parameter or neither may use a params parameter - - If one part of a partial method specifies a `params` parameter, the other part must specify one also. - -## To correct this error - -1. Either add the `params` modifier in one part of the method, or remove it in the other. - -## Example - - The following code generates CS0758: - -```csharp -using System; - - public partial class C - { - partial void Part(int i, params char[] array); - partial void Part(int i, char[] array) // CS0758 - { - } - - public static int Main() - { - return 1; - } - - } -``` - -## See also - -- [Partial Classes and Methods](../programming-guide/classes-and-structs/partial-classes-and-methods.md) -- [params](../language-reference/keywords/method-parameters.md#params-modifier) diff --git a/docs/csharp/misc/cs1104.md b/docs/csharp/misc/cs1104.md deleted file mode 100644 index 63cfec3b8e61f..0000000000000 --- a/docs/csharp/misc/cs1104.md +++ /dev/null @@ -1,37 +0,0 @@ ---- -description: "Compiler Error CS1104" -title: "Compiler Error CS1104" -ms.date: 07/20/2015 -f1_keywords: - - "CS1104" -helpviewer_keywords: - - "CS1104" -ms.assetid: 65bfe85f-8dd1-4aed-bcd1-1f7e0635868c ---- -# Compiler Error CS1104 - -A parameter array cannot be used with 'this' modifier on an extension method. - - The first parameter of an extension method cannot be a params array. - -## To correct this error - -1. Remember that the first parameter of an extension method definition specifies which type the method will "extend". It is not an input parameter. Therefore, it makes no sense to have a params array in this location. If you do have to pass in a params array, make it the second parameter. - -## Example - - The following example generates CS1104: - -```csharp -// cs1104.cs -// Compile with: /target:library -public static class Extensions -{ - public static void Test(this params T[] tArr) {} // CS1104 -} -``` - -## See also - -- [Extension Methods](../programming-guide/classes-and-structs/extension-methods.md) -- [params](../language-reference/keywords/method-parameters.md#params-modifier) diff --git a/docs/csharp/misc/cs1611.md b/docs/csharp/misc/cs1611.md deleted file mode 100644 index 404a31b87a599..0000000000000 --- a/docs/csharp/misc/cs1611.md +++ /dev/null @@ -1,32 +0,0 @@ ---- -description: "Compiler Error CS1611" -title: "Compiler Error CS1611" -ms.date: 07/20/2015 -f1_keywords: - - "CS1611" -helpviewer_keywords: - - "CS1611" -ms.assetid: 48bfba77-6be2-4242-b1d2-98bf471b6d1e ---- -# Compiler Error CS1611 - -The params parameter cannot be declared as in ref or out - - The keywords [in](../language-reference/keywords/method-parameters.md#in-parameter-modifier), [ref](../language-reference/keywords/ref.md) or [out](../language-reference/keywords/method-parameters.md#out-parameter-modifier) cannot be used with the [params](../language-reference/keywords/method-parameters.md#params-modifier) keyword. - - The following sample generates CS1611: - -```csharp -// CS1611.cs -public class MyClass -{ - public static void Test(params ref int[] a) // CS1611, remove ref - { - } - - public static void Main() - { - Test(1); - } -} -``` diff --git a/docs/csharp/misc/cs1670.md b/docs/csharp/misc/cs1670.md deleted file mode 100644 index 5fb4bf633da47..0000000000000 --- a/docs/csharp/misc/cs1670.md +++ /dev/null @@ -1,38 +0,0 @@ ---- -description: "Learn more about: Compiler Error CS1670" -title: "Compiler Error CS1670" -ms.date: 07/20/2015 -f1_keywords: - - "CS1670" -helpviewer_keywords: - - "CS1670" -ms.assetid: ee2507e5-b509-4af3-a15e-2c1f2da7159c ---- -# Compiler Error CS1670 - -params is not valid in this context - - A number of C# features are incompatible with variable argument lists, and do not allow the `params` keyword, including the following: - -- Parameter lists of anonymous methods - -- Overloaded operators - -## Example - - The following sample generates CS1670: - -```csharp -// CS1670.cs -public class C -{ - public bool operator +(params int[] paramsList) // CS1670 - { - return false; - } - - static void Main() - { - } -} -```