9
I asked the following question: What value is checked in a condition operation with a variable value assignment? and the user @Maniero answered me, however, in the reply he used an operator and that generated me a new doubt. I asked the same about the use of the operator and he indicated me the following link for clarification: What is the purpose of the operator => in the use of lists?. However, it is not yet clear to me.
What are the benefits of using the operator =>
in methods unrelated to lists or lambda expression?
If the operator has no relation to lists and no lambda expression. How the operation would be called in case it is not related to an anonymous function?
I tried to execute the following code in Consoleapplication, however, from the operator declaration error =>, saying that ";" is expected. If that operator has that function it should not present such an error.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
public class C
{
public int Main() {
var conta = new Conta();
var txtValor = new Form();
bool retorno;
if ((retorno = conta.Saca(Convert.ToDouble(txtValor.Text)))) {
Console.WriteLine(retorno);
return 1;
}
return 0;
}
}
public class Conta {
public bool Saca(double x) => true;
}
public class Form {
public String Text;
}
}
It’s just to shorten the code.
– Jéf Bueno
All right, but it doesn’t work the way @bigown explained, or I got it / tested wrong
– Diego Farias
Or you’re not using C# 6 (?)
– Jéf Bueno
No, I am using the 2012 in case, I will test with the 2017
– Diego Farias
This only came to exist in C# 6.
– Jéf Bueno
I get it, I didn’t know that. I’m gonna test
– Diego Farias