← Back to C# Course | Chapter 15: Modern C# Features | Lesson 6 of 6

Expression-Bodied Members

Expression-Bodied Members

Expression-bodied members let you write a method, property, or constructor whose entire body is a single expression using => instead of a full { } block with a return. This is purely a syntactic shortcut for one-line members and doesn't change behavior. It's widely used for simple properties and small computed methods.

Note: Expression-bodied syntax works for methods, read-only properties, and even constructors and finalizers — not just fields.

Example: Expression-Bodied Members

markup
using System;

class Circle
{
    public double Radius;

    public Circle(double radius) => Radius = radius;

    public double Area => Math.PI * Radius * Radius;

    public double Diameter() => Radius * 2;
}

class Program
{
    static void Main(string[] args)
    {
        Circle c = new Circle(4);
        Console.WriteLine(c.Area);
        Console.WriteLine(c.Diameter());
    }
}
🔒

Chapter Quiz — Complete all 6 topics to unlock

0/6 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.