return a = “hello”; What will Happen?

added by shayfriedman
4/29/2010 1:00:52 AM

1073 Views

I came across an interesting piece of code the other day, something I didn’t even know possible in C# - return a = "hello";. What do you think this line returns?


1 comments

zychr
5/1/2010 3:37:23 PM
Shay,
It would first assign a to "hello" and then return "hello" because of the assignment operator's chaining effect (i.e. a = b = c = ...).
HTH,
zychr