Menu
CoddyTech
Course

C# for Ruby Developers

Use your Ruby experience to learn C# types, flow, methods, collections and object design. Build and test a multi-file order-processing program with compatible Mono C#.

Ruby and C# side by side

The same program in Ruby and in C#, from the lessons of this course.

  1. Run Your First C# Program

    Ruby runs a script from its first line, executing top-level statements as it reads them, with no entry method. C# first compiles declared classes and methods, then starts Main. These examples compare behavior; the challenge editor runs C#, not Ruby.

    Ruby
    1puts "C# is ready"
    C#
    1Console.WriteLine("C# is ready");
  2. Output, Comments and Main

    Ruby puts becomes Console.WriteLine, and Ruby print, which adds no newline, becomes Console.Write. Ruby # comments become // comments. Ruby closes blocks with end and ends statements at a newline, while braces define C# blocks and semicolons terminate…

    Ruby
    1puts "Hi, " + "Mina" # A comment
    C#
    1Console.WriteLine("Hi, " + "Mina"); // A comment
  3. Boolean Logic and Equality

    Ruby treats only nil and false as falsy, so 0, an empty string and an empty array all pass an if. C# conditions require bool and use &&/||/!. A Ruby test such as if items cannot be copied into C#; write an explicit null check or Length comparison instead.

    Ruby
    1active = true2puts((20 >= 18 && active) ? "true" : "false")
    C#
    1bool active = true;2Console.WriteLine((20 >= 18 && active) ? "true" : "false");
  4. Arrays and Bounds

    Ruby arrays grow with push or <<, accept negative indexes, and return nil for a read past the end. A C# array has a fixed length, negative indices are invalid, and an out-of-range read throws IndexOutOfRangeException instead of producing nil. Use List<T> when…

    Ruby
    1values = [4, 6]2puts values.length
    C#
    1int[] values = { 4, 6 };2Console.WriteLine(values.Length);
  5. Dictionaries and Missing Keys

    A Ruby Hash returns nil, or the default given to Hash.new(0), for a missing key, and only fetch raises KeyError. A C# Dictionary indexer behaves like fetch without a default: reading a missing key throws KeyNotFoundException. TryGetValue separates the…

    Ruby
    1counts = Hash.new(0)2counts["pen"] += 13puts counts["missing"]4puts counts["pen"]5puts counts.key?("missing")
    C#
    1var counts = new Dictionary<string, int>(StringComparer.Ordinal);2int count;3counts.TryGetValue("pen", out count);4counts["pen"] = count + 1;5Console.WriteLine(counts.TryGetValue("missing", out count) ? count : 0);6Console.WriteLine(counts["pen"]);7Console.WriteLine(counts.ContainsKey("missing"));
  6. Methods, Defaults and params

    Ruby's splat *tags corresponds to a C# params array, and a default such as prefix = "tags" to an optional parameter. To pass an existing array, Ruby needs a splat at the call site; C# accepts the array directly. A params string[] accepts only strings, where a…

    Ruby
    1def join_tags(prefix = "tags", *tags)2  prefix + ":" + tags.join(",")3end4puts join_tags("names", "A", "B")5puts join_tags("ids", *["7", "8"])6puts join_tags
    C#
    1static string JoinTags(string prefix = "tags", params string[] tags) { return prefix + ":" + string.Join(",", tags); }

Syllabus

11 chapters48 lessons1 project48 challenges99 quiz questions

Start Here

1 lesson

More courses for Ruby developers

Learn C# from another language

Frequently asked questions

Who is C# for Ruby Developers for?

For people who already write Ruby and want to learn C#. Each lesson starts from Ruby you know and shows how C# does the same thing, so you skip the beginner basics.

Do I need to know C# already?

No. The course starts with your first C# program. You need Ruby basics: variables, conditions, loops, functions and collections.

How many lessons does C# for Ruby Developers have?

C# for Ruby Developers contains 48 interactive lessons you can complete at your own pace.

What does C# for Ruby Developers cover?

The course is organized into chapters covering: Start Here, C# Values and Text, Decisions and Missing Values, Loops and Sequences, and more.

Is C# for Ruby Developers free?

Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.

Coddy programming languages illustration

Start C# for Ruby Developers for free

Get started