Feature VB.NET C# Scala PHP Python Golang
Type Inference Dim x = 10 var x = 10 val x = 10 $x = 10; x = 10 x := 10
Generics New List(Of Integer) new List<int>() ListInt array() [] []int{}
Lambdas list.ForEach(Function(x) Console.WriteLine(x)) list.ForEach(x => Console.WriteLine(x)) list.foreach(x => println(x)) array_walk($list, function($x) { echo $x; }) [print(x) for x in list] for _, x := range list { fmt.Println(x) }
Pattern Matching Select Case x Case 1 : Console.WriteLine("one") Case 2 : Console.WriteLine("two") Case Else : Console.WriteLine("other") End Select x switch { 1 => "one", 2 => "two", _ => "other"} x match { case 1 => "one"; case 2 => "two"; case _ => "other" } switch ($x) { case 1: echo "one"; break; case 2: echo "two"; break; default: echo "other"; break; } if x == 1: print("one") elif x == 2: print("two") else: print("other") if x == 1 { fmt.Println("one") } else if x == 2 { fmt.Println("two") } else { fmt.Println("other") }
For Loop For i As Integer = 1 To 5 Console.WriteLine(i) Next for (int i = 1; i <= 5; i++) Console.WriteLine(i); for (i <- 1 to 5) println(i) for ($i = 1; $i <= 5; $i++): echo $i; endfor; for i in range(1, 6): print(i) for i := 1; i <= 5; i++ { fmt.Println(i) }
While Loop While x < 5 Console.WriteLine(x) x = x + 1 End While while (x < 5) { Console.WriteLine(x); x++; } while (x < 5) { println(x); x += 1 } while (x < 5) { echo x; x++; } while x < 5: print(x); x += 1 for x < 5 { fmt.Println(x); x++ }
Do-While Loop Do Console.WriteLine("loop") Loop While x > 0 do { Console.WriteLine("loop"); } while (x > 0); do { println("loop") } while (x > 0) do { echo "loop"; } while (x > 0); while True: print("loop"); if x <= 0: break for x > 0 { fmt.Println("loop") }
Lambdas Function(x As Integer) x + 1 x => x + 1 (x: Int) => x + 1 function($x) { return $x + 1; }; lambda x: x + 1 func(x int) int { return x + 1 }
Return Return 1 return 1; return 1 return 1; return 1 return 1
Traits N/A N/A trait Hello { def sayHello = println("Hello World!") } trait Hello { public function sayHello() { echo "Hello!"; } } N/A type Hello interface { SayHello() }
Inheritance Class Cat Inherits Animal class Cat : Animal { } class Cat extends Animal class Cat extends Animal { } class Cat(Animal): pass type Cat struct { Animal }
Interfaces Interface IShape Sub Draw() End Interface interface IShape { void Draw(); } trait IShape { def draw() } interface IShape { public function Draw(); } from abc import ABC, abstractmethod class IShape(ABC): @abstractmethod def Draw(): pass type IShape interface { Draw() }
Feature VB.NET C# Scala PHP Python Golang
If/Else If x > 0 Then Console.WriteLine("Positive") Else Console.WriteLine("Negative") End If if (x > 0) { Console.WriteLine("Positive"); } else { Console.WriteLine("Negative"); } if (x > 0) println("Positive") else println("Negative") if ($x > 0) { echo "Positive"; } else { echo "Negative"; } if x > 0: print("Positive") else: print("Negative") if x > 0 { fmt.Println("Positive") } else { fmt.Println("Negative") }
Event Handling AddHandler btn.Click, AddressOf ButtonClick btn.Click += ButtonClick; btn.onClick(() => {...}) $btn.on('click', function() {...}) btn.clicked.connect(buttonClick) btn.OnClick(func() {...})
Delegates Delegate Sub Del() Del d = AddressOf Method delegate void Del(); Del d = Method; type Del = () => Unit val d: Del = () => {...} $d = function() {...}; def delegate(): ... d = delegate type Del func() d := Method
Properties Property Name As String public string Name {get; set;} var name = ""; def name_= (value: String) = name = value; def name = name $name; public function getName() {...} public function setName($name) {...} @property def name(self): return self._name @name.setter def name(self, value): self._name = value type T struct { name string }
Virtual Methods Public Overrides Sub Draw() MyBase.Draw() Console.WriteLine("Cat") End Sub public override void Draw() { base.Draw(); Console.WriteLine("Cat"); } override def draw(): Unit = { super.draw() println("Cat") } public function draw() { parent::draw(); echo "Cat"; } def draw(self): super().draw() print("Cat") func (t *T) Draw() { t.Animal.Draw() fmt.Println("Cat") }
Custom Types Structure Point X As Integer Y As Integer End Structure struct Point { public int X; public int Y; } case class Point(x: Int, y: Int) class Point { public $x; public $y; } class Point: def init(self, x, y): self.x = x self.y = y type Point struct { X, Y int }
Imports Imports System.IO using System.IO; import scala.io._ require 'io_module.php'; import io_module import "io"
Edit
Pub: 10 Nov 2023 06:00 UTC
Edit: 10 Nov 2023 06:24 UTC
Views: 61