<?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/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	>

<channel>
	<title>list &#8211; MaxVergelli.com</title>
	<atom:link href="https://www.maxvergelli.com/tag/list/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.maxvergelli.com</link>
	<description>sourcecode repository</description>
	<lastBuildDate>Fri, 27 May 2016 14:37:49 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://i2.wp.com/www.maxvergelli.com/wp-content/uploads/2020/04/wp-1586823685141.png?fit=32%2C32&#038;ssl=1</url>
	<title>list &#8211; MaxVergelli.com</title>
	<link>https://www.maxvergelli.com</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">34603511</site>	<item>
		<title>The fastest algorithm in C#/VB.Net to count how many times a value is repeated in a List of items</title>
		<link>https://www.maxvergelli.com/how-to-count-how-many-times-a-value-is-repeated-in-a-list/</link>
					<comments>https://www.maxvergelli.com/how-to-count-how-many-times-a-value-is-repeated-in-a-list/#respond</comments>
		
		<dc:creator><![CDATA[Max]]></dc:creator>
		<pubDate>Fri, 27 May 2016 13:57:51 +0000</pubDate>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[VB.Net]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[algorithm]]></category>
		<category><![CDATA[c#]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[enumerate]]></category>
		<category><![CDATA[enumerating]]></category>
		<category><![CDATA[filtering]]></category>
		<category><![CDATA[function]]></category>
		<category><![CDATA[list]]></category>
		<category><![CDATA[parse]]></category>
		<category><![CDATA[parsing]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[string-manipulation]]></category>
		<category><![CDATA[vb.net]]></category>
		<guid isPermaLink="false">http://www.maxvergelli.com/?p=24</guid>

					<description><![CDATA[The faster way (with the best system performance) to count how many times a particular value is repeated in a List of items, it&#8217;s like this [sourcecode language=&#8221;vb&#8221;] Const chars As String = &#34;ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz&#34; Dim rnd As New Random() &#8216;create &#8230; <a class="kt-excerpt-readmore" href="https://www.maxvergelli.com/how-to-count-how-many-times-a-value-is-repeated-in-a-list/" aria-label="The fastest algorithm in C#/VB.Net to count how many times a value is repeated in a List of items">Read More</a>]]></description>
										<content:encoded><![CDATA[<p>The faster way (with the best system performance) to count how many times a particular value is repeated in a List of items, it&#8217;s like this</p>
[sourcecode language=&#8221;vb&#8221;]
Const chars As String = &quot;ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz&quot;<br />
Dim rnd As New Random()</p>
<p>&#8216;create a long list of random letters<br />
Dim random_letters As List(Of String) = Enumerable.Range(1, 100000).Select(Function(i) chars(rnd.Next(0, chars.Length)).ToString).ToList</p>
<p>&#8216;create a long list of random numbers<br />
Dim random_numbers As List(Of Integer) = Enumerable.Range(1, 100000).Select(Function(i) rnd.Next(100000)).ToList()</p>
<p>&#8216;get a lookup table<br />
Dim lookup_table = random_letters.GetLookupTable</p>
<p>&#8216;count how many times a particular value &quot;B&quot; is repeated in the lookup table of random_letters List<br />
Dim count As Integer = lookup_table.CountValue(&quot;B&quot;)<br />
[/sourcecode]
<p>To do that, You have to add the following two extension methods, <strong>optimized for the best performance</strong>, to my .Net module (at <a href="http://www.maxvergelli.com/useful-extension-methods-for-string-net-class-with-support-of-intellisense/">http://www.maxvergelli.com/useful-extension-methods-for-string-net-class-with-support-of-intellisense/</a>) that extends the String class</p>
[sourcecode language=&#8221;vb&#8221;]
 &#8216;CountValue() count how many times a particular value is repeated in a lookup table</p>
<p>         _<br />
        Public Function CountValue(Of T)(ByRef lookup_table As Dictionary(Of T, Int32), ByRef value As T) As Integer<br />
            Dim c As Integer = 0<br />
            lookup_table.TryGetValue(value, c)<br />
            Return c<br />
        End Function</p>
<p>        &#8216;get a lookup table from a List of items</p>
<p>         _<br />
        Public Function GetLookupTable(Of T)(ByRef list As List(Of T)) As Dictionary(Of T, Int32)<br />
            Dim table As New Dictionary(Of T, Integer)<br />
            For Each s As T In list<br />
                Dim count As Int32 = 0<br />
                If table.TryGetValue(s, count) Then<br />
                    table(s) = count + 1<br />
                Else<br />
                    table(s) = 1<br />
                End If<br />
            Next<br />
            Return table<br />
        End Function<br />
[/sourcecode]
<p>Enjoy,<br />
Max 🙂</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.maxvergelli.com/how-to-count-how-many-times-a-value-is-repeated-in-a-list/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">24</post-id>	</item>
	</channel>
</rss>
