Skip to main content
CSharpUniversity ASP.NET and C# lessons

The search runs entirely in your browser over the published lesson list.

New language features in C# 4.0

Language releases tend to add features that remove small daily annoyances. The C# 4.0 era added several worth knowing.

Named and optional arguments

You can skip an argument that has a default and name the ones you do pass, which makes a call with many parameters readable.

C#
public void Send(string to, string subject = "Hello",
    bool urgent = false) { }

Send("[email protected]", urgent: true);

Dynamic typing

A dynamic variable defers type checking until the program runs, which is useful when talking to a system that does not describe itself in advance. It trades compile time safety for flexibility, so use it sparingly.

Learn the reason, not the trick. Each feature exists to solve a specific problem. Named arguments solve unclear calls. Dynamic typing solves late bound interfaces. Knowing the problem tells you when to reach for the feature.

These features build on the fundamentals in building your own types, so learn those first if you have not already.

New lessons by email

Leave your address and get a short note whenever a fresh lesson is published. No account needed and you can stop at any time.

Thank you. Your address has been noted in this browser session. Connect a mailing service to deliver the notes for real.