Skip to end of metadata
Go to start of metadata

This page notes some differences between C# and boo.

C# to Boo Converter

The easiest way to see how code in boo differs from C# is to use the C# to boo converter included in the Boo AddIn For SharpDevelop.

The converter is also accessible online via a webform here:

While viewing a C# file in SharpDevelop, you can select from the menu: Tools -> Convert C# to boo. Or you can convert an entire C# project at once by right-clicking on the project icon and selecting: Convert -> C# to boo. Note, however, the converter is still new and in development.

The converter will convert C# to legal boo code, but it will not show you the simplest way to write that code. For example, instead of "System.Console.WriteLine(error) ", in boo you can simply say "print x". And many times the type will be declared "x as int" when it is unnecessary since the type can be inferred by the boo compiler: "x = 3" or "m = MyClass()".

C# vs. Boo Syntax Examples

Here is a table noting some diffences between C# and boo, based on this table from the Nemerle programming language site. See also the C# language specification.





Types are inferred, no semicolons needed

No "new" keyword required

See Lists and Arrays

See Generics

Types are inferred when you use arrays

Use "raise" to generate an exception.

See Casting Types

You can creates aliases for namespaces.
Also use print instead of console.writeline.

Read-only and constant fields.

Type definitions




Use "def" for methods and functions.
Types are declared with the "as" keyword like VB.

Illustrates a class with a superclass and
a constructor

a class with a field

or else a "const" keyword may be added to boo

Implementing two interfaces that have
the same named method.

Use the DefaultMember attribute.

char() builtin

Uses "single" instead of "float"

Miscellaneous Differences and Similarities




C++ style commenting plus Python # comments.

Quoted string literals.
Triple-quoted strings can span multiple lines, too.

Other Notes on Differences Between C# and Boo

These are some early notes from looking at the C# language specification.

Assigning multiple variables at once

In C#, you can assign a value to two variables at once like so:

In boo, however, "a, b" refers to a sequence. So you would instead use:

Note also declaring the type is unnecessary because of boo's Type Inference.

Use "a, b" when unpacking multiple values. For example:

Also note in boo you can use the "print" statement instead of System.Console.WriteLine.

Buffer overflow checking

You can turn off overflow checking in boo like so:

Variable number of parameters.

Boo uses syntax similar to python:

By reference and output parameters.

In C# you can pass types to functions by reference using "ref" or "out" keywords.

Boo supports the "ref" keyword, too, but not "out", which is unnecessary in boo.

Note though that in this particular sample, you can swap two values more easily like so:

As a more general alternative to by reference parameters, in boo you can also return multiple values from a function instead:

Things in C# but not Boo

do..while loop

Boo doesn't have do..while or do..until loops like C# or VB.NET.

You can emulate them with "while true" loops.

unsafe code

  • No labels


  1. Does Boo have the ability to create sealed classes?

    // C# code
    public sealed class MyClass {

  2. final class MyClass:

  3. The C# example for assigning multiple variables at once is incorrect. It's missing a semicolon, but more importantly it would be equivalent to the following:

    int a;
    int b = 1;

    To make it equivalent to the Boo example, do the following:

    int a, b = 1;
    a = b;

    Or the following:

    int a, b;
    a = b = 1;

    Also, the following C# examples should be corrected. Comments indicate corrections, modifications, and additions.

    First array example:

    Class[] c = new Class[size]; // added semicolon

    Second array example:

    Type[] a = new Type[] { expr_1, expr_2, ..., expr_n }; // changed l to a (readability), changed the second expr_1 to expr_2, added semicolon

    Try-catch example:

    try { ... } // added braces
    catch(FooException e) { ... }
    catch(BarException e) { ... }

    Cast example:

    type t = (type) expr; // outer parenthesis unnecessary, added semicolon
    // or
    // null if cast fails:
    type t = expr as type; // added as-operator example

    Constants example:

    readonly int X = 2;
    const int Y = 3;
    static readonly string Z = String.Format("{0} + {1}", X, Y); // added static readonly example; static readonly is similar to const