开发者

How does this test run the queries, are they delegates? What is Action<int>?

开发者 https://www.devze.com 2023-02-22 18:59 出处:网络
http://code.google.com/p/dapper-dot-net/source/browse/PerformanceTests.cs Confused, PerformanceTest.Run initializes the list by adding test objects.

http://code.google.com/p/dapper-dot-net/source/browse/PerformanceTests.cs

Confused, PerformanceTest.Run initializes the list by adding test objects.

How does it actually run the query?

I'm guessing it is the line:

for (int i = 1; i <= iterations; i++)
{
    foreach (var test in this.OrderBy(ignore => rand.Next()))
    {
        test.Watch.Start();
        test.Iteration(i);
        test.Watch.Stop();
开发者_JAVA百科    }
}

test.iteration(i);

But how? Is this a delegate?


Yes, Action type is the key here. Action<T> is a built-in delegate type that has no return value and (in this case) takes one parameter of type T. Iteration is the property of type Action<int> where the test action is stored in Test object, and () operator just invokes the method with i parameter.


Yes, Action<int> is a delegate that accepts an integer as an argument (in this case, the iteration number).

0

精彩评论

暂无评论...
验证码 换一张
取 消