<?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>Always Get Better &#187; C#</title>
	<atom:link href="http://www.alwaysgetbetter.com/blog/category/general-programming/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.alwaysgetbetter.com/blog</link>
	<description>Never stop looking for ways to improve</description>
	<lastBuildDate>Wed, 02 Jun 2010 12:16:01 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Display Class Objects in CheckedListBox</title>
		<link>http://www.alwaysgetbetter.com/blog/2010/03/28/display-class-objects-checkedlistbox/</link>
		<comments>http://www.alwaysgetbetter.com/blog/2010/03/28/display-class-objects-checkedlistbox/#comments</comments>
		<pubDate>Sun, 28 Mar 2010 17:10:43 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[SiteAssistant]]></category>
		<category><![CDATA[data types]]></category>
		<category><![CDATA[interfaces]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.alwaysgetbetter.com/blog/?p=303</guid>
		<description><![CDATA[If you want to use anything more complex than a list of strings in a ListBox, you&#8217;re in luck because the control accepts all types of objects.
In this case, I want to display a list of posts found in a blog. Blog is a class which contains Posts, an array of Post classes. To start, [...]


Related posts:<ol><li><a href='http://www.alwaysgetbetter.com/blog/2009/11/14/living-firstperson-shooter-disease/' rel='bookmark' title='Permanent Link: Living With First-Person Shooter Disease'>Living With First-Person Shooter Disease</a></li>
<li><a href='http://www.alwaysgetbetter.com/blog/2009/11/11/microsoft-xbox-owners-mod-consoles/' rel='bookmark' title='Permanent Link: Microsoft to Xbox Owners: Don&#8217;t Mod Your Consoles'>Microsoft to Xbox Owners: Don&#8217;t Mod Your Consoles</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>If you want to use anything more complex than a list of strings in a ListBox, you&#8217;re in luck because the control accepts all types of objects.</p>
<div id="attachment_304" class="wp-caption aligncenter" style="width: 654px"><a href="http://www.alwaysgetbetter.com/blog/wp-content/uploads/2010/03/CheckedListBox.png"><img src="http://www.alwaysgetbetter.com/blog/wp-content/uploads/2010/03/CheckedListBox.png" alt="Custom Objects (Blog Posts) Displayed in a CheckListBox" title="Custom Objects (Blog Posts) Displayed in a CheckListBox" width="644" height="480" class="size-full wp-image-304" /></a><p class="wp-caption-text">Custom Objects (Blog Posts) Displayed in a CheckListBox</p></div>
<p>In this case, I want to display a list of posts found in a blog. <strong>Blog</strong> is a class which contains <em>Posts</em>, an array of <strong>Post</strong> classes. To start, I created the CheckedListBox in the form designer, and I add the posts to it like this:</p>
<pre class="brush: csharp; light: true;">
clbPages.Items.AddRange(_blog.Posts);
</pre>
<p>If I do nothing else, the ListBox will call the Post&#8217;s ToString() method and will display as:</p>
<pre>
Post
Post
Post
Post
</pre>
<p>We have two options for displaying this correctly:</p>
<p>1. Override the <strong>ToString()</strong> method. I don&#8217;t recommend doing this because ToString() is much more appropriately used in a debugging context.</p>
<p>2. Add a string converter: This will automatically convert each post object to a usable string when called by an object like a ListBox. ListBox uses Convert.ToString() &#8211; this uses that converter more appropriately. ToString() should only be used as a fallback.</p>
<pre class="brush: csharp; wrap-lines: false;">
&lt;pre&gt;
// Use System for the Type object
using System;
// Use ComponentModel for the TypeConvert base class
using System.ComponentModel;

namespace SiteAssistant.Blog
{
    /// &lt;summary&gt;
    /// Converts a post into a list-friendly string, for checkbox lists
    /// &lt;/summary&gt;
    class PostConverter : TypeConverter
    {
        /// &lt;summary&gt;
        /// Indicates whether the Post can be converted to a destination type
        /// &lt;/summary&gt;
        /// &lt;remarks&gt;
        /// We only support conversions to STRING at present
        /// &lt;/remarks&gt;
        /// &lt;param name=&quot;context&quot;&gt;&lt;/param&gt;
        /// &lt;param name=&quot;destinationType&quot;&gt;&lt;/param&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        public override bool CanConvertTo(ITypeDescriptorContext context,
            Type destinationType)
        {
            if (destinationType == typeof(string))
                return true;
            else
                return base.CanConvertTo(context, destinationType);
        }

        /// &lt;summary&gt;
        /// Converts the post to the destination type. If the destination
        /// type is not supported, the base Conversion is applied.
        /// &lt;/summary&gt;
        /// &lt;remarks&gt;
        /// We only support converting posts to strings at present.
        /// &lt;/remarks&gt;
        /// &lt;param name=&quot;context&quot;&gt;&lt;/param&gt;
        /// &lt;param name=&quot;culture&quot;&gt;&lt;/param&gt;
        /// &lt;param name=&quot;value&quot;&gt;&lt;/param&gt;
        /// &lt;param name=&quot;destinationType&quot;&gt;&lt;/param&gt;
        /// &lt;returns&gt;&lt;/returns&gt;
        public override object ConvertTo(ITypeDescriptorContext context,
            System.Globalization.CultureInfo culture, object value,
            Type destinationType)
        {
            if (destinationType == typeof(string))
            {
                string text = &quot;&quot;;
                Post p = value as Post;
                // Ensure that the Post is not null, avoid errors
                if (null != p)
                {
                    text = p.Title;
                }
                return text;
            }
            else
            {
                return base.ConvertTo(context, culture, value, destinationType);
            }
        }
    }
}
&lt;/pre&gt;
</pre>
<p>The code we write in .NET is like the meat inside a sandwich. The framework is the bread that wraps around our logic and keeps our application together. Our new Posts string converter will be called by the application without us needing to override the <strong>Convert</strong> function.</p>
<p>It doesn&#8217;t happen by magic of course. The final change we have to make is to add information about our conversion function to the posts class:</p>
<pre class="brush: csharp; wrap-lines: false;">
&lt;pre&gt;
    [System.ComponentModel.TypeConverter(typeof(PostConverter))]
    public class Post
    {
        // Rest of the code goes here
    }
&lt;/pre&gt;
</pre>
<p>That&#8217;s all there is to it! Now we can pass a list of Posts to the CheckedListBox and manipulate each item directly. In this application, I will be using this technique to provide the Post object to the text editor with a double-click.</p>


<p>Related posts:<ol><li><a href='http://www.alwaysgetbetter.com/blog/2009/11/14/living-firstperson-shooter-disease/' rel='bookmark' title='Permanent Link: Living With First-Person Shooter Disease'>Living With First-Person Shooter Disease</a></li>
<li><a href='http://www.alwaysgetbetter.com/blog/2009/11/11/microsoft-xbox-owners-mod-consoles/' rel='bookmark' title='Permanent Link: Microsoft to Xbox Owners: Don&#8217;t Mod Your Consoles'>Microsoft to Xbox Owners: Don&#8217;t Mod Your Consoles</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.alwaysgetbetter.com/blog/2010/03/28/display-class-objects-checkedlistbox/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C#: using Statement</title>
		<link>http://www.alwaysgetbetter.com/blog/2009/05/14/statement/</link>
		<comments>http://www.alwaysgetbetter.com/blog/2009/05/14/statement/#comments</comments>
		<pubDate>Fri, 15 May 2009 02:45:25 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[memory management]]></category>

		<guid isPermaLink="false">http://www.alwaysgetbetter.com/blog/?p=228</guid>
		<description><![CDATA[One of my absolute favourite statements in C# is the using statement (not to be confused with the using directive, which is what we use to import libraries like System.Web into our projects).
using forces us as programmers to be honest about releasing memory to the CLR. Whenever we use an unmanaged resource like an SQL [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p>One of my absolute favourite statements in C# is the <em>using</em> statement (not to be confused with the using directive, which is what we use to import libraries like System.Web into our projects).</p>
<p><em>using</em> forces us as programmers to be honest about releasing memory to the CLR. Whenever we use an unmanaged resource like an SQL connection or file IO handler, the garbage collector will eventually eliminate any open streams or connections associated with that resource. However, &#8220;eventually&#8221; doesn&#8217;t cut it when we&#8217;re dealing with SQL connections on a production server &#8211; we need to make sure the connections are released no later than <a href="http://www.alwaysgetbetter.com/blog/2008/02/15/sql-connections-in-aspnet-what-you-learned-is-wrong/">when we&#8217;re done</a> with them.</p>
<p>If you come from the C++ world, you&#8217;re probably (hopefully) used to calling <strong>delete</strong> to deallocate any memory you reserved. You also know that forgetting the <strong>delete</strong> (or <strong>delete []</strong> on arrays) results in a memory leak. You might think of <strong>Dispose()</strong> as C#&#8217;s implementation of the <strong>delete</strong> statement.</p>
<p><code><br />
using ( SqlCommand cmd = new SqlCommand( sqlStatement, sqlConnection ) )<br />
{<br />
   // Do something<br />
}<br />
</code></p>
<p><em>using</em> acts as a try&#8230;catch&#8230;finally block, so if your code fails your object will still be disposed. The using statement keeps everything wrapped into a neat little package so you don&#8217;t forget to keep your local variables in scope.</p>
<p>Like I said, this is one of my favourite features in .NET (<em>lock { }</em> is similarly beautiful). You can use the same construct in VB as well.</p>


<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.alwaysgetbetter.com/blog/2009/05/14/statement/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Implementing Lazy Load Using a Proxy Class</title>
		<link>http://www.alwaysgetbetter.com/blog/2009/02/28/implementing-lazy-load-proxy-class/</link>
		<comments>http://www.alwaysgetbetter.com/blog/2009/02/28/implementing-lazy-load-proxy-class/#comments</comments>
		<pubDate>Sat, 28 Feb 2009 20:28:56 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Design Patterns]]></category>
		<category><![CDATA[data types]]></category>
		<category><![CDATA[efficiency]]></category>

		<guid isPermaLink="false">http://www.alwaysgetbetter.com/blog/?p=183</guid>
		<description><![CDATA[
 photo credit: Gog Llundain
Lazy load is a design pattern wherein an object is not instantiated until the last possible minute. This is very handy when working with lists of items whose contents are expensive to retrieve from the data store.
There are typically three ways of implementing lazy load:
1. Lazy Initialization &#8211; The object is [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<div class="alignright"><a title="Relaxing in Slippers" href="http://www.flickr.com/photos/76045572@N00/3258171732/" target="_blank"><img src="http://farm4.static.flickr.com/3096/3258171732_38e877e923_m.jpg" border="0" alt="Relaxing in Slippers" /></a><br />
<small><a title="Attribution-ShareAlike License" href="http://creativecommons.org/licenses/by-sa/2.0/" target="_blank"><img src="http://www.alwaysgetbetter.com/blog/wp-content/plugins/photo-dropper/images/cc.png" border="0" alt="Creative Commons License" width="16" height="16" align="absmiddle" /></a> <a href="http://www.photodropper.com/photos/" target="_blank">photo</a> credit: <a title="Gog Llundain" href="http://www.flickr.com/photos/76045572@N00/3258171732/" target="_blank">Gog Llundain</a></small></div>
<p>Lazy load is a design pattern wherein an object is not instantiated until the last possible minute. This is very handy when working with lists of items whose contents are expensive to retrieve from the data store.</p>
<p>There are typically three ways of implementing lazy load:<br />
1. Lazy Initialization &#8211; The object is set to <em>null</em> and checked/loaded when data is needed<br />
2. Proxy &#8211; A proxy class for the object is created using the same interface as the original class; whenever a property is called, the proxy creates the object and returns the correct data<br />
3. Ghost &#8211; The class loads only a partial set of its information until more is needed</p>
<h2>Example Situation</h2>
<p>In my example situation, we handling a catalogue of artists owned by a fictional record label. For each artist, we will store a name, musical genre, web site address, and number of albums.</p>
<div id="attachment_184" class="wp-caption aligncenter" style="width: 152px"><img class="size-full wp-image-184" title="Artist Class" src="http://www.alwaysgetbetter.com/blog/wp-content/uploads/2009/02/artist_class.png" alt="UML for Artist Class" width="142" height="155" /><p class="wp-caption-text">UML for Artist Class</p></div>
<p>Let&#8217;s pretend we have thousands of artists on our roster, and we need to print a catalogue containing all of their information. Rather than loading all of that data into memory right away and having to wait until that process is done before we can begin printing, it makes more sense to get a list of how many artists will be printed (so our software knows how many pages to print) but to only load the actual information when we are ready to print it.</p>
<p>The solution is to create an ArtistProxy class. ArtistProxy has an _artist variable who is set to <em>null</em> when it is initialized. Whenever we try to access the artist&#8217;s name, web site, etc from ArtistProxy, the class creates an Artist (only if not already done) and returns the property from _artist.</p>
<p>Our print function is never aware of ArtistProxy &#8211; as far as it is concerned it only ever deals with Artist. We accomplish this by creating an interface &#8211; IArtist &#8211; which acts as a contract for both ArtistProxy and Artist. If we add more properties to Artist later on, IArtist will keep us honest by forcing us to also update ArtistProxy.</p>
<div id="attachment_186" class="wp-caption aligncenter" style="width: 489px"><img class="size-full wp-image-186" title="Artist, ArtistProxy, and IArtist UML Diagram" src="http://www.alwaysgetbetter.com/blog/wp-content/uploads/2009/02/artist_lazyload.png" alt="Artist, ArtistProxy, and IArtist UML Diagram" width="479" height="368" /><p class="wp-caption-text">Artist, ArtistProxy, and IArtist UML Diagram</p></div>
<p>Now that we understand how our classes relate to each other, it&#8217;s time to use them in code:</p>
<p>// Our printArtists() function looks something like this.<br />
// Notice how we are unaware whether the artist is<br />
// an actual object, or a whether it is a proxy.<br />
public function printArtists( IArtist [] artistList )<br />
{<br />
  foreach ( IArtist artist in artistList )<br />
  {<br />
    printOneArtist( artist );<br />
  }<br />
}</p>
<p>// Implementation of the IArtist interface<br />
public interface IArtist<br />
{<br />
  string Name { get; set; }<br />
  string Genre { get; set; }<br />
  string Website { get; set; }<br />
  int getNumberOfAlbums();<br />
}</p>
<p>// Implementation of Artist class<br />
public class Artist : IArtist<br />
{<br />
  private int _id;<br />
  private string _name;<br />
  private string _genre;<br />
  private string _website;</p>
<p>  public Artist( id )<br />
  {<br />
    _id = id;<br />
  }</p>
<p>  public string Name<br />
  {<br />
    get { return _name; }<br />
    set { _name = value; }<br />
  }</p>
<p>  public string Genre<br />
  {<br />
    get { return _genre; }<br />
    set { _genre = value; }<br />
  }</p>
<p>  public string Website<br />
  {<br />
    get { return _website; }<br />
    set { _website = value; }<br />
  }</p>
<p>  public int getNumberOfAlbums()<br />
  {<br />
    return fictionalDataConnection-&gt;getNumberOfAlbums( _id );<br />
  }<br />
}</p>
<p>// Implementation of ArtistProxy class<br />
public class ArtistProxy : IArtist<br />
{<br />
  private Artist _artist;<br />
  private int _id;</p>
<p>  public ArtistProxy( id )<br />
  {<br />
    _artist = null;<br />
    _id = id;<br />
  }</p>
<p>  public string Name<br />
  {<br />
    get<br />
    {<br />
      if ( null == _artist ) _artist = new Artist( _id );<br />
      return _artist.Name;<br />
    }<br />
    set<br />
    {<br />
      if ( null == _artist ) _artist = new Artist( _id );<br />
      _artist.Name = value;<br />
    }<br />
  }</p>
<p>  public string Genre<br />
  {<br />
    get<br />
    {<br />
      if ( null == _artist ) _artist = new Artist( _id );<br />
      return _artist.Genre;<br />
    }<br />
    set<br />
    {<br />
      if ( null == _artist ) _artist = new Artist( _id );<br />
      _artist.Genre = value;<br />
    }<br />
  }</p>
<p>  public string Website<br />
  {<br />
    get<br />
    {<br />
      if ( null == _artist ) _artist = new Artist( _id );<br />
      return _artist.Website;<br />
    }<br />
    set<br />
    {<br />
      if ( null == _artist ) _artist = new Artist( _id );<br />
      _artist.Website = value;<br />
    }<br />
  }</p>
<p>  public int getNumberOfAlbums()<br />
  {<br />
    if ( null == _artist ) _artist = new Artist( _id );<br />
    return _artist.getNumberOfAlbums();<br />
  }<br />
}</p>
<p>Of course for the sake of convenience a few things are missing from my example:<br />
1. An actual data source<br />
2. Delegates (presumably one would include a &#8216;LoadArtist&#8217; delegate so the proxy will be able to pass the actual loading of its artist to the data layer)</p>


<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.alwaysgetbetter.com/blog/2009/02/28/implementing-lazy-load-proxy-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CommandEventHandler Event Won&#8217;t Fire for Button in ASP.NET Custom Control</title>
		<link>http://www.alwaysgetbetter.com/blog/2008/09/24/commandeventhandler-event-wont-fire-for-button-in-aspnet-custom-control/</link>
		<comments>http://www.alwaysgetbetter.com/blog/2008/09/24/commandeventhandler-event-wont-fire-for-button-in-aspnet-custom-control/#comments</comments>
		<pubDate>Wed, 24 Sep 2008 23:03:04 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[VB.Net]]></category>

		<guid isPermaLink="false">http://www.alwaysgetbetter.com/blog/?p=55</guid>
		<description><![CDATA[Problem: I created a custom control with a dynamic button and attached an event handler to that button.  When I run the control, clicking the button causes a postback but the event is not fired.
Solution: Changed the class inheritance from WebControl to CompositeControl.  Re-compiled and it worked like a charm.


No related posts.


No related posts.]]></description>
			<content:encoded><![CDATA[<p><strong>Problem</strong>: I created a custom control with a dynamic button and attached an event handler to that button.  When I run the control, clicking the button causes a postback but the event is not fired.</p>
<p><strong>Solution:</strong> Changed the class inheritance from <em>WebControl</em> to <em>CompositeControl</em>.  Re-compiled and it worked like a charm.</p>


<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.alwaysgetbetter.com/blog/2008/09/24/commandeventhandler-event-wont-fire-for-button-in-aspnet-custom-control/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Replacing / Adding Line Breaks in GridView Text</title>
		<link>http://www.alwaysgetbetter.com/blog/2008/05/27/replacing-adding-line-breaks-in-gridview-text/</link>
		<comments>http://www.alwaysgetbetter.com/blog/2008/05/27/replacing-adding-line-breaks-in-gridview-text/#comments</comments>
		<pubDate>Tue, 27 May 2008 14:19:08 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[HTML]]></category>

		<guid isPermaLink="false">http://www.alwaysgetbetter.com/blog/?p=34</guid>
		<description><![CDATA[The GridView is a powerful control for quickly and easily displaying tables of data.  However, a raw dump of information is not always good &#8211; when displayed by a web browser, normal line breaks are simply rendered as spaces.
For long blocks of text, it may be desirable to have your GridView insert HTML line [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p>The GridView is a powerful control for quickly and easily displaying tables of data.  However, a raw dump of information is not always good &#8211; when displayed by a web browser, normal line breaks are simply rendered as spaces.</p>
<p>For long blocks of text, it may be desirable to have your GridView insert HTML line breaks into your data.  This can be accomplished either programatically or declaratively.</p>
<h2>Programatically</h2>
<p>As a programmer, my first instinct is to try to solve the problem using code behind.  I add a RowDataBound event handler to my GridView and create the command this way:</p>
<p>protected void gvMessageList_RowDataBound(object sender, GridViewRowEventArgs e)<br />
{<br />
GridViewRow row = e.Row;<br />
if (e.Row.RowType == DataControlRowType.DataRow)<br />
{<br />
row.Cells[2].Text = row.Cells[2].Text.Replace(&#8220;\n&#8221;, &#8220;&#8221;);<br />
}<br />
}</p>
<p>Although it works, it has several drawbacks:</p>
<ul>
<li>This solution uses a <em>magic number</em> to cause the compiler to replace the third column in the row.  If the structure of the GridView were to change, this function may break</li>
<li>This solution requires the developer to be aware of the final layout of the GridView and to make the connection between the control&#8217;s declaration and its logical code.</li>
</ul>
<h2>Use The Design</h2>
<p>By far, the better solution is to simply declare the formatting changes in the same place as the GridView.  Using a Template field, I can add line breaks to my message by adding this:</p>
<p>&lt;%# Eval(&#8220;Message&#8221;).ToString().Replace(&#8220;\n&#8221;, &#8220;&lt;br /&gt;&#8221;) %&gt;</p>
<h2>More Information</h2>
<p>This solution assumes the contents of &#8220;Message&#8221; are not null.  For more information about this technique (including how to deal with null values), I recommend the ASP.NET message boards: http://forums.asp.net/p/1027728/1403884.aspx</p>


<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.alwaysgetbetter.com/blog/2008/05/27/replacing-adding-line-breaks-in-gridview-text/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>C#: Using Suffixes to Declare Data Literals</title>
		<link>http://www.alwaysgetbetter.com/blog/2008/05/01/c-using-suffixes-to-declare-data-literals/</link>
		<comments>http://www.alwaysgetbetter.com/blog/2008/05/01/c-using-suffixes-to-declare-data-literals/#comments</comments>
		<pubDate>Fri, 02 May 2008 02:04:21 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[data types]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.alwaysgetbetter.com/blog/?p=29</guid>
		<description><![CDATA[This isn&#8217;t new, but handy to have.  In order to tell the compiler which data type we&#8217;re using, we use suffix notation as follows:

Unsigned integer, U: e.g. 34506U
Long integer (signed), L: e.g. 5297532L
Unsigned long integer, UL: e.g. 30958UL
Float, F: e.g. 13.6F
Double, D: e.g. 14.3D
Decimal, M: e.g. 19.95M



No related posts.


No related posts.]]></description>
			<content:encoded><![CDATA[<p>This isn&#8217;t new, but handy to have.  In order to tell the compiler which data type we&#8217;re using, we use suffix notation as follows:</p>
<ul>
<li>Unsigned integer, U: e.g. 34506U</li>
<li>Long integer (signed), L: e.g. 5297532L</li>
<li>Unsigned long integer, UL: e.g. 30958UL</li>
<li>Float, F: e.g. 13.6F</li>
<li>Double, D: e.g. 14.3D</li>
<li>Decimal, M: e.g. 19.95M</li>
</ul>


<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.alwaysgetbetter.com/blog/2008/05/01/c-using-suffixes-to-declare-data-literals/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C#: Finding the Number of Days Between Two DateTime Items</title>
		<link>http://www.alwaysgetbetter.com/blog/2008/04/29/c-finding-the-number-of-days-between-two-datetime-items/</link>
		<comments>http://www.alwaysgetbetter.com/blog/2008/04/29/c-finding-the-number-of-days-between-two-datetime-items/#comments</comments>
		<pubDate>Tue, 29 Apr 2008 11:43:58 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[General Programming]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.alwaysgetbetter.com/blog/?p=27</guid>
		<description><![CDATA[One very common requirement is for the number of days elapsed since a particular Date and Time.  In C# this can be accomplished through the use of the TimeSpan class.
The easiest way to create a TimeSpan is like this:
TimeSpan tsMySpan = DateTime.Now.Subtract( dtCompareTime );
// The number of days elapsed can be accessed like this:
// [...]


Related posts:<ol><li><a href='http://www.alwaysgetbetter.com/blog/2009/11/16/279-days-overnight-success/' rel='bookmark' title='Permanent Link: 279 Days to Overnight Success'>279 Days to Overnight Success</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>One very common requirement is for the number of days elapsed since a particular Date and Time.  In C# this can be accomplished through the use of the <b>TimeSpan</b> class.</p>
<p>The easiest way to create a TimeSpan is like this:</p>
<p>TimeSpan tsMySpan = DateTime.Now.Subtract( dtCompareTime );</p>
<p>// The number of days elapsed can be accessed like this:<br />
// tsMySpan.Days</p>


<p>Related posts:<ol><li><a href='http://www.alwaysgetbetter.com/blog/2009/11/16/279-days-overnight-success/' rel='bookmark' title='Permanent Link: 279 Days to Overnight Success'>279 Days to Overnight Success</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://www.alwaysgetbetter.com/blog/2008/04/29/c-finding-the-number-of-days-between-two-datetime-items/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Handling Relative Paths Programmatically In ASP.NET</title>
		<link>http://www.alwaysgetbetter.com/blog/2008/04/25/handling-relative-paths-programmatically-in-aspnet/</link>
		<comments>http://www.alwaysgetbetter.com/blog/2008/04/25/handling-relative-paths-programmatically-in-aspnet/#comments</comments>
		<pubDate>Fri, 25 Apr 2008 15:28:27 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://www.alwaysgetbetter.com/blog/?p=26</guid>
		<description><![CDATA[One of the nicest features in ASP.NET is its out-of-box support for relative paths in hyper links and other controls.  This is very important for developers whose code resides within the root of their testing environment but within a sub-directory of the production server.
Whereas one would have to carefully program things like image links [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p>One of the nicest features in ASP.NET is its out-of-box support for relative paths in hyper links and other controls.  This is very important for developers whose code resides within the root of their testing environment but within a sub-directory of the production server.</p>
<p>Whereas one would have to carefully program things like image links to point at <strong>&#8220;/applicationbasepath/images/&#8221;</strong>, in ASP.NET we can simply use <strong>&#8220;~/images&#8221;</strong>.  Genious!</p>
<p>When writing custom code, however, the work isn&#8217;t done for us automatically.  We have to pass our URL to a server-side function in order to convert the &#8220;<strong>~/</strong>&#8221; into a base path usable by our visitors.</p>
<p>There are two ways of doing this:</p>
<h2>Using Relative Paths From a Web Page or Control</h2>
<p>If we are programming a page template or a server control, we can use the <strong>ResolveUrl()</strong> function provided by our environment context.</p>
<p>string resolvedUrl = ResolveUrl( &#8220;~/index.php&#8221; );</p>
<p>On AlwaysGetBetter.com, &#8220;~/index.php&#8221; would resolve to <strong>http://www.alwaysgetbetter.com/blog/index.php</strong>.  On another site, it might resolve to the root such as <strong>http://www.abetterblog.com/index.php</strong>.  Programming this way makes our solution more portable.</p>
<h2>Using Relative Paths From Outside a Web Page</h2>
<p>Sometimes we need to use relative paths from outside the context of a web page.  For example, if we were to make a change in our Global.asx file, the program code we use may not be considered to be within a web page scope.</p>
<p>Fortunately, .NET provides us with the static helper class <em>VirtualPathUtility</em>.</p>
<p>string redirUrl = VirtualPathUtility.ToAbsolute(&#8220;~/redirPage.aspx&#8221;);<br />
Response.Redirect( redirUrl );</p>


<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.alwaysgetbetter.com/blog/2008/04/25/handling-relative-paths-programmatically-in-aspnet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C#: Instantiating a class of Unknown Type</title>
		<link>http://www.alwaysgetbetter.com/blog/2008/04/05/c-instantiating-a-class-of-unknown-type/</link>
		<comments>http://www.alwaysgetbetter.com/blog/2008/04/05/c-instantiating-a-class-of-unknown-type/#comments</comments>
		<pubDate>Sat, 05 Apr 2008 20:28:53 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[polymorphism]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.alwaysgetbetter.com/blog/2008/04/05/c-instantiating-a-class-of-unknown-type/</guid>
		<description><![CDATA[The project I am currently working on has several dozen different types of Form classes, each of which is accessible from a common menu strip.  Rather than repeatedly instantiating each of the forms from the menu item handlers, I wanted to funnel the request to a single function.
The problem is: How do you instantiate [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p>The project I am currently working on has several dozen different types of <strong>Form</strong> classes, each of which is accessible from a common menu strip.  Rather than repeatedly instantiating each of the forms from the menu item handlers, I wanted to funnel the request to a single function.</p>
<p>The problem is: <em>How do you instantiate a form when the type is unknown?</em></p>
<p>The code snippet is:</p>
<p>CreateForm( typeof(CustomFormType) );</p>
<p>Form CreateForm( Type formType )<br />
{<br />
return (Form)Activator.CreateInstance(formType);<br />
}</p>


<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.alwaysgetbetter.com/blog/2008/04/05/c-instantiating-a-class-of-unknown-type/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>C#: Form.Close() vs Form.Dispose()</title>
		<link>http://www.alwaysgetbetter.com/blog/2008/04/04/c-formclose-vs-formdispose/</link>
		<comments>http://www.alwaysgetbetter.com/blog/2008/04/04/c-formclose-vs-formdispose/#comments</comments>
		<pubDate>Sat, 05 Apr 2008 00:16:12 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://www.alwaysgetbetter.com/blog/2008/04/04/c-formclose-vs-formdispose/</guid>
		<description><![CDATA[When working with a Windows GUI, it may seem unclear whether to use Form.Close() or Form.Dispose() to get rid of a dialog at runtime.
Form.Close() removes the dialog from sight and calls the Closing() and Closed() methods.  You can still access the form and bring it back later on.
Form.Dispose() destroys the dialog and frees its resources [...]


No related posts.]]></description>
			<content:encoded><![CDATA[<p>When working with a Windows GUI, it may seem unclear whether to use Form.Close() or Form.Dispose() to get rid of a dialog at runtime.</p>
<p><strong>Form.Close()</strong> removes the dialog from sight and calls the Closing() and Closed() methods.  You can still access the form and bring it back later on.</p>
<p><strong>Form.Dispose()</strong> destroys the dialog and frees its resources back to the operating system.   <em>It does not call the form&#8217;s Closing() and Closed() methods. </em>Once disposed, you may not recall a form.</p>
<p>Which to use? If you have no logic in the form&#8217;s close methods and don&#8217;t intend to re-use the form, go with Dispose().  Otherwise, go with Close().  Some programmers aren&#8217;t sure which to use, and they use both &#8211; Close() then Dispose()!</p>


<p>No related posts.</p>]]></content:encoded>
			<wfw:commentRss>http://www.alwaysgetbetter.com/blog/2008/04/04/c-formclose-vs-formdispose/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
