C++ for C# Developers
Transfer C# experience to C++17: values, flow, functions, containers, headers, classes, virtual dispatch, RAII, and move ownership. Build a connected library desk.
C# and C++ side by side
The same program in C# and in C++, from the lessons of this course.
Strings and Output
C# strings are immutable UTF-16 reference objects; C++ std::string is a mutable byte container. C++ std::string owns a mutable byte sequence; stream insertion formats values. Length counts bytes, not Unicode characters.
C#1using System;2using System.Collections.Generic;3using System.Linq;4class Program {5 6static void Main() {7Console.WriteLine("oak".Length);8}9}C++1#include <iostream>2#include <string>3#include <vector>4#include <array>5#include <map>6#include <set>7#include <algorithm>8#include <memory>9#include <sstream>10#include <stdexcept>11#include <utility>12 13int main(){14std::string name="oak";std::cout<<name.size()<<"\n";15}Text Equality
C# string == compares text, but reference identity has separate APIs. C++ equality likewise depends on the operand type. C++ std::string equality compares contents. Raw pointer equality compares addresses; user classes need a deliberate equality operation.
C#1using System;2using System.Collections.Generic;3using System.Linq;4class Program {5 6 static void Main() {7 object a=3, b="3"; Console.WriteLine(a.Equals(b));8 }9}C++1#include <iostream>2#include <string>3#include <vector>4#include <array>5#include <map>6#include <set>7#include <algorithm>8#include <memory>9#include <sstream>10#include <stdexcept>11#include <utility>12 13int main(){14std::string a="red",b="red";std::cout<<std::boolalpha<<(a==b)<<"\n";15}Fixed-size Arrays
C# arrays are reference types, even when their elements are value types. C++ std::array is itself a value. C++ std::array<T,N> is a fixed-size value type. Its size is part of its type, and normal copy duplicates its elements.
C#1using System;2using System.Collections.Generic;3using System.Linq;4class Program {5 6static void Main() {7int[] a={4,5,6};Console.WriteLine(a.Length+" "+a[1]);8}9}C++1#include <iostream>2#include <string>3#include <vector>4#include <array>5#include <map>6#include <set>7#include <algorithm>8#include <memory>9#include <sstream>10#include <stdexcept>11#include <utility>12 13int main(){14std::array<int,3> a{4,5,6};std::cout<<a.size()<<" "<<a.at(1)<<"\n";15}Value Copies
C# structs copy as values while classes alias by reference. C++ classes normally copy as values unless their operations prohibit it. C++ vector and string copies own independent storage. Copying a raw pointer still shares the pointed-to object and does not…
C#1using System;2using System.Collections.Generic;3using System.Linq;4class Program {5 6 static void Main() {7 var a=new List<int>{1,2}; var b=new List<int>(a); b[0]=9; Console.WriteLine(a[0]);8 }9}C++1#include <iostream>2#include <string>3#include <vector>4#include <array>5#include <map>6#include <set>7#include <algorithm>8#include <memory>9#include <sstream>10#include <stdexcept>11#include <utility>12 13int main(){14std::vector<int> a{4};auto b=a;b.push_back(9);std::cout<<a.size()<<" "<<b.size()<<"\n";15}Functions and Returns
C# methods normally live in types; C++ free functions need no enclosing class. C++ function declarations establish parameter and return types. A return value is not automatically printed.
C#1using System;2using System.Collections.Generic;3using System.Linq;4class Program {5 static int Twice(int n) { return n*2; }6 static void Main() {7 Console.WriteLine(Twice(4));8 }9}C++1#include <iostream>2#include <string>3#include <vector>4#include <array>5#include <map>6#include <set>7#include <algorithm>8#include <memory>9#include <sstream>10#include <stdexcept>11#include <utility>12int triple(int n){return 3*n;}13int main(){14std::cout<<triple(4)<<"\n";15}Streams and Exact Parsing
C# TryParse reports conversion success explicitly. C++ streams expose state that callers must check after extraction. C++ stream extraction reports success through stream state. Validate conversion and reject unexpected trailing tokens when the contract…
C#1using System;2using System.Collections.Generic;3using System.Linq;4class Program {5 6static void Main() {7int n;bool ok=int.TryParse("7",out n);Console.WriteLine(ok+" "+n);8}9}C++1#include <iostream>2#include <string>3#include <vector>4#include <array>5#include <map>6#include <set>7#include <algorithm>8#include <memory>9#include <sstream>10#include <stdexcept>11#include <utility>12 13int main(){14std::istringstream in("oak 7");std::string word;int n;if(in>>word>>n)std::cout<<word<<"/"<<n<<"\n";15}
Syllabus
10 chapters48 lessons1 project48 challenges99 quiz questionsC++ Files and Values
6 lessonsConditions and Iteration
5 lessonsStandard Containers
5 lessonsCopies and Algorithms
5 lessonsFunctions and Templates
5 lessonsParsing and Lifetime
5 lessonsObjects and Invariants
6 lessonsComposition and Ownership
5 lessonsProject: Library Desk
4 lessonsFinal Challenges
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: C++ Files and Values, Conditions and Iteration, Standard Containers, Copies and Algorithms, 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.