Home arrow BrainDump arrow Page 3 - A Quick Tour of Boo

Arrays and Collections - BrainDump

If you're looking for a portable .NET language and don't want to use a C-style syntax, you might want to take a look at Boo. Don't let the name spook you; if you're comfortable with Python, you'll feel right at home with Boo.

  1. A Quick Tour of Boo
  2. Program Structure and Variables
  3. Arrays and Collections
  4. Conditionals and Loops
  5. Functions and Types
By: Peyton McCullough
Rating: starstarstarstarstar / 4
August 06, 2007

print this article



In Boo, arrays are defined a little differently from the way they are defined in other languages. Here, we create an array of integers and an array of strings:

ints = array(int,4)

ints[0] = 3

ints[1] = 6

ints[2] = 8

ints[3] = 90

strings = array(string, ["one", "two", "three"])

Note how the type of the array's elements is passed, followed by either the size of the array or the array's elements.

One very useful feature of arrays is slicing, which Python users will recognize. Slicing provides an easy way to extract a portion of an array:

theArray = [1, 2, 3, 4, 5]

print theArray[1:]

print theArray[1:3]

print theArray[2:]

[2, 3, 4, 5]

[2, 3]

[3, 4, 5]

Boo has support for two built-in collections, lists (for which slicing also works) and hashtables:

a = [4, 8, 15, 16, 23, 42]

a[0] = 8

a[1] = 15


b = {"jdoe": "John Doe", "jsmith": "John Smith"}

b["msmith"] = "Mary Smith"

However, the two collections are not type-safe:

c = [1,2]


d = {1: "one", "two": 2}

Fortunately, Boo has recently added support for generics, so one can create a type-safe collection using the collections in System.Collections.Generic:

import System.Collections.Generic


names = List of string()





rooms = Dictionary[of int,string]()

rooms.Add(100, names[0])

rooms.Add(200, names[1])

rooms.Add(300, names[2])

>>> More BrainDump Articles          >>> More By Peyton McCullough

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort


- Apple Founder Steve Jobs Dies
- Steve Jobs` Era at Apple Ends
- Google's Chrome Developer Tool Updated
- Google's Chrome 6 Browser Brings Speed to th...
- New Open Source Update Fedora 13 is Released...
- Install Linux with Knoppix
- iPad Developers Flock To SDK 3.2
- Managing a Linux Wireless Access Point
- Maintaining a Linux Wireless Access Point
- Securing a Linux Wireless Access Point
- Configuring a Linux Wireless Access Point
- Building a Linux Wireless Access Point
- Migrating Oracle to PostgreSQL with Enterpri...
- Demystifying SELinux on Kernel 2.6
- Yahoo and Microsoft Create Ad Partnership

Developer Shed Affiliates


Dev Shed Tutorial Topics: