score:94

Accepted answer

that is a lambda expression. it is a very special anonymous delegate. basically you are defining a method and not giving a name. its parameters are to the left of the => and the method body is to the right of the =>. in your particular case,

(se, cert, chain, sslerror) => { return true; };

is an anonymous method defined by a lambda expression. this particular method has four parameters

object se
x509certificate cert
x509chain chain
sslpolicyerrors sslerror

and the method body is

return true;

it's as if you had said

class servercertificatevalidation {
    public bool onremotecertificatevalidation(
        object se,
        x509certificate cert,
        x509chain chain,
        sslpolicyerrors sslerror
    ) {
        return true;
    }
}

and then

var validation = new servercertificatevalidation();
system.net.servicepointmanager.servercertificatevalidationcallback +=
    validation.onremotecertificatevalidation;

how is that (blah,blah,blah)=>{return true;} construct called and where can i find more info on such constructs?

it's called the same way that any other method is called. for example, you can do this:

func<int, int, int> adder = (m, n) => m + n;

here i am defining a method that eats a pair of int and returns an int. that int is obtained by adding the values of the input parameters. it can be invoked like any other method.

int four = adder(2, 2); 

here's an article on msdn on lambda expressions and an article on the lambda operator. if you're really interested, the name comes from lambda calculus.

score:1

this snippet is called anonymous function. it builds an anonymous method around the callback delegate and allways returns true.

score:3

jason explains it very well. here is an example using an event that is listened to using different techniques:

using system;

namespace events
{
   class program
    {
        static void main(string[] args)
        {
            events e = new events();
            e.fireevents();
            console.readline();
        }
    }

    public class events
    {
        private event eventhandler<eventargs> eventtest;

        public events()
        {
            eventtest += new eventhandler<eventargs>(function);

            eventtest += delegate
            {
                console.writeline("written by an anonymous method.");
            };

            eventtest += (o, e) =>
            {
                console.writeline("written by a lambda expression");
            };
        }

        private void function(object sender, eventargs e)
        {
            console.writeline("written by a function.");
        }

        public void fireevents()
        {
            if (eventtest != null)
                eventtest(this, new eventargs()); 
        }
    }
}

score:4

(blah,blah,blah)=>{return true;} 

is a lambda expression. it doesn't look like the lambdas you're used to because it doesn't use any arguments which get passed to it. the compiler will turn this lambda into a delegate function for you, without you having to go through the long, annoying process of creating a whole function which implements the delegate specification that servicepointmanager.servercertificatevalidationcallback uses.

score:6

the =>-operator represents a lambda expression.

but for those of you who visit the question nowadays, another use-case might be the arrow as a shorthand for a property getter. this feature got introduced in c# 6. so instead of writing

public string foo
{
    get
    {
        return this.bar;
    }
}

you can use following snippet:

public string foo 
{
    get => this.bar;
}

or even shorter:

public string foo => this.bar;

score:19

for completeness (for search results, etc): in more recent versions of c# (since 6.0), the => syntax has been extended from just lambdas for delegates and expression trees, to cover expression-bodied members. this means that a range of simple members such as properties, methods, etc - can be implemented as expression bodies; for example:

public int foo { get { return innerobj.someprop; } }
public void bar() { write("thing"); }

can be written:

public int foo => innerobj.someprop;
public void bar() => write("thing");

Related Query

More Query from same tag