Previous installments

General Data Structures

Trees

Looking at too many tree structures is bound to make your eyes bleed, so we'll take a bit of of break to discuss one of the simpler data structures NGenerics offers - the ObjectMatrix. The ObjectMatrix is a representation of a 2-dimensional array of objects, like, for example, a game board :

Why not just use a two-dimensional array in the first place?  The ObjectMatrix offers several useful operations, which, at the time of writing are :

  • Rows and Colums - formal definition of rows and columns - much better than having .Length scattered all over your code.
  • GetSubMatrix -  enables the retrieval of a subset of the matrix.
  • InterchangeRows and InterchangeColumns - swap individual rows and columns easily.
  • GetRow and GetColumn - provides an easy way of retrieving individual rows and columns.
  • AddRow and AddColumn - add new rows and columns when you need more space.
  • DeleteRow and DeleteColumn - delete individual rows and columns.
  • Resize - resize the matrix to have any arbitrary column/row count.

Use it exactly like you would use any two dimensional array :

400: Invalid request

The ObjectMatrix is also the base class for one of the biggest classes in NGenerics - the mathematical Matrix, which we'll get to in a later post.