F
F
Funnix2020-11-20 10:19:48
C++ / C#
Funnix, 2020-11-20 10:19:48

How to read this line?

public static void Main(string[] args)
        {
            CreateHostBuilder(args).Build().Run();
        }

        public static IHostBuilder CreateHostBuilder(string[] args) =>
            Host.CreateDefaultBuilder(args)
                .ConfigureWebHostDefaults(webBuilder =>
                {
                    webBuilder.UseStartup<Startup>();
                });

I am interested in this line: CreateHostBuilder(args).Build().Run();
Greetings, please explain how this line is read? I'm in the process of learning the basics of C#, so I still don't understand a lot of things. In this line, for example, CreateHostBuilder () is a class, then the Run () method is triggered, which is an internal Build () method, or what? Or is it not methods at all? This is from an empty Web App project in ASP.NET in Visual Studio.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vasily Bannikov, 2020-11-20
@Nbqz

CreateHostBuilder()- this is the method that is declared below, it returns IHostBuilder
Build() - this is the IHostBuilder method , it returns the assembled IHost
Run() - this is an extension method on IHost
My personal advice: first learn the basics of the language, and then start aspnet, otherwise you will stupid questions will arise at every step.
Also pay attention to refactoring.guru

V
Vladimir S, 2020-11-20
@hePPer

read like this:

var a=CreateHostBuilder(args);
var b=a.Build();
b.Run();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question