473,406 Members | 2,281 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Left and right value of assignment for functions returning reference types

Hi all,

This is an excerpt from the Book "Programming Microsoft Visual C#: The
Language":

A function evaluates to the return value. When a reference type is
returned, a function is available as a left- or right-value of an
assignment. Functions that return a value type are restricted to
right-values of an assignment.

To test that statment I did sth like this:

class Program
{

static int Add(int x, int y)
{
return x + y;
}

static string AddS(string i, string j)
{
return i + j;
}

static void Main(string[] args)
{
//Add(2, 3) = 5; // this is an error - good
AddS("mulu", "geta") = "thomas"; // why is this an
error?
}
}

Can you help?

Thanks in advance

Nov 29 '06 #1
2 2310
"muler" <mu*************@gmail.comwrote in message
news:11**********************@l12g2000cwl.googlegr oups.com...
Hi all,

This is an excerpt from the Book "Programming Microsoft Visual C#: The
Language":

A function evaluates to the return value. When a reference type is
returned, a function is available as a left- or right-value of an
assignment. Functions that return a value type are restricted to
right-values of an assignment.
I think the author is wrong.
I tried to hunt around in the C# spec to see where this comment
originated, but I couldn't find anything even close.
The only mention of lvalues (variable-reference in the spec), in
relation to methods, has to do with ref/out parameters.

If I may speculate a bit, take the following:

Foo() = "Bar"; // sample of what the Author is saying is OK

this is (sort of ) equivalent to

string temp = Foo();
temp = "Bar";

In other words, you are assigning the string to a temporary variable.
Even if it was allowed, I am sure it would be doing what you expected.

Bill
Nov 29 '06 #2
You should have something like

String Thomas = AddS(mulu", "geta");

instead.

chanmm

"muler" <mu*************@gmail.comwrote in message
news:11**********************@l12g2000cwl.googlegr oups.com...
Hi all,

This is an excerpt from the Book "Programming Microsoft Visual C#: The
Language":

A function evaluates to the return value. When a reference type is
returned, a function is available as a left- or right-value of an
assignment. Functions that return a value type are restricted to
right-values of an assignment.

To test that statment I did sth like this:

class Program
{

static int Add(int x, int y)
{
return x + y;
}

static string AddS(string i, string j)
{
return i + j;
}

static void Main(string[] args)
{
//Add(2, 3) = 5; // this is an error - good
AddS("mulu", "geta") = "thomas"; // why is this an
error?
}
}

Can you help?

Thanks in advance
Nov 30 '06 #3

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

Similar topics

9
by: mjm | last post by:
Folks, Stroustrup indicates that returning by value can be faster than returning by reference but gives no details as to the size of the returned object up to which this holds. My question is...
3
by: Sree | last post by:
Hello All, When will it be benefical to return a value from a function as a const reference ? Say I have classes like this class B { public: int someValue1; int someValue2;
15
by: lawrence | last post by:
Sorry for the dumb question but I'm new to Javascript. I wrote this script hoping to animate some div blocks on a page. You can see the page here: http://www.keymedia.biz/demo.htm Can anyone...
4
by: gsyoon | last post by:
hi, all. I'm trying to make a "framework" to store the return value of a function to a global memory. My first attempt was 1) void store_to_global( char * type_name ) { if ( strcmp(...
5
by: Neal Coombes | last post by:
Posted to comp.lang.c++.moderated with little response. Hoping for better from the unmoderated groups: -------- Original Message -------- Subject: Return appropriately by value, (smart)...
9
by: Angel | last post by:
Hi again, I'm trying to call functions from a proprietary DLL but it's turned out to be more difficult than I thought. I have this W32.DLL which was written in C by USPS. They don't provide the...
19
by: Dennis | last post by:
I have a public variable in a class of type color declared as follows: public mycolor as color = color.Empty I want to check to see if the user has specified a color like; if mycolor =...
12
by: subramanian100in | last post by:
For a class Test, we write the assignment operator as Test & Test::operator=(const Test & rhs); instead of const Test & Test::operator=(const Test & rhs); that is, the return type of...
2
by: =?Utf-8?B?TWlrZQ==?= | last post by:
Anyone know of any way to get a reference to the argument to the left (lvalue I believe it is called) of the assignment operator? I realize you can't overload the assignment operator in C#, but...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...
0
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...

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.