What does () => mean in C#?

前端 未结 6 1365
再見小時候
再見小時候 2020-12-06 06:20

I\'ve been reading through the source code for Moq and I came across the following unit test:

Assert.Throws(() => Times         


        
6条回答
  •  北荒
    北荒 (楼主)
    2020-12-06 06:56

    ()=> is a nullary lambda expression. it represents an anonymous function that's passed to assert.Throws, and is called somewhere inside of that function.

    void DoThisTwice(Action a) { 
        a();
        a();
    }
    Action printHello = () => Console.Write("Hello ");
    DoThisTwice(printHello);
    
    // prints "Hello Hello "
    

提交回复
热议问题