expression-body

What does the first arrow operator in this Func<T, TReturn> mean?

倾然丶 夕夏残阳落幕 提交于 2021-01-27 05:59:37
问题 Given this example code: enum op { add, remove } Func<op, int> combo(string head, double tail) => (op op) => op == op.add ? Int32.Parse(head) + Convert.ToInt32(tail) : Int32.Parse(head) - Convert.ToInt32(tail); Console.WriteLine(combo("1", 2.5)(op.remove)); Which returns: -1 What does the first arrow operator mean? By specification it does not look like an expression body or a lambda operator. Is there any reference in the C# language specification about this usage? 回答1: What does the first

Why use expression-bodied properties for primitive values? [duplicate]

你。 提交于 2020-07-31 06:12:29
问题 This question already has answers here : What is the difference between a field and a property? (32 answers) Closed 13 days ago . What are the pros and cons of expression-bodied properties vs straight property declarations? For example, is there any advantage to using; public string Foo => "Bar" vs simply public string Foo = "Bar" My understanding was the => is used when the value comes from a method, like a lambda function. If the value is a primitive like a string or int, why would anyone