0

What's the difference?

Hello, can someone please tell me what the difference between the two methods is? // 1. class SampleClass { private int _sample; public int Sample { // Return the value stored in a field. get => _sample; // Store the value in the field. set => _sample = value; } } //2. class SampleClass { private int _sample; public int Sample { // Return the value stored in a field. get { return _sample; } // Store the value in the field. set { value = _sample; } } } I found this code while I was researching about classes and objects https://docs.microsoft.com/de-de/dotnet/csharp/programming-guide/concepts/object-oriented-programming (I think the web-page is German) I know that the 1.st method uses lambda expression, but is there any difference between the two Or is the 1.st method just better to read and write?

10th Mar 2020, 11:34 PM
Michael
1 Odpowiedź
+ 2
You can change to english by replacing /de-de/ with /en-us/ in the url. https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/object-oriented-programming Quote Starting with C# 7.0, you can implement the get accessor as an expression-bodied member. Source: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/get arrow function is new syntax. they delivers same result. https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/lambda-operator
11th Mar 2020, 12:11 AM
Gordon
Gordon - avatar