Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Errors and warnings related to the
There are a few errors related to the lock statement and thread synchronization:
- CS0225: The params parameter must be a single-dimensional array or have a valid collection type
- CS0231: A params parameter must be the last parameter in a formal parameter list.
- CS0466: 'method1' should not have a params parameter since 'method2' does not
- CS0674: Do not use
System.ParamArrayAttributeorSystem.ParamArrayAttribute/System.Runtime.CompilerServices.ParamCollectionAttribute. Use theparamskeyword instead. - CS0758: Both partial method declarations must use a
paramsparameter or neither may use aparamsparameter - CS1104: A parameter array cannot be used with
thismodifier on an extension method. - CS1611: The params parameter cannot be declared as in
reforout - CS1670:
paramsis not valid in this context - CS1751: Cannot specify a default value for a parameter array.
- 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.
- 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.
- CS9227: Type does not contain a definition for a suitable instance
Addmethod. - CS9228: Non-array params collection type must have an applicable constructor that can be called with no arguments.
- CS9272: Implicitly typed lambda parameter cannot have the 'params' modifier.
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
thismodifier on an extension method. - CS1611: The params parameter cannot be declared as in
reforout - CS1670:
paramsis 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
paramsmodifier 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
paramsmodifier is used. - The
paramsmodifier can't be applied to reference parameter. A reference parameter is one with thein,ref readonly,reforoutmodifier. - The
paramsmodifier can't be combined with thethismodifier on an extension method. - The
paramsmodifier 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.
- 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
Addmethod. - CS9228: Non-array params collection type must have an applicable constructor that can be called with no arguments.
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.
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.ParamArrayAttributeorSystem.Runtime.CompilerServices.ParamCollectionAttribute. Use theparamskeyword instead. - CS0758: Both partial method declarations must use a
paramsparameter or neither may use aparamsparameter - 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.
- CS9272: Implicitly typed lambda parameter cannot have the 'params' modifier.
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 System.ParamArrayAttribute or System.Runtime.CompilerServices.ParamCollectionAttribute.
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
Addmethod takes aparamscollection of the same type. - The compiler emits CS9224 when the
Createmethod for the collection type is less accessible than the method that takes theparamsparameter 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 System.Diagnostics.CodeAnalysis.SetsRequiredMembersAttribute on the parameterless constructor.
- The compiler emits CS9272 when you've used the
paramsmodifier without type information on a lambda expression. You must specify the types for all lambda expression parameters to use theparamsmodifier.