Monday, 5 November 2007

Chapter 4, Lesson 4 - Using Specialized Collections.

Problem: ArrayList, Sequence Lists, And Dictionary classese can be used to store any object. However often leads to having to cast objects on retrieval from the collection.

Answer: System.Collection.Specialized - collns that are meant to work with specific types of data.

BitArray
  • Resizeable colln that stores bools.
  • supports std bit-lvl ops.
  • constructor - specify size, and then chang size ~ Length property.
  • does not support Add() or Remove().
  • default value of bits - false.
  • set individual bits ~ indexer.
  • Can perform ops on 2 BitArray objs of same size.

BitVector32

  • Purpose - to aid in manipulating bits in a 32-bit integer.
  • not resizeable.

BitVector32 & Bit Masks

  • All ops on BitVector32 structure actually change the value of the integer within the structure itself.
  • Data property - gets the stored integer.
  • CreateMask() - static

BitVector32 & Bit Packing

  • taking several smaller numbers & packing them into 1 large number.
  • often done to decrease storage of small numbers.
  • create sections in structure - CreateSection().

StringCollection

  • simple, dynamically sized collection that can only store strings.
  • Working with it is virtually identical to using ArrayList.
  • no casting on retrieval + will generate compile error it try to insert non-string.

StringDictionary

  • Like HashTable - but both key + value are strings.
  • keys are case-insensitive by default.

CollectionsUtil - case-insensitive collns of strings

  • Creating case-insentitive dictionary collns is so common, there are 2 shortcuts:
  • CollectionsUtil.CreateCaseINsensitiveHashtable().
  • CollectionsUtil.CreateCaseInsensitiveSortedList().

NameValueCollection Class

  • like StringDictionary - keys + values are strings.
  • Allows mult. values per key
  • can be retrieved by index as well as key.

No comments: