diff --git a/index.html b/index.html index 255fdba..3860fd2 100644 --- a/index.html +++ b/index.html @@ -98,7 +98,7 @@ font-weight: 300; letter-spacing: 0.05em; } -
Kotlin is like C#
Compare the syntax of Kotlin vs C#. Don't take language likeness comparison too seriously.
Fixes, improvents and additions are welcome. Open an issue or a pull request.
BASICS
Hello World
Kotlin
println("Hello, world!")
+
Kotlin is like C#
Compare the syntax of Kotlin vs C#. Don't take language likeness comparison too seriously.
Fixes, improvements and additions are welcome. Open an issue or a pull request.
BASICS
Hello World
Kotlin
println("Hello, world!")
 
C#
public void Main() 
 {
     Console.WriteLine("Hello, world!");
@@ -339,7 +339,7 @@
 // Person is called Jack
Range Operator
Kotlin
val names = arrayOf("Anna", "Alex", "Brian", "Jack")
 val count = names.count()
 
-for (i in 0..
Collection Range and Index
Kotlin
val names = arrayOf("Anna", "Alex", "Brian", "Jill", "Jack")
 val count = names.count()
 
-for (name in names.slice(1.. 3 * e);
 // [ 60, 57, 21, 36 ]
Sort
Kotlin
val ordered = listOf(1, 5, 3, 12, 2).sorted()
 // [ 1, 2, 3, 5, 12 ]
C#
var ordered = new[] { 1, 5, 3, 12, 2 }.OrderBy(i => i);
-// [ 1, 2, 3, 5, 12 ]
Filter / GroupBy / Average
Kotlin
val datas = listOf(
+// [ 1, 2, 3, 5, 12 ]
Filter / GroupBy / Average
Kotlin
val data = listOf(
     SensorData(1, "A", 2.89),
     SensorData(2, "B", 12.01),
     SensorData(3, "B", 11.89),
@@ -406,13 +406,13 @@
     SensorData(5, "A", -456.0)
 )
 
-val avgs = datas
+val avgs = data
     .filter { it.value > -50.0 }
     .groupBy(SensorData::location)
     .map { Location(it.key, it.value.map(SensorData::value).average()) }
 
 // (location=A, value=3.0)
-// (location=B, value=11.95)
C#
var datas = new List<SensorData> 
+// (location=B, value=11.95)
C#
var data = new List<SensorData> 
 {
     new SensorData { Id = 1, Location = "A", Value = 2.89 },
     new SensorData { Id = 2, Location = "B", Value = 12.01 },
@@ -421,7 +421,7 @@
     new SensorData { Id = 5, Location = "A", Value = -456.0 }
 };
 
-var avgs = datas
+var avgs = data
             .Where(e => e.Value > -50.0)
             .GroupBy(e => e.Location)
             .Select(g => new { 
@@ -746,10 +746,10 @@
 var nb = 42;
 var text = nb switch
 {
-    int i when i < 10 => "single digit",
+    int i when i < 10 => "single digit",
     10 => "double digits",
-    int i when i < 100 => "double digits",
-    int i when i < 1000 => "triple digits",
+    int i when i < 100 => "double digits",
+    int i when i < 1000 => "triple digits",
     _ => "four or more digits"
 };
 
@@ -757,9 +757,9 @@
 var nb = 42;
 var text = nb switch
 {
-    < 10 => "single digit",
-    10 or (>= 11 and < 100) => "double digits",
-    < 1000 => "triple digits",
+    < 10 => "single digit",
+    10 or (>= 11 and < 100) => "double digits",
+    < 1000 => "triple digits",
     _ => "for or more digits",
 };
 // double digits
Is Expression / When Clause / Property Pattern
Kotlin
// Not supported yet
@@ -767,7 +767,7 @@
 // http://openjdk.java.net/jeps/305
C#
var result = item switch
 {
     Square s => Handle(s),
-    Circle { Radius: < 10 } c => HandleUnder10(c),
+    Circle { Radius: < 10 } c => HandleUnder10(c),
     Circle { Radius: 20 } c => Handle20(c),
     Circle c => Handle(c),
     _ => throw new Exception("Unknown shape")
@@ -776,7 +776,7 @@
 // Same with if statements
 if (item is Square s)
 { }
-else if (item is Circle { Radius: < 10 })
+else if (item is Circle { Radius: < 10 })
 { }
 else if (item is Circle { Radius: 20 })
 { }