C# Basics

Methods, Parameters, and Tuples

Define reusable methods with named results and multiple return values.

Introduction

Methods group behavior behind a clear contract. Tuples are convenient for returning a small set of related values.

Named tuple elements make the returned values self-documenting without requiring a dedicated class.

Runnable C# example

C#
Run code →
Program.cs
using System;
using System.Linq;

class Program
{
    static (int Min, int Max) Range(int[] values)
        => (values.Min(), values.Max());

    static void Main()
    {
        var range = Range(new[] { 8, 3, 14, 5 });
        Console.WriteLine($"{range.Min}..{range.Max}");
    }
}
Result of running the code
3..14

Practice with the debugger

Set a breakpoint on an important assignment or condition, click Debug, and inspect the local values before stepping to the next line.

Practice with a challenge

Use what this lesson covers to solve a real problem. Each challenge runs in your browser with instant tests and an AI review.

All challenges