Here is an updated table with a Golang column added:

Feature C# VB.NET Python PHP Golang
Type Inference var x = 10 Dim x = 10 x = 10 $x = 10; x := 10
Generics new List<int>() New List(Of Integer) [] array() []int{}
Lambdas list.ForEach(x => Console.WriteLine(x)) list.ForEach(Function(x) Console.WriteLine(x)) [print(x) for x in list] array_walk($list, function($x) { echo $x; }) for _, x := range list { fmt.Println(x) }
Pattern Matching x switch { 1 => "one", 2 => "two", _ => "other"} Select Case x Case 1 : Console.WriteLine("one") Case 2 : Console.WriteLine("two") Case Else : Console.WriteLine("other") End Select if x == 1: print("one") elif x == 2: print("two") else: print("other") switch ($x) { case 1: echo "one"; break; case 2: echo "two"; break; default: echo "other"; break; } if x == 1 { fmt.Println("one") } else if x == 2 { fmt.Println("two") } else { fmt.Println("other") }
For Loop for (int i = 1; i <= 5; i++) Console.WriteLine(i); For i As Integer = 1 To 5 Console.WriteLine(i) Next for i in range(1, 6): print(i) for ($i = 1; $i <= 5; $i++): echo $i; endfor; for i := 1; i <= 5; i++ { fmt.Println(i) }
While Loop while (x < 5) { Console.WriteLine(x); x++; } While x < 5 Console.WriteLine(x) x = x + 1 End While while x < 5: print(x); x += 1 while (x < 5) { echo x; x++; } for x < 5 { fmt.Println(x); x++ }
Do-While Loop do { Console.WriteLine("loop"); } while (x > 0); Do Console.WriteLine("loop") Loop While x > 0 while True: print("loop"); if x <= 0: break do { echo "loop"; } while (x > 0); for x > 0 { fmt.Println("loop") }
Lambdas x => x + 1 Function(x As Integer) x + 1 lambda x: x + 1 function($x) { return $x + 1; }; func(x int) int { return x + 1 }
Return return 1; Return 1 return 1 return 1; return 1
Traits N/A N/A N/A trait Hello { public function sayHello() { echo "Hello!"; } } type Hello interface { SayHello() }
Inheritance class Cat : Animal { } Class Cat Inherits Animal class Cat(Animal): pass class Cat extends Animal { } type Cat struct { Animal }
Interfaces interface IShape { void Draw(); } Interface IShape Sub Draw() End Interface from abc import ABC, abstractmethod class IShape(ABC): @abstractmethod def Draw(): pass interface IShape { public function Draw(); } type IShape interface { Draw() }

Let me know if you would like me to add or change anything in the table.

Edit
Pub: 10 Nov 2023 05:49 UTC
Views: 20