<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Veggerby : IBlog &#187; Reference Sheet</title>
	<atom:link href="http://blog.veggerby.dk/category/reference-sheet/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.veggerby.dk</link>
	<description>Low decoupling, highly incoherent</description>
	<lastBuildDate>Fri, 28 May 2010 19:47:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Must have tools for .NET developers</title>
		<link>http://blog.veggerby.dk/2008/09/12/must-have-tools-for-net-developers/</link>
		<comments>http://blog.veggerby.dk/2008/09/12/must-have-tools-for-net-developers/#comments</comments>
		<pubDate>Fri, 12 Sep 2008 15:17:44 +0000</pubDate>
		<dc:creator>nosey</dc:creator>
				<category><![CDATA[.NET General]]></category>
		<category><![CDATA[Reference Sheet]]></category>
		<category><![CDATA[ASP.NET WPF]]></category>
		<category><![CDATA[On .NET]]></category>
		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://blog.veggerby.dk/2008/09/12/must-have-tools-for-net-developers/</guid>
		<description><![CDATA[Like so many others have done before me I would like to present my take on a compiled list of favorite tools for developing using .NET. Here goes: Reflector The most useful tool ever to reverse engineer assemblies &#8211; yes, it is a gray-zone regarding IP, but nonetheless very, very use full. Kudos to Lutz [...]]]></description>
			<content:encoded><![CDATA[<p>Like so many others have done before me I would like to present my take on a compiled list of favorite tools for developing using .NET.</p>
<p>Here goes:</p>
<p><a href="http://www.red-gate.com/products/reflector/">Reflector</a></p>
<p>The most useful tool ever to reverse engineer assemblies &#8211; yes, it is a gray-zone regarding <a href="http://en.wikipedia.org/wiki/Intellectual_property">IP</a>, but nonetheless very, very use full. <a href="http://en.wikipedia.org/wiki/Kudos">Kudos</a> to <a href="http://www.lutzroeder.com/">Lutz Roeder</a> for this ultimate tool, and thank you very much for your effort in this. Lutz announced some days ago that he would end his work on Reflector. Red Gate (known for their useful tool SQL Compare &#8211; as mentioned later on <img src='http://blog.veggerby.dk/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> ) has taken over and &quot;(&#8230;) will continue to <strong>maintain a free version for the benefit of the community</strong>&quot;. Do they implicitly say that there will be a commercial version!? I hope not &#8211; that would for sure have <u>some</u> effect on the <a href="http://www.codeplex.com/reflectoraddins">Reflector community</a>.</p>
<p><a href="http://www.red-gate.com/products/SQL_Compare/index.htm">Red Gate SQL Compare</a></p>
<p>I really, really hate to include a commercial product in my toolbox, but being there are no free alternatives to a much required tool, I will include the best one I know of (or rather the only one I have used, but it is extremely useful and good so why bother with the others!?). Please drop a comment if you know of free and/or good/better alternatives. Price tag on the basic SQL Compare is $395.</p>
<p><a href="http://www.linqpad.net/">LINQPad</a></p>
<p>Query Analyzer for <a href="http://msdn.microsoft.com/en-us/library/bb308959.aspx">LINQ</a>. Very nice tool to help build, execute and debug queries, wether it be LINQ for SQL, LINQ for Objects or LINQ for XML.</p>
<p><a href="http://code.msdn.microsoft.com/sourceanalysis">StyleCop</a></p>
<p>StyleCop is a <a href="http://msdn.microsoft.com/en-us/vstudio/default.aspx">Visual Studio</a> plug-in that performs code analysis directly on source code with the intent on enforcing a common coding standard for layout, readability, documentation and maintainability. SDK documentation for creating custom rules is available. StyleCop was originally created by one devoted (and might I add brilliant) <a href="http://microsoft.com/">Microsoft</a> employee (Jason Allor) <em>in his spare time</em>. The tool has been <a href="http://blogs.msdn.com/sourceanalysis/archive/2008/05/23/announcing-the-release-of-microsoft-source-analysis.aspx">used internally</a> in Microsoft for years, but was first made available to the general public earlier this year. Follow Jason&#8217;s/the StyleCop blog <a href="http://blogs.msdn.com/sourceanalysis/">here</a>.</p>
<p><a href="http://code.msdn.microsoft.com/codeanalysis">FxCop</a></p>
<p>FxCop is a tool to analyze managed assemblies for possible security issues and possible design and performance improvements that can be implemented. </p>
<p><a href="http://visualsvn.com/">VisualSVN</a></p>
<p>Sorry, but yet another commercial product. If you are using the most excellent <a href="http://en.wikipedia.org/wiki/Revision_control">version control system</a>&#160;<a href="http://subversion.tigris.org/">Subversion</a> (if not then consider it!), there is a most excellent plug-in for Visual Studio. Comes with a free <a href="http://visualsvn.com/server/">server</a> version as well, which simplifies setup of Subversion on a Windows box. A free alternative &#8211; however I did not find it nearly as good as Visual SVN &#8211; is <a href="http://ankhsvn.open.collab.net/">AnkhSVN</a>. Neither unfortunately though are <a href="http://msdn.microsoft.com/en-us/library/bb166170(VS.80).aspx">MSSCCI</a> (Microsoft Source Code Control Interface) which means that they do not plug-in to the native source control module in Visual Studio. Price tag for Visual SVN is $49. For more information about Subversion you can read the <a href="http://svnbook.red-bean.com/">SVN Book online</a>.</p>
<h2>For ASP.NET Developers</h2>
<p>Must haves:</p>
<p><a href="http://getfirefox.com/">Firefox</a> with <a href="http://getfirebug.com/">Firebug</a> and <a href="https://addons.mozilla.org/en-US/firefox/addon/60">Web Developer Toolbar</a></p>
<p>Firefox speaks for itself, and so should Firebug, but a brief introduction: Firebug allows you to inspect and modify HTML, CSS and DOM. Debugging JavaScript and explicitly capture JavaScript <a href="http://www.w3.org/TR/XMLHttpRequest/">XmlHttpRequest</a> calls for debugging <a href="http://en.wikipedia.org/wiki/Ajax_(programming)">AJAX</a>. The Web Developer Toolbar provides some additional functionality to what Firebug adds, but to some extent is a complimentary plugin.</p>
<p>Internet Explorer with <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=E59C3964-672D-4511-BB3E-2D5E1DB91038&amp;displaylang=en">Developer Toolbar</a></p>
<p>It is inevitable that as a web developer you need to assure <a href="http://en.wikipedia.org/wiki/Cross-browser">cross-browser compatibility</a>. Therefor a similar tool exists for Internet Explorer 6 and 7, however it not nearly as cool, so for general debugging, etc. Firebug is the choice, but for IE specific, the Internet Explorer Developer Toolbar does come handy.</p>
<p><a href="http://www.fiddlertool.com/fiddler/">Fiddler</a></p>
<p>Another tool that can help in debugging web applications/services is Fiddler. Fiddler acts as a HTTP proxy, logging all HTTP traffic from the local computer to other computers. This however means that out-of-the-box HTTP debugging when using <a href="http://blog.veggerby.dk/2007/05/20/differences-between-using-cassini-and-iis/">Cassini</a> (i.e. the development web &quot;server&quot; in Visual Studio) is not possible. <a href="http://weblogs.asp.net/asptest/archive/2008/08/13/tip-on-using-fiddler-with-cassini-and-localhost.aspx">It</a> <a href="http://www.codinghorror.com/blog/archives/000590.html">has</a> <a href="http://weblogs.asp.net/lorenh/archive/2008/01/10/tip-for-using-fiddler-on-localhost.aspx">to</a> <a href="http://weblogs.asp.net/scottcate/archive/2008/05/22/working-with-fiddler-on-localhost.aspx">be</a> <a href="http://www.treeratfishing.com/2008/06/08/using-fiddler-with-localhost-traffic/">tweaked</a>.</p>
<h2>For WPF / Silverlight Developers</h2>
<p><a href="http://www.kaxaml.com/">Kaxaml</a></p>
<p>Kaxaml is a lightweight <a href="http://msdn.microsoft.com/en-us/library/ms752059.aspx">XAML</a> editor with the split design / output view similar to the Visual Studio IDE. Kaxaml is a complimentary tool to <a href="http://en.wikipedia.org/wiki/Microsoft_Expression_Blend">Expression Blend</a>, however Blend provides much more functionality, hence &quot;lightweight&quot;.</p>
<p><a href="http://www.codeproject.com/KB/macros/MoleForVisualStudioEdit.aspx">Mole</a></p>
<p>Mole is a reverse engineering tool, similar to Reflector. However Mole disassembles the XAML of a <a href="http://msdn.microsoft.com/en-us/netframework/aa663326.aspx">WPF</a>/<a href="http://silverlight.net">Silverlight</a> application and provides a tree view of the XAML structure. Nice for &quot;how did they do that&quot;, but again gray zone concerning IP.</p>
<h2><a href="http://en.wikipedia.org/wiki/Dark_horse">&quot;Dark Horses&quot;</a></h2>
<p>Since I have not had any real experience with these I will put them on a &quot;dark horse&quot; list, just for reference, since they might prove themselves valuable given the time/opportunity to use them.</p>
<p><a href="http://code.msdn.microsoft.com/fds">Framework Design Studio</a></p>
<p>Quoting the FDS site:</p>
<blockquote><p>Framework Design Studio is a set of tools for reusable library designers. The package contains a GUI tool for viewing, reviewing, and comparing versions of managed APIs. It also contains a command line tool for generating API diff reports. Simple user guide explaining the basics of the tool is included in the setup.</p>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://blog.veggerby.dk/2008/09/12/must-have-tools-for-net-developers/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Type.IsAssignableFrom() to check inheritance</title>
		<link>http://blog.veggerby.dk/2008/07/13/using-typeisassignablefrom-to-check-inheritance/</link>
		<comments>http://blog.veggerby.dk/2008/07/13/using-typeisassignablefrom-to-check-inheritance/#comments</comments>
		<pubDate>Sun, 13 Jul 2008 22:07:32 +0000</pubDate>
		<dc:creator>nosey</dc:creator>
				<category><![CDATA[.NET General]]></category>
		<category><![CDATA[Reference Sheet]]></category>
		<category><![CDATA[inheritance]]></category>

		<guid isPermaLink="false">http://blog.veggerby.dk/2008/07/13/using-typeisassignablefrom-to-check-inheritance/</guid>
		<description><![CDATA[Having been in the situation needing to check if a given instance of an object either implements an interface or a class in the form of a given Type object (i.e. &#34;if A is B&#34; wont do) I decided to write a little &#34;note to self&#34; post which others might find useful. This is basically [...]]]></description>
			<content:encoded><![CDATA[<p>Having been in the situation needing to check if a given instance of an object either implements an interface or a class in the form of a given <a href="http://msdn.microsoft.com/en-us/library/system.type.aspx">Type</a> object (i.e. &quot;if A is B&quot; wont do) I decided to write a little &quot;note to self&quot; post which others might find useful.</p>
<p>This is basically just a &quot;wrapper&quot; around <a href="http://www.hanselman.com/blog/">Scott Hanselman&#8217;s</a> post from a long time ago <a href="http://www.hanselman.com/blog/DoesATypeImplementAnInterface.aspx">Does a Type Implement an Interface?</a></p>
<p>For a &quot;class type&quot; you can use the <a href="http://msdn.microsoft.com/en-us/library/system.type.issubclassof.aspx">Type.IsSubclassOf()</a> method and for an interface you can use something in the line of:</p>
<div class="vscode"><span style="color: #0000ff">if</span> (<span style="color: #0000ff">typeof</span>(<span style="color: #2b91af">MyClass</span>).GetInterface(<span style="color: #a31515">&quot;MyNamespace.IMyInterface&quot;</span>) != <span style="color: #0000ff">null</span>)    <br />{    <br />&#160;&#160;&#160; <span style="color: #008000">// MyClass implements IMyInterface     <br /></span>}</div>
<p>However the string literal looks bad also neither solution provides a simple check for &quot;is this type implementing/a subclass of this interface/class&quot;.</p>
<p>The gist of Scott&#8217;s post is that using <a href="http://msdn.microsoft.com/en-us/library/system.type.isassignablefrom.aspx">Type.IsAssignableFrom()</a> can solve your problem concerning interfaces, but the same logic applies for classes. So:</p>
<div class="vscode"><span style="color: #0000ff">if</span> (<span style="color: #0000ff">typeof</span>(<span style="color: #2b91af">IMyInterface</span>).IsAssignableFrom(<span style="color: #0000ff">typeof</span>(<span style="color: #2b91af">MyClass</span>)))    <br />{    <br />&#160;&#160;&#160; <span style="color: #008000">// MyClass implements IMyInterface     <br /></span>}    </p>
<p><span style="color: #0000ff">if</span> (<span style="color: #0000ff">typeof</span>(<span style="color: #2b91af">MyClass</span>).IsAssignableFrom(<span style="color: #0000ff">typeof</span>(<span style="color: #2b91af">MySubClass</span>)))    <br />{    <br />&#160;&#160;&#160; <span style="color: #008000">// MySubClass is a subclass of MyClass     <br /></span>}    </p>
<p><span style="color: #0000ff">if</span> (<span style="color: #0000ff">typeof</span>(<span style="color: #2b91af">IMyExtendedInterface</span>).IsAssignableFrom(<span style="color: #0000ff">typeof</span>(<span style="color: #2b91af">IMyInterface</span>)))    <br />{    <br />&#160;&#160;&#160; <span style="color: #008000">// IMyExtendedInterface extends IMyInterface     <br /></span>}</div>
<p>Actually this is exactly what the MSDN page for Type.IsAssignableFrom() states:</p>
<blockquote><p>true if c and the current Type represent the same type, or if the current Type is in the inheritance hierarchy of c, or if the current Type is an interface that c implements, <u>or if c is a generic type parameter and the current Type represents one of the constraints of c</u></p>
</blockquote>
<p>First in &quot;layman&quot; terms it means:</p>
<div class="vscode"><span style="color: #2b91af">TypeA</span> a;    <br /><span style="color: #2b91af">TypeB</span> b;    <br /><span style="color: #0000ff">if</span> (<span style="color: #0000ff">typeof</span>(<span style="color: #2b91af">TypeA</span>).IsAssignableFrom(<span style="color: #0000ff">typeof</span>(<span style="color: #2b91af">TypeB</span>)))    <br />{    <br />&#160;&#160;&#160; a = b; <span style="color: #008000">// this will work     <br /></span>}</div>
<p>But what does the underlined text then mean in the context of this check? The samples on this on the MSDN page are totally nonsense (e.g. text states &quot;List&lt;int&gt; assignable from List&lt;Type&gt;&quot; but in fact List&lt;int&gt; and int[] are compared). </p>
<p>The point in that statement is that A&lt;T&gt; is assignable from A&lt;S&gt; if T is assignable from S.</p>
<p>So it is a little more inclusive (which is no surprise) than just checking inheritance, but as long as the &quot;master&quot; class/interface is known explicitly (which is most often the case, since a scenario for this is checking if a type specified in config is in the correct inheritance tree) the check will be safe.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.veggerby.dk/2008/07/13/using-typeisassignablefrom-to-check-inheritance/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Custom Sorting using Compare method(s)</title>
		<link>http://blog.veggerby.dk/2007/04/26/custom-sorting-using-compare-methods/</link>
		<comments>http://blog.veggerby.dk/2007/04/26/custom-sorting-using-compare-methods/#comments</comments>
		<pubDate>Thu, 26 Apr 2007 13:09:21 +0000</pubDate>
		<dc:creator>nosey</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Reference Sheet]]></category>
		<category><![CDATA[compare]]></category>

		<guid isPermaLink="false">http://blog.veggerby.dk/2007/04/26/custom-sorting-using-compare-methods/</guid>
		<description><![CDATA[Are you (just like me) one of these people who just can&#8217;t remember wether A &#62; B should yield 1 or -1 in a compare method. I know there must be some (higher) form of logic behind it that makes it easily deductible when you just think about it. Anyway as small reference sheet: Compare(A,B) [...]]]></description>
			<content:encoded><![CDATA[<p>Are you (just like me) one of these people who just can&#8217;t remember wether A &gt; B should yield 1 or -1 in a compare method. I know there must be some (higher) form of logic behind it that makes it easily deductible when you just think about it.</p>
<p>Anyway as small reference sheet:</p>
<p><strong>Compare(A,B) or A.CompareTo(B)</strong></p>
<p>This should yield:</p>
<table>
<tr>
<th>&#8220;Compare statement&#8221;</th>
<th>Yields</th>
<th>Resulting order</th>
</tr>
<tr>
<td>A &gt; B</td>
<td>1</td>
<td>B, A</td>
</tr>
<tr>
<td>A = B</td>
<td>0</td>
<td><em>non-deterministic</em></td>
</tr>
<tr>
<td>A &lt; B</td>
<td>-1</td>
<td>A, B</td>
</tr>
</table>
]]></content:encoded>
			<wfw:commentRss>http://blog.veggerby.dk/2007/04/26/custom-sorting-using-compare-methods/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Formatting strings</title>
		<link>http://blog.veggerby.dk/2007/04/15/formatting-strings/</link>
		<comments>http://blog.veggerby.dk/2007/04/15/formatting-strings/#comments</comments>
		<pubDate>Sun, 15 Apr 2007 10:27:00 +0000</pubDate>
		<dc:creator>nosey</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Reference Sheet]]></category>
		<category><![CDATA[string formatting]]></category>

		<guid isPermaLink="false">http://blog.veggerby.dk/2007/04/15/formatting-strings/</guid>
		<description><![CDATA[After having clicked myself through the MSDN pages of string.Format() one too many times I will, part for my own reference and part for other not wanting to waste valuable synapses memorizing this, compile a list of the common strings when using string.Format(). NB! all results depend more or less on which culture is used, [...]]]></description>
			<content:encoded><![CDATA[<p>After having clicked myself through the MSDN pages of <a href="http://msdn2.microsoft.com/en-us/library/system.string.format.aspx">string.Format()</a> one too many times I will, part for my own reference and part for other not wanting to waste valuable synapses memorizing this, compile a list of the common strings when using string.Format().</p>
<p>NB! all results depend more or less on which culture is used, I am for the sake of the majority showing examples in en-us.</p>
<table>
<tr>
<th>Format</th>
<th>Name</th>
<th>Type</th>
<th>Sample value</th>
<th>Sample format</th>
<th>Sample result</th>
</tr>
<tr>
<td>C or c</td>
<td>Currency</td>
<td>any numerical</td>
<td>12345.6<br />
12345.6<br />
-123.567</td>
<td>{0:C}<br />
{0:C3}<br />
{0:C2}</td>
<td>$12,345.60<br />
$12,345.600<br />
($123.57)</td>
</tr>
<tr>
<td>D or d</td>
<td>Decimal</td>
<td>integer values</td>
<td>12<br />
12<br />
-12</td>
<td>{0:D}<br />
{0:D4}<br />
{0:D4}</td>
<td>12<br />
0012<br />
-0012</td>
</tr>
<tr>
<td>D or d</td>
<td>&nbsp;</td>
<td>enumeration</td>
<td>DayOfWeek.Monday<br />
WD.Fri | WD.Mon</td>
<td>{0:D}</td>
<td>5,<br />
17</td>
</tr>
<tr>
<td>d</td>
<td>Short date pattern</td>
<td>DateTime</td>
<td>21:00:00 2007-02-20</td>
<td>{0:d}</td>
<td>2/20/2007</td>
</tr>
<tr>
<td>D</td>
<td>Long date pattern</td>
<td>DateTime</td>
<td>21:00:00 2007-02-20</td>
<td>{0:D}</td>
<td>Tuesday, February 20, 2007</td>
</tr>
<tr>
<td>E or e</td>
<td>Scientific</td>
<td>any numerical</td>
<td>123.5<br />
123.5<br />
123.5</td>
<td>{0:E}<br />
{0:E4}<br />
{0:e4}</td>
<td>1.235000E+002<br />
1.2350E+002<br />
1.2350e+002</td>
</tr>
<tr>
<td>F or f</td>
<td>Fixed-point</td>
<td>any numerical</td>
<td>123.5<br />
123.5<br />
-123.5</td>
<td>{0:F}<br />
{0:F3}<br />
{0:F2}</td>
<td>123.50<br />
123.500<br />
-123.50</td>
</tr>
<tr>
<td>F or f</td>
<td>&nbsp;</td>
<td>enumeration</td>
<td>DayOfWeek.Monday<br />
WD.Fri | WD.Mon</td>
<td>{0:F}</td>
<td>Monday<br />
Mon, Fri</td>
</tr>
<tr>
<td>f</td>
<td>Full date/time pattern (short time)</td>
<td>DateTime</td>
<td>21:00:00 2007-02-20</td>
<td>{0:f}</td>
<td>Tuesday, February 20, 2007 9:00 PM</td>
</tr>
<tr>
<td>F</td>
<td>Full date/time pattern (long time)</td>
<td>DateTime</td>
<td>21:00:00 2007-02-20</td>
<td>{0:F}</td>
<td>Tuesday, February 20, 2007 9:00:00 PM</td>
</tr>
<tr>
<td>G or g</td>
<td>General</td>
<td>floating point</td>
<td>123456.7<br />
123.5<br />
123.5<br />
123.5<br />
123.5<br />
123.5<br />
-123.50</td>
<td>{0:G}<br />
{0:G2}<br />
{0:g2}<br />
{0:G3}<br />
{0:G4}<br />
{0:G5}<br />
{0:G2}</td>
<td>123456.7<br />
1.2E+02<br />
1.2e+02<br />
124<br />
123.5<br />
123.5<br />
-1.2E+02</td>
</tr>
<tr>
<td>G or g</td>
<td>General</td>
<td>integer value</td>
<td>123 (default precision based on type)</td>
<td>{0:G}<br />
{0:G1}<br />
{0:g2}<br />
{0:G3}<br />
{0:G4}</td>
<td>123<br />
1E+02<br />
1.2e+02<br />
123<br />
123</td>
</tr>
<tr>
<td>G or g</td>
<td>&nbsp;</td>
<td>enumeration</td>
<td>DayOfWeek.Monday<br />
WD.Fri | WD.Mon</td>
<td>{0:G}</td>
<td>Monday<br />
Mon, Fri</td>
</tr>
<tr>
<td>g</td>
<td>General date/time pattern (short time)</td>
<td>DateTime</td>
<td>21:00:00 2007-02-20</td>
<td>{0:g}</td>
<td>2/20/2007 9:00 PM</td>
</tr>
<tr>
<td>G</td>
<td>General date/time pattern (long time)</td>
<td>DateTime</td>
<td>21:00:00 2007-02-20</td>
<td>{0:G}</td>
<td>2/20/2007 9:00:00 PM</td>
</tr>
<tr>
<td>M or m</td>
<td>Month day pattern</td>
<td>DateTime</td>
<td>21:00:00 2007-02-20</td>
<td>{0:M}</td>
<td>February 20</td>
</tr>
<tr>
<td>N or n</td>
<td>Number</td>
<td>any numerical</td>
<td>123456.7<br />
12345.6<br />
12345.6<br />
12345.6<br />
-123.45</td>
<td>{0:N}<br />
{0:N0}<br />
{0:N1}<br />
{0:N2}<br />
{0:N1}</td>
<td>123,456.70<br />
12,346<br />
12,345.6<br />
12,345.60<br />
-123.5</td>
</tr>
<tr>
<td>o</td>
<td>Round-trip date/time pattern</td>
<td>DateTime</td>
<td>21:00:00 2007-02-20</td>
<td>{0:o}</td>
<td>2007-02-20T21:00:00.0000000</td>
</tr>
<tr>
<td>P or p</td>
<td>Percent</td>
<td>any numerical</td>
<td>0.123<br />
0.1234<br />
1.234</td>
<td>{0:P}<br />
{0:P1}<br />
{0:P2}</td>
<td>12.30%<br />
12.3%<br />
123.40%</td>
</tr>
<tr>
<td>R or r</td>
<td>Round-trip</td>
<td>single or double</td>
<td>123456789.012</td>
<td>{0:R}</td>
<td>123456789.012</td>
</tr>
<tr>
<td>R or r</td>
<td>RFC1123 pattern</td>
<td>DateTime</td>
<td>21:00:00 2007-02-20</td>
<td>{0:R}</td>
<td>Tue, 20 Feb 2007 21:00:00 GMT</td>
</tr>
<tr>
<td>s</td>
<td>Sortable date/time pattern; conforms to ISO 8601</td>
<td>DateTime</td>
<td>21:00:00 2007-02-20</td>
<td>{0:s}</td>
<td>2007-02-20T21:00:00</td>
</tr>
<tr>
<td>t</td>
<td>Short time pattern</td>
<td>DateTime</td>
<td>21:00:00 2007-02-20</td>
<td>{0:t}</td>
<td>9:00 PM</td>
</tr>
<tr>
<td>T</td>
<td>Long time pattern</td>
<td>DateTime</td>
<td>21:00:00 2007-02-20</td>
<td>{0:T}</td>
<td>9:00:00 PM</td>
</tr>
<tr>
<td>u</td>
<td>Universal sortable date/time pattern</td>
<td>DateTime</td>
<td>21:00:00 2007-02-20</td>
<td>{0:u}</td>
<td>2007-02-20 21:00:00Z</td>
</tr>
<tr>
<td>U</td>
<td>Universal sortable date/time pattern</td>
<td>DateTime</td>
<td>21:00:00 2007-02-20</td>
<td>{0:U}</td>
<td>Tuesday, February 20, 2007 8:00:00 PM</td>
</tr>
<tr>
<td>Y or y</td>
<td>Year month pattern</td>
<td>DateTime</td>
<td>21:00:00 2007-02-20</td>
<td>{0:D}</td>
<td>February, 2007</td>
</tr>
<tr>
<td>X or x</td>
<td>Hexadecimal</td>
<td>integer value</td>
<td>23712<br />
23712<br />
23712<br />
23712</td>
<td>{0:X}<br />
{0:X2}<br />
{0:X6}<br />
{0:x}</td>
<td>5CA0<br />
5CA0<br />
005CA0<br />
5ca0</td>
</tr>
<tr>
<td>X or x</td>
<td>&nbsp;</td>
<td>enumeration</td>
<td>DayOfWeek.Monday<br />
WD.Fri | WD.Mon</td>
<td>{0:X}</td>
<td>00000005<br />
00000011</td>
</tr>
</table>
<p>Note: When scientific notation comes into play, the case of the format specifier is significant. To have the output with E (capital e), i.e. 1.02E+02 you must you capital format specifier, i.e. {0:E2}. Note that General provides the same result as doing (byte|int|double|...).ToString()</p>
<p>The Round-trip specifier is a bit special. It only allows single or double values and is used to guarantee that a number can be converted back into the same numerical value from it's string representation. It is quite similar to General, and actually tries the General method first and then parses it back into a double or single. If it is not the same result, it extends the default General precision (15 for double and 7 for single) to 17 and 9 respectively. A presicion specifier is ignored for Round-trip.</p>
<p>For the enumeration with FlagsAttribute I have used a custom WD (WeekDay) enumeration like the following:</p>
<div class="igBar"><span id="lcsharp-2"><a href="#" onclick="javascript:showPlainTxt('csharp-2'); return false;">PLAIN TEXT</a></span></div>
<div class="syntax_hilite"><span class="langName">C#:</span>
<div id="csharp-2">
<div class="csharp">
<ol>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000;">&#91;</span>Flags<span style="color: #000000;">&#93;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">enum</span> WD</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000;">&#123;</span></div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Mon = 0x1,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Tue = 0x2,</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Wed = 0x4,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Thu = 0x8,</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Fri = 0x10,</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Sat = 0x20,</div>
</li>
<li style="font-weight: bold;color:#26536A;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;">Sun = 0x40</div>
</li>
<li style="font-family: 'Courier New', Courier, monospace; color: black; font-weight: normal; font-style: normal;color:#3A6A8B;">
<div style="font-family: 'Courier New', Courier, monospace; font-weight: normal;"><span style="color: #000000;">&#125;</span> </div>
</li>
</ol>
</div>
</div>
</div>
<p></p>
<p>One thing that I often want is to have a number with unknown number of decimals, fx. 1234.567 displayed with thousand separators but <u>without</u> trailing 0 (zeros), i.e. as 1,234.567 not 1,234.58 or 1,234.5670. To accomplish this one can do this (almost perfectly) with custom formatting. If you specify the format string "#,#0.#" (read on this is not the complete truth!!!) it will display all numbers before the decimal separator (specified by "." in the format string) will be thousand separated ("#,#"). The 0 (zero) ensures that 0.12345 is displayed as "0.12345" and not ".12345". The # after the decimal symbol specifies that a decimal should appear (note! <u>a</u> decimal), so "#,#0.#" will display 123456.789 as 123,456.8 (using en-us culture). This is the "almost perfect" part: you'll have to specify the <u>maximum</u> number of decimals to use, so if you use the format string "#,#0.######" you can have a maximum of 6 decimals, but trailing/non-significant zero's are left out.</p>
<p>You can read more about <a href="http://msdn2.microsoft.com/en-us/library/0c899ak8.aspx">Custom</a> <a href="http://msdn2.microsoft.com/en-us/library/8kb3ddd4.aspx">Formatting</a>, the most interesting part is probably the custom date formatting.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.veggerby.dk/2007/04/15/formatting-strings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
