Click here to Skip to main content
15,892,809 members
Home / Discussions / C#
   

C#

 
GeneralRe: want to change theme of controls..... Pin
Johnny J.4-Jun-10 2:25
professionalJohnny J.4-Jun-10 2:25 
GeneralRe: want to change theme of controls..... Pin
Dave Kreskowiak4-Jun-10 4:36
mveDave Kreskowiak4-Jun-10 4:36 
QuestionHow to Create DB in SQL server Pin
Joe Rozario3-Jun-10 18:05
Joe Rozario3-Jun-10 18:05 
AnswerRe: How to Create DB in SQL server Pin
dan!sh 3-Jun-10 18:26
professional dan!sh 3-Jun-10 18:26 
GeneralRe: How to Create DB in SQL server Pin
Joe Rozario4-Jun-10 0:14
Joe Rozario4-Jun-10 0:14 
AnswerRe: How to Create DB in SQL server Pin
Gonzalo Cao4-Jun-10 3:29
Gonzalo Cao4-Jun-10 3:29 
QuestionDisparity between value semantics behavior with List< struct > vs. array of struct Pin
Stache3-Jun-10 15:07
Stache3-Jun-10 15:07 
AnswerRe: Disparity between value semantics behavior with List vs. array of struct [modified] PinPopular
Anthony Mushrow3-Jun-10 17:19
professionalAnthony Mushrow3-Jun-10 17:19 
Normally in C# most things are passed by reference so when you access the item in your list and call Increment on it you modify the actual object in the list.

However in C# structs are value types (like an Int for example) and when they are passed around what you actually get are copies. So if you had a list of Ints and you accessed them in your list you wouldn't get the actual object from the list, you just get a copy that you can do whatever you like with. If you modified the Int you'd have to actually set it back to the list to actually make any changes:
List<int> myList = new List<int>();
myList.Add(5);
myList.Add(2);
//myList == {5, 2}

int number = myList[1];
number += 3;
//myList == {5, 2}, like you would expect
myList[1] = number;
//myList == {5, 5}


With a normal array you are actually accessing the items directly so in your case they get modified as expected, but with a generic list the array subscript operator is the same as calling a function like
int GetAtIndex(int i)
{
  return theActualList[i];
}

And because the struct isn't passed by reference what you end up with is a copy of what's stored in the list and that's what you're actually modifying.

If you wanted it to work the same for both then you could simply change your struct for a class

http://msdn.microsoft.com/en-us/library/ms173109.aspx[^]

Well I hope that makes sense, it's rather late and I'm off to bed now Poke tongue | ;-P
And I also hope I haven't made and blindingly obvious mistakes.
My current favourite quote is: Punch them in the face, see what happens!
-SK Genius


modified on Thursday, June 3, 2010 11:28 PM

GeneralRe: Disparity between value semantics behavior with List vs. array of struct Pin
Stache4-Jun-10 4:23
Stache4-Jun-10 4:23 
QuestionEnglish wordlist database for word processing app?? Pin
Jaison V3-Jun-10 7:57
Jaison V3-Jun-10 7:57 
AnswerRe: English wordlist database for word processing app?? Pin
#realJSOP3-Jun-10 8:14
mve#realJSOP3-Jun-10 8:14 
GeneralRe: English wordlist database for word processing app?? [modified] Pin
Jaison V3-Jun-10 21:16
Jaison V3-Jun-10 21:16 
GeneralRe: English wordlist database for word processing app?? Pin
PIEBALDconsult4-Jun-10 5:30
mvePIEBALDconsult4-Jun-10 5:30 
JokeRe: English wordlist database for word processing app?? Pin
Jaison V4-Jun-10 9:33
Jaison V4-Jun-10 9:33 
GeneralRe: English wordlist database for word processing app?? Pin
#realJSOP5-Jun-10 4:20
mve#realJSOP5-Jun-10 4:20 
GeneralRe: English wordlist database for word processing app?? Pin
Jaison V4-Jun-10 9:35
Jaison V4-Jun-10 9:35 
GeneralRe: English wordlist database for word processing app?? Pin
#realJSOP5-Jun-10 4:18
mve#realJSOP5-Jun-10 4:18 
QuestionHow to replace windows login form... Pin
Xelalem3-Jun-10 7:08
Xelalem3-Jun-10 7:08 
AnswerRe: How to replace windows login form... Pin
Hristo-Bojilov3-Jun-10 10:22
Hristo-Bojilov3-Jun-10 10:22 
AnswerRe: How to replace windows login form... Pin
Dave Kreskowiak3-Jun-10 11:06
mveDave Kreskowiak3-Jun-10 11:06 
GeneralRe: How to replace windows login form... Pin
V.3-Jun-10 23:45
professionalV.3-Jun-10 23:45 
GeneralRe: How to replace windows login form... Pin
Henry Minute4-Jun-10 0:37
Henry Minute4-Jun-10 0:37 
GeneralRe: How to replace windows login form... Pin
V.4-Jun-10 1:41
professionalV.4-Jun-10 1:41 
GeneralRe: How to replace windows login form... Pin
Dave Kreskowiak4-Jun-10 1:44
mveDave Kreskowiak4-Jun-10 1:44 
QuestionMessage Removed Pin
3-Jun-10 6:40
professionalN_tro_P3-Jun-10 6:40 

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.