Will Delegate with params keyword match any method?
No. They still have to respect type variance.
params is only syntatic sugar for saying that from that point and beyond, all parameters of the call site are considered to be part of the same array on the method.
So, for a method defined as:
TimeSpan BenchmarkMethod(SomeMethod someMethod, params Company[] parameters)
You can do:
Company company1 = null;
Company company2 = null;
//In BenchmarkMethod, company1 and company2 are considered to be part of
//parameter 'parameters', an array of Company;
BenchmarkMethod(dlg, company1, company2);
but not:
Company company1 = null;
object company3 = new Company();
BenchmarkMethod(dlg, company1, company3);
Because, although company3 contains a Company at runtime, it's static type is object.
So now we know that params simply defines an array on a method, that allows you to use a more convenient syntax at the call site.
Now let's go on with the real reason for your code not working as you expected: Type variance
Your delegate is defined as:
public delegate void SomeMethod(params object[] parameters);
and you target method as:
public abstract void InsertObjects (Company c);
When invoking the delegate:
SomeMethod dlg = new SomeMethod(InsertObjects);
TimeSpan executionTime = BenchmarkMethod(dlg, c);
You are essentialy saying you can call InsertObjects passing it an array with any type of object instead of an object of type Company.
That of course is not allowed by the compiler.
If instead, you invert the types of the delegate and the target method such as in:
public delegate void SomeMethod(params Company[] parameters);
public TimeSpan BenchmarkMethod(SomeMethod someMethod, params Company[] parameters) {
DateTime benchmarkStart = DateTime.Now;
someMethod(parameters);
DateTime benchmarkFinish = DateTime.Now;
return benchmarkFinish - benchmarkStart;
}
public void InsertObjects(object c) {
Console.WriteLine(c);
}
Then it will compile, because you'll be passing an array of Customer to a method that accepts any kind of object.
Conclusion:
params does not affect type variance rules.