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.
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.
Ruby1puts "C# is ready"C#1Console.WriteLine("C# is ready");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…
Ruby1puts "Hi, " + "Mina" # A commentC#1Console.WriteLine("Hi, " + "Mina"); // A commentBoolean 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.
Ruby1active = true2puts((20 >= 18 && active) ? "true" : "false")C#1bool active = true;2Console.WriteLine((20 >= 18 && active) ? "true" : "false");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…
Ruby1values = [4, 6]2puts values.lengthC#1int[] values = { 4, 6 };2Console.WriteLine(values.Length);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…
Ruby1counts = 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"));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…
Ruby1def join_tags(prefix = "tags", *tags)2 prefix + ":" + tags.join(",")3end4puts join_tags("names", "A", "B")5puts join_tags("ids", *["7", "8"])6puts join_tagsC#1static string JoinTags(string prefix = "tags", params string[] tags) { return prefix + ":" + string.Join(",", tags); }
Syllabus
11 chapters48 lessons1 project48 challenges99 quiz questionsStart Here
1 lessonC# Values and Text
6 lessonsDecisions and Missing Values
5 lessonsLoops and Sequences
5 lessonsCollections and Queries
5 lessonsMethods and Callbacks
5 lessonsReliable C# Modules
5 lessonsClasses and Encapsulation
5 lessonsPolymorphism and Equality
5 lessonsProject: Order Pipeline
4 lessonsFinal Challenges
2 lessonsFrequently 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.