HexLibraryHexLibrary
</> HexCodeSign inSign up
PythonJavaScriptTypeScriptCC++JavaPHPGoRustRubyBashSQLLuaPerlCOBOLPascalDelphiFortranDartSwiftC#JuliaGroovyRElixirHaskellKotlinScalaClassic ASPClipperMS-DOS
LESSONS
Introduction to C#VariablesData TypesOperatorsStringsListsConditions (if / else)Loops (for / while)Functions
REFERENCE
📖 Overview
🖥️ Output
📦 Variables & Types
🔢 Numbers & Math
✍️ String
📚 List & Dictionary
🔀 Condition & Loop
🧩 Function
Local functionArrow function ( => )
C#›REFERENCE›Function
🧩

Function

Local functions, return, and the arrow (=>).

CommandDescription
Local functionDefines your own command.
Arrow function ( => )Short single-expression functions.

Local function

Try it yourself →

Defines your own command.

Syntax

ReturnType Name(params) { return ...; }

Description

Defined with a return type (void = none), name, and parameters. return gives the result back. Local functions can be defined directly in top-level programs.

Example

using System;
int Square(int x) {
  return x * x;
}
Console.WriteLine(Square(5));

Expected output

25

When to use?

Preventing code repetition, breaking the program into parts.

Arrow function ( => )

Try it yourself →

Short single-expression functions.

Syntax

ReturnType Name(params) => expression;

Description

Functions whose body is a single expression are written in a single line using =>. Does the same thing as { return expression; } — more readable.

Example

using System;
int addUp(int a, int b) => a + b;
string greet(string name) => $"Hello {name}";
Console.WriteLine(addUp(8, 9));
Console.WriteLine(greet("C#"));

Expected output

17
Hello C#

When to use?

Short helper functions, LINQ expressions.

HexLibraryHexLibrary

Learn programming more clearly. Every command is explained line by line with colors, reinforced with runnable exercises, test your code instantly — all in one place, free.

Learn

  • Home
  • Languages & Lessons
  • HexCode

Company

  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

Other Projects

  • HexToolz
  • Free Service Manuals
© 2026 HexLibrary · The clearest way to learn code