params ?
. .
params - , , .
, , :
TimeSpan BenchmarkMethod(SomeMethod someMethod, params Company[] parameters)
:
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);
, :
Company company1 = null;
object company3 = new Company();
BenchmarkMethod(dlg, company1, company3);
, company3 , - .
, , params , .
, , : Type variance
:
public delegate void SomeMethod(params object[] parameters);
, :
public abstract void InsertObjects (Company c);
:
SomeMethod dlg = new SomeMethod(InsertObjects);
TimeSpan executionTime = BenchmarkMethod(dlg, c);
, InsertObjects, , Company.
, , .
, :
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);
}
, , .
:
params .