C for C# Developers
Move from C# to C17: explicit interfaces, pointers, arrays, strings, ownership and structs. Build a multi-file stock ledger and port two complete programs.
C# and C side by side
The same program in C# and in C, from the lessons of this course.
Printing and Comments
C# composite formatting reads managed values. C printf uses variadic arguments and conversion specifiers; a mismatched argument type can cause undefined behavior rather than a managed formatting exception.
C#1using System;2using System.Collections.Generic;3using System.Linq;4using System.Globalization;5class Program {6 7static void Main(){8Console.WriteLine("value={0}",7);9}10}C1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stddef.h>5#include <stdbool.h>6#include <limits.h>7#include <errno.h>8 9int main(void) {10printf("value=%d\n",7);11return 0;12}Booleans and Branches
C# requires bool conditions. C accepts scalar truth tests, and a non-null pointer to an empty string is true; testing emptiness requires inspecting the terminator or length.
C#1using System;2using System.Collections.Generic;3using System.Linq;4using System.Globalization;5class Program {6 7static void Main(){8string s="";Console.WriteLine(s.Length==0?"true":"false");9}10}C1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stddef.h>5#include <stdbool.h>6#include <limits.h>7#include <errno.h>8 9int main(void) {10const char *s=""; printf("%s\n",s?"true":"false");11return 0;12}Arrays Need Lengths
C# arrays are reference objects with a Length property. A C pointer parameter carries no array extent; pass length explicitly, and use sizeof for element counts only while the actual array type is visible.
C#1using System;2using System.Collections.Generic;3using System.Linq;4using System.Globalization;5class Program {6 7static void Main(){8int[] a={2,4,6};Console.WriteLine(a.Length);9}10}C1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stddef.h>5#include <stdbool.h>6#include <limits.h>7#include <errno.h>8 9int main(void) {10int a[]={2,4,6};printf("%zu\n",sizeof a/sizeof a[0]);11return 0;12}Function Arguments Are Values
Ordinary C# parameters and C parameters pass values. C# also has ref and out language modes; C expresses such updates through explicit pointer parameters instead.
C#1using System;2using System.Collections.Generic;3using System.Linq;4using System.Globalization;5class Program {6static void Change(int x){x=9;}7static void Main(){8int x=2;Change(x);Console.WriteLine(x);9}10}C1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stddef.h>5#include <stdbool.h>6#include <limits.h>7#include <errno.h>8static void change(int n){n=9;(void)n;}9int main(void) {10int x=2;change(x);printf("%d\n",x);11return 0;12}Addresses and Dereferencing
C# ref permits checked by-reference access in ordinary managed code. C uses addresses and dereferencing directly; it does not enforce pointer lifetime or borrowing rules.
C#1using System;2using System.Collections.Generic;3using System.Linq;4using System.Globalization;5class Program {6static void Set(ref int n){n=5;}7static void Main(){8int n=2;Set(ref n);Console.WriteLine(n);9}10}C1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stddef.h>5#include <stdbool.h>6#include <limits.h>7#include <errno.h>8 9int main(void) {10int n=2;int *p=&n;*p=5;printf("%d\n",n);11return 0;12}Parsing with Status Results
C# TryParse separates success from its output value. C sscanf reports assigned fields and can accept a prefix; a successful assignment alone does not establish full-input validity.
C#1using System;2using System.Collections.Generic;3using System.Linq;4using System.Globalization;5class Program {6 7static void Main(){8int n;Console.WriteLine(int.TryParse("12x",out n)?"valid":"invalid");9}10}C1#include <stdio.h>2#include <stdlib.h>3#include <string.h>4#include <stddef.h>5#include <stdbool.h>6#include <limits.h>7#include <errno.h>8 9int main(void) {10const char *s="12x";int ok=*s!=0;for(size_t i=0;s[i];i++)if(s[i]<'0'||s[i]>'9')ok=0;printf("%d\n",ok);11return 0;12}
Syllabus
10 chapters48 lessons1 project48 challenges99 quiz questionsCompile and Compute
6 lessonsDecisions and Loops
5 lessonsArrays and Text
5 lessonsFunctions and Interfaces
5 lessonsPointers and Structs
5 lessonsValidation and Text Buffers
5 lessonsOwned Dynamic Memory
5 lessonsTagged Data and Composition
6 lessonsProject: Stock Ledger
4 lessonsFinal Source Ports
2 lessonsFrequently 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: Compile and Compute, Decisions and Loops, Arrays and Text, Functions and Interfaces, 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.