2023-05-03 11:06:20 +02:00
== Why is this an issue?
2023-02-02 09:30:33 +01:00
There's no point in creating an array solely for the purpose of passing it to a `params` parameter. Simply pass the elements directly. They will be consolidated into an array automatically.
2021-09-20 15:38:42 +02:00
2023-05-03 11:06:20 +02:00
=== Noncompliant code example
2021-09-20 15:38:42 +02:00
2023-02-02 09:30:33 +01:00
[source,csharp]
----
public void Base()
{
Method(new string[] { "s1", "s2" }); // Noncompliant: unnecessary
Method(new string[] { }); // Noncompliant
Method(new string[12]); // Compliant
}
2021-09-20 15:38:42 +02:00
2023-02-02 09:30:33 +01:00
public void Method(params string[] args)
{
// ...
}
----
2021-09-20 15:38:42 +02:00
2023-05-03 11:06:20 +02:00
=== Compliant solution
2023-02-02 09:30:33 +01:00
[source,csharp]
----
public void Base()
{
Method("s1", "s2");
Method();
Method(new string[12]);
}
public void Method(params string[] args)
{
// ...
}
----