C# for Lua Developers
Use your Lua experience to learn C# types, flow, methods, collections and object design. Build and test a multi-file order-processing program with compatible Mono C#.
Lua and C# side by side
The same program in Lua and in C#, from the lessons of this course.
Run Your First C# Program
Lua runs a chunk from top to bottom and needs no entry function. C# first compiles declared classes and methods, then starts Main. These examples compare behavior; the challenge editor runs C#, not Lua.
Lua1print("C# is ready")C#1Console.WriteLine("C# is ready");Output, Comments and Main
Lua print becomes Console.WriteLine, and Lua -- comments become // comments. Lua joins strings with .., while C# uses +. Lua closes blocks with end and semicolons are optional, but braces define C# blocks and semicolons terminate statements. Helper methods…
Lua1print("Hi, " .. "Mina") -- A commentC#1Console.WriteLine("Hi, " + "Mina"); // A commentBoolean Logic and Equality
Lua treats every value except nil and false as true, so 0 and an empty string pass a Lua if. C# conditions require bool and use &&, || and ! where Lua uses and, or and not, and != where Lua uses ~=. A Lua condition on a number, a string or a table cannot be…
Lua1local active = true2print((20 >= 18 and active) and "true" or "false")C#1bool active = true;2Console.WriteLine((20 >= 18 && active) ? "true" : "false");Arrays and Bounds
Lua sequences are tables that start at index 1, grow on assignment and return nil for a missing index. C# arrays start at 0 and have a fixed length, and reading past either end throws IndexOutOfRangeException instead of giving nil. The Lua # operator becomes…
Lua1local values = {4, 6}2print(#values)C#1int[] values = { 4, 6 };2Console.WriteLine(values.Length);Dictionaries and Missing Keys
Lua returns nil for a missing key, and values[key] or 0 supplies a default. A C# Dictionary indexer throws KeyNotFoundException instead, so TryGetValue reports presence as a bool and delivers the value through out. Lua compares string keys byte for byte…
Lua1local values = {}2print(values["missing"] or 0)C#1var values = new Dictionary<string,int>();2int count;3Console.WriteLine(values.TryGetValue("missing", out count) ? count : 0);Methods, Defaults and params
Lua's ... vararg corresponds to a C# params array. Lua has no default parameters, so code writes factor = factor or 2, while C# declares the default in the signature. Lua drops extra arguments and fills missing ones with nil; C# rejects a call whose arguments…
Lua1local function total(factor, ...)2 factor = factor or 23 local sum = 04 for _, v in ipairs({...}) do sum = sum + v end5 return sum * factor6end7print(total(3, 2, 4))C#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 Lua Developers for?
For people who already write Lua and want to learn C#. Each lesson starts from Lua 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 Lua basics: variables, conditions, loops, functions and collections.
How many lessons does C# for Lua Developers have?
C# for Lua Developers contains 48 interactive lessons you can complete at your own pace.
What does C# for Lua 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 Lua Developers free?
Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.