Sipo Sipo - 1 month ago 6
C# Question

What does "=>" operator means in a property in C#?

What is this code means?

public bool property => method();


Try to google it but all I have found is this, which is not helpful for me.

Answer

This is an expression-bodied property, a new syntax for computed properties introduced in C# 6, which lets you create computed properties in the same way as you would create a lambda expression. This syntax is equivalent to

public bool property {
    get {
        return method();
    }
}

Similar syntax works for methods, too:

public int TwoTimes(int number) => 2 * number;