Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up
New features added to C# 5.0

New features added to C# 5.0

Beginner 8 min read 19 Sep 2025 156K views
New features added to C# 5.0

C# 5.0: An Overview

We know the new features of C# 3.0 and 4.0. We now have C# 6.0, but we’ll regress to tour C# 5.0’s new features since a lot of our programmer wants to know more about C# 5.0.C #'s most recent version 5.0 was released on August 15, 2012, with .NET Framework 4.5 and Visual Studio 2012.

In this C# Tutorial, we will explore more about features of C# 5.0. To dive deeper into these features and enhance your programming skills, you can enroll in a C Sharp Course Free and start learning today! The top two features added in the C# 5.0 version are as follows: 

  • Async Programming 
  • Caller Information. 

C# 5.0 feature,C# version evolution

Let's understand both of these features in detail as given below.

Async Feature (Asynchronous Methods)

C# 5.0 The Async feature introduces two keywords async and await which allows you to write asynchronous code more easily and intuitively than synchronous code. Before C# 5.0, for writing an asynchronous code, you need to define callbacks (also known as continuations) to capture what happens after an asynchronous process finishes. This makes your code and other routine task such as exception handling complicated.

Both keywords are used in combination with each other. Hence, an await operator is applied to one or more than one expression of an async method. An async method returns a Task or Task<TResult> that represents the ongoing work of the method. The task contains information that the caller of the asynchronous method can use, such as the status of the task, its unique ID, and the method's result. Let's elaborate on this in the C# compiler.

Example:

public async Task<IEnumerable<Product>> GetProductList()
{
 HttpClient client = new HttpClient();
 Uri address = new Uri("http://scholarhat.com/");
 client.BaseAddress = address;

 HttpResponseMessage response = await client.GetAsync("myservice/product/ProductList");

 if (response.IsSuccessStatusCode)
 {
 var list = await response.Content.ReadAsAsync<IEnumerable<Product>>();
 return list;
 }
 else
 {
 return null;
 }
}
 

Read More - C# Interview Questions For Freshers

Caller Information (Caller info attributes)

Caller Information can help you in tracing, debugging, and creating diagnosis tools. It will help you to avoid duplicate codes which are generally invoked in many methods for the same purpose, such as logging and tracing. You could get the following information on the caller method.

1.CallerFilePathAttribute

The full path of the source file that contains the caller. This is the file path at compile time.

2.CallerLineNumberAttribute

Line number in the source file at which the method is called.

3.CallerMemberNameAttribute

Method or property name of the caller.

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Example
{
 static void Main(string[] args)
 {
 Console.WriteLine("Main method Start");
 InsertLog("Main");
 MyMethodB();
 MyMethodA();
 Console.WriteLine("Main method End!");
 Console.ReadLine(); // hold on result
 }

 static void MyMethodA()
 {
 InsertLog("MyMethodA");
 MyMethodB();
 }

 static void MyMethodB()
 {
 // some code here. 
 }

 static void InsertLog(string method)
 {
 Console.WriteLine("{0} called MyMethodB at {1}", method,
 DateTime.Now);
 }
}
  

Output:

 
 Main method Start
 Main called MyMethodB at 11/17/2013 11:12:24 PM
 MyMethodA called MyMethodB at 11/17/2013 11:12:24 PM
 Main method End!
 

In both Main and MyMethodA, the method InsertLog is invoked for logging. Now we can change the above code as follows.

 
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

class Example
{
 static void Main(string[] args)
 {
 Console.WriteLine("Main method Start");
 MyMethodB();
 MyMethodA();
 Console.WriteLine("Main method End!");
 Console.ReadLine();
 }

 static void MyMethodA()
 {
 MyMethodB();
 }

 static void MyMethodB([CallerMemberName] string memberName = "", [CallerFilePath] string sourceFilePath = "", [CallerLineNumber] int sourceLineNumber = 0)
 {
 InsertLog(memberName);
 }

 static void InsertLog(string method)
 {
 Console.WriteLine("{0} called MyMethodB at {1}", method, DateTime.Now);
 }
}
 

Output:

 
 Main method Start
 Main called MyMethodB at 11/17/2013 10:30:11 PM
 MyMethodA called MyMethodB at 11/17/2013 10:30:11 PM
 Main method End!

Read More - C# Roadmap For Beginners

Conclusion:

I hope you will enjoy these new features of C# 5.0 while programming. C# 5.0 was a major milestone in the evolution of the language, introducing features that significantly improved asynchronous programming and caller information tracking.

Over 10,000 companies seek certified .NET full stack developers in India. Start your journey with our full stack .NET developer course and seize top opportunities!

Test yourself in 5 minutes

Take the free Csharp skill challenge to see your strengths and the gaps to fix next.

Start the challenge
Share LinkedIn X Facebook WhatsApp

About the author

Shailendra Chauhan

Shailendra Chauhan

Microsoft MVP, Founder & CEO at ScholarHat

He is a renowned Speaker, Solution Architect, Mentor, and 11-time Microsoft MVP (2016–2026). With expertise in AI/ML, GenAI, System Design, Azure Cloud, .NET, Angular, React, Node.js, Microservices, DevOps, and Cross-Platform Mobile App Development, he bridges traditional frameworks with next-gen innovations.

He has trained 1 Lakh+ professionals across the globe, authored 45+ bestselling eBooks and 1000+ technical articles, and mentored 20+ free courses. As a corporate trainer for leading MNCs like IBM, Cognizant, and Dell, Shailendra continues to deliver world-class learning experiences through technology & AI.

Keep learning

Courses that go with this tutorial