<?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>Codepolice.net &#187; C#</title>
	<atom:link href="http://codepolice.net/category/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://codepolice.net</link>
	<description>C#, ASP.NET, MVC, LINQ, Wordpress and stuff like that</description>
	<lastBuildDate>Mon, 26 Jul 2010 08:58:47 +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>IN queries with LINQ to SQL</title>
		<link>http://codepolice.net/2010/06/01/in-queries-with-linq-to-sql/</link>
		<comments>http://codepolice.net/2010/06/01/in-queries-with-linq-to-sql/#comments</comments>
		<pubDate>Tue, 01 Jun 2010 13:33:12 +0000</pubDate>
		<dc:creator>Ola</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[in]]></category>
		<category><![CDATA[Linq to sql]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[string array]]></category>

		<guid isPermaLink="false">http://codepolice.net/?p=277</guid>
		<description><![CDATA[This is another awesome feature in LINQ to SQL that i always forget about. Sometimes you have an array of strings or any other type and want to query the database for all values that have one of the values in the array. string platform = "windows&#124;linux"; string[] platformList = platform.Split('&#124;'); itemQuery = from m [...]]]></description>
			<content:encoded><![CDATA[<p>This is another awesome feature in LINQ to SQL that i always forget about. Sometimes you have an array of strings or any other type and want to query the database for all values that have one of the values in the array.</p>
<pre class="brush:c#">string platform = "windows|linux";
string[] platformList = platform.Split('|');
itemQuery = from m in itemQuery
from p in m.PlattformItemRelations
where platformList.Contains(p.Plattform.Text.ToLower())
select m;</pre>
<p>Ain&#8217;t that a beauty? I got this tip from <a href="http://blog.wekeroad.com/2008/02/27/creating-in-queries-with-linq-to-sql/">Ron Connery</a> so all the kudos to him.</p>
]]></content:encoded>
			<wfw:commentRss>http://codepolice.net/2010/06/01/in-queries-with-linq-to-sql/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Create a comma separated list with LINQ in C#</title>
		<link>http://codepolice.net/2010/04/20/create-a-comma-separated-list-with-linq-in-c/</link>
		<comments>http://codepolice.net/2010/04/20/create-a-comma-separated-list-with-linq-in-c/#comments</comments>
		<pubDate>Tue, 20 Apr 2010 13:29:59 +0000</pubDate>
		<dc:creator>Ola</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[string]]></category>

		<guid isPermaLink="false">http://codepolice.net/?p=274</guid>
		<description><![CDATA[For some reason I always forget that you do not do .Join on your actual string array. So i might as well write it down here so i never forget about this again. string mycommalist = string.Join(",", alternatives.Select(x=>x.Item.Name).ToArray())]]></description>
			<content:encoded><![CDATA[<p>For some reason I always forget that you do not do .Join on your actual string array. So i might as well write it down here so i never forget about this again.</p>
<pre class="brush:c#">string mycommalist = string.Join(",", alternatives.Select(x=>x.Item.Name).ToArray())</pre>
]]></content:encoded>
			<wfw:commentRss>http://codepolice.net/2010/04/20/create-a-comma-separated-list-with-linq-in-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Convert String Array to Int Array and vice versa in C#</title>
		<link>http://codepolice.net/2009/11/07/convert-string-array-to-int-array-and-vice-versa-in-c/</link>
		<comments>http://codepolice.net/2009/11/07/convert-string-array-to-int-array-and-vice-versa-in-c/#comments</comments>
		<pubDate>Sat, 07 Nov 2009 15:35:17 +0000</pubDate>
		<dc:creator>Ola</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[int]]></category>
		<category><![CDATA[int array]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[string array]]></category>

		<guid isPermaLink="false">http://codepolice.net/?p=181</guid>
		<description><![CDATA[Sometimes you want to convert arrays back and forth. This is to nice extension methods to convert a int array into a string array and vice versa. public static class ExtensionMethods { public static string[] ToStringArray(this int[] intArray) { return Array.ConvertAll&#60;int, string&#62;(intArray, delegate(int intParameter) { return intParameter.ToString(); }); } public static int[] ToIntArray(this string[] strArray) [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes you want to convert arrays back and forth. This is to nice extension methods to convert a int array into a string array and vice versa.</p>
<pre class="brush:c#">public static class ExtensionMethods {

  public static string[] ToStringArray(this int[] intArray) {
   return Array.ConvertAll&lt;int, string&gt;(intArray, delegate(int intParameter) { return intParameter.ToString(); });
  }

  public static int[] ToIntArray(this string[] strArray) {
   return Array.ConvertAll&lt;string, int&gt;(strArray, delegate(string intParameter) { return int.Parse(intParameter.ToString()); });
  }
}</pre>

]]></content:encoded>
			<wfw:commentRss>http://codepolice.net/2009/11/07/convert-string-array-to-int-array-and-vice-versa-in-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>file_get_contents() in asp.net/C#</title>
		<link>http://codepolice.net/2009/02/13/file_get_contents-in-aspnetc/</link>
		<comments>http://codepolice.net/2009/02/13/file_get_contents-in-aspnetc/#comments</comments>
		<pubDate>Fri, 13 Feb 2009 11:25:59 +0000</pubDate>
		<dc:creator>Ola</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[bit.ly]]></category>
		<category><![CDATA[file_get_contents()]]></category>
		<category><![CDATA[StreamReader]]></category>
		<category><![CDATA[WebRequest]]></category>

		<guid isPermaLink="false">http://codepolice.net/?p=137</guid>
		<description><![CDATA[The URL shortening service http://bit.ly has a really simple and convient API that lets just get a short url like this. http://bit.ly/api?url=http://www.myreallylong.com/url/with/lots?of=crap I&#8217;ve used this in a wordpress installation with PHP before and there i could just do. $twitter_url .= file_get_contents&#40;'http://bit.ly/api?url=' . get_permalink&#40;&#41;&#41;; Simple and clean. But today i wanted to do the same thing [...]]]></description>
			<content:encoded><![CDATA[<p>The URL shortening service http://bit.ly has a really simple and convient API that lets just get a short url like this.</p>
<p>http://bit.ly/api?url=http://www.myreallylong.com/url/with/lots?of=crap</p>
<p>I&#8217;ve used this in a wordpress installation with PHP before and there i could just do.</p>
<div class="codecolorer-container php twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="php codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #000088;">$twitter_url</span> <span style="color: #339933;">.=</span> <a href="http://www.php.net/file_get_contents"><span style="color: #990000;">file_get_contents</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'http://bit.ly/api?url='</span> <span style="color: #339933;">.</span> get_permalink<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></div></div>
<p>Simple and clean. But today i wanted to do the same thing with asp.net and found myself kind of lost. At last i came up with this, not as simple solution. But it works.</p>
<div class="codecolorer-container csharp twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap"><span style="color: #6666cc; font-weight: bold;">string</span> shortUrl <span style="color: #008000;">=</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> StreamReader<span style="color: #008000;">&#40;</span>WebRequest<span style="color: #008000;">.</span><span style="color: #0000FF;">Create</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;http://bit.ly/api?url=http://fragor.ohsohightech.se&quot;</span> <span style="color: #008000;">+</span> Url<span style="color: #008000;">.</span><span style="color: #0000FF;">Action</span><span style="color: #008000;">&#40;</span><span style="color: #666666;">&quot;Question&quot;</span>, <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> <span style="color: #008000;">&#123;</span> number <span style="color: #008000;">=</span> question<span style="color: #008000;">.</span><span style="color: #0000FF;">Number</span>, title <span style="color: #008000;">=</span> question<span style="color: #008000;">.</span><span style="color: #0000FF;">Title</span><span style="color: #008000;">.</span><span style="color: #0000FF;">ConvertTextToUrl</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetResponse</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">GetResponseStream</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: #0000FF;">ReadToEnd</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></div></div>

]]></content:encoded>
			<wfw:commentRss>http://codepolice.net/2009/02/13/file_get_contents-in-aspnetc/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Create a tag cloud with limited amout of tags in ASP.NET and LINQ</title>
		<link>http://codepolice.net/2008/10/14/create-a-tag-cloud-with-limited-amout-of-tags-in-aspnet-and-linq/</link>
		<comments>http://codepolice.net/2008/10/14/create-a-tag-cloud-with-limited-amout-of-tags-in-aspnet-and-linq/#comments</comments>
		<pubDate>Tue, 14 Oct 2008 15:13:12 +0000</pubDate>
		<dc:creator>Ola</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Tag]]></category>
		<category><![CDATA[Tag Cloud]]></category>
		<category><![CDATA[TagCloud]]></category>

		<guid isPermaLink="false">http://www.codepolice.net/?p=24</guid>
		<description><![CDATA[Today i built a Tag cloud for my new site. I found this great article about on how to do it with LINQ and C#. But i missed some features. Especially how to limit the number of tags that was shown. So if you read that article and then have a look at this code [...]]]></description>
			<content:encoded><![CDATA[<p>Today i built a Tag cloud for my new site. I found <a href="http://kosta.apostolou.ca/software-development/how-to-create-a-tagcloud-using-linq-and-aspnet" target="_blank">this great article about on how to do it with LINQ and C#</a>. But i missed some features. Especially how to limit the number of tags that was shown. So if you read that article and then have a look at this code if you have the same problem as me.</p>
<div class="codecolorer-container csharp twitlight" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="csharp codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">var tagSummary <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">from</span> ti <span style="color: #0600FF; font-weight: bold;">in</span> db<span style="color: #008000;">.</span><span style="color: #0000FF;">TagItemRelations</span><br />
&nbsp; &nbsp; group ti by ti<span style="color: #008000;">.</span><span style="color: #0000FF;">Tag</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Text</span> into tagGroup<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">select</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; Tag <span style="color: #008000;">=</span> tagGroup<span style="color: #008000;">.</span><span style="color: #0000FF;">Key</span>,<br />
&nbsp; &nbsp; TagFrequency <span style="color: #008000;">=</span> tagGroup<span style="color: #008000;">.</span><span style="color: #0000FF;">Count</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><br />
<span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">OrderByDescending</span><span style="color: #008000;">&#40;</span>x<span style="color: #008000;">=&amp;</span>gt<span style="color: #008000;">;</span>x<span style="color: #008000;">.</span><span style="color: #0000FF;">TagFrequency</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Take</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">20</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
<span style="color: #6666cc; font-weight: bold;">int</span> maxTagFrequency <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">from</span> t <span style="color: #0600FF; font-weight: bold;">in</span> tagSummary <span style="color: #0600FF; font-weight: bold;">select</span> t<span style="color: #008000;">.</span><span style="color: #0000FF;">TagFrequency</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">Max</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span><br />
<br />
var tagCloud <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #0600FF; font-weight: bold;">from</span> ti <span style="color: #0600FF; font-weight: bold;">in</span> tagSummary<br />
&nbsp; &nbsp; <span style="color: #0600FF; font-weight: bold;">select</span> <a href="http://www.google.com/search?q=new+msdn.microsoft.com"><span style="color: #008000;">new</span></a> TagCloudItem <span style="color: #008000;">&#123;</span><br />
&nbsp; &nbsp; Tag <span style="color: #008000;">=</span> ti<span style="color: #008000;">.</span><span style="color: #0000FF;">Tag</span>,<br />
&nbsp; &nbsp; Weight <span style="color: #008000;">=</span> <span style="color: #008000;">&#40;</span><span style="color: #6666cc; font-weight: bold;">double</span><span style="color: #008000;">&#41;</span>ti<span style="color: #008000;">.</span><span style="color: #0000FF;">TagFrequency</span> <span style="color: #008000;">/</span> maxTagFrequency <span style="color: #008000;">*</span> <span style="color: #FF0000;">100</span><br />
<span style="color: #008000;">&#125;</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">.</span><span style="color: #0000FF;">OrderBy</span><span style="color: #008000;">&#40;</span>x<span style="color: #008000;">=&amp;</span>gt<span style="color: #008000;">;</span>x<span style="color: #008000;">.</span><span style="color: #0000FF;">Tag</span><span style="color: #008000;">&#41;</span><span style="color: #008000;">;</span></div></div>
<p>The main difference between my code and the code in the article is that i have slightly more complex data model (should not matter) and that i make the second query against the &#8220;result&#8221; from the first query. This allow me to first order by popularity and then in alphabetic order.</p>
<p>Please leave a comment if there is any better way to do this or if you have any questions.</p>
]]></content:encoded>
			<wfw:commentRss>http://codepolice.net/2008/10/14/create-a-tag-cloud-with-limited-amout-of-tags-in-aspnet-and-linq/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->