Skip to content

Latest commit

 

History

History
119 lines (88 loc) · 1.64 KB

README.md

File metadata and controls

119 lines (88 loc) · 1.64 KB

well-hello-kotlin

A project I'm using to start learning about Kotlin.

In the beginning, I plan on solving simple Kotlin exercises found on Exercism and Kotlin Koans.

I am coming from C#, and aim to populate my Kotlin from C# cheat sheet below as I advance through the exercises.

Kotlin from C# – Cheat sheet

Function/Method

Signature structure

Kotlin
fun functionName(inputName: InputType): ReturnType {
  ...
}
C#
ReturnType MethodName(InputType inputName)
{
  ...
}

Example

Kotlin
fun equalsOne(number: Int): Boolean {
  return number == 1
}
C#
bool EqualsOne(int number)
{
  return number == 1;
}

When a function/method does not return anything, ReturnType is omitted in Kotlin:

Kotlin
fun doNothing() { }
C#
void DoNothing() { }

Default arguments / Optional arguments

Default arguments in Kotlin correspond to optional arguments in C#. They are provided in the exact same way.

Kotlin
fun equalsOne(number: Int = 1): Boolean {
  return number == 1
}
C#
bool EqualsOne(int number = 1)
{
  return number == 1;
}

Named arguments

Named arguments exist in both Kotlin and C#.

Kotlin
equalsOne(number = 0)
C#
EqualsOne(number: 0)