Dart for C# Developers
Move from C# to standalone Dart through typed functions, null safety, collections, errors and object contracts. Build a four-step parcel depot, use classes, interfaces and mixins, then port two complete C# programs.
C# and Dart side by side
The same program in C# and in Dart, from the lessons of this course.
Output and Comments
C# interpolation prefixes the string with a dollar sign and uses braces. Dart interpolation occurs inside ordinary strings using dollar-prefixed names or braces. print is the line-oriented counterpart of Console.WriteLine.
C#1using System;2using System.Collections.Generic;3using System.Linq;4class Program {5 6static void Main(){int lane=3;Console.WriteLine($"lane:{lane}");}7}Dart1void main(){final lane=3;print('lane:$lane');}Boolean Conditions
C# and Dart require Boolean conditions and short-circuit &&. Dart bool? handles nullable absence explicitly, but ordinary logical conditions still need non-nullable bool.
C#1using System;2using System.Collections.Generic;3using System.Linq;4class Program {5static bool Probe(){Console.WriteLine("probe");return true;}6static void Main(){Console.WriteLine(false&&Probe()?"open":"closed");}7}Dart1bool probe(){print('probe');return true;}2void main(){if(false && probe()){print('open');}else{print('closed');}}Functions and Returns
C# expression-bodied methods resemble Dart arrow functions. Dart additionally permits top-level functions in libraries. The result type controls which values callers can use, including nullability.
C#1using System;2using System.Collections.Generic;3using System.Linq;4class Program {5static bool IsLog(string name)=>name.EndsWith(".log");6static void Main(){Console.WriteLine(IsLog("server.log"));}7}Dart1bool isLog(String name)=>name.endsWith('.log');2void main(){print(isLog('server.log'));}Iterables and Laziness
C# LINQ IEnumerable pipelines and Dart Iterables can both be deferred and traversed again. ToList materializes in C#, and toList does so in Dart. Callback side effects can repeat with repeated traversal.
C#1using System;2using System.Collections.Generic;3using System.Linq;4class Program {5 6static void Main(){var result=new[]{2,3}.Select(n=>{Console.WriteLine("visit:"+n);return n*2;});Console.WriteLine("made");Console.WriteLine(result.First());}7}Dart1void main(){final result=[2,3].map((n){print('visit:$n');return n*2;});print('made');print(result.first);}Parsing and Validation
C# TryParse reports success with a Boolean and writes an out parameter. Dart tryParse returns the nullable parsed value directly. Culture-sensitive C# overloads should not be assumed equivalent to Dart decimal parsing.
C#1using System;2using System.Collections.Generic;3using System.Linq;4class Program {5 6static void Main(){int n;Console.WriteLine(int.TryParse("nope",out n)?n.ToString():"invalid");Console.WriteLine(int.Parse("42"));}7}Dart1void main(){print(int.tryParse('nope')??'invalid');print(int.tryParse('42'));}Classes and Instances
C# class objects and Dart class objects have reference semantics. C# structs are a separate value-type feature; ordinary Dart class instances do not acquire struct-style copying. Fields belong to each instance.
C#1using System;2using System.Collections.Generic;3using System.Linq;4class Program {5class Lamp{public bool On=false;public void Toggle(){On=!On;}}6static void Main(){var a=new Lamp();var b=new Lamp();a.Toggle();Console.WriteLine(a.On+":"+b.On);}7}Dart1class Lamp{bool on=false;void toggle(){on=!on;}}2void main(){final a=Lamp(),b=Lamp();a.toggle();print('${a.on}:${b.on}');}
Syllabus
10 chapters48 lessons1 project48 challenges99 quiz questionsFirst Dart Programs
6 lessonsFlow and Decisions
5 lessonsFunctions and Values
6 lessonsCollection Pipelines
6 lessonsParsing and Failures
3 lessonsObjects and State
6 lessonsContracts and Reuse
7 lessonsEquality and Testing
3 lessonsParcel Depot Project
4 lessonsFinal Source Ports
2 lessonsFrequently asked questions
Who is Dart for C# Developers for?
For people who already write C# and want to learn Dart. Each lesson starts from C# you know and shows how Dart does the same thing, so you skip the beginner basics.
Do I need to know Dart already?
No. The course starts with your first Dart program. You need C# basics: variables, conditions, loops, functions and collections.
How many lessons does Dart for C# Developers have?
Dart for C# Developers contains 48 interactive lessons you can complete at your own pace.
What does Dart for C# Developers cover?
The course is organized into chapters covering: First Dart Programs, Flow and Decisions, Functions and Values, Collection Pipelines, and more.
Is Dart 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.