Okay so lets say I have a valuetype - lets say DateTime.
Look at this code .
List<DateTime> dt = new List<DateTime>( ) ;
dt.Add(new dateTime(1999,1 2,1))
dt[0].AddDays(1) ;
<--- This statement won't actually change the date time stored in the
List<T> dt.
The best I can determine is that soon as a method is called on any date time
stored in "dt", it creates a new instance of DateTime, and leaves the
original inside dt untouched. Similar behavior for non generic collections.
Can anyone explain the reasoning?
- Sahil Malik [MVP]
Look at this code .
List<DateTime> dt = new List<DateTime>( ) ;
dt.Add(new dateTime(1999,1 2,1))
dt[0].AddDays(1) ;
<--- This statement won't actually change the date time stored in the
List<T> dt.
The best I can determine is that soon as a method is called on any date time
stored in "dt", it creates a new instance of DateTime, and leaves the
original inside dt untouched. Similar behavior for non generic collections.
Can anyone explain the reasoning?
- Sahil Malik [MVP]
Comment