473,657 Members | 2,932 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

What is this syntax???

double c = double.NaN;

Console.WriteLi ne(c = 10);
Console.WriteLi ne(c += 5);
Console.WriteLi ne(c);

output:
10
15
15

Question: Has it always been possible to do these assingments and
operations, and how can such an operations return a value?? I like it, but
thought that this kind of operations were nice candy back from my c++ days
and not allowed in c#.

regards Jesper.

Nov 4 '08 #1
6 1356
Jesper wrote:
double c = double.NaN;

Console.WriteLi ne(c = 10);
Console.WriteLi ne(c += 5);
Console.WriteLi ne(c);

output:
10
15
15

Question: Has it always been possible to do these assingments and
operations, and how can such an operations return a value?? I like it, but
thought that this kind of operations were nice candy back from my c++ days
and not allowed in c#.
What you have inside of the first two WriteLine() calls is an assignment
expression. So
c = 10
assigns 10 to c and evaluates to the assigned value, similar
c += 5
inrements c by 5 and evaluates to the assigned value.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Nov 4 '08 #2
The logical result of any assignent is the value that was assigned. So
this behaves as expected. This also allows the abbreviated syntax:

obj.Foo = obj.Bar = true;

where true is assigned to Bar and Foo (Bar is not queried at any point;
the result of the first assignment (true) is used for the second
assignment).

Marc
Nov 4 '08 #3
Jesper wrote:
double c = double.NaN;

Console.WriteLi ne(c = 10);
Console.WriteLi ne(c += 5);
Console.WriteLi ne(c);

output:
10
15
15

Question: Has it always been possible to do these assingments and
operations, and how can such an operations return a value?? I like it, but
thought that this kind of operations were nice candy back from my c++ days
and not allowed in c#.
They are allowed in C#.

Your examples are not examples of where it makes sense.

But you will see the following a lot:

string line;
while((line = sr.ReadLine()) != null)
{
....
}

And it is using the same feature.

Arne
Nov 4 '08 #4
"Jesper, Denmark" <Je***********@ discussions.mic rosoft.comwrote in message
news:06******** *************** ***********@mic rosoft.com...
Question: Has it always been possible to do these assingments and
operations, and how can such an operations return a value?? I like it, but
thought that this kind of operations were nice candy back from my c++ days
and not allowed in c#.
Quite the opposite; the usage is expanding: not only are they allowed in C#,
but as of the first version of VB.NET the syntax was added to that language
too!
Nov 4 '08 #5
VB has never allowed assignments within expressions.
--
http://www.tangiblesoftwaresolutions.com
C++ to C#
C++ to VB
C++ to Java
VB & C# to Java
Java to VB & C#
Instant C#: VB to C#
Instant VB: C# to VB
Instant C++: VB, C#, or Java to C++/CLI
"Jeff Johnson" wrote:
"Jesper, Denmark" <Je***********@ discussions.mic rosoft.comwrote in message
news:06******** *************** ***********@mic rosoft.com...
Question: Has it always been possible to do these assingments and
operations, and how can such an operations return a value?? I like it, but
thought that this kind of operations were nice candy back from my c++ days
and not allowed in c#.

Quite the opposite; the usage is expanding: not only are they allowed in C#,
but as of the first version of VB.NET the syntax was added to that language
too!
Nov 4 '08 #6
"David Anton" <Da********@dis cussions.micros oft.comwrote in message
news:A6******** *************** ***********@mic rosoft.com...
Question: Has it always been possible to do these assingments and
operations, and how can such an operations return a value?? I like it,
but
thought that this kind of operations were nice candy back from my c++
days
and not allowed in c#.

Quite the opposite; the usage is expanding: not only are they allowed in
C#,
but as of the first version of VB.NET the syntax was added to that
language
too!
VB has never allowed assignments within expressions.
Sorry, I was only referring to the <operator>= syntax (for standalone
assignments). Obviously I was unclear.
Nov 4 '08 #7

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

Similar topics

28
3287
by: David MacQuigg | last post by:
I'm concerned that with all the focus on obj$func binding, &closures, and other not-so-pretty details of Prothon, that we are missing what is really good - the simplification of classes. There are a number of aspects to this simplification, but for me the unification of methods and functions is the biggest benefit. All methods look like functions (which students already understand). Prototypes (classes) look like modules. This will...
37
2594
by: Bengt Richter | last post by:
ISTM that @limited_expression_producing_function @another def func(): pass is syntactic sugar for creating a hidden list of functions. (Using '|' in place of '@' doesn't change the picture much (except for people whose tools depend on '@' ;-)). I.e., (not having the source or time to delve) the apparent semantics of the above is something roughly like
70
8858
by: Roy Yao | last post by:
Does it mean "(sizeof(int))* (p)" or "sizeof( (int)(*p) )" ? According to my analysis, operator sizeof, (type) and * have the same precedence, and they combine from right to left. Then this expression should equal to "sizeof( (int)(*p) )", but the compiler does NOT think so. Why? Can anyone help me? Thanks. Best regards. Roy
121
10023
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode support IDEs are DreamWeaver 8 and Zend PHP Studio. DreamWeaver provides full support for Unicode. However, DreamWeaver is a web editor rather than a PHP IDE. It only supports basic IntelliSense (or code completion) and doesn't have anything...
8
4032
by: Hermawih | last post by:
Hello , I want your opinion about this . In order to say it clearly , I think I have to describe it in long sentences . I could consider myself as Intermediate/Advance Access Developer ; Intermediate/Advanced Database designer . Because of the requirements , I must create Web Application . Access Pages is not suitable for that so I think about learning VB Net / ASP Net . I am
6
407
by: Daniel Rudy | last post by:
What is wrong with this program? When I try to compile it, I get the following error. Compiler is gcc on FreeBSD. strata:/home/dcrudy/c 1055 $$$ ->cc -g -oe6-3 e6-3.c e6-3.c: In function `main': e6-3.c:32: syntax error before `||' e6-3.c:33: syntax error before `printf' e6-3.c:36: syntax error before `||' e6-3.c:40: syntax error before `(' e6-3.c:40: syntax error before `strcpy'
10
3220
by: Protoman | last post by:
Could you tell me what's wrong with this program, it doesn't compile: #include <iostream> #include <cstdlib> using namespace std; class Everything { public: static Everything* Instance()
3
16227
by: Manuel | last post by:
I'm trying to compile glut 3.7.6 (dowbloaded from official site)using devc++. So I've imported the glut32.dsp into devc++, included manually some headers, and start to compile. It return a very strange error. In your experience, where I should looking to find the real error? Surely the sintax of glut is correct... gcc.exe -c glut_bitmap.c -o glut_bitmap.o -I"C:/Dev-Cpp/include" -I"../../include" -D__GNUWIN32__ -W -DWIN32 -DNDEBUG...
5
2381
by: Cylix | last post by:
this.menus = { root: new Array };
14
9844
by: gimme_this_gimme_that | last post by:
What is going on here with the dollar signs and parenthesis? $(document).ready(function(){ $("li").behavior("click",function(){ $(this).load(menu.html"); }); }); And when do you use click vs. onclick? Is onclick only an attribute thing?
0
8302
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,...
0
8820
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8718
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8601
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6162
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
4150
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
2726
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
1937
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1601
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.