<?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>Think In Geek &#187; .net</title>
	<atom:link href="http://thinkingeek.com/tag/net/feed/" rel="self" type="application/rss+xml" />
	<link>http://thinkingeek.com</link>
	<description>In geek we trust</description>
	<lastBuildDate>Wed, 01 Feb 2012 14:45:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Get the number of days in a month in .NET</title>
		<link>http://thinkingeek.com/2010/12/02/get-the-number-of-days-in-a-month-in-net/</link>
		<comments>http://thinkingeek.com/2010/12/02/get-the-number-of-days-in-a-month-in-net/#comments</comments>
		<pubDate>Thu, 02 Dec 2010 16:38:53 +0000</pubDate>
		<dc:creator>brafales</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[c#]]></category>

		<guid isPermaLink="false">http://thinkingeek.com/?p=143</guid>
		<description><![CDATA[If you&#8217;ve ever wondered how to get the number of days for a given month in .NET, the solution is pretty easy: System.DateTime.DaysInMonth&#40;int year, int month&#41; Hope it helps!]]></description>
			<content:encoded><![CDATA[<p>If you&#8217;ve ever wondered how to get the number of days for a given month in .NET, the solution is pretty easy:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">DateTime</span><span style="color: #008000;">.</span><span style="color: #0000FF;">DaysInMonth</span><span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> year, <span style="color: #6666cc; font-weight: bold;">int</span> month<span style="color: #008000;">&#41;</span></pre></div></div>

<p>
Hope it helps!</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fthinkingeek.com%2F2010%2F12%2F02%2Fget-the-number-of-days-in-a-month-in-net%2F&amp;title=Get%20the%20number%20of%20days%20in%20a%20month%20in%20.NET" id="wpa2a_2" onclick="pageTracker._trackPageview('/outgoing/www.addtoany.com/share_save_url=http_3A_2F_2Fthinkingeek.com_2F2010_2F12_2F02_2Fget-the-number-of-days-in-a-month-in-net_2F_amp_title=Get_20the_20number_20of_20days_20in_20a_20month_20in_20.NET?referer=');"><img src="http://thinkingeek.com/wp-content/plugins/add-to-any/share_save_120_16.gif" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://thinkingeek.com/2010/12/02/get-the-number-of-days-in-a-month-in-net/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using IronPython to extend your .NET applications</title>
		<link>http://thinkingeek.com/2009/03/11/using-ironpython-to-extend-your-net-applications/</link>
		<comments>http://thinkingeek.com/2009/03/11/using-ironpython-to-extend-your-net-applications/#comments</comments>
		<pubDate>Wed, 11 Mar 2009 15:44:32 +0000</pubDate>
		<dc:creator>brafales</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[ironpython]]></category>
		<category><![CDATA[ironruby]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[ruby]]></category>

		<guid isPermaLink="false">http://thinkingeek.com/?p=93</guid>
		<description><![CDATA[One of the interesting new things on the .NET platform is the recent addition of Python and Ruby to the CLR. Both versions for .NET are called IronPython and IronRuby respectively, and they provide some new and good things to the platform. Python and Ruby lovers will see now that they can use all the [...]]]></description>
			<content:encoded><![CDATA[<p>
One of the interesting new things on the .NET platform is the recent addition of <a href="http://www.python.org/" onclick="pageTracker._trackPageview('/outgoing/www.python.org/?referer=');">Python</a> and <a href="http://ruby-lang.org/" onclick="pageTracker._trackPageview('/outgoing/ruby-lang.org/?referer=');">Ruby</a> to the CLR. Both versions for .NET are called <a href="http://www.codeplex.com/IronPython" onclick="pageTracker._trackPageview('/outgoing/www.codeplex.com/IronPython?referer=');">IronPython</a> and <a href="http://www.ironruby.net/" onclick="pageTracker._trackPageview('/outgoing/www.ironruby.net/?referer=');">IronRuby</a> respectively, and they provide some new and good things to the platform.
</p>
<p>
Python and Ruby lovers will see now that they can use all the library and features of the .NET platform programming in their favorite scripting language. Since both of them are object oriented, you can now write fully fledged apps using either of them.
</p>
<p>
However, there&#8217;s another interesting application for IronPython and IronRuby: adding scripting support for your existing .NET applications. This can be a very useful and powerful way to extend your applications and give the user freedom to program their own mini programs, scripts or whatever in your applications. It could be good for defining rules, assigning and calculating values, etc.
</p>
<p>
I&#8217;ll provide a simple class you can use to add scripting to your application. I&#8217;ll use IronPython in this example.
</p>
<p>
First of all, you have to download IronPython and install it, and add the references to the assemblies on your project references.
</p>
<p>
The usual way to proceed in those cases is to provide the user of some local variables you give them access to, execute the script, and then recover the values of those or new variables. To do so, You can use a class similar to this one:
</p>
<p>
<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Collections.Generic</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Text</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">IronPython.Hosting</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">Microsoft.Scripting.Hosting</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">Microsoft.Scripting</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">namespace</span> Scripting
<span style="color: #008000;">&#123;</span>
	<span style="color: #0600FF; font-weight: bold;">internal</span> <span style="color: #6666cc; font-weight: bold;">class</span> PythonEngine
	<span style="color: #008000;">&#123;</span>
        ScriptEngine m_engine<span style="color: #008000;">;</span>
        ExceptionOperations m_exceptionOperations<span style="color: #008000;">;</span>
        SortedDictionary<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span>, <span style="color: #6666cc; font-weight: bold;">object</span><span style="color: #008000;">&gt;</span> m_inputVariables<span style="color: #008000;">;</span>
        <span style="color: #6666cc; font-weight: bold;">string</span> m_script<span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">internal</span> PythonEngine<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            m_engine <span style="color: #008000;">=</span> Python<span style="color: #008000;">.</span><span style="color: #0000FF;">CreateEngine</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            m_exceptionOperations <span style="color: #008000;">=</span> m_engine<span style="color: #008000;">.</span><span style="color: #0000FF;">GetService</span><span style="color: #008000;">&lt;</span>ExceptionOperations<span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">internal</span> SortedDictionary<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span>, <span style="color: #6666cc; font-weight: bold;">object</span><span style="color: #008000;">&gt;</span> ScriptVariables
        <span style="color: #008000;">&#123;</span>
            set <span style="color: #008000;">&#123;</span> m_inputVariables <span style="color: #008000;">=</span> value<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">internal</span> <span style="color: #6666cc; font-weight: bold;">string</span> Script
        <span style="color: #008000;">&#123;</span>
            set <span style="color: #008000;">&#123;</span> m_script <span style="color: #008000;">=</span> value<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">internal</span> ExceptionOperations ExceptionOperations
        <span style="color: #008000;">&#123;</span>
            get <span style="color: #008000;">&#123;</span> <span style="color: #0600FF; font-weight: bold;">return</span> m_exceptionOperations<span style="color: #008000;">;</span> <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF; font-weight: bold;">internal</span> SortedDictionary<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span>, <span style="color: #6666cc; font-weight: bold;">object</span><span style="color: #008000;">&gt;</span> Execute<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">//Create structures</span>
            SourceCodeKind sc <span style="color: #008000;">=</span> SourceCodeKind<span style="color: #008000;">.</span><span style="color: #0000FF;">Statements</span><span style="color: #008000;">;</span>
            ScriptSource source <span style="color: #008000;">=</span> m_engine<span style="color: #008000;">.</span><span style="color: #0000FF;">CreateScriptSourceFromString</span><span style="color: #008000;">&#40;</span>m_script, sc<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            ScriptScope scope <span style="color: #008000;">=</span> m_engine<span style="color: #008000;">.</span><span style="color: #0000FF;">CreateScope</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008080; font-style: italic;">//Fill input variables</span>
            <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span>KeyValuePair<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span>, <span style="color: #6666cc; font-weight: bold;">object</span><span style="color: #008000;">&gt;</span> variable <span style="color: #0600FF; font-weight: bold;">in</span> m_inputVariables<span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                scope<span style="color: #008000;">.</span><span style="color: #0000FF;">SetVariable</span><span style="color: #008000;">&#40;</span>variable<span style="color: #008000;">.</span><span style="color: #0000FF;">Key</span>, variable<span style="color: #008000;">.</span><span style="color: #0000FF;">Value</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
            SortedDictionary<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span>, <span style="color: #6666cc; font-weight: bold;">object</span><span style="color: #008000;">&gt;</span> outputVariables <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SortedDictionary<span style="color: #008000;">&lt;</span><span style="color: #6666cc; font-weight: bold;">string</span>, <span style="color: #6666cc; font-weight: bold;">object</span><span style="color: #008000;">&gt;</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008080; font-style: italic;">//Execute the script</span>
            <span style="color: #0600FF; font-weight: bold;">try</span>
            <span style="color: #008000;">&#123;</span>
                source<span style="color: #008000;">.</span><span style="color: #0000FF;">Execute</span><span style="color: #008000;">&#40;</span>scope<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #008080; font-style: italic;">//Recover variables</span>
                <span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> variable <span style="color: #0600FF; font-weight: bold;">in</span> scope<span style="color: #008000;">.</span><span style="color: #0000FF;">GetVariableNames</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#123;</span>
                    outputVariables<span style="color: #008000;">.</span><span style="color: #0000FF;">Add</span><span style="color: #008000;">&#40;</span>variable, scope<span style="color: #008000;">.</span><span style="color: #0000FF;">GetVariable</span><span style="color: #008000;">&#40;</span>variable<span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
            <span style="color: #008000;">&#125;</span>
            <span style="color: #0600FF; font-weight: bold;">catch</span> <span style="color: #008000;">&#40;</span>Exception e<span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                <span style="color: #6666cc; font-weight: bold;">string</span> error <span style="color: #008000;">=</span> m_exceptionOperations<span style="color: #008000;">.</span><span style="color: #0000FF;">FormatException</span><span style="color: #008000;">&#40;</span>e<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #008080; font-style: italic;">//Do something with the pretty printed error</span>
                <span style="color: #0600FF; font-weight: bold;">throw</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
            <span style="color: #0600FF; font-weight: bold;">return</span> outputVariables<span style="color: #008000;">;</span>
        <span style="color: #008000;">&#125;</span>
	<span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

</p>
<p>
Usage of this class is pretty simple. You have to provide the object the script you want to execute and the input variables the script will have available as local variables. Once this is done, you have to call the Execute method, and this method will either return the output variables of the execution of the resulting script, or throw an exception.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fthinkingeek.com%2F2009%2F03%2F11%2Fusing-ironpython-to-extend-your-net-applications%2F&amp;title=Using%20IronPython%20to%20extend%20your%20.NET%20applications" id="wpa2a_4" onclick="pageTracker._trackPageview('/outgoing/www.addtoany.com/share_save_url=http_3A_2F_2Fthinkingeek.com_2F2009_2F03_2F11_2Fusing-ironpython-to-extend-your-net-applications_2F_amp_title=Using_20IronPython_20to_20extend_20your_20.NET_20applications?referer=');"><img src="http://thinkingeek.com/wp-content/plugins/add-to-any/share_save_120_16.gif" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://thinkingeek.com/2009/03/11/using-ironpython-to-extend-your-net-applications/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Full view of ComboBox drop-down list components in C# 3.0</title>
		<link>http://thinkingeek.com/2008/11/18/full-view-of-combobox-drop-down-list-components-in-c-30/</link>
		<comments>http://thinkingeek.com/2008/11/18/full-view-of-combobox-drop-down-list-components-in-c-30/#comments</comments>
		<pubDate>Tue, 18 Nov 2008 12:43:02 +0000</pubDate>
		<dc:creator>alopez</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[programming tips]]></category>

		<guid isPermaLink="false">http://thinkingeek.com/?p=88</guid>
		<description><![CDATA[By default in C# 3.0 ComboBox controls don’t provide support for showing drop-down list items if they exceed the width of their parent ComboBox, like this one: This is annoying because users cannot read properly the information. To solve that problem, all we have to do is derive the ComboBox class and override the DropDown [...]]]></description>
			<content:encoded><![CDATA[<p>By default in C# 3.0 ComboBox controls don’t provide support for showing drop-down list items if they exceed the width of their parent ComboBox, like this one:
</p>
<div id="attachment_89" class="wp-caption aligncenter" style="width: 246px"><a href="http://thinkingeek.com/wp-content/uploads/2008/11/image001.png"  rel="lightbox[roadtrip]"><img src="http://thinkingeek.com/wp-content/uploads/2008/11/image001.png" alt="Cropped ComboBox" title="Cropped ComboBox" width="236" height="123" class="size-medium wp-image-89" /></a><p class="wp-caption-text">Cropped ComboBox</p></div>
<p>
This is annoying because users cannot read properly the information. To solve that problem, all we have to do is derive the ComboBox class and override the DropDown event as follows:
</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">public</span> <span style="color: #6666cc; font-weight: bold;">class</span> ComboBoxEx <span style="color: #008000;">:</span> ComboBox
<span style="color: #008000;">&#123;</span>
	<span style="color: #0600FF; font-weight: bold;">public</span> ComboBoxEx<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
		<span style="color: #008000;">:</span> <span style="color: #0600FF; font-weight: bold;">base</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		DropDown <span style="color: #008000;">+=</span> <span style="color: #008000;">new</span> EventHandler<span style="color: #008000;">&#40;</span>event_DropDown<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #008000;">&#125;</span>
&nbsp;
	<span style="color: #6666cc; font-weight: bold;">void</span> event_DropDown<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">object</span> sender, EventArgs e<span style="color: #008000;">&#41;</span>
	<span style="color: #008000;">&#123;</span>
		<span style="color: #0600FF; font-weight: bold;">try</span>
		<span style="color: #008000;">&#123;</span>
			ComboBox comboBox <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span>ComboBox<span style="color: #008000;">&#41;</span>sender<span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// Catch the combo firing this event</span>
			<span style="color: #6666cc; font-weight: bold;">int</span> width <span style="color: #008000;">=</span> comboBox<span style="color: #008000;">.</span><span style="color: #0000FF;">Width</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// Current width for ComboBox</span>
			Graphics g <span style="color: #008000;">=</span> comboBox<span style="color: #008000;">.</span><span style="color: #0000FF;">CreateGraphics</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// Get graphics for ComboBox</span>
			Font font <span style="color: #008000;">=</span> comboBox<span style="color: #008000;">.</span><span style="color: #0000FF;">Font</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// Doesn't change original font</span>
&nbsp;
			<span style="color: #008080; font-style: italic;">//checks if a scrollbar will be displayed.</span>
			<span style="color: #6666cc; font-weight: bold;">int</span> vertScrollBarWidth<span style="color: #008000;">;</span>
			<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>comboBox<span style="color: #008000;">.</span><span style="color: #0000FF;">Items</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span> <span style="color: #008000;">&gt;</span> comboBox<span style="color: #008000;">.</span><span style="color: #0000FF;">MaxDropDownItems</span><span style="color: #008000;">&#41;</span>
			<span style="color: #008000;">&#125;</span>
				<span style="color: #008080; font-style: italic;">//If yes, then get its width to adjust the size of the drop down list.</span>
				vertScrollBarWidth <span style="color: #008000;">=</span> SystemInformation<span style="color: #008000;">.</span><span style="color: #0000FF;">VerticalScrollBarWidth</span><span style="color: #008000;">;</span>
			<span style="color: #008000;">&#125;</span>
			<span style="color: #0600FF; font-weight: bold;">else</span>
			<span style="color: #008000;">&#123;</span>
				<span style="color: #008080; font-style: italic;">//Otherwise set to 0</span>
				vertScrollBarWidth <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span>
			<span style="color: #008000;">&#125;</span>
			<span style="color: #008080; font-style: italic;">//Loop through list items and check size of each items.</span>
			<span style="color: #008080; font-style: italic;">//set the width of the drop down list to the width of the largest item.</span>
			<span style="color: #6666cc; font-weight: bold;">int</span> newWidth<span style="color: #008000;">;</span>
			<span style="color: #0600FF; font-weight: bold;">foreach</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span> s <span style="color: #0600FF; font-weight: bold;">in</span> comboBox<span style="color: #008000;">.</span><span style="color: #0000FF;">Items</span><span style="color: #008000;">&#41;</span>
			<span style="color: #008000;">&#123;</span>
				<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>s <span style="color: #008000;">!=</span> <span style="color: #0600FF; font-weight: bold;">null</span><span style="color: #008000;">&#41;</span>
				<span style="color: #008000;">&#123;</span>
					newWidth <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span><span style="color: #008000;">&#41;</span>g<span style="color: #008000;">.</span><span style="color: #0000FF;">MeasureString</span><span style="color: #008000;">&#40;</span>s<span style="color: #008000;">.</span><span style="color: #0000FF;">Trim</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span>, font<span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Width</span> <span style="color: #008000;">+</span> vertScrollBarWidth<span style="color: #008000;">;</span>
					<span style="color: #0600FF; font-weight: bold;">if</span> <span style="color: #008000;">&#40;</span>width <span style="color: #008000;">&lt;</span> newWidth<span style="color: #008000;">&#41;</span>
						width <span style="color: #008000;">=</span> newWidth<span style="color: #008000;">;</span>
				<span style="color: #008000;">&#125;</span>
			<span style="color: #008000;">&#125;</span>
			<span style="color: #008080; font-style: italic;">// Finally, adjust the new width</span>
			comboBox<span style="color: #008000;">.</span><span style="color: #0000FF;">DropDownWidth</span> <span style="color: #008000;">=</span> width<span style="color: #008000;">;</span>
		<span style="color: #008000;">&#125;</span>
		<span style="color: #0600FF; font-weight: bold;">catch</span> <span style="color: #008000;">&#123;</span>  <span style="color: #008000;">&#125;</span>
	<span style="color: #008000;">&#125;</span>   
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>
The following picture shows the results of using the above control instead of the default one:
</p>
<div id="attachment_90" class="wp-caption aligncenter" style="width: 246px"><a href="http://thinkingeek.com/wp-content/uploads/2008/11/image003.png"  rel="lightbox[roadtrip]"><img src="http://thinkingeek.com/wp-content/uploads/2008/11/image003.png" alt="Non Cropped ComboBox" title="Non Cropped ComboBox" width="236" height="123" class="size-medium wp-image-90" /></a><p class="wp-caption-text">Non Cropped ComboBox</p></div>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fthinkingeek.com%2F2008%2F11%2F18%2Ffull-view-of-combobox-drop-down-list-components-in-c-30%2F&amp;title=Full%20view%20of%20ComboBox%20drop-down%20list%20components%20in%20C%23%203.0" id="wpa2a_6" onclick="pageTracker._trackPageview('/outgoing/www.addtoany.com/share_save_url=http_3A_2F_2Fthinkingeek.com_2F2008_2F11_2F18_2Ffull-view-of-combobox-drop-down-list-components-in-c-30_2F_amp_title=Full_20view_20of_20ComboBox_20drop-down_20list_20components_20in_20C_23_203.0?referer=');"><img src="http://thinkingeek.com/wp-content/plugins/add-to-any/share_save_120_16.gif" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://thinkingeek.com/2008/11/18/full-view-of-combobox-drop-down-list-components-in-c-30/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>C# and the StringBuilder class</title>
		<link>http://thinkingeek.com/2008/07/16/c-and-the-stringbuilder-class/</link>
		<comments>http://thinkingeek.com/2008/07/16/c-and-the-stringbuilder-class/#comments</comments>
		<pubDate>Wed, 16 Jul 2008 17:07:37 +0000</pubDate>
		<dc:creator>brafales</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[programming tips]]></category>

		<guid isPermaLink="false">http://thinkingeek.com/?p=67</guid>
		<description><![CDATA[This morning I was working on a project at work. It&#8217;s a Web Application using the ASP .NET 2.0 framework and C# as a code behind language. My friend Ioannis came over to see what was I doing and when he saw I was appending some strings together he asked me this question: &#8220;are you [...]]]></description>
			<content:encoded><![CDATA[<p>This morning I was working on a project at work. It&#8217;s a Web Application using the ASP .NET 2.0 framework and C# as a code behind language. My friend Ioannis came over to see what was I doing and when he saw I was appending some strings together he asked me this question: &#8220;<em>are you using a StringBuilder to use those strings?</em>&#8220;. And I replied with this answer: &#8220;<em>no, I am not</em>&#8220;. This kind of stupid dialog came over because last week we were discussing about using StringBuilders instead of the default String class operators to append strings each other in Java. It seemed using the StringBuilder class resulted in an overall performance gain. It was then when I asked: &#8220;<em>don&#8217;t tell me this happens with C#, too?</em>&#8220;. And he answered: &#8220;<em>yes, it does!</em>&#8220;.</p>
<p>So, what&#8217;s the matter with StringBuilders in C#?</p>
<p><span id="more-67"></span></p>
<p>It seems the same thing happens with Strings, C# and Java. Here is a copy paste from the <a href="http://msdn2.microsoft.com/en-us/library/2839d5h5%28vs.80%29.aspx" onclick="pageTracker._trackPageview('/outgoing/msdn2.microsoft.com/en-us/library/2839d5h5_28vs.80_29.aspx?referer=');">MSDN web page</a> about the StringBuilder usage:</p>
<blockquote><p>
The <strong>String</strong> object is immutable. Every time you use one of the methods in the <strong>System.String</strong> class, you create a new string object in memory, which requires a new allocation of space for that new object. In situations where you need to perform repeated modifications to a string, the overhead associated with creating a new <strong>String</strong> object can be costly. The <a href="http://msdn2.microsoft.com/en-us/library/system.text.stringbuilder%28VS.80%29.aspx" onclick="pageTracker._trackPageview('/outgoing/msdn2.microsoft.com/en-us/library/system.text.stringbuilder_28VS.80_29.aspx?referer=');">System.Text.StringBuilder</a> class can be used when you want to modify a string without creating a new object. For example, using the <strong>StringBuilder</strong> class can boost performance when concatenating many strings together in a loop.
</p></blockquote>
<p>
So I decided to run some tests to see how much it was worth to change my code to use the StringBuilder class, because I use the string &#8216;+&#8217; operator a lot in my program, and the results are simply amazing. Here you can find a chart comparing the times it took to concatenate a given number of strings using both methods. See for yourself and then&#8230; use StringBuilders from now on!
</p>
<div id="attachment_68" class="wp-caption aligncenter" style="width: 310px"><a href="http://thinkingeek.com/wp-content/uploads/2008/11/string.png"  rel="lightbox[roadtrip]"><img src="http://thinkingeek.com/wp-content/uploads/2008/11/string-300x180.png" alt="String usage" title="String usage" width="300" height="180" class="size-medium wp-image-68" /></a><p class="wp-caption-text">String usage</p></div>
<div id="attachment_69" class="wp-caption aligncenter" style="width: 310px"><a href="http://thinkingeek.com/wp-content/uploads/2008/11/stringbuilder.png"  rel="lightbox[roadtrip]"><img src="http://thinkingeek.com/wp-content/uploads/2008/11/stringbuilder-300x180.png" alt="StringBuilder usage" title="StringBuilder usage" width="300" height="180" class="size-medium wp-image-69" /></a><p class="wp-caption-text">StringBuilder usage</p></div>
<p>
Here&#8217;s the source code i used if you want to try it for yourself:
</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Collections.Generic</span><span style="color: #008000;">;</span>
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">System.Text</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">using</span> <span style="color: #008080;">Adapdev.Diagnostics</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF; font-weight: bold;">namespace</span> SBuilder
<span style="color: #008000;">&#123;</span>
    <span style="color: #6666cc; font-weight: bold;">class</span> Program
    <span style="color: #008000;">&#123;</span>
        <span style="color: #0600FF; font-weight: bold;">static</span> <span style="color: #6666cc; font-weight: bold;">void</span> Main<span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">&#91;</span><span style="color: #008000;">&#93;</span> args<span style="color: #008000;">&#41;</span>
        <span style="color: #008000;">&#123;</span>
            HiPerfTimer timer <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> HiPerfTimer<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> i <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> i <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">100</span><span style="color: #008000;">;</span> i<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span>
            <span style="color: #008000;">&#123;</span>
                StringBuilder sb <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> StringBuilder<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                timer<span style="color: #008000;">.</span><span style="color: #0000FF;">Start</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> j <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> j <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">1000</span> <span style="color: #008000;">&lt;</span>strong<span style="color: #008000;">&gt;</span> i<span style="color: #008000;">;</span> j<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#123;</span>
                    sb<span style="color: #008000;">.</span><span style="color: #0000FF;">Append</span><span style="color: #008000;">&#40;</span>j<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
                timer<span style="color: #008000;">.</span><span style="color: #0000FF;">Stop</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #6666cc; font-weight: bold;">double</span> timeStringBuilder <span style="color: #008000;">=</span> timer<span style="color: #008000;">.</span><span style="color: #0000FF;">Duration</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #6666cc; font-weight: bold;">string</span> s <span style="color: #008000;">=</span> <span style="color: #6666cc; font-weight: bold;">string</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Empty</span><span style="color: #008000;">;</span>
                timer<span style="color: #008000;">.</span><span style="color: #0000FF;">Start</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF; font-weight: bold;">for</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">int</span> j <span style="color: #008000;">=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> j <span style="color: #008000;">&lt;</span> <span style="color: #FF0000;">1000</span> <span style="color: #008000;">&lt;/</span>strong<span style="color: #008000;">&gt;</span> i<span style="color: #008000;">;</span> j<span style="color: #008000;">++</span><span style="color: #008000;">&#41;</span>
                <span style="color: #008000;">&#123;</span>
                    s <span style="color: #008000;">+=</span> j<span style="color: #008000;">;</span>
                <span style="color: #008000;">&#125;</span>
                timer<span style="color: #008000;">.</span><span style="color: #0000FF;">Stop</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #6666cc; font-weight: bold;">double</span> timeString <span style="color: #008000;">=</span> timer<span style="color: #008000;">.</span><span style="color: #0000FF;">Duration</span><span style="color: #008000;">;</span>
&nbsp;
                StringBuilder line <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> StringBuilder<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                line<span style="color: #008000;">.</span><span style="color: #0000FF;">Append</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">1000</span> <span style="color: #008000;">*</span> i<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                line<span style="color: #008000;">.</span><span style="color: #0000FF;">Append</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;;&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                line<span style="color: #008000;">.</span><span style="color: #0000FF;">Append</span><span style="color: #008000;">&#40;</span>timeStringBuilder<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                line<span style="color: #008000;">.</span><span style="color: #0000FF;">Append</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;;&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                line<span style="color: #008000;">.</span><span style="color: #0000FF;">Append</span><span style="color: #008000;">&#40;</span>timeString<span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #000000;">System</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Console</span><span style="color: #008000;">.</span><span style="color: #0000FF;">WriteLine</span><span style="color: #008000;">&#40;</span>line<span style="color: #008000;">.</span><span style="color: #0000FF;">ToString</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span>
            <span style="color: #008000;">&#125;</span>
        <span style="color: #008000;">&#125;</span>
    <span style="color: #008000;">&#125;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>
You can download the external timer classes from <a href="http://www.codeproject.com/csharp/highperformancetimercshar.asp" onclick="pageTracker._trackPageview('/outgoing/www.codeproject.com/csharp/highperformancetimercshar.asp?referer=');">The Code Project</a>.</p>
<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fthinkingeek.com%2F2008%2F07%2F16%2Fc-and-the-stringbuilder-class%2F&amp;title=C%23%20and%20the%20StringBuilder%20class" id="wpa2a_8" onclick="pageTracker._trackPageview('/outgoing/www.addtoany.com/share_save_url=http_3A_2F_2Fthinkingeek.com_2F2008_2F07_2F16_2Fc-and-the-stringbuilder-class_2F_amp_title=C_23_20and_20the_20StringBuilder_20class?referer=');"><img src="http://thinkingeek.com/wp-content/plugins/add-to-any/share_save_120_16.gif" width="120" height="16" alt="Share"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://thinkingeek.com/2008/07/16/c-and-the-stringbuilder-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

