<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Trivial but useful extension method</title><link>http://blogs.msdn.com/avip/archive/2008/09/30/trivial-but-useful-extension-method.aspx</link><description>Don’t know why I didn’t write this before; it makes code very readable. Often when you write anything graphics related, you want to constrain coordinates to window edges (for example). So a simple method: 1: /// &amp;lt;summary&amp;gt; 2: /// Ensure that the</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: Trivial but useful extension method</title><link>http://blogs.msdn.com/avip/archive/2008/09/30/trivial-but-useful-extension-method.aspx#8969929</link><pubDate>Tue, 30 Sep 2008 09:36:24 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8969929</guid><dc:creator>brilsmurf</dc:creator><description>&lt;p&gt;Nice, but why not make it generic?&lt;/p&gt;
&lt;p&gt;public static T Constrain&amp;lt;T&amp;gt;(this T value, T min, T max) where T : IComparable&amp;lt;T&amp;gt;&lt;/p&gt;
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt; &amp;nbsp;if (value.CompareTo(min)&amp;lt;0)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;return min;&lt;/p&gt;
&lt;p&gt; &amp;nbsp;else if (value.CompareTo(max)&amp;gt;0)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;return max;&lt;/p&gt;
&lt;p&gt; &amp;nbsp;else&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;return value;&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;</description></item><item><title>re: Trivial but useful extension method</title><link>http://blogs.msdn.com/avip/archive/2008/09/30/trivial-but-useful-extension-method.aspx#8969961</link><pubDate>Tue, 30 Sep 2008 10:23:56 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8969961</guid><dc:creator>Avi Pilosof</dc:creator><description>&lt;p&gt;Yep, even better!&lt;/p&gt;
</description></item><item><title>re: Trivial but useful extension method</title><link>http://blogs.msdn.com/avip/archive/2008/09/30/trivial-but-useful-extension-method.aspx#9891448</link><pubDate>Fri, 04 Sep 2009 18:39:55 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9891448</guid><dc:creator>Dave</dc:creator><description>&lt;P&gt;"It’s just a Floor combined with a Ceiling, but it reads nicely:"&lt;/P&gt;
&lt;P&gt;Your code dosen't read like that, whythe ifs?&lt;/P&gt;
&lt;P&gt;public static int Constraint(this int value, int min, int max)&lt;/P&gt;
&lt;P&gt;{&lt;/P&gt;
&lt;P&gt;return Math.Min(Math.Max(value,min), max);&lt;/P&gt;
&lt;P&gt;}&lt;/P&gt;</description></item></channel></rss>