Rust for C# Developers
Move from C# classes, value types, interfaces, LINQ and exceptions to Rust ownership, borrowing, traits and explicit errors. Complete 48 tasks, a parcel depot project and two C# program ports.
C# and Rust side by side
The same program in C# and in Rust, from the lessons of this course.
Output and Comments
A C# console application calls Console.WriteLine; Rust calls the println! macro. The exclamation mark belongs to the macro name. Both examples print a literal containing braces, but their formatting rules differ: the one-argument C# overload treats braces as…
C#1using System;2class Program {3 static void Main() {4 // A literal with braces.5 Console.WriteLine("{ready}");6 Console.WriteLine("{0}:{1}", "port", 3);7 }8}Rust1fn main() {2 // A literal with braces.3 println!("{{ready}}");4 println!("{}:{}", "port", 3);5}Boolean Conditions
Both C# and Rust require boolean conditions. Rust does not treat a nonzero integer as true. The short-circuit operators && and || evaluate their right operand only when the left operand cannot decide the result. That matters when the right side calls a method…
C#1using System;2class Program {3 static bool Probe() { Console.WriteLine("probe"); return true; }4 static void Main() {5 bool enabled = false;6 Console.WriteLine(enabled && Probe() ? "open" : "closed");7 }8}Rust1fn probe() -> bool { println!("probe"); true }2fn main() {3 let enabled = false;4 println!("{}", if enabled && probe() { "open" } else { "closed" });5}Functions and Returns
C# methods live in types, and return statements make their result explicit. Rust free functions can live at module scope and commonly return the final expression. Parameter and return types belong in a Rust function signature; local inference does not infer…
C#1using System;2class Program {3 static bool IsDraft(string name) { return name.StartsWith("draft-", StringComparison.Ordinal); }4 static void Main() { Console.WriteLine(IsDraft("draft-map") ? "draft" : "final"); }5}Rust1fn is_draft(name: &str) -> bool { name.starts_with("draft-") }2fn main() { println!("{}", if is_draft("draft-map") { "draft" } else { "final" }); }Ownership and Moves
Assigning a C# List<T> copies a managed reference: both variables can access the same list. Assigning a Rust Vec<T> moves ownership unless you explicitly borrow or clone. A move does not mean copying every element into a new allocation; it transfers…
C#1using System;2using System.Collections.Generic;3class Program {4 static void Main() {5 var first = new List<int> { 3 };6 var second = first;7 second.Add(8);8 Console.WriteLine("{0} {1}", first.Count, second.Count);9 }10}Rust1fn main() {2 let first = vec![3];3 let mut second = first;4 second.push(8);5 println!("{}", second.len());6}Strings and UTF-8
C# strings expose UTF-16 code units through their indexer. A supplementary Unicode scalar occupies a surrogate pair, so a single char may be only half of it. Rust String and str use UTF-8 and reject integer character indexing. Iterating with chars() yields…
C#1using System;2class Program {3 static void Main() {4 string symbol = "🦀!";5 Console.WriteLine((int)symbol[0]);6 Console.WriteLine(symbol.EndsWith("!", StringComparison.Ordinal));7 }8}Rust1fn main() {2 let symbol = "🦀!";3 let first = symbol.chars().next().unwrap();4 println!("{}", first as u32);5 println!("{}", symbol.ends_with('!'));6}Option and Matching
C# int? wraps an integer with a presence flag; zero is a present value, not absence. Rust Option<i32> similarly distinguishes Some(0) from None, but Option<T> works for arbitrary payload types, including owned strings and borrowed references. This is not a…
C#1using System;2class Program {3 static void Show(int? value) {4 Console.WriteLine(value.HasValue ? "present:" + value.Value : "absent");5 }6 static void Main() { Show(0); Show(null); }7}Rust1fn show(value: Option<i32>) {2 match value {3 Some(n) => println!("present:{}", n),4 None => println!("absent"),5 }6}7fn main() { show(Some(0)); show(None); }
Syllabus
10 chapters48 lessons1 project48 challenges99 quiz questionsFirst Rust Programs
6 lessonsDecisions and Loops
5 lessonsFunctions and Sequences
4 lessonsOwnership and Borrowing
5 lessonsText and Collections
4 lessonsAbsence and Failure
5 lessonsStructs and State
6 lessonsTraits and Generic Code
7 lessonsProject: Parcel Depot
4 lessonsFinal Ports
2 lessonsFrequently asked questions
Who is Rust for C# Developers for?
For people who already write C# and want to learn Rust. Each lesson starts from C# you know and shows how Rust does the same thing, so you skip the beginner basics.
Do I need to know Rust already?
No. The course starts with your first Rust program. You need C# basics: variables, conditions, loops, functions and collections.
How many lessons does Rust for C# Developers have?
Rust for C# Developers contains 48 interactive lessons you can complete at your own pace.
What does Rust for C# Developers cover?
The course is organized into chapters covering: First Rust Programs, Decisions and Loops, Functions and Sequences, Ownership and Borrowing, and more.
Is Rust for C# Developers free?
Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.