1

I was going through a tutorial on ASP.NET Core 2.0 and made a fresh web app by using the following command: dotnet new web -o mywebapp. It created a directory containing a Startup.cs file containing the following code:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;

namespace mywebapp
{
    public class Program
    {
        public static void Main(string[] args)
        {
            BuildWebHost(args).Run();
        }

        public static IWebHost BuildWebHost(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .UseStartup<Startup>()
                .Build();
    }
}

I am having difficulty in understanding the syntax of the following lines:

public static IWebHost BuildWebHost(string[] args) =>
            WebHost.CreateDefaultBuilder(args)
                .UseStartup<Startup>()
                .Build();

Although I am aware of lambda expressions in C#, but I have never seen this kind of usage of them. Can anybody explain what those lines mean? Thanks!

  • 14
    "Weird fat arrow" guess i'am calling it this way from now on. – N.K May 04 '18 at 09:31
  • Just so OP is clear, it's not a single character, it's a `=` followed by a `>`! – DavidG May 04 '18 at 09:37
  • I've heard it referred to as "fish", "lambda operator", "goes to", and now "fat arrow". I think I like "fat arrow" best too. Is there an official name for this "operator"? – Bradley Uffner May 04 '18 at 10:17
  • 1
    @BradleyUffner in C# it can be named the lambda operator, and when used in expression bodied members I think that the convention is to call it the fat arrow. See https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/lambda-operator. – AndreasHassing May 04 '18 at 10:43

0 Answers0