What does () => mean in C#?

c#-3.0

Solution

()=> 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 "

Problem

I've been reading through the source code for Moq and I came across the following unit test: ``` Assert.Throws<ArgumentOutOfRangeException>(() => Times.AtLeast(0)); ``` And for the life of me, I can't remember what () => actually does. I'm think it has something to do with anonymous methods or lambdas. And I'm sure I know what it does, I just can't remember at the moment.... And to make matters worse....google isn't being much help and neither is stackoverflow Can someone give me a quick answer to a pretty noobish question?

Original source