Skip to main content

Anonymous method cannot have 'params' parameter

In This Article

CodeRush Classic shows the Anonymous method cannot have ‘params’ parameter code issue if an anonymous method includes a params parameter.

#Fix

Use a usual parameter of an array type instead of the params parameter.

#Purpose

Highlights the anonymous method declarations, which would cause the params is not valid in this context compilation error.

#Example

delegate void MyDelegate(string[] data);
public void TestMethod()
{
    MyDelegate mDel = delegate(params string[] data) 
    {
        foreach(string str in data)
            Console.WriteLine(str);
    };
}

Fix:

delegate void MyDelegate(string[] strings);
public void TestMethod()
{
    MyDelegate mDel = delegate(string[] data) 
    {
        foreach(string str in data)
            Console.WriteLine(str);
    };
}