I am new to this LINQ field and one thing am trying to do.
I have an action delegate(written below) which i want to convert in lambda expression.
Action<string> custom = delegate(string name)
{
lstCutomers.Add(new Customer(name, coutries[cnt]));
name = name + " Object Created";
};
What will be the lambda expression for same. I just want to know that can i write multiple statements in lambda if no then Why?
Thanks in advance.
In particular, a lambda function has the following characteristics: It can only contain expressions and can't include statements in its body.
No, you can't write multiline lambda in Python because the lambda functions can have only one expression. The creator of the Python programming language – Guido van Rossum, answered this question in one of his blogs. where he said that it's theoretically possible, but the solution is not a Pythonic way to do that.
A lambda function is a small anonymous function. A lambda function can take any number of arguments, but can only have one expression.
You can't create a lambda expression, since you're not returning anything. You can however create a statement lambda:
Action<string> custom = (name) =>
{
lstCutomers.Add(new Customer(name, coutries[cnt]));
name = name + " Object Created";
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With