Menu
CoddyTech
Course

C# for C Developers

Use your C experience to learn C# types, flow, methods, collections and object design. Build and test a multi-file order-processing program with compatible Mono C#.

C and C# side by side

The same program in C and in C#, from the lessons of this course.

  1. Run Your First C# Program

    C compiles straight to native code and starts at a global main function; this C# course compiles declared classes with mcs and starts a static Main under Mono. C# frees objects with a garbage collector, so there is no malloc and free to pair up, but resource…

    C
    1#include <stdio.h>2
    3int main(void) {4    printf("C# is ready\n");5    return 0;6}
    C#
    1Console.WriteLine("C# is ready");
  2. Output, Comments and Main

    C printf becomes Console.WriteLine, which takes the value directly and appends the newline for you. C has no string + operator, so the C version passes both pieces to a %s format; C# joins them with +. There is no header to include, and Main is a static…

    C
    1#include <stdio.h>2
    3int main(void) {4    printf("%s%s\n", "Hi, ", "Mina"); // A comment5    return 0;6}
    C#
    1Console.WriteLine("Hi, " + "Mina"); // A comment
  3. Boolean Logic and Equality

    C treats any scalar as a condition: a nonzero int or a non-null pointer is true, and comparisons yield the int 1 or 0. C# conditions must be bool, so if (count) does not compile; write count != 0. Also, == on two C char pointers compares addresses and needs…

    C
    1#include <stdbool.h>2#include <stdio.h>3
    4int main(void) {5    bool active = true;6    printf("%s\n", (20 >= 18 && active) ? "true" : "false");7    return 0;8}
    C#
    1bool active = true;2Console.WriteLine((20 >= 18 && active) ? "true" : "false");
  4. Arrays and Bounds

    A C array carries no length: sizeof values / sizeof values[0] works only where the array is declared, and once it decays to a pointer in a call, the size must travel as a separate parameter. A C# array is an object that knows its Length. Every indexed access…

    C
    1#include <stdio.h>2
    3int main(void) {4    int values[] = {4, 6};5    printf("%zu\n", sizeof values / sizeof values[0]);6    return 0;7}
    C#
    1int[] values = { 4, 6 };2Console.WriteLine(values.Length);
  5. Dictionaries and Missing Keys

    The C standard library has no map. A C lookup is your own loop or hash table, string keys are compared with strcmp, and the found or missing signal is whatever convention you pick, often a return flag plus an int * out argument. C# Dictionary<TKey,TValue> is…

    C
    1#include <stdio.h>2#include <string.h>3
    4struct entry { const char *key; int value; };5
    6static int find(const struct entry *entries, size_t count, const char *key, int *out) {7    for (size_t i = 0; i < count; i++) {8        if (strcmp(entries[i].key, key) == 0) {9            *out = entries[i].value;10            return 1;11        }12    }13    return 0;14}15
    16int main(void) {17    struct entry values[] = { { "apple", 3 } };18    int count;19    printf("%d\n", find(values, 1, "missing", &count) ? count : 0);20    return 0;21}
    C#
    1var values = new Dictionary<string,int> { { "apple", 3 } };2int count;3Console.WriteLine(values.TryGetValue("missing", out count) ? count : 0);
  6. Methods, Defaults and params

    C has no default arguments and no overloading, so a C API adds a second function or asks callers to pass a sentinel such as NULL. A C variadic function uses ... with va_list: the callee cannot tell how many arguments arrived or their types, so the caller…

    C
    1#include <stdarg.h>2#include <stdio.h>3
    4static void join_tags(const char *prefix, int count, ...) {5    va_list args;6    va_start(args, count);7    printf("%s:", prefix);8    for (int i = 0; i < count; i++) {9        if (i) printf(",");10        printf("%s", va_arg(args, const char *));11    }12    va_end(args);13    printf("\n");14}15
    16int main(void) {17    join_tags("names", 2, "A", "B");18    return 0;19}
    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 C developers

Learn C# from another language

Frequently asked questions

Who is C# for C Developers for?

For people who already write C and want to learn C#. Each lesson starts from C 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 C basics: variables, conditions, loops, functions and collections.

How many lessons does C# for C Developers have?

C# for C Developers contains 48 interactive lessons you can complete at your own pace.

What does C# for C 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 C 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 C Developers for free

Get started