User Tools

Site Tools


collections

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
collections [2018/02/04 18:40] wolfgangriedmanncollections [2018/02/05 05:20] (current) wolfgangriedmann
Line 12: Line 12:
   * [[https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1|System.Collections.Generic.List<T>]]   * [[https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.list-1|System.Collections.Generic.List<T>]]
   * [[https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.dictionary-2|System.Collections.Generic.Dictionary<TKey,TValue>]]   * [[https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.dictionary-2|System.Collections.Generic.Dictionary<TKey,TValue>]]
 +  * [[https://docs.microsoft.com/en-us/dotnet/api/system.collections.sortedlist|System.Collections.SortedList]]
   * [[https://docs.microsoft.com/en-us/dotnet/api/system.collections.arraylist|System.Collections.ArrayList]]   * [[https://docs.microsoft.com/en-us/dotnet/api/system.collections.arraylist|System.Collections.ArrayList]]
  
Line 18: Line 19:
   * [[https://docs.microsoft.com/en-us/dotnet/standard/collections/selecting-a-collection-class|MSDN: Selecting a collection class]]   * [[https://docs.microsoft.com/en-us/dotnet/standard/collections/selecting-a-collection-class|MSDN: Selecting a collection class]]
   * [[https://docs.microsoft.com/en-us/dotnet/standard/collections/commonly-used-collection-types|MSDN: Commonly used collection types]]   * [[https://docs.microsoft.com/en-us/dotnet/standard/collections/commonly-used-collection-types|MSDN: Commonly used collection types]]
 +
 +There are a few very important things you should know about collections:
 +  * They are not arrays, and therefore they are **0-based**, so the first member of the collection is **element 0**, and there is no compiler switch that can change this, because it are the classes itself that are written this was
 +  * You **cannot** change a collection while you are using it in a ''foreach'' loop.
 +  * most collections are using generics, to you need to specify the type(s) of the elements in the declaration of the variable
 +
 +A few code samples (please look at samples for the single classes [[collections:list|System.Collections.Generic.List]] and [[collections:dictionary|System.Collections.Generic.Dictionary]]) for deeper looks):
 +<code>using System.Collections.Generic
 +local oList as List<string>
 +local nCount as int
 +
 +oList := List<string>{}
 +oList:Add( "Hi girls" )
 +oList:Add( "Hi guys" )
 +nCount := oList:Count                  
 +foreach cItem as string in oList
 +  // do something
 +next
 +oList:Remove( "Hi guys" )
 +oList:RemoveAt( 0 )</code>
 +<code>local oDictionary as Dictionary<int,string>
 +local nCount as int
 +
 +oDictionary := Dictionary<int,string>{}
 +oDictionary:Add( 1, "Hi girls" )
 +oDictionary:Add( 2, "Hi guys" )
 +foreach oItem as KeyValuePair<int,string> in oDictionary
 +  // do something
 +next</code>
 +
 +
 +
 +
 +
  
  
  
  
collections.1517769602.txt.gz · Last modified: 2018/02/04 18:40 by wolfgangriedmann