Click here to Skip to main content
15,914,010 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
GeneralRe: You can't assign to an array element within a For Each loop! Pin
Luc Pattyn13-Sep-10 8:33
sitebuilderLuc Pattyn13-Sep-10 8:33 
GeneralRe: You can't assign to an array element within a For Each loop! Pin
Peter R. Fletcher13-Sep-10 9:24
Peter R. Fletcher13-Sep-10 9:24 
GeneralRe: You can't assign to an array element within a For Each loop! Pin
Luc Pattyn13-Sep-10 9:28
sitebuilderLuc Pattyn13-Sep-10 9:28 
GeneralRe: You can't assign to an array element within a For Each loop! [modified] Pin
harold aptroot13-Sep-10 11:18
harold aptroot13-Sep-10 11:18 
GeneralRe: You can't assign to an array element within a For Each loop! Pin
Luc Pattyn13-Sep-10 11:25
sitebuilderLuc Pattyn13-Sep-10 11:25 
GeneralRe: You can't assign to an array element within a For Each loop! Pin
harold aptroot13-Sep-10 11:29
harold aptroot13-Sep-10 11:29 
GeneralRe: You can't assign to an array element within a For Each loop! Pin
Luc Pattyn13-Sep-10 11:43
sitebuilderLuc Pattyn13-Sep-10 11:43 
GeneralRe: You can't assign to an array element within a For Each loop! Pin
harold aptroot13-Sep-10 12:00
harold aptroot13-Sep-10 12:00 
Thanks Smile | :)

By the way, they don't disallow all code to change "the foreach value". For example, if you have an array of Rectangles you can still call Inflate on them. Code like that has the effect of changing the second copy, and that's the same as changing "the foreach value".
This snippet shows that behaviour:
C#
Rectangle[] aBunchOfRectangles = new Rectangle[10];
foreach (Rectangle rect in aBunchOfRectangles)
{
    Console.WriteLine(rect);
    rect.Inflate(1, 1);
    Console.WriteLine(rect);
}

That would explain why the struct is copied from the array to the stack once (though it is also done when the method doesn't change the instance), the other copy is still a mystery to me..
GeneralRe: You can't assign to an array element within a For Each loop! Pin
DaveyM6913-Sep-10 12:27
professionalDaveyM6913-Sep-10 12:27 
Questionhow do I auto relocate component when resizing the window? Pin
bimbambumbum12-Sep-10 14:09
bimbambumbum12-Sep-10 14:09 
AnswerRe: how do I auto relocate component when resizing the window? Pin
PIEBALDconsult12-Sep-10 14:30
mvePIEBALDconsult12-Sep-10 14:30 
GeneralRe: how do I auto relocate component when resizing the window? Pin
bimbambumbum12-Sep-10 14:39
bimbambumbum12-Sep-10 14:39 
Questiondatagridview Pin
Jefry boycot12-Sep-10 2:28
Jefry boycot12-Sep-10 2:28 
AnswerRe: datagridview Pin
Abhinav S12-Sep-10 3:45
Abhinav S12-Sep-10 3:45 
GeneralRe: datagridview Pin
Jefry boycot16-Sep-10 7:17
Jefry boycot16-Sep-10 7:17 
QuestionVS2010 Pin
Herboren11-Sep-10 8:01
Herboren11-Sep-10 8:01 
AnswerRe: VS2010 Pin
Abhinav S11-Sep-10 19:43
Abhinav S11-Sep-10 19:43 
AnswerRe: VS2010 Pin
Thomas Stockwell12-Sep-10 8:32
professionalThomas Stockwell12-Sep-10 8:32 
AnswerRe: VS2010 Pin
PIEBALDconsult12-Sep-10 16:37
mvePIEBALDconsult12-Sep-10 16:37 
QuestionPutting window inside the desktop Pin
Khao9-Sep-10 17:41
Khao9-Sep-10 17:41 
AnswerRe: Putting window inside the desktop Pin
Thomas Stockwell12-Sep-10 8:34
professionalThomas Stockwell12-Sep-10 8:34 
GeneralBackward Compatibility Pin
Herboren9-Sep-10 7:18
Herboren9-Sep-10 7:18 
GeneralRe: Backward Compatibility Pin
fjdiewornncalwe9-Sep-10 7:25
professionalfjdiewornncalwe9-Sep-10 7:25 
GeneralRe: Backward Compatibility Pin
The Man from U.N.C.L.E.9-Sep-10 7:36
The Man from U.N.C.L.E.9-Sep-10 7:36 
GeneralRe: Backward Compatibility Pin
Luc Pattyn9-Sep-10 12:59
sitebuilderLuc Pattyn9-Sep-10 12:59 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.