473,806 Members | 2,605 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Lambda Expression issue

Hey,

Am trying to write a lambda expression for a delegate, am getting an error as
------------------------------
only assignment, call, increment, decrement, and new expression can be used
as a statement
-----------------------------

For the following code.

// Delegate Declaration
delegate void dgSmp(string str);

//Lambda Expression
dgSmp dbObj = x =x + " Morning "; // Here throws the error
string strX = dbObj("Happy "); // expted value at strX is "Happy Morning"

------------------------------------------

Can some one help me to understand where i went wrong ..

Thanks
Ruth
Jul 19 '07 #1
2 2202
Ruth,

Your delegate doesn't have a return type. You need to do the following:

delegate string dgSmp(string str);

dgSmp dbObj = x =x + " Morning "; // Here throws the error
string strX = dbObj("Happy "); // expted value at strX is "Happy Morning"

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Ruth Mark" <Ru******@discu ssions.microsof t.comwrote in message
news:1B******** *************** ***********@mic rosoft.com...
Hey,

Am trying to write a lambda expression for a delegate, am getting an error
as
------------------------------
only assignment, call, increment, decrement, and new expression can be
used
as a statement
-----------------------------

For the following code.

// Delegate Declaration
delegate void dgSmp(string str);

//Lambda Expression
dgSmp dbObj = x =x + " Morning "; // Here throws the error
string strX = dbObj("Happy "); // expted value at strX is "Happy Morning"

------------------------------------------

Can some one help me to understand where i went wrong ..

Thanks
Ruth
Jul 20 '07 #2
Hey,

Interpret the message by the compiler. That clearly states that you can do
all the possible activities, but you are not allowing the delegate to do
that. Your Lambda expression has some string value return.

The possible ways to resolve the issue is either rewrite your lambda
expression or change the signature of the deligate

HTH
--
Every thing is perfect, as long as you share!!!

Don''t forget to rate the post
"Ruth Mark" wrote:
Hey,

Am trying to write a lambda expression for a delegate, am getting an error as
------------------------------
only assignment, call, increment, decrement, and new expression can be used
as a statement
-----------------------------

For the following code.

// Delegate Declaration
delegate void dgSmp(string str);

//Lambda Expression
dgSmp dbObj = x =x + " Morning "; // Here throws the error
string strX = dbObj("Happy "); // expted value at strX is "Happy Morning"

------------------------------------------

Can some one help me to understand where i went wrong ..

Thanks
Ruth
Jul 20 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

31
1652
by: Jason Zheng | last post by:
I'm wondering why python still has limited lambda support. What's stopping the developers of python to support more lisp-like lambda function?
63
3429
by: Stephen Thorne | last post by:
Hi guys, I'm a little worried about the expected disappearance of lambda in python3000. I've had my brain badly broken by functional programming in the past, and I would hate to see things suddenly become harder than they need to be. An example of what I mean is a quick script I wrote for doing certain actions based on a regexp, which I will simlify in this instance to make the pertanant points more relevent.
1
2552
by: Matthias Kaeppler | last post by:
Hi, in my program, I have this funtion to compute the sum of a bunch of files: Glib::ustring DirBrowser::get_total_file_size() { using namespace boostfs; // boostfs = boost::filesystem using namespace lambda; // lambda = boost::lambda boost::intmax_t sum = 0; std::for_each(m_first_file,m_files.end(),sum+=bind(&file_size,*_1));
267
10873
by: Xah Lee | last post by:
Python, Lambda, and Guido van Rossum Xah Lee, 2006-05-05 In this post, i'd like to deconstruct one of Guido's recent blog about lambda in Python. In Guido's blog written in 2006-02-10 at http://www.artima.com/weblogs/viewpost.jsp?thread=147358
23
5340
by: Kaz Kylheku | last post by:
I've been reading the recent cross-posted flamewar, and read Guido's article where he posits that embedding multi-line lambdas in expressions is an unsolvable puzzle. So for the last 15 minutes I applied myself to this problem and come up with this off-the-wall proposal for you people. Perhaps this idea has been proposed before, I don't know. The solutions I have seen all assume that the lambda must be completely inlined within the...
5
2165
by: Octal | last post by:
How does the lambda library actually works. How does it know how to evaluate _1, how does it recognize _1 as a placeholder, how does it then calculate _1+_2, or _1+2 etc. The source files seem a bit complicated so any explanation would be appreciated. Thanks
15
4855
by: Matt | last post by:
Hi There, Can anyone explain me the real advantages of (other than syntax) lambda expressions over anonymous delegates? advantage for one over the other. delegate int F(int a); F fLambda = a =a++; F fAnonymous = delegate(int a) { return a++; }; fLambda(1);
21
1860
by: globalrev | last post by:
i have a rough understanding of lambda but so far only have found use for it once(in tkinter when passing lambda as an argument i could circumvent some tricky stuff). what is the point of the following function? def addn(n): return lambda x,inc=n: x+inc if i do addn(5) it returns
11
1691
by: puzzlecracker | last post by:
I am not understanding what's happening in the code below (from accelerated c#) -- I know what the outcome but not how .net does it: using System; using System.Linq; public class LambdaTest { static void Main()
0
9719
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9598
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10373
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9192
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7650
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5546
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4330
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3852
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3010
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.