Menu
CoddyTech
Course

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.

  1. 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…

    R
    1cat("C# is ready\n")
    C#
    1Console.WriteLine("C# is ready");
  2. 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…

    R
    1writeLines(paste0("Hi, ", "Mina"))  # A comment
    C#
    1Console.WriteLine("Hi, " + "Mina"); // A comment
  3. Boolean 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 &&/||/!…

    R
    1active <- TRUE2cat(if (20 >= 18 && active) "true" else "false", "\n", sep = "")
    C#
    1bool active = true;2Console.WriteLine((20 >= 18 && active) ? "true" : "false");
  4. 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 -…

    R
    1values <- c(4L, 6L)2cat(length(values), "\n", sep = "")
    C#
    1int[] values = { 4, 6 };2Console.WriteLine(values.Length);
  5. 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…

    R
    1values <- 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);
  6. 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…

    R
    1total <- 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 questions

Start Here

1 lesson

More courses for R developers

Learn C# from another language

Frequently 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.

Coddy programming languages illustration

Start C# for R Developers for free

Get started