[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pnet-developers] [bug #15345] strings created in a while loop are not m
From: |
Andrew Yates |
Subject: |
[Pnet-developers] [bug #15345] strings created in a while loop are not made null each iteration |
Date: |
Sat, 31 Dec 2005 23:27:23 +0000 |
User-agent: |
Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8) Gecko/20051111 Firefox/1.5 |
URL:
<http://savannah.gnu.org/bugs/?func=detailitem&item_id=15345>
Summary: strings created in a while loop are not made null
each iteration
Project: DotGNU Portable.NET
Submitted by: andrewy
Submitted on: Sat 12/31/05 at 23:27
Category: None
Severity: 3 - Normal
Item Group: None
Status: None
Privacy: Public
Assigned to: None
Open/Closed: Open
_______________________________________________________
Details:
Strings (and probably every other type) created in a while loop are not made
null each iteration. Instead, their value is preserved across iterations.
I don't claim to be a C# expert, but it is my understanding that they should
be made null each iteration.
Consider the following code:
public class adsf {
static void Main() {
int a=0;
while (a<=3) {
string test;
test += a.ToString();
Console.WriteLine("{0}", test);
a++;
}
}
}
This compiles fine with cscc, and gives this output:
0
01
012
0123
As you can see, the value of the string "test" is preserved across
iterations. csc or mcs both refuse to compile this code unless the line is
changed to: string test = ""
Regardless of whether or not cscc lets it compile, I believe that the string
should be set to null every iteration.
_______________________________________________________
Reply to this item at:
<http://savannah.gnu.org/bugs/?func=detailitem&item_id=15345>
_______________________________________________
Message sent via/by Savannah
http://savannah.gnu.org/
- [Pnet-developers] [bug #15345] strings created in a while loop are not made null each iteration,
Andrew Yates <=