-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Short syntax for lambda declaration #7463
Comments
Your second case isn't valid C# syntax currently since you are referring to a method group. The valid syntax would be |
HaloFour, maybe Action y => Console.WriteLine isn't good example. |
You are suggesting a special assignment operator just for a lambda expression that takes no args? and if I get it right the whole proposal saves two keystrokes per each lambda expression that takes no args? and number 3 is basically #3990. |
for improvment by number 3: //how it's work now: //not work now //how it's doing work. "() => {...}" automaic casting to Delegate object. //how it's doing work with improvment by number 1 Q: You are suggesting a special assignment operator just for a lambda expression that takes no args? and if I get it right the whole proposal saves two keystrokes per each lambda expression that takes no args? A:
|
We are now taking language feature discussion on https://github.com/dotnet/csharplang for C# specific issues, https://github.com/dotnet/vblang for VB-specific features, and https://github.com/dotnet/csharplang for features that affect both languages. |
//short lambda declaration for delegates without return keyword
//1. current syntax
example
.ExampleMethodName(() => x + 1)
.ExampleMethodName(() => x + 1).
.ExampleMethodName(() => x + 2).
.ExampleMethodName(() => x + 3).
//short syntax
var x = 0;
example
.ExampleMethodName(=> Console.WriteLine("1"))
.ExampleMethodName(=> x + 1).
.ExampleMethodName(=> x + 2).
.ExampleMethodName(=> x + 3).
//2. short lamda syntax for variable declaration
//current syntax
Action y = () => Console.WriteLine("123");
y();
//short syntax with '=>' operator
Action y => Console.WriteLine("123");
y();
//maybe var y => Console.WriteLine if Console.WriteLine have once signature;
//3. autocast lamda syntax for delegate
//current syntax
Invoke(new Action(() => {..})); or Invoke(delegate () => {..});
//short syntax
Invoke(=> {..});
Where Invoke method have signature > void Invoke(Delegate proc);
The text was updated successfully, but these errors were encountered: