C# for R Developers
Use your R experience to learn C# types, flow, methods, collections and object design. Build and test a multi-file order-processing program with compatible Mono C#.
R and C# side by side
The same program in R and in C#, from the lessons of this course.
Run Your First C# Program
An R script runs its top-level expressions one after another, and at the console R prints the value of each one automatically. C# first compiles declared classes and methods, then starts Main, and nothing is printed unless a statement asks for it. These…
R1cat("C# is ready\n")C#1Console.WriteLine("C# is ready");Output, Comments and Main
R writeLines becomes Console.WriteLine, and R # comments become // comments. R joins strings with paste0 because + on two strings is an error there; C# + concatenates strings. A newline ends an R statement, but braces define every C# class and method body and…
R1writeLines(paste0("Hi, ", "Mina")) # A commentC#1Console.WriteLine("Hi, " + "Mina"); // A commentBoolean Logic and Equality
R if accepts a number, treating nonzero as TRUE, so if (length(x)) is a common nonempty test. C# conditions require bool, so write an explicit check such as values.Length > 0. R && and || work on single values while & and | work elementwise; C# uses &&/||/!…
R1active <- TRUE2cat(if (20 >= 18 && active) "true" else "false", "\n", sep = "")C#1bool active = true;2Console.WriteLine((20 >= 18 && active) ? "true" : "false");Arrays and Bounds
R vectors start at index 1, grow when you assign past the end, and return NA for an out-of-range read, while values[-1] drops the first element. C# arrays start at 0, have a fixed Length, and throw IndexOutOfRangeException for any index outside 0 to Length -…
R1values <- c(4L, 6L)2cat(length(values), "\n", sep = "")C#1int[] values = { 4, 6 };2Console.WriteLine(values.Length);Dictionaries and Missing Keys
An R list returns NULL for a missing name with [[ ]] or $, so absence passes silently, and $ even matches partial names. A C# Dictionary indexer throws KeyNotFoundException instead, and TryGetValue separates the presence bool from the out value. C# keys match…
R1values <- list()2count <- values[["missing"]]3cat(if (is.null(count)) 0 else count, "\n", sep = "")C#1var values = new Dictionary<string,int>();2int count;3Console.WriteLine(values.TryGetValue("missing", out count) ? count : 0);Methods, Defaults and params
R ... collects extra arguments much like a C# params array, but ... can mix types and names, while params is one typed array. R defaults are evaluated lazily and may refer to other arguments; C# optional parameter defaults must be compile-time constants. R…
R1total <- function(factor = 2, ...) {2 sum(...) * factor3}4cat(total(3, 2, 4), "\n", sep = "")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 R Developers for?
For people who already write R and want to learn C#. Each lesson starts from R 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 R basics: variables, conditions, loops, functions and collections.
How many lessons does C# for R Developers have?
C# for R Developers contains 48 interactive lessons you can complete at your own pace.
What does C# for R 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 R Developers free?
Yes. Every course on Coddy is free to start. You can complete lessons in your browser without any downloads or signup.