This question already has answers here:
What does the operator '=>' mean in C#?
(4 answers)
Closed 7 years ago.
PlayGamesPlatform.Instance.localUser.Authenticate((bool success) =>
In the code snippet above what does this "=>" mean?
I have been unable to find any references for this
Its not always obvious however in this case its part of making a lamda peice of code, so rather than
PlayGamesPlatform.Instance.localUser.Authenticate(something);
where something is declared as
bool something()
{
.. code ..
}
you can do something on the fly with
PlayGamesPlatform.Instance.localUser.Authenticate((bool success) => { .. code .. } );
Related
This question already has answers here:
Shortest way to check for null and assign another value if not
(12 answers)
Closed 2 years ago.
Is it possible to execute a function within a short statement if the statement is true?
Something like that:
myObject.subObject != null ?? Db.LoadReferences(myObject.subObject); // ORMLite function
yes:
if(myObject.subObject != null) Db.LoadReferences(myObject.subObject);
At just 1 single character more than your original.
This question already has answers here:
What does question mark and dot operator ?. mean in C# 6.0?
(3 answers)
Closed 5 years ago.
I've encountered this operator in C# when dealing with custom events: MyEvent?.Invoke(this, new EventArgs());. What is the purpose of the ?. portion of this statement?
It's making sure it's not null. They have these in swift and their called optionals. If the variable is null then it returns null
This question already has answers here:
Best and shortest way to evaluate mathematical expressions
(8 answers)
Evaluating string "3*(4+2)" yield int 18 [duplicate]
(13 answers)
Closed 9 years ago.
Guys I have to evaluate a mathematical expression(which is represented by a string).
Till now I had simple expressions thus the following was working fine
var result = new DataTable().Compute(STRING_HERE, null);
However now my string expression is becoming a bit more complex and the above method is starting to give errors.
Any idea of how I can handle this situation ?
Please I would like some kind of inbuilt method or function like apporach(preferably).
Not inbuild, but NCalc (http://ncalc.codeplex.com/) is a very nice library for evaluating math expressions.
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
.NET Enumeration allows comma in the last field
i noticed while i was refreshing my memory on c# that with enums, you dont get a complaint from the compiler when you leave a comma after the last variable... EG
enum fruit {
apple,
pear,
watermelon,
}
i was wondering you can do this? shouldnt the compiler say "syntax error: ," or something?
It is part of the C# specification, the compiler is simply following it.
Document: http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-334.pdf
Page 363, Section 19.7
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Scope-resolution operator :: versus member-access operator . in C#
What we call :: in following example?
MyNamespace.Properties.Resources.myImage;
global::MyNamespace.Properties.Resources.myImage;
We call it the namespace alias qualifier.