<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>BCL Team Blog</title><link>http://blogs.msdn.com/bclteam/default.aspx</link><description>Basetypes, Collections, Diagnostics, IO, RegEx...</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Code Contracts at PDC 2009</title><link>http://blogs.msdn.com/bclteam/archive/2009/11/17/code-contracts-at-pdc-2009.aspx</link><pubDate>Tue, 17 Nov 2009 19:22:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9923774</guid><dc:creator>BCLTeam</dc:creator><slash:comments>0</slash:comments><comments>http://blogs.msdn.com/bclteam/comments/9923774.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bclteam/commentrss.aspx?PostID=9923774</wfw:commentRss><description>&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;FONT size=3 face=Calibri&gt;If you’re at &lt;/FONT&gt;&lt;A href="http://microsoftpdc.com/" mce_href="http://microsoftpdc.com/"&gt;&lt;FONT size=3 face=Calibri&gt;PDC&lt;/FONT&gt;&lt;/A&gt;&lt;FONT size=3 face=Calibri&gt; this year and interested in Code Contracts, go watch Mike Barnett and Nikolai Tillmann talk about Code Contracts and Pex (another MSR tool).&amp;nbsp; Their session is called &lt;/FONT&gt;&lt;A href="http://microsoftpdc.com/Sessions/VTL01" mce_href="http://microsoftpdc.com/Sessions/VTL01"&gt;&lt;FONT size=3 face=Calibri&gt;Code Contracts and Pex: Power Charge Your Assertions and Unit Tests&lt;/FONT&gt;&lt;/A&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;.&amp;nbsp; It's Tuesday at 4:30 in 408A.&amp;nbsp; They’ll give you details on some of the latest developments in the Code Contract tools.&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;&amp;nbsp; &lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P style="MARGIN: 0in 0in 0pt" class=MsoNormal&gt;&lt;FONT size=3&gt;&lt;FONT face=Calibri&gt;There will also be a table in the exhibition area where Manuel Fahndrich will have a demo and be able to answer questions.&lt;o:p&gt;&lt;/o:p&gt;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9923774" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/bclteam/archive/tags/Contracts/default.aspx">Contracts</category></item><item><title>What's New in the BCL in .NET 4 Beta 2 [Justin Van Patten]</title><link>http://blogs.msdn.com/bclteam/archive/2009/10/21/what-s-new-in-the-bcl-in-net-4-beta-2-justin-van-patten.aspx</link><pubDate>Wed, 21 Oct 2009 22:58:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9910988</guid><dc:creator>BCLTeam</dc:creator><slash:comments>32</slash:comments><comments>http://blogs.msdn.com/bclteam/comments/9910988.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bclteam/commentrss.aspx?PostID=9910988</wfw:commentRss><description>&lt;P&gt;Visual Studio 2010 and .NET Framework 4 Beta 2 are now available to &lt;A href="http://msdn.microsoft.com/en-us/vstudio/dd582936.aspx" mce_href="http://msdn.microsoft.com/en-us/vstudio/dd582936.aspx"&gt;download&lt;/A&gt;.&amp;nbsp; .NET 4 Beta 2 contains several new BCL features and enhancements in addition to what was included in &lt;A href="http://blogs.msdn.com/bclteam/archive/2009/05/22/what-s-new-in-the-bcl-in-net-4-beta-1-justin-van-patten.aspx" mce_href="http://blogs.msdn.com/bclteam/archive/2009/05/22/what-s-new-in-the-bcl-in-net-4-beta-1-justin-van-patten.aspx"&gt;.NET 4 Beta 1&lt;/A&gt;.&amp;nbsp; Many of these improvements were added in large part due to specific feedback and suggestions reported by customers through &lt;A href="https://connect.microsoft.com/VisualStudio/content/content.aspx?ContentID=14625" mce_href="https://connect.microsoft.com/VisualStudio/content/content.aspx?ContentID=14625"&gt;Microsoft Connect&lt;/A&gt;.&lt;/P&gt;
&lt;H3&gt;Summary of New BCL Functionality in .NET 4 Beta 2&lt;/H3&gt;
&lt;UL&gt;
&lt;LI&gt;Complex Number&lt;/LI&gt;
&lt;LI&gt;Location&lt;/LI&gt;
&lt;LI&gt;IObservable&amp;lt;T&amp;gt;&lt;/LI&gt;
&lt;LI&gt;Stream.CopyTo&lt;/LI&gt;
&lt;LI&gt;Guid.TryParse, Version.TryParse, and Enum.TryParse&amp;lt;T&amp;gt;&lt;/LI&gt;
&lt;LI&gt;Enum.HasFlag&lt;/LI&gt;
&lt;LI&gt;String.Concat and String.Join overloads that take IEnumerable&amp;lt;T&amp;gt;&lt;/LI&gt;
&lt;LI&gt;String.IsNullOrWhiteSpace&lt;/LI&gt;
&lt;LI&gt;Environment.SpecialFolder additions&lt;/LI&gt;
&lt;LI&gt;Environment.Is64BitProcess and Environment.Is64BitOperatingSystem&lt;/LI&gt;
&lt;LI&gt;Path.Combine params support&lt;/LI&gt;
&lt;LI&gt;TimeSpan Globalized Formatting and Parsing&lt;/LI&gt;
&lt;LI&gt;Stopwatch.Restart&lt;/LI&gt;
&lt;LI&gt;StringBuilder.Clear&lt;/LI&gt;
&lt;LI&gt;IntPtr and UIntPtr Addition and Subtraction operators&lt;/LI&gt;
&lt;LI&gt;ServiceInstaller.DelayedAutoStart&lt;/LI&gt;
&lt;LI&gt;ObservableCollection&amp;lt;T&amp;gt; moved to System.dll&lt;/LI&gt;&lt;/UL&gt;
&lt;H3&gt;Complex Number&lt;/H3&gt;
&lt;P&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/system.numerics.complex(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.numerics.complex(VS.100).aspx"&gt;System.Numerics.Complex&lt;/A&gt; represents a complex number comprised of a real number and imaginary number.&amp;nbsp; Complex supports both rectangular coordinates (real and imaginary) and polar coordinates (magnitude and phase measured in radians) and supports arithmetic and trigonometric operations.&amp;nbsp; Complex numbers are used in a number of areas including high-performance computing, graphing and charting, electrical engineering (e.g. Fourier transforms), and other numerical applications.&lt;/P&gt;
&lt;H3&gt;Location&lt;/H3&gt;
&lt;P&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/system.device.location(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.device.location(VS.100).aspx"&gt;System.Device.Location&lt;/A&gt; (which can be found in System.Device.dll) enables .NET applications running on Windows 7 to determine the current geo-location (e.g. latitude/longitude) of the device.&amp;nbsp; Windows 7 supports a number of different location sensors, including GPS devices and WWAN radios, and automatically handles transitioning between different sensors — if multiple sensors are available — to provide the most accurate data for the current situation.&amp;nbsp;.NET applications will be able to use this new API to access the following data (if available): latitude, longitude, altitude, horizontal and vertical accuracy, course, speed, and civic address (i.e. country/region, state/province, city, postal code, street, building, floor level).&amp;nbsp; &lt;SPAN style="COLOR: red; FONT-WEIGHT: bold"&gt;Note that we are planning to make some changes to the shape of the location API between Beta 2 and RC&lt;/SPAN&gt;, so please keep this in mind as you evaluate and use the Beta 2 location API in apps.&amp;nbsp; A separate blog post will provide more details on the planned changes for RC.&lt;/P&gt;
&lt;H3&gt;IObservable&amp;lt;T&amp;gt;&lt;/H3&gt;
&lt;P&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/dd990377(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/dd990377(VS.100).aspx"&gt;System.IObservable&amp;lt;T&amp;gt;&lt;/A&gt; and &lt;A href="http://msdn.microsoft.com/en-us/library/dd783449(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/dd783449(VS.100).aspx"&gt;System.IObserver&amp;lt;T&amp;gt;&lt;/A&gt; provide a general mechanism for push-based notifications and can be used to represent push-based, or &lt;I&gt;observable&lt;/I&gt;, collections.&amp;nbsp; Anyone familiar with design patterns will recognize these interfaces as representations of the well-known observer pattern.&amp;nbsp; IObservable&amp;lt;T&amp;gt; opens up the doors to some exciting new paradigms for event-based and asynchronous programming on .NET.&amp;nbsp; A great example of this is the &lt;A href="http://channel9.msdn.com/shows/Going+Deep/Expert-to-Expert-Brian-Beckman-and-Erik-Meijer-Inside-the-NET-Reactive-Framework-Rx/" mce_href="http://channel9.msdn.com/shows/Going+Deep/Expert-to-Expert-Brian-Beckman-and-Erik-Meijer-Inside-the-NET-Reactive-Framework-Rx/"&gt;Reactive Framework&lt;/A&gt; (RX), which is a library of extension methods (not included as part of .NET 4) that implement the LINQ Standard Query Operators and other useful stream transformation functions for IObservable&amp;lt;T&amp;gt;.&amp;nbsp; F# first-class events also support IObservable&amp;lt;T&amp;gt; and F# includes a library of Observable operators similar to those available in RX.&amp;nbsp; Imagine being able to do LINQ-style queries against events; this is just one of the kinds of things that IObservable&amp;lt;T&amp;gt; enables.&amp;nbsp; To help grasp the power of IObservable&amp;lt;T&amp;gt;, I encourage you to watch the Channel 9 videos of Erik Meijer &lt;A href="http://channel9.msdn.com/shows/Going+Deep/Expert-to-Expert-Brian-Beckman-and-Erik-Meijer-Inside-the-NET-Reactive-Framework-Rx/" mce_href="http://channel9.msdn.com/shows/Going+Deep/Expert-to-Expert-Brian-Beckman-and-Erik-Meijer-Inside-the-NET-Reactive-Framework-Rx/"&gt;introducing RX&lt;/A&gt; and Wes Dyer and Kim Hamilton &lt;A href="http://channel9.msdn.com/shows/Going+Deep/Kim-Hamilton-and-Wes-Dyer-Inside-NET-Rx-and-IObservableIObserver-in-the-BCL-VS-2010/" mce_href="http://channel9.msdn.com/shows/Going+Deep/Kim-Hamilton-and-Wes-Dyer-Inside-NET-Rx-and-IObservableIObserver-in-the-BCL-VS-2010/"&gt;discussing IObservable&amp;lt;T&amp;gt; in the BCL&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;You may be wondering if IObservable&amp;lt;T&amp;gt; is meant to replace events in .NET.&amp;nbsp; The answer is largely “no,” but you certainly could use it in place of events if you wanted to.&amp;nbsp; Events are a well-known mechanism for notification in .NET and are already familiar to .NET developers.&amp;nbsp; As such, they will continue to be the primary mechanism for notification that we recommend for .NET APIs.&amp;nbsp; The great thing about IObservable&amp;lt;T&amp;gt; is that it is fairly straightforward for callers to convert any existing event into an IObservable&amp;lt;T&amp;gt;.&amp;nbsp; RX provides built-in methods that do this conversion and F# has support for this built-in to the language.&amp;nbsp; Stay tuned to this blog for more news about RX in the future.&lt;/P&gt;
&lt;H3&gt;Stream.CopyTo&lt;/H3&gt;
&lt;P&gt;When working with Streams, how many times have you had to write the following boiler-plate code to read from one stream and write the contents to another stream?&lt;/P&gt;&lt;PRE style="BORDER-BOTTOM: silver 1px solid; BORDER-LEFT: silver 1px solid; PADDING-BOTTOM: 10px; PADDING-LEFT: 10px; PADDING-RIGHT: 10px; FONT-FAMILY: 'Courier New'; COLOR: black; MARGIN-LEFT: 20px; FONT-SIZE: 10pt; BORDER-TOP: silver 1px solid; BORDER-RIGHT: silver 1px solid; PADDING-TOP: 10px"&gt;Stream source = ...;
Stream destination = ...;
byte[] buffer = new byte[4096];
int read;
while ((read = source.Read(buffer, 0, buffer.Length)) != 0) {
    destination.Write(buffer, 0, read);
}&lt;/PRE&gt;
&lt;P&gt;In .NET 4, you no longer have to write this code.&amp;nbsp; We’ve added a new &lt;A href="http://msdn.microsoft.com/en-us/library/system.io.stream.copyto(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.io.stream.copyto(VS.100).aspx"&gt;CopyTo&lt;/A&gt; method to Stream that allows you to simply write:&lt;/P&gt;&lt;PRE style="BORDER-BOTTOM: silver 1px solid; BORDER-LEFT: silver 1px solid; PADDING-BOTTOM: 10px; PADDING-LEFT: 10px; PADDING-RIGHT: 10px; FONT-FAMILY: 'Courier New'; COLOR: black; MARGIN-LEFT: 20px; FONT-SIZE: 10pt; BORDER-TOP: silver 1px solid; BORDER-RIGHT: silver 1px solid; PADDING-TOP: 10px"&gt;Stream source = ...;
Stream destination = ...;
source.CopyTo(destination);&lt;/PRE&gt;
&lt;H3&gt;Guid.TryParse, Version.TryParse, and Enum.TryParse&amp;lt;T&amp;gt;&lt;/H3&gt;
&lt;P&gt;We’ve added TryParse to &lt;A href="http://msdn.microsoft.com/en-us/library/system.guid.tryparse(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.guid.tryparse(VS.100).aspx"&gt;System.Guid&lt;/A&gt;, &lt;A href="http://msdn.microsoft.com/en-us/library/system.version.tryparse(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.version.tryparse(VS.100).aspx"&gt;System.Version&lt;/A&gt;, and &lt;A href="http://msdn.microsoft.com/en-us/library/dd991876(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/dd991876(VS.100).aspx"&gt;System.Enum&lt;/A&gt;.&amp;nbsp; Enum.TryParse is generic, a nice improvement over the existing non-generic Parse method, which leads to much cleaner code.&lt;/P&gt;
&lt;P&gt;On previous versions of .NET, to parse an enum value, you’d write something like this:&lt;/P&gt;&lt;PRE style="BORDER-BOTTOM: silver 1px solid; BORDER-LEFT: silver 1px solid; PADDING-BOTTOM: 10px; PADDING-LEFT: 10px; PADDING-RIGHT: 10px; FONT-FAMILY: 'Courier New'; COLOR: black; MARGIN-LEFT: 20px; FONT-SIZE: 10pt; BORDER-TOP: silver 1px solid; BORDER-RIGHT: silver 1px solid; PADDING-TOP: 10px"&gt;try {
    string value = Console.ReadLine();
    FileOptions fo = (FileOptions)Enum.Parse(typeof(FileOptions), value);
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;// Success
}
catch {
    // Error
}&lt;/PRE&gt;
&lt;P&gt;On .NET 4, you can use the new generic TryParse method:&lt;/P&gt;&lt;PRE style="BORDER-BOTTOM: silver 1px solid; BORDER-LEFT: silver 1px solid; PADDING-BOTTOM: 10px; PADDING-LEFT: 10px; PADDING-RIGHT: 10px; FONT-FAMILY: 'Courier New'; COLOR: black; MARGIN-LEFT: 20px; FONT-SIZE: 10pt; BORDER-TOP: silver 1px solid; BORDER-RIGHT: silver 1px solid; PADDING-TOP: 10px"&gt;string value = Console.ReadLine();
FileOptions fo;
if (Enum.TryParse(value, out fo)) {
    // Success
}&lt;/PRE&gt;
&lt;H3&gt;Enum.HasFlag&lt;/H3&gt;
&lt;P&gt;We’ve added a &lt;A href="http://msdn.microsoft.com/en-us/library/system.enum.hasflag(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.enum.hasflag(VS.100).aspx"&gt;new convenience method to System.Enum&lt;/A&gt; that makes it super easy to determine if a flag is set on a particular Flags enum, without having to remember how to use the bitwise operators.&amp;nbsp; This also allows for more readable code.&lt;/P&gt;
&lt;P&gt;In VB:&lt;/P&gt;&lt;PRE style="BORDER-BOTTOM: silver 1px solid; BORDER-LEFT: silver 1px solid; PADDING-BOTTOM: 10px; PADDING-LEFT: 10px; PADDING-RIGHT: 10px; FONT-FAMILY: 'Courier New'; COLOR: black; MARGIN-LEFT: 20px; FONT-SIZE: 10pt; BORDER-TOP: silver 1px solid; BORDER-RIGHT: silver 1px solid; PADDING-TOP: 10px"&gt;Dim cm As ConsoleModifiers = ConsoleModifiers.Alt Or ConsoleModifiers.Shift
Dim hasAlt1 As Boolean = (cm And ConsoleModifiers.Alt) = ConsoleModifiers.Alt ' using bitwise operators
Dim hasAlt2 As Boolean = cm.HasFlag(ConsoleModifiers.Alt) ' using HasFlag&lt;/PRE&gt;
&lt;P&gt;In C#:&lt;/P&gt;&lt;PRE style="BORDER-BOTTOM: silver 1px solid; BORDER-LEFT: silver 1px solid; PADDING-BOTTOM: 10px; PADDING-LEFT: 10px; PADDING-RIGHT: 10px; FONT-FAMILY: 'Courier New'; COLOR: black; MARGIN-LEFT: 20px; FONT-SIZE: 10pt; BORDER-TOP: silver 1px solid; BORDER-RIGHT: silver 1px solid; PADDING-TOP: 10px"&gt;ConsoleModifiers cm = ConsoleModifiers.Alt | ConsoleModifiers.Shift;
bool hasAlt1 = (cm &amp;amp; ConsoleModifiers.Alt) == ConsoleModifiers.Alt; // using bitwise operators
bool hasAlt2 = cm.HasFlag(ConsoleModifiers.Alt); // using HasFlag&lt;/PRE&gt;
&lt;H3&gt;String.Concat and String.Join overloads that take IEnumerable&amp;lt;T&amp;gt;&lt;/H3&gt;
&lt;P&gt;We’ve added new overloads of &lt;A href="http://msdn.microsoft.com/en-us/library/dd784338(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/dd784338(VS.100).aspx"&gt;String.Concat&lt;/A&gt; and &lt;A href="http://msdn.microsoft.com/en-us/library/dd783876(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/dd783876(VS.100).aspx"&gt;String.Join&lt;/A&gt; that take IEnumerable&amp;lt;T&amp;gt;, adding to the existing overloads that take arrays.&amp;nbsp; This means you can pass any collection that implements IEnumerable&amp;lt;T&amp;gt; to these APIs without having to first convert the collection into an array.&amp;nbsp; We’ve also added &lt;A href="http://msdn.microsoft.com/en-us/library/57a79xd0(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/57a79xd0(VS.100).aspx"&gt;“params” support to the existing array-based String.Join overload&lt;/A&gt;, which allows you to write more succinct code.&amp;nbsp; In C#:&lt;/P&gt;&lt;PRE style="BORDER-BOTTOM: silver 1px solid; BORDER-LEFT: silver 1px solid; PADDING-BOTTOM: 10px; PADDING-LEFT: 10px; PADDING-RIGHT: 10px; FONT-FAMILY: 'Courier New'; COLOR: black; MARGIN-LEFT: 20px; FONT-SIZE: 10pt; BORDER-TOP: silver 1px solid; BORDER-RIGHT: silver 1px solid; PADDING-TOP: 10px"&gt;String.Join(", ", new string[] { "A", "B", "C", "D" }); // you used to have to write this
String.Join(", ", "A", "B", "C", "D"); // now you can write this&lt;/PRE&gt;
&lt;H3&gt;String.IsNullOrWhiteSpace&lt;/H3&gt;
&lt;P&gt;This &lt;A href="http://msdn.microsoft.com/en-us/library/system.string.isnullorwhitespace(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.string.isnullorwhitespace(VS.100).aspx"&gt;new convenience method&lt;/A&gt; is similar to the existing IsNullOrEmpty method, but in addition to checking if the string is null or empty, it also checks to see if the string only consists of white-space characters, as defined by Char.IsWhiteSpace.&amp;nbsp; It works great for Code Contract preconditions.&lt;/P&gt;
&lt;H3&gt;Environment.SpecialFolder additions&lt;/H3&gt;
&lt;P&gt;We’ve added a number of new values to the &lt;A href="http://msdn.microsoft.com/en-us/library/system.environment.specialfolder(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.environment.specialfolder(VS.100).aspx"&gt;Environment.SpecialFolder&lt;/A&gt; enum:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;AdminTools&lt;/LI&gt;
&lt;LI&gt;CDBurning&lt;/LI&gt;
&lt;LI&gt;CommonAdminTools&lt;/LI&gt;
&lt;LI&gt;CommonDesktopDirectory&lt;/LI&gt;
&lt;LI&gt;CommonDocuments&lt;/LI&gt;
&lt;LI&gt;CommonMusic&lt;/LI&gt;
&lt;LI&gt;CommonOemLinks&lt;/LI&gt;
&lt;LI&gt;CommonPictures&lt;/LI&gt;
&lt;LI&gt;CommonProgramFilesX86&lt;/LI&gt;
&lt;LI&gt;CommonPrograms&lt;/LI&gt;
&lt;LI&gt;CommonStartMenu&lt;/LI&gt;
&lt;LI&gt;CommonStartup&lt;/LI&gt;
&lt;LI&gt;CommonTemplates&lt;/LI&gt;
&lt;LI&gt;CommonVideos&lt;/LI&gt;
&lt;LI&gt;Fonts&lt;/LI&gt;
&lt;LI&gt;LocalizedResources&lt;/LI&gt;
&lt;LI&gt;MyVideos&lt;/LI&gt;
&lt;LI&gt;NetworkShortcuts&lt;/LI&gt;
&lt;LI&gt;PrinterShortcuts&lt;/LI&gt;
&lt;LI&gt;ProgramFilesX86&lt;/LI&gt;
&lt;LI&gt;Resources&lt;/LI&gt;
&lt;LI&gt;SystemX86&lt;/LI&gt;
&lt;LI&gt;Templates&lt;/LI&gt;
&lt;LI&gt;UserProfile&lt;/LI&gt;
&lt;LI&gt;Windows&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;We’ve also added a new overload to &lt;A href="http://msdn.microsoft.com/en-us/library/dd992682(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/dd992682(VS.100).aspx"&gt;Environment.GetFolderPath&lt;/A&gt; that takes a new &lt;A href="http://msdn.microsoft.com/en-us/library/system.environment.specialfolderoption(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.environment.specialfolderoption(VS.100).aspx"&gt;SpecialFolderOption&lt;/A&gt; enum, allowing you to specify some additional options, such as “Create” (to create the directory if it doesn’t exist) and “DoNotVerify” (to just return the path without checking if it exists, which can help reduce lag time if the directory is on a network share).&lt;/P&gt;
&lt;H3&gt;Environment.Is64BitProcess and Environment.Is64BitOperatingSystem&lt;/H3&gt;
&lt;P&gt;These new convenience APIs make it easy to determine the bitness of the current process and operating system.&amp;nbsp; &lt;A href="http://msdn.microsoft.com/en-us/library/system.environment.is64bitprocess(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.environment.is64bitprocess(VS.100).aspx"&gt;Environment.Is64BitProcess&lt;/A&gt; is equivalent to calling IntPtr.Size == 8.&amp;nbsp; &lt;A href="http://msdn.microsoft.com/en-us/library/system.environment.is64bitoperatingsystem(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.environment.is64bitoperatingsystem(VS.100).aspx"&gt;Environment.Is64BitOperatingSystem&lt;/A&gt; will tell you if the underlying OS is 64-bit.&amp;nbsp; Note that it is possible for Environment.Is64BitProcess to return false and Environment.Is64BitOperatingSystem to return true if the process is a 32-bit process running on a 64-bit operating system under &lt;A href="http://msdn.microsoft.com/en-us/library/aa384249(VS.85).aspx" mce_href="http://msdn.microsoft.com/en-us/library/aa384249(VS.85).aspx"&gt;WOW64&lt;/A&gt;.&lt;/P&gt;
&lt;H3&gt;Path.Combine params support&lt;/H3&gt;
&lt;P&gt;Have you ever had to nest calls to &lt;A href="http://msdn.microsoft.com/en-us/library/system.io.path.combine(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.io.path.combine(VS.100).aspx"&gt;Path.Combine&lt;/A&gt; like this:&lt;/P&gt;&lt;PRE style="BORDER-BOTTOM: silver 1px solid; BORDER-LEFT: silver 1px solid; PADDING-BOTTOM: 10px; PADDING-LEFT: 10px; PADDING-RIGHT: 10px; FONT-FAMILY: 'Courier New'; COLOR: black; MARGIN-LEFT: 20px; FONT-SIZE: 10pt; BORDER-TOP: silver 1px solid; BORDER-RIGHT: silver 1px solid; PADDING-TOP: 10px"&gt;Path.Combine("dir1", Path.Combine("dir2", Path.Combine("dir3", "dir4")));&lt;/PRE&gt;
&lt;P&gt;With .NET 4, you can simply write:&lt;/P&gt;&lt;PRE style="BORDER-BOTTOM: silver 1px solid; BORDER-LEFT: silver 1px solid; PADDING-BOTTOM: 10px; PADDING-LEFT: 10px; PADDING-RIGHT: 10px; FONT-FAMILY: 'Courier New'; COLOR: black; MARGIN-LEFT: 20px; FONT-SIZE: 10pt; BORDER-TOP: silver 1px solid; BORDER-RIGHT: silver 1px solid; PADDING-TOP: 10px"&gt;Path.Combine("dir1", "dir2", "dir3", "dir4");&lt;/PRE&gt;
&lt;H3&gt;TimeSpan Globalized Formatting and Parsing&lt;/H3&gt;
&lt;P&gt;In previous versions of .NET, TimeSpan only supported a single culture-agnostic format for formatting and parsing.&amp;nbsp; This meant if you called ToString on a French machine the output would not match culture settings, making the application appear not to be globalized.&amp;nbsp; This is often noticeable in apps that display results from SQL databases that use the frequently used Time column type, because SQL’s Time maps to TimeSpan in .NET.&amp;nbsp; For example:&lt;/P&gt;&lt;PRE style="BORDER-BOTTOM: silver 1px solid; BORDER-LEFT: silver 1px solid; PADDING-BOTTOM: 10px; PADDING-LEFT: 10px; PADDING-RIGHT: 10px; FONT-FAMILY: 'Courier New'; COLOR: black; MARGIN-LEFT: 20px; FONT-SIZE: 10pt; BORDER-TOP: silver 1px solid; BORDER-RIGHT: silver 1px solid; PADDING-TOP: 10px"&gt;Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-FR");
Console.WriteLine(new TimeSpan(0, 1, 1, 1, 1));
Console.WriteLine(12.34);&lt;/PRE&gt;
&lt;P&gt;Output:&lt;/P&gt;&lt;PRE style="BORDER-BOTTOM: silver 1px solid; BORDER-LEFT: silver 1px solid; PADDING-BOTTOM: 10px; PADDING-LEFT: 10px; PADDING-RIGHT: 10px; FONT-FAMILY: 'Courier New'; COLOR: black; MARGIN-LEFT: 20px; FONT-SIZE: 10pt; BORDER-TOP: silver 1px solid; BORDER-RIGHT: silver 1px solid; PADDING-TOP: 10px"&gt;01:01:01&lt;SPAN style="BACKGROUND-COLOR: #ffff00"&gt;.&lt;/SPAN&gt;0010000
12&lt;SPAN style="BACKGROUND-COLOR: #ffff00"&gt;,&lt;/SPAN&gt;34&lt;/PRE&gt;
&lt;P&gt;The output from TimeSpan.ToString is a culture-agnostic format so it uses a '.' as the decimal separator, whereas Double uses ',' based on the current culture.&lt;/P&gt;
&lt;P&gt;In .NET 4, System.TimeSpan now supports formatting and parsing based on culture settings via new overloads of &lt;A href="http://msdn.microsoft.com/en-us/library/dd992632(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/dd992632(VS.100).aspx"&gt;ToString&lt;/A&gt;, &lt;A href="http://msdn.microsoft.com/en-us/library/dd783872(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/dd783872(VS.100).aspx"&gt;Parse&lt;/A&gt;, and &lt;A href="http://msdn.microsoft.com/en-us/library/dd992769(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/dd992769(VS.100).aspx"&gt;TryParse&lt;/A&gt;, and new &lt;A href="http://msdn.microsoft.com/en-us/library/system.timespan.parseexact(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.timespan.parseexact(VS.100).aspx"&gt;ParseExact&lt;/A&gt; and &lt;A href="http://msdn.microsoft.com/en-us/library/system.timespan.tryparseexact(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.timespan.tryparseexact(VS.100).aspx"&gt;TryParseExact&lt;/A&gt; methods.&amp;nbsp; The default ToString overload still behaves the same for backwards compatibility, outputting a constant, culture-agnostic format, but the new overloads allow you to specify additional culture-sensitive formats.&amp;nbsp; You can pass the “g” format (general format) to the new ToString overload to specify a culture-sensitive format:&lt;/P&gt;&lt;PRE style="BORDER-BOTTOM: silver 1px solid; BORDER-LEFT: silver 1px solid; PADDING-BOTTOM: 10px; PADDING-LEFT: 10px; PADDING-RIGHT: 10px; FONT-FAMILY: 'Courier New'; COLOR: black; MARGIN-LEFT: 20px; FONT-SIZE: 10pt; BORDER-TOP: silver 1px solid; BORDER-RIGHT: silver 1px solid; PADDING-TOP: 10px"&gt;Thread.CurrentThread.CurrentCulture = new CultureInfo("fr-FR");
Console.WriteLine(new TimeSpan(0, 1, 1, 1, 1)&lt;SPAN style="BACKGROUND-COLOR: #ffff00"&gt;.ToString("g")&lt;/SPAN&gt;);
Console.WriteLine(12.34);&lt;/PRE&gt;
&lt;P&gt;Output:&lt;/P&gt;&lt;PRE style="BORDER-BOTTOM: silver 1px solid; BORDER-LEFT: silver 1px solid; PADDING-BOTTOM: 10px; PADDING-LEFT: 10px; PADDING-RIGHT: 10px; FONT-FAMILY: 'Courier New'; COLOR: black; MARGIN-LEFT: 20px; FONT-SIZE: 10pt; BORDER-TOP: silver 1px solid; BORDER-RIGHT: silver 1px solid; PADDING-TOP: 10px"&gt;01:01:01&lt;SPAN style="BACKGROUND-COLOR: #ffff00"&gt;,&lt;/SPAN&gt;0010000
12&lt;SPAN style="BACKGROUND-COLOR: #ffff00"&gt;,&lt;/SPAN&gt;34&lt;/PRE&gt;
&lt;P&gt;With this new format, the output from TimeSpan is in line with the user’s culture settings.&lt;/P&gt;
&lt;H3&gt;Stopwatch.Restart&lt;/H3&gt;
&lt;P&gt;This is a &lt;A href="http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.restart(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch.restart(VS.100).aspx"&gt;new convenience method&lt;/A&gt; that is equivalent to calling Stopwatch.Reset followed by Stopwatch.Start.&lt;/P&gt;
&lt;H3&gt;StringBuilder.Clear&lt;/H3&gt;
&lt;P&gt;In previous versions of .NET, you could clear StringBuilder by setting the Length property to 0.&amp;nbsp; This isn’t very discoverable, so we’ve added &lt;A href="http://msdn.microsoft.com/en-us/library/system.text.stringbuilder.clear(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.text.stringbuilder.clear(VS.100).aspx"&gt;StringBuilder.Clear&lt;/A&gt; as a more discoverable equivalent.&lt;/P&gt;
&lt;H3&gt;IntPtr and UIntPtr Addition and Subtraction operators&lt;/H3&gt;
&lt;P&gt;Adding an offset to an IntPtr or UIntPtr can be error prone and often introduces subtle bugs on 64-bit machines if not done correctly.&amp;nbsp; .NET 4 includes &lt;A href="http://msdn.microsoft.com/en-us/library/system.intptr.op_addition(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.intptr.op_addition(VS.100).aspx"&gt;addition&lt;/A&gt; and &lt;A href="http://msdn.microsoft.com/en-us/library/system.intptr.op_subtraction(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.intptr.op_subtraction(VS.100).aspx"&gt;subtraction&lt;/A&gt; operators on these types, along with &lt;A href="http://msdn.microsoft.com/en-us/library/system.intptr.add(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.intptr.add(VS.100).aspx"&gt;Add&lt;/A&gt; and &lt;A href="http://msdn.microsoft.com/en-us/library/system.intptr.subtract(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.intptr.subtract(VS.100).aspx"&gt;Subtract&lt;/A&gt; methods, to help prevent these kinds of errors.&lt;/P&gt;
&lt;H3&gt;ServiceInstaller.DelayedAutoStart&lt;/H3&gt;
&lt;P&gt;.NET-based services that start automatically can now set a new &lt;A href="http://msdn.microsoft.com/en-us/library/system.serviceprocess.serviceinstaller.delayedautostart(VS.100).aspx" mce_href="http://msdn.microsoft.com/en-us/library/system.serviceprocess.serviceinstaller.delayedautostart(VS.100).aspx"&gt;DelayedAutoStart&lt;/A&gt; property to true (recommended), which will delay auto-starting the service until after other auto-start services are started plus a short delay to improve system boot performance when running on Vista or greater.&lt;/P&gt;
&lt;H3&gt;ObservableCollection&amp;lt;T&amp;gt; moved to System.dll&lt;/H3&gt;
&lt;P&gt;We’ve type-forward System.Collections.ObjectModel.ObservableCollection&amp;lt;T&amp;gt;, System.Collections.ObjectModel.ReadOnlyObservableCollection&amp;lt;T&amp;gt;, and System.Collections.Specialized.INotifyCollectionChanged from WindowsBase.dll (a WPF assembly) to System.dll.&amp;nbsp; This allows you to use these collections without taking a dependency on a WPF assembly and enables a cleaner separation between model and view.&lt;/P&gt;
&lt;P&gt;We hope you like what we’ve added to the BCL in .NET 4 Beta 2.&amp;nbsp; &lt;A href="http://msdn.microsoft.com/en-us/vstudio/dd582936.aspx" mce_href="http://msdn.microsoft.com/en-us/vstudio/dd582936.aspx"&gt;Download Visual Studio 2010 and .NET 4 Beta 2&lt;/A&gt; today.&amp;nbsp; Be sure to &lt;A href="https://connect.microsoft.com/VisualStudio/content/content.aspx?ContentID=14625" mce_href="https://connect.microsoft.com/VisualStudio/content/content.aspx?ContentID=14625"&gt;let us know what you think and report any bugs you run into&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;&lt;B&gt;Update:&lt;/B&gt; Added links to the MSDN documentation for each feature throughout. We'd appreciate any feedback on the docs as well. Also updated ServiceInstaller with the correct name (fixed from ServiceProcessInstaller).&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9910988" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/bclteam/archive/tags/News/default.aspx">News</category><category domain="http://blogs.msdn.com/bclteam/archive/tags/.NET+Framework+4/default.aspx">.NET Framework 4</category></item><item><title>Code Contracts CLR Inside Out Article [Melitta Andersen]</title><link>http://blogs.msdn.com/bclteam/archive/2009/08/21/code-contracts-clr-inside-out-article-melitta-andersen.aspx</link><pubDate>Fri, 21 Aug 2009 22:26:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9879152</guid><dc:creator>BCLTeam</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/bclteam/comments/9879152.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bclteam/commentrss.aspx?PostID=9879152</wfw:commentRss><description>&lt;P&gt;&lt;A href="http://msdn.microsoft.com/en-us/magazine/cc157190.aspx" mce_href="http://msdn.microsoft.com/en-us/magazine/cc157190.aspx"&gt;&lt;IMG border=0 hspace=12 alt="MSDN Magazine" align=right src="http://i.msdn.microsoft.com/dd365188.0809.gif" width=150 height=197 mce_src="http://i.msdn.microsoft.com/dd365188.0809.gif"&gt;&lt;/A&gt;In the &lt;A href="http://msdn.microsoft.com/en-us/magazine/cc157190.aspx" mce_href="http://msdn.microsoft.com/en-us/magazine/cc157190.aspx"&gt;August 2009 issue&lt;/A&gt; of &lt;I&gt;&lt;A href="http://msdn.microsoft.com/en-us/magazine/default.aspx" mce_href="http://msdn.microsoft.com/en-us/magazine/default.aspx"&gt;MSDN Magazine&lt;/A&gt;&lt;/I&gt;, we have a &lt;A href="http://msdn.microsoft.com/en-us/magazine/cc501040.aspx" mce_href="http://msdn.microsoft.com/en-us/magazine/cc501040.aspx"&gt;CLR Inside Out&lt;/A&gt; article on the BCL’s experience with &lt;A href="http://msdn.microsoft.com/en-us/magazine/ee236408.aspx" mce_href="http://msdn.microsoft.com/en-us/magazine/ee236408.aspx"&gt;adding code contracts to the BCL&lt;/A&gt;.&amp;nbsp; It includes both an overview of the feature, as well as a few best practices we came up with as we went along.&amp;nbsp; For regular readers of this blog who have read the previous posts on code contracts and followed all of the links, this article probably won’t provide much new information with the overview, but some of the tips will likely be useful if you plan on using code contracts.&lt;/P&gt;
&lt;P&gt;As always, comments and questions are welcome here or on the &lt;A href="http://social.msdn.microsoft.com/Forums/en-US/codecontracts/threads/" mce_href="http://social.msdn.microsoft.com/Forums/en-US/codecontracts/threads/"&gt;Code Contracts forum&lt;/A&gt;.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9879152" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/bclteam/archive/tags/.NET+Framework+4/default.aspx">.NET Framework 4</category><category domain="http://blogs.msdn.com/bclteam/archive/tags/Contracts/default.aspx">Contracts</category></item><item><title>Free LiveMeeting with the CLR Team on CLR 4 [Justin Van Patten]</title><link>http://blogs.msdn.com/bclteam/archive/2009/07/14/free-livemeeting-with-the-clr-team-on-clr-4-justin-van-patten.aspx</link><pubDate>Tue, 14 Jul 2009 21:55:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9833409</guid><dc:creator>BCLTeam</dc:creator><slash:comments>4</slash:comments><comments>http://blogs.msdn.com/bclteam/comments/9833409.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bclteam/commentrss.aspx?PostID=9833409</wfw:commentRss><description>&lt;P&gt;Join the CLR team for a free interactive LiveMeeting session / conference call on What's New in CLR 4 on Friday, July 17, 2009.&amp;nbsp; We'll specifically be covering Garbage Collection, NGEN, and Performance.&lt;/P&gt;
&lt;P&gt;Here are&amp;nbsp;the details:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Date:&lt;/STRONG&gt; Friday, July 17&lt;BR&gt;&lt;STRONG&gt;Time:&lt;/STRONG&gt; 10:00AM-11:00AM PST&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;LiveMeeting: &lt;BR&gt;&lt;/STRONG&gt;&lt;A href="https://www.livemeeting.com/cc/0000000379_103/join?id=76P755&amp;amp;role=attend&amp;amp;pw=p%2C%2Fzk2K%7CM"&gt;https://www.livemeeting.com/cc/0000000379_103/join?id=76P755&amp;amp;role=attend&amp;amp;pw=p%2C%2Fzk2K%7CM&lt;/A&gt; &lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Conf call:&lt;/STRONG&gt; &lt;BR&gt;Toll Free: 866-500-6738 &lt;BR&gt;Toll: 203-480-8000 &lt;BR&gt;Participant code: #198585&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9833409" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/bclteam/archive/tags/News/default.aspx">News</category><category domain="http://blogs.msdn.com/bclteam/archive/tags/.NET+Framework+4/default.aspx">.NET Framework 4</category></item><item><title>Building Tuple [Matt Ellis]</title><link>http://blogs.msdn.com/bclteam/archive/2009/07/07/building-tuple-matt-ellis.aspx</link><pubDate>Wed, 08 Jul 2009 04:47:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9823361</guid><dc:creator>BCLTeam</dc:creator><slash:comments>28</slash:comments><comments>http://blogs.msdn.com/bclteam/comments/9823361.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bclteam/commentrss.aspx?PostID=9823361</wfw:commentRss><description>&lt;P&gt;&lt;A href="http://msdn.microsoft.com/en-us/magazine/dd942829.aspx" mce_href="http://msdn.microsoft.com/en-us/magazine/dd942829.aspx"&gt;&lt;IMG style="BORDER-RIGHT-WIDTH: 0px; FLOAT: right; BORDER-TOP-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px" alt="MSDN Magazine" src="http://i.msdn.microsoft.com/dd767791.0709Cover(en-us,MSDN.10).jpg" width=182 height=239 mce_src="http://i.msdn.microsoft.com/dd767791.0709Cover(en-us,MSDN.10).jpg"&gt;&lt;/A&gt;For readers who are interested in the work that goes into designing a feature, I wrote an article for MSDN Magazine that appears in this month’s issue.&amp;nbsp; Check out &lt;A href="http://msdn.microsoft.com/en-us/magazine/dd942829.aspx" mce_href="http://msdn.microsoft.com/en-us/magazine/dd942829.aspx"&gt;CLR Inside Out: Building Tuple&lt;/A&gt; which introduces the new Tuple type as well as discusses the design work we did behind it.&lt;/P&gt;
&lt;P&gt;I’d love to hear feedback on what you think about the article and if you’d like to see more behind the scenes design articles in the future.&amp;nbsp; I’d also love to answer any questions about the design or why we made the decisions we did.&lt;/P&gt;
&lt;P&gt;Also, there is one change we are thinking about making between Beta 1 and Beta 2 around tuple.&amp;nbsp; In Beta 1 we have a factory method, Tuple.Create, which builds tuples and has some nice type inference properties.&amp;nbsp; In Beta 1 the overload of this method which takes eight arguments requires that the last element is a tuple and builds an extended tuple.&amp;nbsp; For example:&lt;/P&gt;
&lt;P&gt;Tuple.Create(1, 2, 3, 4, 5, 6, 7, Tuple.Create(8));&lt;/P&gt;
&lt;P&gt;Will build an eight element tuple that looks like [1, 2, 3, 4, 5, 6, 7, 8].&lt;/P&gt;
&lt;P&gt;Tuple.Create(1, 2, 3, 4, 5, 6, 7, Tuple.Create(8, 9));&lt;/P&gt;
&lt;P&gt;Will build a nine element tuple that looks like [1, 2, 3, 4, 5, 6, 7, 8, 9]&lt;/P&gt;
&lt;P&gt;For Beta 2 we hope to change this so that eight argument version of Tuple.Create always builds an eight element tuple.&amp;nbsp; In this case:&lt;/P&gt;
&lt;P&gt;Tuple.Create(1, 2, 3, 4, 5, 6, 7, 8);&lt;/P&gt;
&lt;P&gt;Will build an eight element tuple that looks like [1, 2, 3, 4, 5, 6, 7, 8]&lt;/P&gt;
&lt;P&gt;Tuple.Create(1, 2, 3, 4, 5, 6, 7, Tuple.Create(8));&lt;/P&gt;
&lt;P&gt;Will build an eight element tuple that looks like [1, 2, 3, 4, 5, 6, 7, [8]].&lt;/P&gt;
&lt;P&gt;Tuple.Create(1, 2, 3, 4, 5, 6, 7, Tuple.Create(8, 9));&lt;/P&gt;
&lt;P&gt;Will build an element tuple that looks like [1, 2, 3, 4, 5, 6, 7, [8, 9]]&lt;/P&gt;
&lt;P&gt;If you want to build tuples with more than eight elements and your language doesn’t have special tuple syntax, you’ll have to use the Tuple constructors directly.&amp;nbsp; If we see lots of people doing this we’ll add more overloads to Tuple.Create.&lt;/P&gt;
&lt;P&gt;Thanks for reading; I hope everyone enjoys the article and look forward to your questions and comments.&amp;nbsp; Cheers!&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9823361" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/bclteam/archive/tags/.NET+Framework+4/default.aspx">.NET Framework 4</category><category domain="http://blogs.msdn.com/bclteam/archive/tags/Tuples/default.aspx">Tuples</category></item><item><title>What's New in Globalization in .NET 4 Beta 1 [Melitta Andersen]</title><link>http://blogs.msdn.com/bclteam/archive/2009/06/08/what-s-new-in-globalization-in-net-4-beta-1-melitta-andersen.aspx</link><pubDate>Mon, 08 Jun 2009 18:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9707823</guid><dc:creator>BCLTeam</dc:creator><slash:comments>2</slash:comments><comments>http://blogs.msdn.com/bclteam/comments/9707823.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bclteam/commentrss.aspx?PostID=9707823</wfw:commentRss><description>&lt;P&gt;In Justin’s recent post outlining &lt;A href="http://blogs.msdn.com/bclteam/archive/2009/05/22/what-s-new-in-the-bcl-in-net-4-beta-1-justin-van-patten.aspx" mce_href="http://blogs.msdn.com/bclteam/archive/2009/05/22/what-s-new-in-the-bcl-in-net-4-beta-1-justin-van-patten.aspx"&gt;What’s New in the BCL in .NET 4 Beta 1&lt;/A&gt;, there were only a few lines about the globalization updates.&amp;nbsp; That’s because Mohamed Elgazzar was working on a more extensive document which provides details about the extent of the changes and additions to that space.&amp;nbsp; I’m happy to say that the document is now live.&amp;nbsp; Please check it out here: &lt;A href="http://msdn.microsoft.com/en-us/netframework/dd890508.aspx" mce_href="http://msdn.microsoft.com/en-us/netframework/dd890508.aspx"&gt;Microsoft .NET Framework 4 (Beta 1): What is New in Globalization&lt;/A&gt;.&amp;nbsp; &lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9707823" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/bclteam/archive/tags/Globalization/default.aspx">Globalization</category><category domain="http://blogs.msdn.com/bclteam/archive/tags/News/default.aspx">News</category><category domain="http://blogs.msdn.com/bclteam/archive/tags/.NET+Framework+4/default.aspx">.NET Framework 4</category></item><item><title>What's New in the BCL in .NET 4 Beta 1 [Justin Van Patten]</title><link>http://blogs.msdn.com/bclteam/archive/2009/05/22/what-s-new-in-the-bcl-in-net-4-beta-1-justin-van-patten.aspx</link><pubDate>Sat, 23 May 2009 04:31:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9636439</guid><dc:creator>BCLTeam</dc:creator><slash:comments>27</slash:comments><comments>http://blogs.msdn.com/bclteam/comments/9636439.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bclteam/commentrss.aspx?PostID=9636439</wfw:commentRss><description>&lt;P&gt;Visual Studio 2010 and .NET Framework 4 Beta 1&amp;nbsp;are available for &lt;A href="http://go.microsoft.com/fwlink/?LinkId=151799" mce_href="http://go.microsoft.com/fwlink/?LinkId=151799"&gt;download&lt;/A&gt;.&amp;nbsp; .NET 4 Beta 1 contains new functionality and improvements throughout the framework.&amp;nbsp; In this post I’ll discuss the changes specific to the BCL.&lt;/P&gt;
&lt;P&gt;Many of the features listed below were previously announced when we released the .NET Framework 4 CTP back in November of last year.&amp;nbsp; I’ve included these features again below for completeness.&amp;nbsp; New functionality in Beta 1 that wasn’t present in the CTP is denoted as such.&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;B&gt;Code Contracts&lt;/B&gt;&lt;BR&gt;System.Diagnostics.Contracts provides a language-agnostic way to express coding assumptions in .NET programs.&amp;nbsp; The contracts take the form of pre-conditions, post-conditions, and object invariants.&amp;nbsp; Contracts act as checked documentation of your external and internal APIs.&amp;nbsp; The contracts are used to improve testing via runtime checking, enable static contract verification, and could be used in documentation generation.&amp;nbsp; We partnered with Microsoft Research to deliver this feature in .NET 4.&amp;nbsp; More information and links to the tools are available on the &lt;A href="http://msdn.microsoft.com/en-us/devlabs/dd491992.aspx" mce_href="http://msdn.microsoft.com/en-us/devlabs/dd491992.aspx"&gt;Code Contracts DevLabs site&lt;/A&gt;.&lt;BR&gt;&lt;I&gt;&lt;SPAN style="COLOR: #cc0000"&gt;(new in Beta 1)&lt;/SPAN&gt;&lt;/I&gt; The latest release of the tools works with Visual Studio 2010 Beta 1.&lt;BR&gt;&lt;BR&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;B&gt;Parallel Extensions&lt;/B&gt;&lt;BR&gt;The Parallel Computing Platform team worked with us to add the Task Parallel Library (TPL), Coordination Data Structures, and Parallel LINQ (PLINQ) to the BCL in .NET 4.&amp;nbsp; This includes an improved ThreadPool scheduling algorithm for tasks, Task and Task&amp;lt;T&amp;gt;, the static Parallel class, concurrent collections in System.Collections.Concurrent, and other coordination data structures such as Lazy&amp;lt;T&amp;gt;, CountdownEvent, Barrier, SemaphoreSlim, SpinLock, SpinWait, and ManualResetEventSlim.&amp;nbsp; More information is available over at the &lt;A href="http://blogs.msdn.com/pfxteam/default.aspx" mce_href="http://blogs.msdn.com/pfxteam/default.aspx"&gt;PFX team’s blog&lt;/A&gt;.&lt;BR&gt;&lt;BR&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;B&gt;BigInteger&lt;/B&gt;&lt;BR&gt;System.Numerics.BigInteger is an arbitrary-precision integer data type.&amp;nbsp; BigInteger supports all the standard integer operations, including bit manipulation.&amp;nbsp; It can be used from any .NET language, and some of the new .NET languages—such as F# and IronPython—have support built-in to the language.&amp;nbsp; We partnered with the &lt;A href="http://code.msdn.microsoft.com/solverfoundation" mce_href="http://code.msdn.microsoft.com/solverfoundation"&gt;Microsoft Solver Foundation&lt;/A&gt; team to deliver this in .NET 4.&amp;nbsp; &lt;BR&gt;&lt;BR&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;B&gt;Variance annotations &lt;/B&gt;&lt;I&gt;&lt;SPAN style="COLOR: #cc0000"&gt;(new in Beta 1)&lt;/SPAN&gt;&lt;/I&gt;&lt;BR&gt;C# and VB now support safe co- and contra-variance for generic interface and delegate types.&amp;nbsp; Co-variance means that a generic of a type, e.g. an IEnumerable&amp;lt;String&amp;gt;, can be treated as a generic of any supertype, e.g. an IEnumerable&amp;lt;Object&amp;gt;.&amp;nbsp; Contra-variance means that a generic of a type, e.g. an Action&amp;lt;Object&amp;gt;, can be treated as a generic of a subtype, e.g. an Action&amp;lt;String&amp;gt;.&amp;nbsp; In C#, co-variance is annotated with the “out” keyword and contra-variance is annotated with the “in” keyword.&amp;nbsp; VB has similar “In” and “Out” keywords.&amp;nbsp; We’ve annotated several interfaces and delegates in the BCL for variance, including: IEnumerable&amp;lt;T&amp;gt;, IEnumerator&amp;lt;T&amp;gt;, IComparer&amp;lt;T&amp;gt;, IEqualityComparer&amp;lt;T&amp;gt;, IComparable&amp;lt;T&amp;gt;, the Action and Func delegates, Predicate&amp;lt;T&amp;gt;, Comparison&amp;lt;T&amp;gt;, EventHandler&amp;lt;TEventArgs&amp;gt;, and Converter&amp;lt;TInput, TOutput&amp;gt;.&lt;BR&gt;&lt;BR&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;B&gt;Tuples &lt;/B&gt;&lt;I&gt;&lt;SPAN style="COLOR: #cc0000"&gt;(new in Beta 1)&lt;/SPAN&gt;&lt;/I&gt;&lt;BR&gt;We’ve added common Tuple types in the BCL to facilitate language interoperability and to reduce duplication in the framework.&amp;nbsp; A tuple is a simple generic data structure that holds an ordered set of items of heterogeneous types.&amp;nbsp; Tuples are supported natively in languages such as F# and IronPython, but are also easy to use from any .NET language such as C# and VB.&lt;BR&gt;&lt;BR&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;B&gt;SortedSet&amp;lt;T&amp;gt; &lt;/B&gt;&lt;I&gt;&lt;SPAN style="COLOR: #cc0000"&gt;(new in Beta 1)&lt;/SPAN&gt;&lt;/I&gt;&lt;BR&gt;We’ve added a SortedSet&amp;lt;T&amp;gt; collection along with a new ISet&amp;lt;T&amp;gt; interface.&amp;nbsp; SortedSet&amp;lt;T&amp;gt; uses a self-balancing tree which maintains data in sorted order for performance guarantees with insertion, deletion, and searches.&amp;nbsp; Both the new SortedSet&amp;lt;T&amp;gt; and the existing HashSet&amp;lt;T&amp;gt; implement ISet&amp;lt;T&amp;gt;.&lt;BR&gt;&lt;BR&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;B&gt;File System Enumeration Improvements &lt;/B&gt;&lt;I&gt;&lt;SPAN style="COLOR: #cc0000"&gt;(new in Beta 1)&lt;/SPAN&gt;&lt;/I&gt;&lt;BR&gt;System.IO.Directory and System.IO.DirectoryInfo have new APIs for enumerating the file system that return IEnumerable&amp;lt;T&amp;gt;s instead of arrays.&amp;nbsp; These new APIs are more efficient than the array-based APIs because they do not need to allocate a (potentially large) array and you can access the first results immediately instead of waiting for the entire array to be created and returned.&amp;nbsp; We’ve also added new convenience APIs for efficiently reading, writing, and appending lines from/to a text file using IEnumerable&amp;lt;String&amp;gt;.&amp;nbsp; These new APIs are useful in LINQ scenarios where you may want to quickly and efficiently query the contents of a text file and write out the results to a log file without allocating any arrays.&lt;BR&gt;&lt;BR&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;B&gt;MemoryMappedFiles&lt;/B&gt;&lt;BR&gt;System.IO.MemoryMappedFiles exposes the memory mapping functionality provided by Windows as first-class managed APIs.&amp;nbsp; Memory mapped files can be used to efficiently edit very large files and can also be used to create shared memory for inter-process communication.&amp;nbsp; Along with this feature, we’re introducing System.IO.UnmanagedMemoryAccessor, a new class that enables random access to unmanaged memory similar to how UnmanagedMemoryStream enables sequential access to such memory.&lt;BR&gt;&lt;BR&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;B&gt;Registry Improvements &lt;/B&gt;&lt;I&gt;&lt;SPAN style="COLOR: #cc0000"&gt;(new in Beta 1)&lt;/SPAN&gt;&lt;/I&gt;&lt;BR&gt;We’ve added support to Microsoft.Win32.RegistryKey for accessing alternate registry views (32bit and 64bit views) on 64bit Windows.&amp;nbsp; We’ve also added the ability to create volatile keys—keys that are stored in memory and are not persisted when the hive unloads (which typically happens on reboot).&amp;nbsp; In addition, we’ve added new extensibility APIs that take and return a SafeRegistryHandle to make it easier to interoperate with Win32 registry APIs that do not have managed wrappers.&lt;BR&gt;&lt;BR&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;B&gt;Globalization data updated to Unicode 5.1 &lt;/B&gt;&lt;I&gt;&lt;SPAN style="COLOR: #cc0000"&gt;(new in Beta 1)&lt;/SPAN&gt;&lt;/I&gt;&lt;BR&gt;Culture data in .NET 4 has been updated, including updating the character information to Unicode 5.1.&amp;nbsp; We have also added support for new cultures, including new neutral cultures.&lt;BR&gt;&lt;BR&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;B&gt;ResourceManager Improvements&lt;/B&gt;&lt;BR&gt;The ResourceManager in System.Resources has been improved to respect the user’s preferred UI languages when looking for localized resources, instead of only using the CurrentUICulture’s parent chain.&amp;nbsp; This means if the user has specified in Windows that she prefers French and Spanish, the ResourceManager will look for French and Spanish resources before falling back to the neutral resources.&amp;nbsp; This change is present in Silverlight 2 as well as .NET 4.&lt;BR&gt;&lt;BR&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;B&gt;Compression Improvements&lt;/B&gt;&lt;BR&gt;The compression algorithms in System.IO.Compression have been improved in .NET 4.&amp;nbsp; DeflateStream and GZipStream no longer inflate already compressed data.&amp;nbsp; This means that in many cases you’ll see better compression ratios when using these streams on .NET 4.&amp;nbsp; We’ve also removed the 4 GB size limit, so you can now compress streams over 4 GB in length.&lt;BR&gt;&lt;BR&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;You can learn more about what’s new in the BCL in .NET Framework 4 on Channel9: &lt;A href="http://channel9.msdn.com/posts/Charles/Inside-NET-4-Meet-the-BCL-Team/" mce_href="http://channel9.msdn.com/posts/Charles/Inside-NET-4-Meet-the-BCL-Team/"&gt;Inside .NET 4: Meet the BCL Team&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;We hope you enjoy the new functionality and improvements in Beta 1.&amp;nbsp; Be sure to &lt;A href="http://connect.microsoft.com/visualstudio" mce_href="http://connect.microsoft.com/visualstudio"&gt;let us know&lt;/A&gt; if you run into any issues or if you have any further suggestions.&amp;nbsp; And look out for even more improvements and refinements in the next preview release of .NET Framework 4.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9636439" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/bclteam/archive/tags/News/default.aspx">News</category><category domain="http://blogs.msdn.com/bclteam/archive/tags/.NET+Framework+4/default.aspx">.NET Framework 4</category></item><item><title>Preview of Code Contract Tools Now Available [Melitta Andersen]</title><link>http://blogs.msdn.com/bclteam/archive/2009/02/23/preview-of-code-contract-tools-now-available-melitta-andersen.aspx</link><pubDate>Tue, 24 Feb 2009 02:00:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9441884</guid><dc:creator>BCLTeam</dc:creator><slash:comments>11</slash:comments><comments>http://blogs.msdn.com/bclteam/comments/9441884.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bclteam/commentrss.aspx?PostID=9441884</wfw:commentRss><description>&lt;P&gt;In my &lt;A href="http://blogs.msdn.com/bclteam/archive/2008/11/11/introduction-to-code-contracts-melitta-andersen.aspx" mce_href="http://blogs.msdn.com/bclteam/archive/2008/11/11/introduction-to-code-contracts-melitta-andersen.aspx"&gt;Introduction to Code Contracts&lt;/A&gt; post, I mentioned that the tools to enable runtime checking and static analysis were not included in the .NET Framework 4.0 CTP.&lt;/P&gt;
&lt;P&gt;Today we are releasing a preview version of the Code Contracts tools on the &lt;A href="http://msdn.microsoft.com/en-us/devlabs/dd125421.aspx" mce_href="http://msdn.microsoft.com/en-us/devlabs/dd125421.aspx"&gt;DevLabs&lt;/A&gt; site.&amp;nbsp; DevLabs is a site for getting preview releases of innovative new projects for developers out to the community.&amp;nbsp; You can read more about it on &lt;A href="http://blogs.msdn.com/somasegar/archive/2008/10/23/inspiring-through-innovation-devlabs.aspx" mce_href="http://blogs.msdn.com/somasegar/archive/2008/10/23/inspiring-through-innovation-devlabs.aspx"&gt;Soma’s introductory blog post&lt;/A&gt;.&amp;nbsp; The specific Code Contracts page on DevLabs can be found &lt;A href="http://msdn.microsoft.com/en-us/dd491992.aspx" mce_href="http://msdn.microsoft.com/en-us/dd491992.aspx"&gt;here&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;The tools include a binary rewriter to enable runtime checking, a static checker, a new project pane for VS projects, and an updated copy of the Code Contract library.&amp;nbsp; For more details on what these are, you can check out the &lt;A href="http://msdn.microsoft.com/en-us/dd491992.aspx" mce_href="http://msdn.microsoft.com/en-us/dd491992.aspx"&gt;Code Contracts page&lt;/A&gt;, which includes an overview, a video on how to get started, an FAQ, and other useful information.&amp;nbsp; You can also check out the &lt;A href="http://download.microsoft.com/download/C/2/7/C2715F76-F56C-4D37-9231-EF8076B7EC13/userdoc.pdf" mce_href="http://download.microsoft.com/download/C/2/7/C2715F76-F56C-4D37-9231-EF8076B7EC13/userdoc.pdf"&gt;documentation&lt;/A&gt; (PDF), or get an overview in &lt;A href="http://blogs.msdn.com/somasegar/archive/2009/02/23/devlabs-code-contracts-for-net.aspx" mce_href="http://blogs.msdn.com/somasegar/archive/2009/02/23/devlabs-code-contracts-for-net.aspx"&gt;Soma’s recent post on Code Contracts&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;This current release is targeted at Visual Studio 2008 Team System and can be used for commercial development.&amp;nbsp; The academic release that can be used for non-commercial use on any Visual Studio 2008 edition except Express can still be found on the &lt;A href="http://research.microsoft.com/en-us/projects/contracts/" mce_href="http://research.microsoft.com/en-us/projects/contracts/"&gt;Contracts page&lt;/A&gt; on the Microsoft Research site.&lt;/P&gt;
&lt;P&gt;This new release also comes with more ways to provide feedback and get answers.&amp;nbsp; In my last post, I mentioned the Code Contracts thread on the Pex forum.&amp;nbsp; Now Code Contracts has its own &lt;A href="http://social.msdn.microsoft.com/Forums/en-US/codecontracts/threads/" mce_href="http://social.msdn.microsoft.com/Forums/en-US/codecontracts/threads/"&gt;forum&lt;/A&gt;.&amp;nbsp; So please go try out these new tools and tell us what you think.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9441884" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/bclteam/archive/tags/Contracts/default.aspx">Contracts</category></item><item><title>In-depth: How .NET managed services interact with the ServiceControlManager (SCM) [Kim Hamilton]</title><link>http://blogs.msdn.com/bclteam/archive/2009/02/19/in-depth-how-net-managed-services-interact-with-the-servicecontrolmanager-scm-kim-hamilton.aspx</link><pubDate>Fri, 20 Feb 2009 01:44:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9435097</guid><dc:creator>BCLTeam</dc:creator><slash:comments>9</slash:comments><comments>http://blogs.msdn.com/bclteam/comments/9435097.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bclteam/commentrss.aspx?PostID=9435097</wfw:commentRss><description>&lt;P&gt;.NET managed services are based on NT services, and both need to know how to interact with the ServiceControlManager (SCM) to remain responsive. For managed services, many of the complexities of interacting with the SCM are handled for you by System.ServiceProcess.ServiceBase; however, there are some you still need to be aware of.&lt;/P&gt;
&lt;P&gt;I’ll summarize the key interactions between the SCM and &lt;I&gt;any&lt;/I&gt; service (managed or native). I’ll describe how these apply to managed services — which interactions you need to perform and which are handled for you. Lastly, I’ll walk through a representative SCM command to show the full sequence.&lt;/P&gt;
&lt;H2&gt;&lt;U&gt;SCM Interaction 1&lt;/U&gt;&lt;/H2&gt;
&lt;H3&gt;General Guidance&lt;/H3&gt;
&lt;P&gt;When SCM sends a request, acknowledge it by updating the service state (e.g. pending) and spawn a new thread to handle the request so that the SCM can communicate with other services&lt;/P&gt;
&lt;H3&gt;Background&lt;/H3&gt;
&lt;P&gt;The SCM only communicates with one service at a time. This guidance allows the SCM to be unblocked so it can communicate with other services. So the suggested behavior for services is: set the status to pending and kick off a new thread to do any necessary work (thereby unblocking the SCM). The SCM can then move on to interacting with other services, while the worker thread updates the SCM with progress and completion status.&lt;/P&gt;
&lt;H3&gt;Impact for managed services&lt;/H3&gt;
&lt;P&gt;This is only partially relevant for managed services because ServiceBase handles much of this for you. You only need to worry about this if you expect your service will require more time than the “unresponsive” limit, or to spawn a thread that will last the entire lifetime of the service. Here are the details:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;You &lt;B&gt;don’t &lt;/B&gt;need to start a new thread just to unblock the SCM. ServiceBase calls your OnStart/OnStop (we’ll refer to those as OnX) on a worker thread, so when you’re OnStart/OnStop is called, you’re not blocking the SCM&lt;/LI&gt;
&lt;LI&gt;You &lt;B&gt;don’t&lt;/B&gt; set the service state. The ServiceBase class sets the service state to X_PENDING before calling your OnX/OnX. Also, when your OnX method returns, ServiceBase performs the final status update, e.g. to STATUS_STOPPED. (In fact, there’s not even a managed API for setting these states.)&lt;/LI&gt;
&lt;LI&gt;While your OnX thread isn’t blocking the SCM, you &lt;B&gt;do&lt;/B&gt; need ensure it doesn’t exceed its time limit. You can help ensure you have enough time by calling RequestAdditionalTime, discussed in SCM Interaction 2.&lt;/LI&gt;
&lt;LI&gt;You &lt;B&gt;do&lt;/B&gt; need to spawn a new thread in OnStart for any processing that should happen during the entire lifetime of the service.&lt;/LI&gt;&lt;/UL&gt;
&lt;H2&gt;&lt;U&gt;SCM Interaction 2&lt;/U&gt;&lt;/H2&gt;
&lt;H3&gt;General Guidance&lt;/H3&gt;
&lt;P&gt;After the SCM issues a command, the SCM gives each service a default amount of time to complete its work. If the service requires more time it must tell the manager that it needs more time, otherwise the manager will assume it’s hung.&lt;/P&gt;
&lt;H3&gt;Background&lt;/H3&gt;
&lt;P&gt;As mentioned in the previous interaction, it’s important that a service doesn’t block the SCM, so that the SCM can respond to other services. However, the SCM also expects status updates from the service, to ensure the service is responsive. For example, after issuing a start command, the SCM expects the service to update its state to started within 30 seconds. After issuing a stop command, the SCM expects the service to update its state to stopped within 20 seconds.&lt;/P&gt;
&lt;H3&gt;Impact for managed services&lt;/H3&gt;
&lt;P&gt;This is where your managed service needs to pay attention to avoid the SCM flagging your service as unresponsive. &lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;You &lt;B&gt;don’t &lt;/B&gt;have to explicitly update the state; ServiceBase does this for you when your OnStart or OnStop method completes&lt;/LI&gt;
&lt;LI&gt;You &lt;B&gt;do&lt;/B&gt; have to call RequestAdditionalTime if you expect the OnX method to exceed the timeout.&lt;/LI&gt;&lt;/UL&gt;
&lt;H2&gt;&lt;U&gt;SCM Interaction 3&lt;/U&gt;&lt;/H2&gt;
&lt;H3&gt;General Guidance&lt;/H3&gt;
&lt;P&gt;To give SCM impression of progress, update the dwCurrentState or dwCheckPoint&lt;/P&gt;
&lt;H3&gt;Background&lt;/H3&gt;
&lt;P&gt;These state and checkpoints are intermediate “in progress” types of notification to let the SCM know your service isn’t hanging. &lt;/P&gt;
&lt;H3&gt;Impact for managed services&lt;/H3&gt;
&lt;P&gt;With managed services, these details are abstracted away. All you have to do is call RequestAdditionalTime() and those details are handled for you behind the scenes. ServiceBase will handle the state and checkpoint details in its message to the SCM.&lt;/P&gt;
&lt;H2&gt;&lt;U&gt;Walkthrough: how ServiceBase handles Stop command&lt;/U&gt;&lt;/H2&gt;
&lt;P&gt;To demonstrate the above, let’s walk through how ServiceBase responds to a STOP command from the SCM. Note that Start is similar.&lt;/P&gt;
&lt;P&gt;ServiceBase receives STOP command:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;ServiceBase queues up an async call, to call your handler and update status&lt;/LI&gt;
&lt;LI&gt;In the async call, ServiceBase does the following: 
&lt;UL&gt;
&lt;LI&gt;Sets status to STATE_STOP_PENDING&lt;/LI&gt;
&lt;LI&gt;Calls your OnStop (note this is already in a separate thread)&lt;/LI&gt;
&lt;LI&gt;When your OnStop returns, sets state to STATE_STOPPED&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;What should your OnStop look like?&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;If you need more time, just call RequestAdditionalTime. We’ll send this value to the SCM and update the checkpoint for you&lt;/LI&gt;
&lt;LI&gt;If you don’t need more time, you don’t have to do any additional steps. Your method returns and we update the state for you.&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;If your OnStop fails to call RequestAdditionalTime or blocks for longer than 20 (default; see below) seconds, SCM marks service as unresponsive.&lt;/P&gt;
&lt;P&gt;To prevent a service from stopping shutdown, the SCM will only wait up to a limit for your service to stop itself. The default for this limit is 20 seconds (this value is in the registry key WaitToKillServiceTimeout() in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control)&lt;/P&gt;
&lt;H2&gt;Additional Reading&lt;/H2&gt;
&lt;P&gt;The following MSDN article describes writing responsive native services.&lt;/P&gt;
&lt;P&gt;&lt;A href="http://msdn.microsoft.com/en-us/magazine/cc164252.aspx" mce_href="http://msdn.microsoft.com/en-us/magazine/cc164252.aspx"&gt;http://msdn.microsoft.com/en-us/magazine/cc164252.aspx&lt;/A&gt;&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9435097" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/bclteam/archive/tags/Service/default.aspx">Service</category></item><item><title>Working with the ResourceManager [Kim Hamilton]</title><link>http://blogs.msdn.com/bclteam/archive/2009/02/16/working-with-the-resourcemanager-kim-hamilton.aspx</link><pubDate>Tue, 17 Feb 2009 00:28:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9426502</guid><dc:creator>BCLTeam</dc:creator><slash:comments>4</slash:comments><comments>http://blogs.msdn.com/bclteam/comments/9426502.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bclteam/commentrss.aspx?PostID=9426502</wfw:commentRss><description>&lt;H2&gt;&lt;I&gt;The essentials of resource fallback and how to debug failures&lt;/I&gt;&lt;/H2&gt;
&lt;P&gt;Resource loading failures can be tricky to debug. However, once you have a basic overview of how the ResourceManager works, as well as a few debugging tools, you’ll be able to easily get to the bottom of most problems.&lt;/P&gt;
&lt;P&gt;This post will cover the key elements of resource lookup and debugging with a simple code sample, addressing the following:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Basics of resource generation and file structure&lt;/LI&gt;
&lt;LI&gt;How to construct a ResourceManager to find your resources&lt;/LI&gt;
&lt;LI&gt;How resource fallback works&lt;/LI&gt;
&lt;LI&gt;How to debug resource failures&lt;/LI&gt;&lt;/UL&gt;
&lt;H2&gt;Code Sample&lt;/H2&gt;
&lt;P&gt;The code sample is posted&amp;nbsp;in the &lt;A class="" href="http://code.msdn.microsoft.com/bcl/Release/ProjectReleases.aspx?ReleaseId=2271" mce_href="http://code.msdn.microsoft.com/bcl/Release/ProjectReleases.aspx?ReleaseId=2271"&gt;BCL code gallery downloads&lt;/A&gt; as ResourceManagerSample.zip. The zip file contains:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;.restext files in different languages: these are text files containing key, value pairs from which we’ll generate .resources files.&amp;nbsp; Note that the extension restext isn’t important, it can be anything you want.&lt;/LI&gt;
&lt;LI&gt;FallbackTest.cs: sample code that looks up resources in different cultures and prints the results&lt;/LI&gt;
&lt;LI&gt;make.bat: builds main exe and satellite assemblies&lt;/LI&gt;&lt;/UL&gt;
&lt;H3&gt;Instructions&lt;/H3&gt;
&lt;OL&gt;
&lt;LI&gt;Extract the zip file and run make.bat, which does the following: 
&lt;OL style="LIST-STYLE-TYPE: lower-alpha"&gt;
&lt;LI&gt;Converts the .restext files to .resources files (the binary format understood by the ResourceManager) using resgen.&lt;/LI&gt;
&lt;LI&gt;Compiles the main exe and embeds the &lt;I&gt;invariant&lt;/I&gt; resources, or the resources that are always expected to exist if other cultures are missing.&lt;/LI&gt;
&lt;LI&gt;Generates satellite assemblies for the other cultures, placing them in culture-specific subfolders&lt;/LI&gt;&lt;/OL&gt;&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;After Step 1, the directory structure looks like the following:&lt;/P&gt;&lt;PRE style="PADDING-RIGHT: 10px; PADDING-LEFT: 10px; FONT-SIZE: 10pt; PADDING-BOTTOM: 10px; MARGIN-LEFT: 20px; COLOR: black; PADDING-TOP: 10px; FONT-FAMILY: 'Courier New'"&gt;FallbackTest.exe &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(main executable, contains FallbackStrings.resources)
de\FallbackTest.resources.dll &amp;nbsp;&amp;nbsp;&amp;nbsp;(de satellite assembly, contains FallbackStrings.de.resources)
fr\FallbackTest.resources.dll &amp;nbsp;&amp;nbsp;&amp;nbsp;(fr satellite assembly, contains FallbackStrings.fr.resources)
fr-CA\FallbackTest.resources.dll (fr-CA satellite assembly, contains FallbackStrings.fr-CA.resources)&lt;/PRE&gt;
&lt;OL start=2&gt;
&lt;LI&gt;Run FallbackTest.exe to see the results, discussed below&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;Before diving into the results, let’s look at the source of FallbackTest.cs to see what it’s doing.&lt;/P&gt;
&lt;H2&gt;Creating a ResourceManager&lt;/H2&gt;
&lt;P&gt;The ResourceManager can perform two types of resource lookup, depending on how you construct it.&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;File-based: resource files are directly on disk in the binary .resources files. Create this type of ResourceManager via ResourceManager.CreateFileBasedResourceManager.&lt;/LI&gt;
&lt;LI&gt;Assembly-based: resources are embedded in an assembly or a satellite assembly. Create this type of ResourceManager with the standard constructors.&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;Assembly-based is by far the most commonly used; a satellite assembly has the same advantages as a regular assembly such as versioning and the ability to sign. That’s why we’re focusing on assembly-based lookup in this example.&lt;/P&gt;
&lt;P&gt;The code sample creates a ResourceManager as follows:&lt;/P&gt;&lt;PRE style="BORDER-RIGHT: silver 1px solid; PADDING-RIGHT: 10px; BORDER-TOP: silver 1px solid; PADDING-LEFT: 10px; FONT-SIZE: 10pt; PADDING-BOTTOM: 10px; MARGIN-LEFT: 20px; BORDER-LEFT: silver 1px solid; COLOR: black; PADDING-TOP: 10px; BORDER-BOTTOM: silver 1px solid; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="COLOR: #2b91af"&gt;ResourceManager&lt;/SPAN&gt; rm = &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;ResourceManager&lt;/SPAN&gt;(&lt;SPAN style="COLOR: #a31515"&gt;"FallbackStrings"&lt;/SPAN&gt;,
                            &lt;SPAN style="COLOR: #2b91af"&gt;Assembly&lt;/SPAN&gt;.GetExecutingAssembly());&lt;/PRE&gt;
&lt;P&gt;The first argument is baseName — the name of the resources files we’re searching without the culture and “.resources” extension. &amp;nbsp;In step 1a above, resgen created files named, for example, FallbackStrings.fr.resources and FallbackStrings.fr-CA.resources. So baseName in this example would be FallbackStrings.&lt;/P&gt;
&lt;P&gt;The second argument is the main assembly for the resources. Since we’re calling from that assembly, we can just say Assembly.GetExecutingAssembly(). Note that this is the common case.&lt;/P&gt;
&lt;H2&gt;Resource Fallback Model&lt;/H2&gt;
&lt;P&gt;Let’s move to the resource lookups and sample code output. First, notice these lines:&lt;/P&gt;&lt;PRE style="BORDER-RIGHT: silver 1px solid; PADDING-RIGHT: 10px; BORDER-TOP: silver 1px solid; PADDING-LEFT: 10px; FONT-SIZE: 10pt; PADDING-BOTTOM: 10px; MARGIN-LEFT: 20px; BORDER-LEFT: silver 1px solid; COLOR: black; PADDING-TOP: 10px; BORDER-BOTTOM: silver 1px solid; FONT-FAMILY: 'Courier New'"&gt;&lt;SPAN style="COLOR: #2b91af"&gt;CultureInfo&lt;/SPAN&gt; ci = &lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;CultureInfo&lt;/SPAN&gt;(culture);
&lt;SPAN style="COLOR: #2b91af"&gt;Thread&lt;/SPAN&gt;.CurrentThread.CurrentUICulture = ci;&lt;/PRE&gt;
&lt;P&gt;This is done because the ResourceManager uses the current thread’s CurrentUICulture to search for resources by default. ResourceManager.GetString also has overloads that accept a CultureInfo. If provided, that culture will be searched instead.&lt;/P&gt;
&lt;P&gt;After setting the UI Culture, fallback test searches for a couple of localized strings and prints them to the screen.&lt;/P&gt;&lt;PRE style="PADDING-RIGHT: 10px; PADDING-LEFT: 10px; FONT-SIZE: 10pt; PADDING-BOTTOM: 10px; MARGIN-LEFT: 20px; COLOR: black; PADDING-TOP: 10px; FONT-FAMILY: 'Courier New'"&gt;Current UI culture: fr-CA
Greeting: bonjour
End of week: la fin de semaine
------------------------------
Current UI culture: fr-FR
Greeting: bonjour
End of week: le week-end
------------------------------
Current UI culture: de-DE
Greeting: Guten Tag
End of week: weekend
------------------------------
Current UI culture: ja-JP
Greeting: hello
End of week: weekend
------------------------------
&lt;/PRE&gt;
&lt;P&gt;Let’s focus on fr-CA and fr-FR. fr-CA is the French Canadian locale, which has some different words than fr-FR, the French spoken in France. &lt;/P&gt;
&lt;P&gt;In this code sample, we’ve included resources for fr-CA, but none for fr-FR. Instead, we’ve provided resources for fr, which is the &lt;I&gt;neutral&lt;/I&gt; French culture. A neutral culture is not region-specific and is the parent of its corresponding region-specific cultures. For example, fr is the parent culture of both fr-CA and fr-FR.&lt;/P&gt;
&lt;P&gt;A quick aside on this decision:&lt;/P&gt;
&lt;P&gt;Resource divisions like this are fairly common in practice; the most common words for a language (across regions) are placed in the neutral culture’s resource file, and any deviations from that are placed in the specific culture’s resource file. This minimizes duplication in resource files. &amp;nbsp;So in this example, the choice to put greeting in fr allowed us to share resources across French-speaking regions, but adding explicit resources for fr-CA allows French Canadian to differ from the most commonly-used French.&lt;/P&gt;
&lt;P&gt;Now notice in the program output that fr-CA and fr-FR have the same greeting but different words for the end of the week. That’s because for greeting, fr-CA resources didn’t have a value, so it fell back to fr (same as fr-FR). &lt;/P&gt;
&lt;P&gt;In general, a resource fallback chain looks like this. &lt;/P&gt;
&lt;P&gt;Culture passed to GetString(, x) or ThreadUICulture (fr-CA) -&amp;gt; parent culture (fr) -&amp;gt; invariant culture (embedded in main assembly)&lt;/P&gt;
&lt;P&gt;Compare the output for the other cultures above to see why the output makes sense.&lt;/P&gt;
&lt;P&gt;The fallback chain can also vary as follows:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;In .NET 4 (and Silverlight 2), on Windows Vista and above, we merge in user and system preferences according to the API &lt;A href="http://msdn.microsoft.com/en-us/library/dd318128(VS.85).aspx" mce_href="http://msdn.microsoft.com/en-us/library/dd318128(VS.85).aspx"&gt;GetThreadPreferredUILanguages&lt;/A&gt; (with flags MUI_MERGE_USER_FALLBACK | MUI_MERGE_SYSTEM_FALLBACK). These cultures are searched after the specified culture and its parents, but before the invariant culture&lt;/LI&gt;
&lt;LI&gt;NeutralResourcesLanguageAttribute on the assembly: this allows performance improvements and allows ultimate fallback resources to be located in a satellite assembly (and in a different culture), instead of the main assembly. &lt;A href="http://blogs.msdn.com/kimhamil/archive/2008/11/11/what-does-the-neutralresourceslanguageattribute-do.aspx" mce_href="http://blogs.msdn.com/kimhamil/archive/2008/11/11/what-does-the-neutralresourceslanguageattribute-do.aspx"&gt;About the NeutralResourcesLanguageAttribute&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;Specify in the app’s config that only certain assembly locales should be probed. This also allows performance improvements. Note that this won’t add cultures to the fallback chain, it will only remove them. &lt;A href="http://blogs.msdn.com/bclteam/archive/2005/10/11/479330.aspx" mce_href="http://blogs.msdn.com/bclteam/archive/2005/10/11/479330.aspx"&gt;Performance tips for using resources&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;H2&gt;Debugging Resource-Related Issues&lt;/H2&gt;
&lt;P&gt;There are 3 common tools I use for debugging resource-related issues. These are:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Fusion: shows attempts to load satellite assemblies, which can help uncover assembly-loading problems&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://www.red-gate.com/products/reflector/" mce_href="http://www.red-gate.com/products/reflector/"&gt;Reflector&lt;/A&gt;: view embedded .resources file&lt;/LI&gt;
&lt;LI&gt;Resview: same as above but also has diagnostics to tell if there are problems&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;Let’s look at these in-depth by seeing what can go wrong. Comment out the call to GoodTest(), then uncomment the call to BadTest(), and rerun make.bat. This code has a bug, which is that the baseName is incorrect (“Fallback_Strings” instead of “FallbackStrings”). Running the code, we get the following exception:&lt;/P&gt;
&lt;P&gt;System.Resources.MissingManifestResourceException: Could not find any resources appropriate for the specified culture or the neutral culture.&amp;nbsp; Make sure "Fallback_Strings.resources" was correctly embedded or linked into assembly "FallbackTest" at compile time, or that all the satellite assemblies required are loadable and fully signed.&lt;/P&gt;
&lt;P&gt;Let’s investigate this failure showing how the different tools are used:&lt;/P&gt;
&lt;H3&gt;Fusion logs&lt;/H3&gt;
&lt;P&gt;To enable fusion logs, launch the fusion log viewer, fuslogvw.exe, which is provided as a Framework sdk tool (you can find it under Framework\tools). Choose the option “Log all binds to disk”. I also select the “Enable custom log path” checkbox and specify a path such as C:\fuslog. (Since fusion logs are written as html files, I prefer to browse the files directly on disk than view the output in the fusion log viewer.) &lt;/P&gt;
&lt;P&gt;Then run your program and look in C:\fuslog for the results. &lt;/P&gt;
&lt;P&gt;In C:\fuslog\Default\FallbackTest.exe\, I see there were binding attempts for fr-CA and fr, because there are files named, e.g.:&lt;/P&gt;
&lt;P&gt;“FallbackTest.resources, Version=0.0.0.0, Culture=fr-CA, PublicKeyToken=null.HTM”&lt;/P&gt;
&lt;P&gt;Opening those files, you can see that the assembly did load correctly, so the problem isn’t a missing satellite assembly.&lt;/P&gt;
&lt;P&gt;If the fusion log file did indicate a problem with the satellite assembly loading, then you know that either the satellite assembly is missing or has some other problem (version or signing problem), in which case you most likely have a build or install problem to correct.&lt;/P&gt;
&lt;H3&gt;Reflector/Resview&lt;/H3&gt;
&lt;P&gt;Both of these allow you to see the contents of a .resources file embedded in an assembly, but resview (part of the Framework sdk) has additional diagnostic tools. However, &lt;A href="http://www.red-gate.com/products/reflector/" mce_href="http://www.red-gate.com/products/reflector/"&gt;Reflector&lt;/A&gt; provides a nice interface for&amp;nbsp;browsing the resource file, and I most often use that.&lt;/P&gt;
&lt;P&gt;Open up the assembly of interest (either satellite or main) in Reflector. Expand the “Resources” section of the assembly to verify that the baseName we specified is actually present. As expected, we have a resource file named FallbackStrings.X.resources, but not Fallback_Strings.X.resources, and the solution is to remove the underscore from the baseName.&lt;/P&gt;
&lt;P&gt;While this file name problem seems basic, it turns out to be a very common problem, so keep it in mind.&lt;/P&gt;
&lt;P&gt;Another simple common mistake is if the key isn’t actually in the file. You can double-click on the .resources file in reflector to see the contents.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9426502" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/bclteam/archive/tags/System.Resources/default.aspx">System.Resources</category></item><item><title>CLR Team Blog Now Live [Justin Van Patten]</title><link>http://blogs.msdn.com/bclteam/archive/2009/01/07/clr-team-blog-now-live-justin-van-patten.aspx</link><pubDate>Wed, 07 Jan 2009 23:14:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9289906</guid><dc:creator>BCLTeam</dc:creator><slash:comments>3</slash:comments><comments>http://blogs.msdn.com/bclteam/comments/9289906.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bclteam/commentrss.aspx?PostID=9289906</wfw:commentRss><description>&lt;P&gt;If you like this blog, you’ll want to check out and subscribe to the new &lt;A href="http://blogs.msdn.com/clrteam/" mce_href="http://blogs.msdn.com/clrteam/"&gt;CLR Team Blog&lt;/A&gt; that just launched last week.&amp;nbsp; The new blog will serve as one consolidated site to find information on all aspects of the CLR, brought to you by CLR team members.&amp;nbsp; It will aggregate posts from lots of existing CLR team member and feature team blogs.&amp;nbsp; Since the BCL team is a part of the larger CLR team, when we post something on the BCL Team Blog we’ll also include a link to the post on the CLR Team Blog, or cross-post in some cases.&amp;nbsp; Other CLR bloggers and features teams will do the same.&amp;nbsp; The new blog will have its own original content too!&amp;nbsp; Aarthi Ramamurthy’s &lt;A href="http://blogs.msdn.com/clrteam/archive/2009/01/02/welcome-to-the-clr-team-blog.aspx" mce_href="http://blogs.msdn.com/clrteam/archive/2009/01/02/welcome-to-the-clr-team-blog.aspx"&gt;introductory blog post&lt;/A&gt; describes in more detail what the new blog is all about.&amp;nbsp; Check it out, subscribe, and stay tuned for upcoming posts!&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9289906" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/bclteam/archive/tags/News/default.aspx">News</category></item><item><title>Introduction to Code Contracts [Melitta Andersen]</title><link>http://blogs.msdn.com/bclteam/archive/2008/11/11/introduction-to-code-contracts-melitta-andersen.aspx</link><pubDate>Wed, 12 Nov 2008 02:36:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9060979</guid><dc:creator>BCLTeam</dc:creator><slash:comments>20</slash:comments><comments>http://blogs.msdn.com/bclteam/comments/9060979.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bclteam/commentrss.aspx?PostID=9060979</wfw:commentRss><description>&lt;P&gt;This blog post is to provide a bit more detail about the Code Contracts feature that was recently &lt;A href="http://channel9.msdn.com/pdc2008/TL51/" mce_href="http://channel9.msdn.com/pdc2008/TL51/"&gt;announced at the PDC&lt;/A&gt; and in &lt;A href="http://blogs.msdn.com/bclteam/archive/2008/11/04/what-s-new-in-the-bcl-in-net-4-0-justin-van-patten.aspx" mce_href="http://blogs.msdn.com/bclteam/archive/2008/11/04/what-s-new-in-the-bcl-in-net-4-0-justin-van-patten.aspx"&gt;Justin’s blog entry&lt;/A&gt;, and that can be found in the &lt;A href="http://www.microsoft.com/downloads/details.aspx?FamilyID=922b4655-93d0-4476-bda4-94cf5f8d4814&amp;amp;DisplayLang=en" mce_href="http://www.microsoft.com/downloads/details.aspx?FamilyID=922b4655-93d0-4476-bda4-94cf5f8d4814&amp;amp;DisplayLang=en"&gt;Visual Studio 2010 and .NET Framework 4.0 CTP&lt;/A&gt;.&amp;nbsp; I’ll include some information on what can be found in the CTP, some of the history and design decisions we made while developing the feature, and some places to get more information.&amp;nbsp; Both of the announcements mentioned above give details about why we added this feature, but I’ll summarize here.&amp;nbsp; The main point of contracts is to reduce bugs by helping you not write them in the first place, or at least catch them sooner.&amp;nbsp; Contracts let you express statements about the behavior of your code in a way that is accessible to tools for runtime and static analysis.&lt;/P&gt;
&lt;H3&gt;What’s not in the CTP&lt;/H3&gt;
&lt;P&gt;One thing you should note is that the tools to enable runtime checking and static analysis are &lt;B&gt;not&lt;/B&gt; in the CTP.&amp;nbsp; However, you can still write your contracts now and then use the tools when they become available.&amp;nbsp; This works because the contracts are conditionally defined.&amp;nbsp; They’ll only appear in your code when you have the CONTRACTS_FULL symbol defined. &amp;nbsp;Until the tools are available and runtime checking is enabled, do not define this symbol.&amp;nbsp; Full contract checking will not work without the tools.&amp;nbsp; However, you also have the option of getting only preconditions with the CONTRACTS_PRECONDITIONS symbol.&amp;nbsp; Preconditions happen to be in the correct place in the code, so your program will still run with this symbol defined.&amp;nbsp; But the runtime checking tool provides many additional benefits, such as contract inheritance, so checking is still not recommended without the tools.&lt;/P&gt;
&lt;H3&gt;What is in the CTP&lt;/H3&gt;
&lt;P&gt;The CTP includes a CodeContracts class in the System.Diagnostics.Contracts namespace that allows you to write contracts in your code.&amp;nbsp; All contracts are static methods that return void.&amp;nbsp; They take a Boolean expression which encodes the condition that must be true.&amp;nbsp; They also have an overload that takes a string parameter as a message for when the contract is false.&amp;nbsp; Contracts are declarative and come at the beginning of your method.&amp;nbsp; You can think of them as part of the signature.&amp;nbsp; Here’s a rundown of what contracts are in the CTP:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;B&gt;Preconditions&lt;/B&gt;&lt;BR&gt;Preconditions are statements about what must be true at method entry for successful execution of the method.&amp;nbsp; It’s the responsibility of the caller to make sure these conditions are met.&amp;nbsp; Often, preconditions are used for parameter validation.&amp;nbsp; There are 3 possible ways to encode preconditions with code contracts:&lt;BR&gt;&amp;nbsp; 
&lt;UL&gt;
&lt;LI&gt;&lt;B&gt;CodeContract.Requires&lt;/B&gt;&lt;BR&gt;This method simply states a precondition.&amp;nbsp; Here’s an example:&lt;BR&gt;&lt;BR&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; COLOR: #2b91af; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CodeContract&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;.Requires(parameter &amp;gt;= 0);&lt;BR&gt;&lt;BR&gt;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;B&gt;CodeContract.RequiresAlways&lt;/B&gt;&lt;BR&gt;This method is the one exception to the conditional compilation rule.&amp;nbsp; It is always included, no matter which symbols are defined.&amp;nbsp; Thus, you can use RequiresAlways for preconditions that you want in your released code.&amp;nbsp; Here’s an example:&lt;BR&gt;&lt;BR&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; COLOR: #2b91af; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CodeContract&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;.RequiresAlways(parameter &amp;gt;= 0);&lt;BR&gt;&lt;BR&gt;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;B&gt;CodeContract.EndContractBlock&lt;/B&gt;&lt;BR&gt;This method name might seem a bit odd to include in the precondition section, so let me explain.&amp;nbsp; Much code already exists in the world that has some kind of parameter validation in the form of “if [condition] then throw [exception]”, e.g.&lt;BR&gt;&lt;BR&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt; (parameter &amp;lt; 0)&lt;BR&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; throw&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;ArgumentOutOfRangeException&lt;/SPAN&gt;();&lt;BR&gt;&lt;BR&gt;&lt;/SPAN&gt;&lt;BR&gt;We don’t expect everyone to go back and change their existing validation code.&amp;nbsp; However, we wanted a way to let the tools recognize these legacy contracts.&amp;nbsp; So we added the CodeContract.EndContractBlock method, which tells the tools that all if-checks of that form before the call can be considered preconditions.&lt;BR&gt;&lt;BR&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; COLOR: blue; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt; (parameter &amp;lt; 0)&lt;BR&gt;&lt;SPAN style="COLOR: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; throw&lt;/SPAN&gt; &lt;SPAN style="COLOR: blue"&gt;new&lt;/SPAN&gt; &lt;SPAN style="COLOR: #2b91af"&gt;ArgumentOutOfRangeException&lt;/SPAN&gt;();&lt;BR&gt;&lt;SPAN style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CodeContract&lt;/SPAN&gt;.EndContractBlock();&lt;BR&gt;&lt;BR&gt;&lt;/SPAN&gt;&lt;BR&gt;This method is needed only if you have no other contracts in your method, as all CodeContract preconditions and postconditions have this effect.&lt;BR&gt;&lt;BR&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;B&gt;Postconditions&lt;/B&gt;&lt;BR&gt;Post conditions are guarantees a method makes about what must be true at the conclusion of a method.&amp;nbsp; It is the method’s responsibility to live up to those promises.&amp;nbsp; These are declared at the beginning of a method, just like preconditions.&amp;nbsp; The tools take care of checking them at the right times.&amp;nbsp; There are two types of post conditions you can write with the CodeContract class.&lt;BR&gt;&amp;nbsp; 
&lt;UL&gt;
&lt;LI&gt;&lt;B&gt;CodeContract.Ensures&lt;/B&gt;&lt;BR&gt;This method states conditions that must be true upon successful method exit.&amp;nbsp; For example, this condition says that when the method exits the value will not be null.&lt;BR&gt;&lt;BR&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; COLOR: #2b91af; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CodeContract&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;.Ensures(SomeSharedState != &lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;);&lt;BR&gt;&lt;BR&gt;&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;B&gt;CodeContract.EnsuresOnThrow&amp;lt;TException&amp;gt;&lt;/B&gt;&lt;BR&gt;This method makes guarantees about exceptional termination from a method.&amp;nbsp;&amp;nbsp; In general, such guarantees can only be made for very specific exceptions, so letting TException be Exception is not a good idea.&amp;nbsp; For example, the following condition says that if an IOException escapes this method, the given variable is not null.&lt;BR&gt;&lt;BR&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; COLOR: #2b91af; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CodeContract&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;.EnsuresOnThrow&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;IOException&lt;/SPAN&gt;&amp;gt;(SomeSharedState != &lt;SPAN style="COLOR: blue"&gt;null&lt;/SPAN&gt;);&lt;BR&gt;&lt;BR&gt;&lt;/SPAN&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;LI&gt;&lt;B&gt;Special values for postconditions&lt;/B&gt;&lt;BR&gt;As you can imagine, it is often necessary to refer to certain values in postconditions, such as the result of the method, or the value of a variable at method entry.&amp;nbsp; There are methods in the CodeContract class that allow this; they are valid only in a postcondition.&lt;BR&gt;&amp;nbsp; 
&lt;UL&gt;
&lt;LI&gt;&lt;B&gt;CodeContract.Result&amp;lt;T&amp;gt;()&lt;/B&gt;&lt;BR&gt;This method represents the value returned from a method.&amp;nbsp; The T parameter indicates the return type.&amp;nbsp; For example, the following condition says that the result of this method is always non-negative.&lt;BR&gt;&lt;BR&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; COLOR: #2b91af; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CodeContract&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;.Ensures(&lt;SPAN style="COLOR: #2b91af"&gt;CodeContract&lt;/SPAN&gt;.Result&amp;lt;&lt;SPAN style="COLOR: #2b91af"&gt;Int32&lt;/SPAN&gt;&amp;gt;() &amp;gt;= 0);&lt;BR&gt;&lt;BR&gt;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;B&gt;CodeContract.OldValue&amp;lt;T&amp;gt;(T value)&lt;/B&gt;&lt;BR&gt;This method represents the value as it was at the start of the method or property.&amp;nbsp; It captures the pre-call value in a shallow copy.&amp;nbsp; For example, this condition says that the method increased the value of SomeSharedInt.&lt;BR&gt;&lt;BR&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; COLOR: #2b91af; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; CodeContract&lt;/SPAN&gt;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;.Ensures(SomeSharedInt &amp;gt; &lt;SPAN style="COLOR: #2b91af"&gt;CodeContract&lt;/SPAN&gt;.OldValue(SomeSharedInt));&lt;BR&gt;&lt;BR&gt;&lt;/SPAN&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;B&gt;CodeContract.ValueAtReturn&amp;lt;T&amp;gt;(out T value)&lt;/B&gt;&lt;BR&gt;This method is just to let you refer to the final value of an out parameter in a postcondition.&amp;nbsp; Since you write postconditions at the beginning of a method, the compilers would otherwise complain as the parameter hasn’t been assigned yet.&amp;nbsp; Other by-reference parameters don’t need this method.&amp;nbsp; Normal parameters don’t need this method because the compiler doesn’t care if it sees references to their values before it sees an assignment to them.&lt;BR&gt;&lt;BR&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;B&gt;Object Invariants&lt;/B&gt;&lt;BR&gt;The last major kind of contract that can be expressed with the CodeContract class is the object invariant.&amp;nbsp; Object invariants are statements about what must be true at &lt;I&gt;all&lt;/I&gt; public method exits for an object.&amp;nbsp; It is up to the programmer to ensure these invariants are maintained.&amp;nbsp; Object invariants are contained in a separate method that is marked with the ContractInvariantMethodAttribute.&amp;nbsp; The name of the method does not matter, but it must be parameter-less and return void.&amp;nbsp; That method contains some number of calls to the CodeContract.Invariant method.&amp;nbsp; Here’s an example of an invariant stating that the value in Data is always non-negative.&lt;BR&gt;&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;SPAN style="LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; FONT-SIZE: 10pt"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;[&lt;SPAN style="COLOR: #2b91af"&gt;ContractInvariantMethod&lt;/SPAN&gt;]&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: blue"&gt;void&lt;/SPAN&gt; ObjectInvariant() {&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN style="COLOR: #2b91af"&gt;CodeContract&lt;/SPAN&gt;.Invariant(Data &amp;gt;= 0);&lt;BR&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/SPAN&gt;&lt;/LI&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR&gt;&lt;BR&gt;
&lt;LI&gt;&lt;B&gt;CodeContract.Assert and CodeContract.Assume&lt;/B&gt;&lt;BR&gt;I’ll briefly touch on the other two types of contracts included in the class.&amp;nbsp; Assert and Assume, unlike the others, aren’t part of a method’s signature, and unlike the others they don’t come at the beginning of a method.&amp;nbsp; They’re simply statements about what must be true at a particular point in the code.&amp;nbsp; There exists many other ways to do this verification, but the main value with these methods is that they can be recognized by the tools.&amp;nbsp; The difference between Assert and Assume is that an Assume is your way to tell the static checker that instead of trying to prove the expression to be true, it should add the expression to its body of facts for your code.&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;Please note that this is only what is in the CTP.&amp;nbsp; This is a feature still under development, and &lt;B&gt;things could change&lt;/B&gt; before we ship.&amp;nbsp; In fact, we’re considering a couple of changes.&amp;nbsp; One is changing the class name from CodeContract to Contract to make contracts more readable.&amp;nbsp; Another is adding more sophisticated runtime failure behavior that is customizable by applications and hosts.&lt;/P&gt;
&lt;H3&gt;History and Design Decisions&lt;/H3&gt;
&lt;P&gt;The idea for this feature originated with the &lt;A href="http://research.microsoft.com/specsharp/" mce_href="http://research.microsoft.com/specsharp/"&gt;Spec# project&lt;/A&gt; in Microsoft Research.&amp;nbsp; Spec# has its own programming language, an extension of C#, which includes contracts in the syntax of the language.&amp;nbsp; We’re working closely with a team from Microsoft Research to bring contracts to the BCL.&amp;nbsp; One of the main questions we’ve had about the way we are including contracts in the .NET Framework is why we chose to implement them as library calls instead of making them part of “the language.”&lt;/P&gt;
&lt;P&gt;There are quite a few reasons for this, but one of them is that the CLR is the &lt;I&gt;Common&lt;/I&gt; Language Runtime, and we wanted a feature that all of the languages using the .NET Framework could use, not just one of them.&amp;nbsp; The best way to do this was with library calls.&amp;nbsp; As far as compilers need to be concerned, these are just static method calls.&amp;nbsp; Spec# was great because it had contracts integrated into the language, but that only solved the problem for one language.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;People have brought up attributes as another way we could have accomplished this.&amp;nbsp; One argument for that approach is that contracts are declarative, and this would make them look more like part of the method signature instead of the method body.&amp;nbsp; The problem with this approach is that attributes are very limited in what they can express.&amp;nbsp; It would be difficult or impossible to use attributes for all of the contracts you can write in code.&amp;nbsp; &lt;/P&gt;
&lt;P&gt;If you’re concerned about it because of the aesthetics, you might want to check out Scott Guthrie’s demo of VS2010, which starts about 88 minutes into this &lt;A href="http://channel9.msdn.com/pdc2008/KYN02/" mce_href="http://channel9.msdn.com/pdc2008/KYN02/"&gt;PDC2008 Keynote&lt;/A&gt;. &lt;/P&gt;
&lt;H3&gt;More Information&lt;/H3&gt;
&lt;P&gt;There are a few places you can go if you’re looking for more information.&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Microsoft Research’s &lt;A href="http://research.microsoft.com/contracts/" mce_href="http://research.microsoft.com/contracts/"&gt;code contracts website&lt;/A&gt;.&lt;/LI&gt;
&lt;LI&gt;For discussion of contracts, we’re currently sharing the &lt;A href="http://social.msdn.microsoft.com/Forums/en-US/pex/threads/" mce_href="http://social.msdn.microsoft.com/Forums/en-US/pex/threads/"&gt;Pex forum&lt;/A&gt; until we get our own.&amp;nbsp; Please use the &lt;A href="http://social.msdn.microsoft.com/Forums/en-US/pex/thread/14115b4d-52c1-4e93-89cd-19db3fd86756/" mce_href="http://social.msdn.microsoft.com/Forums/en-US/pex/thread/14115b4d-52c1-4e93-89cd-19db3fd86756/"&gt;Code Contracts Community &lt;/A&gt;thread.&lt;/LI&gt;
&lt;LI&gt;To provide feedback, you can make comments to this post, send mail via this blog’s &lt;A href="http://blogs.msdn.com/bclteam/contact.aspx" mce_href="http://blogs.msdn.com/bclteam/contact.aspx"&gt;contact form&lt;/A&gt;, or e-mail &lt;I&gt;codconfb&lt;/I&gt;_at_&lt;I&gt;microsoft&lt;/I&gt;_dot_&lt;I&gt;com&lt;/I&gt;.&lt;/LI&gt;&lt;/UL&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9060979" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/bclteam/archive/tags/.NET+Framework+4/default.aspx">.NET Framework 4</category><category domain="http://blogs.msdn.com/bclteam/archive/tags/Contracts/default.aspx">Contracts</category></item><item><title>What's New in the BCL in .NET 4.0 CTP [Justin Van Patten]</title><link>http://blogs.msdn.com/bclteam/archive/2008/11/04/what-s-new-in-the-bcl-in-net-4-0-justin-van-patten.aspx</link><pubDate>Wed, 05 Nov 2008 03:25:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9042307</guid><dc:creator>BCLTeam</dc:creator><slash:comments>60</slash:comments><comments>http://blogs.msdn.com/bclteam/comments/9042307.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bclteam/commentrss.aspx?PostID=9042307</wfw:commentRss><description>&lt;P&gt;The &lt;A href="http://www.microsoft.com/downloads/details.aspx?FamilyID=922b4655-93d0-4476-bda4-94cf5f8d4814&amp;amp;DisplayLang=en" mce_href="http://www.microsoft.com/downloads/details.aspx?FamilyID=922b4655-93d0-4476-bda4-94cf5f8d4814&amp;amp;DisplayLang=en"&gt;Visual Studio 2010 and .NET Framework 4.0 CTP&lt;/A&gt; is available for download as of last week.&amp;nbsp; The CTP contains new functionality throughout the .NET Framework, including several new BCL features and improvements:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;B&gt;Code Contracts&lt;/B&gt;&lt;BR&gt;System.Diagnostics.Contracts provides a language-agnostic way to express coding assumptions in .NET programs.&amp;nbsp; The contracts take the form of pre-conditions, post-conditions, and object invariants.&amp;nbsp; Contracts act as checked documentation of your external and internal APIs.&amp;nbsp; The contracts are used to improve testing via runtime checking, enable static contract verification, and documentation generation.&amp;nbsp; We partnered with Microsoft Research to deliver this feature in .NET 4.0.&amp;nbsp; More information and tools are available on Microsoft Research’s &lt;A href="http://research.microsoft.com/contracts/" mce_href="http://research.microsoft.com/contracts/"&gt;code contracts website&lt;/A&gt;.&amp;nbsp; There’s also a highly-rated &lt;A href="http://channel9.msdn.com/pdc2008/TL51/" mce_href="http://channel9.msdn.com/pdc2008/TL51/"&gt;PDC session&lt;/A&gt; available online.&lt;BR&gt;&lt;BR&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;B&gt;Parallel Extensions&lt;/B&gt;&lt;BR&gt;We worked with the Parallel Extensions team to add the Task Parallel Library (TPL), Coordination Data Structures, and Parallel LINQ (PLINQ) to the BCL in .NET 4.0.&amp;nbsp; This includes an improved ThreadPool scheduling algorithm for tasks, the static Parallel class, concurrent collections in System.Collections.Concurrent, and other coordination data structures such as LazyInit&amp;lt;T&amp;gt;, CountdownEvent, Barrier, SemaphoreSlim, SpinLock, SpinWait, and ManualResetEventSlim. More information is available over at the &lt;A href="http://blogs.msdn.com/pfxteam/archive/2008/10/31/9026988.aspx" mce_href="http://blogs.msdn.com/pfxteam/archive/2008/10/31/9026988.aspx"&gt;PFX team’s blog&lt;/A&gt;.&amp;nbsp; Also, check out &lt;A href="http://www.danielmoth.com/Blog/" mce_href="http://www.danielmoth.com/Blog/"&gt;Daniel Moth&lt;/A&gt;’s PDC session on &lt;A href="http://channel9.msdn.com/pdc2008/TL26/" mce_href="http://channel9.msdn.com/pdc2008/TL26/"&gt;Parallel Programming for Managed Developers with the Next Version of Microsoft Visual Studio&lt;/A&gt;. &lt;BR&gt;&lt;BR&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;B&gt;BigInteger&lt;/B&gt;&lt;BR&gt;System.Numerics.BigInteger is an arbitrary-precision integer data type.&amp;nbsp; We worked with the &lt;A href="http://code.msdn.microsoft.com/solverfoundation" mce_href="http://code.msdn.microsoft.com/solverfoundation"&gt;Microsoft Solver Foundation&lt;/A&gt; team to deliver a highly performant big integer implementation.&amp;nbsp; BigInteger supports all the standard integer operations, including bit manipulation.&amp;nbsp; It can be used from any .NET language, and some of the new .NET languages—such as F# and IronPython—have support built-in to the language. &lt;BR&gt;&lt;BR&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;B&gt;Memory Mapped Files&lt;/B&gt;&lt;BR&gt;System.IO.MemoryMappedFiles exposes the memory mapping functionality provided by Windows as first-class managed APIs.&amp;nbsp; Memory mapped files can be used to efficiently edit very large files and can also be used to create shared memory for inter-process communication.&amp;nbsp; Along with this feature, we’re also introducing System.IO.UnmanagedMemoryAccessor, a new class that enables random access to unmanaged memory similar to how UnmanagedMemoryStream enables sequential access to such memory. &lt;BR&gt;&lt;BR&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;B&gt;ResourceManager Improvements&lt;/B&gt;&lt;BR&gt;The ResourceManager in System.Resources has been improved to respect the user’s preferred UI languages when looking for localized resources, instead of only using the CurrentUICulture’s parent chain.&amp;nbsp; This means if the user has specified that she prefers French and Spanish, the ResourceManager will look for French and Spanish resources before falling back to the neutral resources.&amp;nbsp; This change is present in Silverlight 2 as well as .NET 4.0. &lt;BR&gt;&lt;BR&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;B&gt;Compression Improvements&lt;/B&gt;&lt;BR&gt;The compression algorithms in System.IO.Compression have been improved in .NET 4.0.&amp;nbsp; DeflateStream and GZipStream no longer inflate already compressed data.&amp;nbsp; This means that in most cases you’ll see much better compression ratios when using these streams on .NET 4.0.&amp;nbsp; We’ve also removed the 4 GB size limit, so you can now compress streams over 4 GB in size.&lt;BR&gt;&lt;BR&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;STRIKE&gt;&lt;B&gt;String Security Changes&lt;/B&gt;&lt;BR&gt;The default partial matching overloads on System.String (StartsWith, EndsWith, IndexOf, and LastIndexOf) have been changed to be culture-agnostic (ordinal) by default.&amp;nbsp; In addition, ToUpper and ToLower on System.String and System.Char have been changed to use the invariant culture instead of the current culture.&amp;nbsp; Although we have &lt;/STRIKE&gt;&lt;A href="http://blogs.msdn.com/bclteam/archive/2005/06/01/424012.aspx" mce_href="http://blogs.msdn.com/bclteam/archive/2005/06/01/424012.aspx"&gt;&lt;STRIKE&gt;guidance&lt;/STRIKE&gt;&lt;/A&gt;&lt;STRIKE&gt; and &lt;/STRIKE&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/bb386080.aspx" mce_href="http://msdn.microsoft.com/en-us/library/bb386080.aspx"&gt;&lt;STRIKE&gt;FxCop rules&lt;/STRIKE&gt;&lt;/A&gt;&lt;STRIKE&gt; that recommend always using overloads that take a StringComparison parameter, unaware developers often just use the default overloads.&amp;nbsp; In previous versions of .NET, these default overloads do a culture-sensitive comparison using the current culture.&amp;nbsp; This can often lead to subtle bugs, most notably security vulnerabilities, when unaware developers use the default overloads to do security-sensitive string comparisons.&amp;nbsp; This change helps mitigate these vulnerabilities.&amp;nbsp; The change is present in both Silverlight 2 and .NET 4.0.&amp;nbsp; Even with these changes, our guidance still stands: whenever an overload exists that takes a StringComparison parameter, use it instead of an overload that does not take this parameter.&amp;nbsp; It makes your code clearer and easier to maintain.&amp;nbsp; This is especially important because the default overloads for String.Compare and String.CompareTo will remain culture-sensitive because these methods are most often used when sorting strings to be shown to the user.&amp;nbsp; We plan to add a compat switch in the beta that will allow an app to specify whether it wants the old behavior.&lt;/STRIKE&gt;&lt;BR&gt;&lt;BR&gt;&lt;STRONG&gt;UPDATE for .NET 4 Beta 1&lt;/STRONG&gt;&amp;nbsp;In order to maintain high compatibility between .NET 4 and previous releases, we have decided to revert this change.&amp;nbsp; The behavior of String's default partial matching overloads and String and Char's ToUpper and ToLower methods now behave the same as they did in .NET 2.0/3.0/3.5.&amp;nbsp; The change back to the original behavior is present in .NET 4 Beta 1.&amp;nbsp; We apologize for any interim confusion this may cause.&amp;nbsp; We continue to &lt;A href="http://blogs.msdn.com/bclteam/archive/2005/06/01/424012.aspx" mce_href="http://blogs.msdn.com/bclteam/archive/2005/06/01/424012.aspx"&gt;recommend&lt;/A&gt; being explicit about the string comparison behavior you want, by always specifying a StringComparison value for the methods on String that accept it.&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;We’re also evaluating a number of potential new features and improvements for .NET 4.0 beta:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;B&gt;Variance annotations&lt;/B&gt;&lt;BR&gt;The next versions of C# and VB support safe co- and contra-variance for generic interface and delegate types.&amp;nbsp; Co-variance means that a generic of a type, e.g. an IEnumerable&amp;lt;String&amp;gt;, can be treated as a generic of any supertype, e.g. an IEnumerable&amp;lt;Object&amp;gt;.&amp;nbsp; Contra-variance means that a generic of a type, e.g. an Action&amp;lt;Object&amp;gt;, can be treated as a generic of a subtype, e.g. an Action&amp;lt;String&amp;gt;.&amp;nbsp; In C#, co-variance is annotated with the “out” keyword and contra-variance is annotated with the “in” keyword.&amp;nbsp; We are annotating several interfaces and delegates in the BCL for variance.&amp;nbsp; You can learn more about co- and contra-variance in Anders Hejlsberg’s PDC session on &lt;A href="http://channel9.msdn.com/pdc2008/TL16/" mce_href="http://channel9.msdn.com/pdc2008/TL16/"&gt;The Future of C#&lt;/A&gt;. &lt;BR&gt;&lt;BR&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;B&gt;Tuples&lt;/B&gt;&lt;BR&gt;We are providing common tuple types in the BCL to facilitate language interoperability and to reduce duplication in the framework.&amp;nbsp; A tuple is a simple generic data structure that holds an ordered set of items of heterogeneous types.&amp;nbsp; Tuples are supported natively in languages such as F# and IronPython, but are also easy to use from any .NET language such as C# and VB. &lt;BR&gt;&lt;BR&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;B&gt;SortedSet&amp;lt;T&amp;gt;&lt;/B&gt;&lt;BR&gt;We plan to add a&amp;nbsp;SortedSet&amp;lt;T&amp;gt; collection along with an ISet&amp;lt;T&amp;gt; interface.&amp;nbsp; SortedSet&amp;lt;T&amp;gt; uses a self-balancing tree which maintains data in sorted order for performance guarantees with insertion, deletion, and searches.&amp;nbsp; Both the new SortedSet&amp;lt;T&amp;gt; and the existing HashSet&amp;lt;T&amp;gt; implement ISet&amp;lt;T&amp;gt;. &lt;BR&gt;&lt;BR&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;B&gt;File System Enumeration Improvements&lt;/B&gt;&lt;BR&gt;We plan to add new file system enumeration APIs to System.IO.Directory and System.IO.DirectoryInfo that return IEnumerable&amp;lt;T&amp;gt;’s instead of arrays.&amp;nbsp; These new APIs are more efficient than the array-based APIs because they do not need to allocate a (potentially large) array and you can access the first results immediately instead of waiting for the entire enumeration to take place.&amp;nbsp; We’re also planning to add new convenience APIs for efficiently reading, writing, and appending lines from/to a text file using IEnumerable&amp;lt;String&amp;gt;.&amp;nbsp; These new APIs are useful in LINQ scenarios where you may want to quickly and efficiently query the contents of a text file and write out the results to a log file without allocating any arrays. &lt;BR&gt;&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;There are also a bunch of improvements to the CLR in .NET 4.0.&amp;nbsp; Here’s a high-level summary:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;In Process Side-by-Side: support for multiple CLR versions running in the same process.&lt;/LI&gt;
&lt;LI&gt;Interop improvements: no PIAs (check out &lt;A href="http://channel9.msdn.com/pdc2008/TL02/" mce_href="http://channel9.msdn.com/pdc2008/TL02/"&gt;Under the Hood: Advances in the .NET Type System&lt;/A&gt; and &lt;A href="http://channel9.msdn.com/pdc2008/TL34/" mce_href="http://channel9.msdn.com/pdc2008/TL34/"&gt;Managed and Native Code Interoperability: Best Practices&lt;/A&gt;)&lt;/LI&gt;
&lt;LI&gt;Simplified security model&lt;/LI&gt;
&lt;LI&gt;GC improvements (notifications and low-latency background collections)&lt;/LI&gt;
&lt;LI&gt;Profiling improvements (ability to attach/detach performance and memory profilers on the server)&lt;/LI&gt;
&lt;LI&gt;Debugging enhancements (support for Windows Error Reporting mini-dumps)&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;You can learn more about the next version of the CLR in Joshua Goodman’s PDC session on &lt;A href="http://channel9.msdn.com/pdc2008/PC49/" mce_href="http://channel9.msdn.com/pdc2008/PC49/"&gt;Microsoft .NET Framework: CLR Futures&lt;/A&gt;.&lt;/P&gt;
&lt;P&gt;Over the next couple of weeks we’ll be posting more about the new functionality that’s available in the CTP.&amp;nbsp; Do note that we’re working on many other improvements for 4.0 that we’re not quite ready to announce just yet.&lt;/P&gt;
&lt;P&gt;As always, we’d love to hear what you think of the CTP and announcements so far.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9042307" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/bclteam/archive/tags/News/default.aspx">News</category><category domain="http://blogs.msdn.com/bclteam/archive/tags/.NET+Framework+4/default.aspx">.NET Framework 4</category></item><item><title>BCL Team at PDC 2008 [Justin Van Patten]</title><link>http://blogs.msdn.com/bclteam/archive/2008/10/24/bcl-team-at-pdc-2008-justin-van-patten.aspx</link><pubDate>Sat, 25 Oct 2008 06:51:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9015688</guid><dc:creator>BCLTeam</dc:creator><slash:comments>1</slash:comments><comments>http://blogs.msdn.com/bclteam/comments/9015688.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bclteam/commentrss.aspx?PostID=9015688</wfw:commentRss><description>&lt;P&gt;Melitta, &lt;A href="http://blogs.msdn.com/kimhamil/" mce_href="http://blogs.msdn.com/kimhamil/"&gt;Kim&lt;/A&gt;, and I will be at &lt;A href="http://www.microsoftpdc.com/" mce_href="http://www.microsoftpdc.com/"&gt;PDC&lt;/A&gt; next week, along with several other members of the CLR team.&amp;nbsp; We’ll mostly be hanging out in the lounges chatting with folks and answering questions.&amp;nbsp; We’ll also be at the Ask-the-Experts night on Wednesday, so if you’ll be at PDC next week, stop by and say hi!&amp;nbsp; We love chatting with customers and listening to your feedback and suggestions.&lt;/P&gt;
&lt;P&gt;This year’s PDC has tons of different &lt;A href="https://sessions.microsoftpdc.com/" mce_href="https://sessions.microsoftpdc.com/"&gt;sessions&lt;/A&gt; on a vast array of .NET technologies including ASP.NET, WCF, WF, ADO.NET, Entity Framework, Data Services, XAML, WPF, Silverlight, and many more.&amp;nbsp; Here are some that you may find of interest:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;&lt;A href="http://channel9.msdn.com/pdc2008/PC49/" mce_href="http://channel9.msdn.com/pdc2008/PC49/"&gt;Microsoft .NET Framework: CLR Futures&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://channel9.msdn.com/pdc2008/TL51/" mce_href="http://channel9.msdn.com/pdc2008/TL51/"&gt;Research: Contract Checking and Automated Test Generation with Pex&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://channel9.msdn.com/pdc2008/TL34/" mce_href="http://channel9.msdn.com/pdc2008/TL34/"&gt;Managed and Native Code Interoperability: Best Practices&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://channel9.msdn.com/pdc2008/TL26/" mce_href="http://channel9.msdn.com/pdc2008/TL26/"&gt;Parallel Programming for Managed Developers with the Next Version of Microsoft Visual Studio&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://channel9.msdn.com/pdc2008/PC58/" mce_href="http://channel9.msdn.com/pdc2008/PC58/"&gt;Framework Design Guidelines&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://channel9.msdn.com/pdc2008/TL49/" mce_href="http://channel9.msdn.com/pdc2008/TL49/"&gt;Microsoft .NET Framework: Overview and Applications for Babies&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://channel9.msdn.com/pdc2008/TL33/" mce_href="http://channel9.msdn.com/pdc2008/TL33/"&gt;Managed Extensibility Framework: Overview&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://channel9.msdn.com/pdc2008/TL36/" mce_href="http://channel9.msdn.com/pdc2008/TL36/"&gt;Microsoft .NET Framework: Declarative Programming Using XAML&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://channel9.msdn.com/pdc2008/TL16/" mce_href="http://channel9.msdn.com/pdc2008/TL16/"&gt;The Future of C#&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://channel9.msdn.com/pdc2008/TL54/" mce_href="http://channel9.msdn.com/pdc2008/TL54/"&gt;Natural Interop with Silverlight, Office, and Python in Microsoft Visual C# and Microsoft Visual Basic&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://channel9.msdn.com/pdc2008/TL12/" mce_href="http://channel9.msdn.com/pdc2008/TL12/"&gt;Future Directions for Microsoft Visual Basic&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://channel9.msdn.com/pdc2008/TL10/" mce_href="http://channel9.msdn.com/pdc2008/TL10/"&gt;Deep Dive: Dynamic Languages in Microsoft .NET&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://channel9.msdn.com/pdc2008/TL44/" mce_href="http://channel9.msdn.com/pdc2008/TL44/"&gt;IronRuby: The Right Language for the Right Job&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://channel9.msdn.com/pdc2008/TL11/" mce_href="http://channel9.msdn.com/pdc2008/TL11/"&gt;An Introduction to Microsoft F#&lt;/A&gt;&lt;/LI&gt;
&lt;LI&gt;&lt;A href="http://channel9.msdn.com/pdc2008/TL27/" mce_href="http://channel9.msdn.com/pdc2008/TL27/"&gt;"Oslo": The Language&lt;/A&gt;&lt;/LI&gt;&lt;/OL&gt;
&lt;P&gt;The first five sessions listed above are the ones most closely related to the BCL and CLR; the first two will specifically touch on some of the features that our team (the BCL team) is delivering in .NET 4.0.&amp;nbsp; Of course there are plenty of other topics to keep an eye on, such as: parallelism, “Oslo”, Visual Studio, cloud computing, Windows 7, Internet Explorer, SQL Server, etc.&lt;/P&gt;
&lt;P&gt;Stay tuned to this blog next week for more details on what we’ll be unveiling next week at PDC 2008.&lt;/P&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9015688" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/bclteam/archive/tags/News/default.aspx">News</category><category domain="http://blogs.msdn.com/bclteam/archive/tags/.NET+Framework+4/default.aspx">.NET Framework 4</category></item><item><title>The Compare Contract [Kim Hamilton]</title><link>http://blogs.msdn.com/bclteam/archive/2008/10/06/the-compare-contract-kim-hamilton.aspx</link><pubDate>Mon, 06 Oct 2008 18:29:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8977955</guid><dc:creator>BCLTeam</dc:creator><slash:comments>13</slash:comments><comments>http://blogs.msdn.com/bclteam/comments/8977955.aspx</comments><wfw:commentRss>http://blogs.msdn.com/bclteam/commentrss.aspx?PostID=8977955</wfw:commentRss><description>&lt;H3&gt;A breaking change?&lt;/H3&gt;
&lt;P&gt;We recently heard from a customer who observed different sorting behavior in .NET FX 3.5 SP1 compared to 3.5 RTM.&lt;/P&gt;
&lt;P&gt;The different behavior was demonstrated with the following code. The class StringWrapper provided a custom sort in which nulls (null StringWrapper references) were moved to the end of the array. To achieve this, StringWrapper implemented IComparable&amp;lt;StringWrapper&amp;gt; and in its CompareTo method, nulls were always greater than non-nulls.&lt;/P&gt;&lt;PRE style="BORDER-BOTTOM: silver 1px solid; BORDER-LEFT: silver 1px solid; PADDING-BOTTOM: 10px; PADDING-LEFT: 10px; PADDING-RIGHT: 10px; FONT-FAMILY: 'Courier New'; COLOR: black; MARGIN-LEFT: 20px; FONT-SIZE: 10pt; BORDER-TOP: silver 1px solid; BORDER-RIGHT: silver 1px solid; PADDING-TOP: 10px"&gt;&lt;SPAN style="COLOR: #000000"&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;class&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;MyClass&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; {
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;static&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;void&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; Main() {
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;StringWrapper&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; a = &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;StringWrapper&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;();
        a.Value = &lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;"a"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;;
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;StringWrapper&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; b = &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;StringWrapper&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;();
        b.Value = &lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;"b"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;;
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;StringWrapper&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; c = &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;StringWrapper&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;();
        c.Value = &lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;"c"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;;
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;StringWrapper&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; d = &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;;

        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Console&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;.WriteLine(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;"Sort 1:"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;);
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;StringWrapper&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;[] src1 = &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;StringWrapper&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;[] { a, c, d, b };
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Array&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;.Sort(src1);
        PrintStringWrappers(src1); &lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;// print elements, method included at end
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;    }
}

&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;class&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;StringWrapper&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; : &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;IComparable&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;StringWrapper&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;&amp;gt; {
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;private&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; _value;
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; Value {
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;get&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; { &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; _value; }
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;set&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; { _value = &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;value&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;; }
    }

    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;// Recall that CompareTo returns:
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;// &amp;lt;0 if this object is less than other
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;//  0 if this object is equal to other
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;// &amp;gt;0 if this object is greater than other
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;int&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; CompareTo(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;StringWrapper&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; other) {
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; (other == &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;) &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; -1; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;// nulls are greater than any non-null
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; Value.CompareTo(other.Value);
    }

    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;override&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; ToString() {
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; Value;
    }
}&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;This custom comparison &lt;I&gt;apparently&lt;/I&gt; worked in .NET FX 3.5 RTM, but not .NET FX 3.5 SP1. &lt;/P&gt;
&lt;P&gt;&lt;U&gt;3.5 RTM output:&lt;/U&gt;&lt;/P&gt;&lt;PRE style="BORDER-BOTTOM: silver 1px solid; BORDER-LEFT: silver 1px solid; PADDING-BOTTOM: 10px; PADDING-LEFT: 10px; PADDING-RIGHT: 10px; FONT-FAMILY: 'Courier New'; COLOR: black; MARGIN-LEFT: 20px; FONT-SIZE: 10pt; BORDER-TOP: silver 1px solid; BORDER-RIGHT: silver 1px solid; PADDING-TOP: 10px"&gt;a
b
c
null&lt;/PRE&gt;
&lt;P&gt;&lt;U&gt;3.5 SP1&amp;nbsp;output:&lt;/U&gt;&lt;/P&gt;&lt;PRE style="BORDER-BOTTOM: silver 1px solid; BORDER-LEFT: silver 1px solid; PADDING-BOTTOM: 10px; PADDING-LEFT: 10px; PADDING-RIGHT: 10px; FONT-FAMILY: 'Courier New'; COLOR: black; MARGIN-LEFT: 20px; FONT-SIZE: 10pt; BORDER-TOP: silver 1px solid; BORDER-RIGHT: silver 1px solid; PADDING-TOP: 10px"&gt;a
b
null
c&lt;/PRE&gt;
&lt;H3&gt;Did the custom comparer really work?&lt;/H3&gt;
&lt;P&gt;The custom comparer worked in that example, in which only one of the array elements was null. Let’s throw in another null and see what happens:&lt;/P&gt;&lt;PRE style="BORDER-BOTTOM: silver 1px solid; BORDER-LEFT: silver 1px solid; PADDING-BOTTOM: 10px; PADDING-LEFT: 10px; PADDING-RIGHT: 10px; FONT-FAMILY: 'Courier New'; COLOR: black; MARGIN-LEFT: 20px; FONT-SIZE: 10pt; BORDER-TOP: silver 1px solid; BORDER-RIGHT: silver 1px solid; PADDING-TOP: 10px"&gt;&lt;SPAN style="COLOR: #000000"&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Console&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;.WriteLine(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;"Sort 2:"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;);
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;StringWrapper&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;[] src2 = &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;StringWrapper&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;[] { a, d, d, c, b };
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Array&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;.Sort(src2);
PrintStringWrappers(src2);&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;U&gt;3.5 RTM output:&lt;/U&gt;&lt;/P&gt;&lt;PRE style="BORDER-BOTTOM: silver 1px solid; BORDER-LEFT: silver 1px solid; PADDING-BOTTOM: 10px; PADDING-LEFT: 10px; PADDING-RIGHT: 10px; FONT-FAMILY: 'Courier New'; COLOR: black; MARGIN-LEFT: 20px; FONT-SIZE: 10pt; BORDER-TOP: silver 1px solid; BORDER-RIGHT: silver 1px solid; PADDING-TOP: 10px"&gt;a
b
null
null
c&lt;/PRE&gt;
&lt;P&gt;The problem is in the CompareTo method, but it isn’t obvious. The first line in CompareTo actually violates the IComparable&amp;lt;T&amp;gt;.CompareTo contract that any object compares greater than a null reference.&lt;/P&gt;&lt;PRE style="BORDER-BOTTOM: silver 1px solid; BORDER-LEFT: silver 1px solid; PADDING-BOTTOM: 10px; PADDING-LEFT: 10px; PADDING-RIGHT: 10px; FONT-FAMILY: 'Courier New'; COLOR: black; MARGIN-LEFT: 20px; FONT-SIZE: 10pt; BORDER-TOP: silver 1px solid; BORDER-RIGHT: silver 1px solid; PADDING-TOP: 10px"&gt;&lt;SPAN style="COLOR: #000000"&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;int&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; CompareTo(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;StringWrapper&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; other) {
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; (other == &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;) &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; -1; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;// violates CompareTo contract!
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; Value.CompareTo(other.Value);
}&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;H3&gt;The Compare Contract&lt;/H3&gt;
&lt;P&gt;&lt;A href="http://msdn.microsoft.com/en-us/library/43hc6wht.aspx" mce_href="http://msdn.microsoft.com/en-us/library/43hc6wht.aspx"&gt;IComparable&amp;lt;T&amp;gt;.CompareTo&lt;/A&gt; has the following requirements (from the MSDN docs)&lt;/P&gt;
&lt;P&gt;For objects A, B, and C, the following must be true: &lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;A.CompareTo(A) is required to return zero.&lt;/LI&gt;
&lt;LI&gt;If A.CompareTo(B) returns zero, then B.CompareTo(A) is required to return zero.&lt;/LI&gt;
&lt;LI&gt;If A.CompareTo(B) returns zero and B.CompareTo(C) returns zero, then A.CompareTo(C) is required to return zero.&lt;/LI&gt;
&lt;LI&gt;If A.CompareTo(B) returns a value other than zero, then B.CompareTo(A) is required to return a value of the opposite sign.&lt;/LI&gt;
&lt;LI&gt;If A.CompareTo(B) returns a value x that is not equal to zero, and B.CompareTo(C) returns a value y of the same sign as x, then A.CompareTo(C) is required to return a value of the same sign as x and y.&lt;/LI&gt;&lt;/UL&gt;
&lt;P&gt;By definition, any object compares greater than a null reference (Nothing in Visual Basic), and two null references compare equal to each other.&lt;/P&gt;
&lt;P&gt;The requirement that any object compares greater than null is a bit of a footnote at the end, so it makes sense that this may not be well known (we should highlight this more). &lt;/P&gt;
&lt;H3&gt;Still, why did the behavior change? (Gory details and a 3.5 RTM performance bug)&lt;/H3&gt;
&lt;P&gt;The high-level problem is that .NET’s sorting makes assumptions based on the Compare contract, so in some cases sorting will special case null, because it “knows” your comparer will adhere to the contract and return values consistent with that assumption. If you don’t adhere to the contract, you’ll get bitten at some point.&lt;/P&gt;
&lt;P&gt;The details are messier. Over the years, a variety of changes were made to improve the performance of Sort. There was a brief window (released in 3.5 RTM) where, during QuickSort, the swap and pivot steps were broken, and in intermediate steps, it would actually unsort certain already sorted arrays (the array had to contain&amp;nbsp; null). The end result would be correct, but because the elements were incorrectly swapped, sorting took much longer than it should.&lt;/P&gt;
&lt;P&gt;We fixed this bug in SP1, and this fix caused the different behavior between RTM and SP1.&lt;/P&gt;
&lt;H3&gt;Comply with Compare contract&lt;/H3&gt;
&lt;P&gt;The only way to ensure stability across versions is to comply with the Compare contract. Otherwise you fall prey to implementation quirks (or even bugs) in the runtime sort implementation. We’d like to be free to change it between releases, because we’d like to keep improving the performance!&lt;/P&gt;
&lt;H3&gt;Enough preaching, what are my options?&lt;/H3&gt;
&lt;P&gt;The interesting thing is that the StringWrapper implementation gets you mostly there. The apparent goal of the wrapper is to implement a special sort of strings that pushes nulls to the end. You can do what you want if you create a StringWrapper with null values, as follows:&lt;/P&gt;&lt;PRE style="BORDER-BOTTOM: silver 1px solid; BORDER-LEFT: silver 1px solid; PADDING-BOTTOM: 10px; PADDING-LEFT: 10px; PADDING-RIGHT: 10px; FONT-FAMILY: 'Courier New'; COLOR: black; MARGIN-LEFT: 20px; FONT-SIZE: 10pt; BORDER-TOP: silver 1px solid; BORDER-RIGHT: silver 1px solid; PADDING-TOP: 10px"&gt;&lt;SPAN style="COLOR: #000000"&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;int&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; CompareTo(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;StringWrapper&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; other) {
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; (other == &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;) &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; 1;
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; (Value == &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &amp;amp;&amp;amp; other.Value == &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;) &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; 0;
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; (Value == &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;) &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; 1;
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; (other.Value == &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;) &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; -1;
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; Value.CompareTo(other.Value);
}&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;P&gt;This actually obeys the compare contract and won’t be brittle to changes in our sort implementation.&lt;/P&gt;
&lt;H3&gt;Full Source &lt;/H3&gt;&lt;PRE style="BORDER-BOTTOM: silver 1px solid; BORDER-LEFT: silver 1px solid; PADDING-BOTTOM: 10px; PADDING-LEFT: 10px; PADDING-RIGHT: 10px; FONT-FAMILY: 'Courier New'; COLOR: black; MARGIN-LEFT: 20px; FONT-SIZE: 10pt; BORDER-TOP: silver 1px solid; BORDER-RIGHT: silver 1px solid; PADDING-TOP: 10px"&gt;&lt;SPAN style="COLOR: #000000"&gt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; System;
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;using&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; System.Collections.Generic;

&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;class&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;MyClass&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; {
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;static&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;void&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; Main() {

        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;StringWrapper&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; a = &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;StringWrapper&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;();
        a.Value = &lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;"a"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;;
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;StringWrapper&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; b = &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;StringWrapper&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;();
        b.Value = &lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;"b"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;;
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;StringWrapper&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; c = &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;StringWrapper&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;();
        c.Value = &lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;"c"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;;
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;StringWrapper&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; d = &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;;
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;StringWrapper&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; e = &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;StringWrapper&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;();
        e.Value = &lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;"e"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;;
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;StringWrapper&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; f = &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;StringWrapper&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;();
        f.Value = &lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;"f"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;;


        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Console&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;.WriteLine(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;"Sort 1:"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;);
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;StringWrapper&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;[] src1 = &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;StringWrapper&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;[] { a, c, d, b };
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Array&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;.Sort(src1);
        PrintStringWrappers(src1);
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;// .NET FX 3.5 RTM output: a b c null
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;// .NET FX 3.5 SP1 output: a b null c

&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Console&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;.WriteLine(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;"-----"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;);
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Console&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;.WriteLine(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;"Sort 2:"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;);
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;StringWrapper&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;[] src2 = &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;new&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;StringWrapper&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;[] { a, d, d, c, b };
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Array&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;.Sort(src2);
        PrintStringWrappers(src2);
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;// .NET FX 3.5 RTM output: a b null null c
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;    }

    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;private&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;static&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;void&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; PrintStringWrappers(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;StringWrapper&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;[] swArray) {
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;foreach&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; (&lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;StringWrapper&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; sw &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;in&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; swArray) {
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; (sw == &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;)
                &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Console&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;.WriteLine(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #a31515"&gt;"null"&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;);
            &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;else
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;                &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;Console&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;.WriteLine(sw);
        }

    }
}

&lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;class&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;StringWrapper&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; : &lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;IComparable&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;StringWrapper&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;&amp;gt; {
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;private&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; _value;
    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; Value {
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;get&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; { &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; _value; }
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;set&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; { _value = &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;value&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;; }
    }

    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;// original CompareTo -- violates Compare contract!
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;int&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; CompareTo(&lt;/SPAN&gt;&lt;SPAN style="COLOR: #2b91af"&gt;StringWrapper&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; other) {
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;if&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; (other == &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;null&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;) &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; -1;
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; Value.CompareTo(other.Value);
    }

    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;// alternate CompareTo, which obeys Compare contract and moves null Values to the end
&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #008000"&gt;/*
    public int CompareTo(StringWrapper other)
    {
        if (other == null) return 1;
        if (Value == null &amp;amp;&amp;amp; other.Value == null) return 0;
        if (Value == null) return 1;
        if (other.Value == null) return -1;
        return Value.CompareTo(other.Value);
    }
    */

&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt;    &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;public&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;override&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;string&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; ToString() {
        &lt;/SPAN&gt;&lt;SPAN style="COLOR: #0000ff"&gt;return&lt;/SPAN&gt;&lt;SPAN style="COLOR: #000000"&gt; Value;
    }
}&lt;/SPAN&gt;&lt;/PRE&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8977955" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/bclteam/archive/tags/System.Collections/default.aspx">System.Collections</category><category domain="http://blogs.msdn.com/bclteam/archive/tags/.NET+Framework+3.5/default.aspx">.NET Framework 3.5</category></item></channel></rss>