Menu
CoddyTech
Course

C# for Rust Developers

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

Rust and C# side by side

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

  1. Run Your First C# Program

    Rust compiles a crate ahead of time and starts at a free fn main; this C# course compiles declared classes with mcs and starts a static Main under Mono. C# reclaims objects with a garbage collector instead of ownership and drop, so resource lifetime still…

    Rust
    1fn main() {2    println!("C# is ready");3}
    C#
    1Console.WriteLine("C# is ready");
  2. Output, Comments and Main

    The Rust println! macro becomes the Console.WriteLine method. C# uses a static Main inside a class rather than a free fn main. Braces and // comments remain, but C# has no macros, and its + operator joins two string literals, which Rust rejects for two &str…

    Rust
    1fn main() {2    println!("{}", String::from("Hi, ") + "Mina"); // A comment3}
    C#
    1Console.WriteLine("Hi, " + "Mina"); // A comment
  3. Boolean Logic and Equality

    Rust and C# both demand a real bool in a condition: neither treats a number, a missing value or a collection as a truth value. Rust has no ?: operator and uses an if expression, which the C# ternary replaces. Rust == always goes through PartialEq, while C# ==…

    Rust
    1fn main() {2    let active = true;3    println!("{}", if 20 >= 18 && active { "true" } else { "false" });4}
    C#
    1bool active = true;2Console.WriteLine((20 >= 18 && active) ? "true" : "false");
  4. Arrays and Bounds

    A Rust array [i32; 2] carries its length in its type and is copied by value. A C# int[] is a heap object reached through a reference, and its Length is a runtime property, closer to a Box<[i32]>. Both check indices: Rust panics and C# throws…

    Rust
    1fn main() {2    let values: [i32; 2] = [4, 6];3    println!("{}", values.len());4}
    C#
    1int[] values = { 4, 6 };2Console.WriteLine(values.Length);
  5. Dictionaries and Missing Keys

    Rust HashMap::get returns Option<&V>, so absence lives in the return type. C# TryGetValue returns a bool and writes the value into an out variable, which gets the default value when the key is absent. Indexing a missing key panics in Rust and throws…

    Rust
    1use std::collections::HashMap;2
    3fn main() {4    let values: HashMap<String, i32> = HashMap::new();5    println!("{}", values.get("missing").copied().unwrap_or(0));6}
    C#
    1var values = new Dictionary<string,int>();2int count;3Console.WriteLine(values.TryGetValue("missing", out count) ? count : 0);
  6. Methods, Defaults and params

    Rust has no default arguments, overloading or variadic functions: an API takes an Option<T> for a value the caller may skip and a slice for any number of values, so every call spells out each argument. C# optional parameters supply a default when the argument…

    Rust
    1fn join_tags(prefix: Option<&str>, tags: &[&str]) -> String {2    format!("{}:{}", prefix.unwrap_or("tags"), tags.join(","))3}4
    5fn main() {6    println!("{}", join_tags(Some("names"), &["A", "B"]));7}
    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 Rust developers

Learn C# from another language

Frequently asked questions

Who is C# for Rust Developers for?

For people who already write Rust and want to learn C#. Each lesson starts from Rust 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 Rust basics: variables, conditions, loops, functions and collections.

How many lessons does C# for Rust Developers have?

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

What does C# for Rust 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 Rust 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 Rust Developers for free

Get started