Menu
CoddyTech
Course

Go for C# Developers

Transfer your C# experience to Go: typed values, control flow, slices, functions, methods, interfaces and error handling. Build a tested multi-file order pipeline.

C# and Go side by side

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

  1. Files and the first run

    C# programs may use a class Main method or newer top-level statements. These Go tasks use func main in a flat package main. Go imports packages per file and has no using directive shared across source files.

    C#
    1using System;2using System.Collections.Generic;3using System.Linq;4
    5class Program { static void Main() {6Console.WriteLine("C# 3");7} }
    Go
    1package main2import ("fmt")3
    4func main(){fmt.Println("Go", 3)}
  2. If and scoped names

    C# supports conditional flow and pattern-bound locals. Go has an explicit if initializer whose variable is scoped to the if and else branches. Go always requires braces and does not use C# pattern syntax.

    C#
    1using System;2using System.Collections.Generic;3using System.Linq;4
    5class Program { static void Main() {6int n="go".Length; if(n>1){Console.WriteLine("long");}else{Console.WriteLine("short");}7} }
    Go
    1package main2import ("fmt")3
    4func main(){if n := len("go"); n > 1 { fmt.Println("long") } else { fmt.Println("short") }}
  3. Arrays are values

    C# arrays are reference types despite their fixed length, so Clone is needed for new outer storage. Go arrays are value types and include length in the type. Go slices, unlike arrays, share backing storage when assigned.

    C#
    1using System;2using System.Collections.Generic;3using System.Linq;4
    5class Program { static void Main() {6int[] a={3,5};int[] b=(int[])a.Clone();b[0]=9;Console.WriteLine(a[0]+" "+b[0]);7} }
    Go
    1package main2import ("fmt")3
    4func main(){a:=[2]int{3,5}5b:=a6b[0]=97fmt.Println(a[0],b[0])}
  4. Typed function contracts

    C# methods may overload and use optional or named arguments. Go functions have one signature and no optional arguments. Go passes values, including descriptors and pointers; explicit pointers provide intentional mutation.

    C#
    1using System;2using System.Collections.Generic;3using System.Linq;4static class Helpers{public static bool IsEven(int n){return n%2==0;}}5class Program { static void Main() {6Console.WriteLine(Helpers.IsEven(6));7} }
    Go
    1package main2import ("fmt")3func IsEven(n int) bool { return n%2==0 }4func main(){fmt.Println(IsEven(6))}
  5. Struct values

    C# structs and Go structs both copy fields on assignment. Go does not also offer a separate class declaration: pointer-to-struct usage provides shared identity. Slices, maps and pointers inside a struct can still share referenced storage.

    C#
    1using System;2using System.Collections.Generic;3using System.Linq;4struct Label{public string Text;}5class Program { static void Main() {6Label a=new Label{Text="old"};Label b=a;b.Text="new";Console.WriteLine(a.Text+" "+b.Text);7} }
    Go
    1package main2import ("fmt")3type Label struct { Text string }4func main(){a:=Label{Text:"old"}5b:=a6b.Text="new"7fmt.Println(a.Text,b.Text)}
  6. Errors are returned values

    C# exceptions propagate until caught, while Go normally returns errors as ordinary values. The error interface reports failure text, and callers explicitly branch or propagate. panic/recover is reserved for exceptional failures, not ordinary validation.

    C#
    1using System;2using System.Collections.Generic;3using System.Linq;4static class Helpers{public static int Positive(int n){if(n<=0)throw new ArgumentException("not positive");return n;}}5class Program { static void Main() {6try{Helpers.Positive(-2);}catch(ArgumentException){Console.WriteLine("rejected");}7} }
    Go
    1package main2import ("fmt";"errors")3func Positive(n int)(int,error) { if n<=0{return 0,errors.New("not positive")};return n,nil }4func main(){_,e:=Positive(-2)5fmt.Println(e!=nil)}

Syllabus

9 chapters48 lessons1 project48 challenges99 quiz questions

More courses for C# developers

Learn Go from another language

Frequently asked questions

Who is Go for C# Developers for?

For people who already write C# and want to learn Go. Each lesson starts from C# you know and shows how Go does the same thing, so you skip the beginner basics.

Do I need to know Go already?

No. The course starts with your first Go program. You need C# basics: variables, conditions, loops, functions and collections.

How many lessons does Go for C# Developers have?

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

What does Go for C# Developers cover?

The course is organized into chapters covering: Values and expressions, Control flow, Collections, Functions and pointers, and more.

Is Go 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 Go for C# Developers for free

Get started