Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Crafting Strings in C#

When the C# compiler compiles the binary + operator with at least one operand of type string, it causes problems with your <totalNumber>. Find out how to manipulate your strings around this bug.

ecently, I came across an application that contained a binary + operator in which at least one of the operands was of type string.

While debugging this app, I found that the Microsoft C# compiler had compiled the the program so that the <totalNumber> value was 158, while the maximum value allowed was 100.

Why is the <totalNumber> value exceeding the maximum value allowed?

Using this small application, test your application's summing of <totalNumber> before compiling.

Recreating the Problem
Suppose you had the following logged string:

string s = a + b + c;

In the above string, a signifies the shown text, while the integer values of b and c represent the value of <totalNumber>, after summing.

Therefore, the question you need to answer is: how is the summing being performed at run time?

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date