C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,656 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I started evaluating .NET 5 in doing some lessons in the learn tutorials.
The Tutorial added this code to the file Program.cs
I didn't find any hint, why there is no need for an entry point main.
Is this a short form?
I am happy for every hint.
using ContosoPets.Api;
using ContosoPets.Api.Data;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
CreateHostBuilder(args).Build().SeedDatabase().Run();
static IHostBuilder CreateHostBuilder(string[] args) =>
Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder => webBuilder.UseStartup<Startup>());
static class IHostExtensions
{
public static IHost SeedDatabase(this IHost host)
{
var scopeFactory = host.Services.GetRequiredService<IServiceScopeFactory>();
using var scope = scopeFactory.CreateScope();
var context = scope.ServiceProvider.GetRequiredService<ContosoPetsContext>();
if (context.Database.EnsureCreated())
SeedData.Initialize(context);
return host;
}
}
Thanks
Charly
Hello @CharlyArtmann-6633
This is C# 9, Top-Level feature, see the following.
using System;
class Program
{
static void Main()
{
Console.WriteLine("Hello World!");
}
}
using System;
Console.WriteLine("Hello World!");