0

As the question indicates i've done a search and have found that it is related to generic type of a method declaration as we can found on the link:

In C#, What is <T> After a Method Declaration? ex: function<\T>(T a,T b)

And there i've seen that it is related to when we want to pass arguments on diferent types.

But on the following example it seems to have a specific type (this is from .NET) and no arguments:

public class Program  
{  
    public static void Main(string[] args)  
    {  
            var host = new WebHostBuilder()  
            .UseKestrel()  
            .UseContentRoot(Directory.GetCurrentDirectory())  
            .UseStartup<Startup>()  
            .Build();  
            host.Run();  
    }  
} 

We can see there .UseStartup() what is the reason of this?

Nmaster88
  • 1,405
  • 2
  • 23
  • 65
  • **[Why isn't anything passed to the .UseStartup() method in default webapi .Net Core application?](https://stackoverflow.com/questions/53841890/why-isnt-anything-passed-to-the-usestartupstartup-method-in-default-webapi)** – Ňɏssa Pøngjǣrdenlarp Nov 23 '19 at 18:45
  • The syntax basically passes a type (as opposed to a value) to a generic method. Your linked post talks about how a generic method is declared. And what you are seeing now is how to call it. Actually the linked post also shows how to call it, how did it not answer your question? – Sweeper Nov 23 '19 at 19:11

1 Answers1

2

There are 2 overloads of UseStartup, one that takes a generic type argument, which is the example you have shown, and a non-generic one that takes a Type argument as a regular parameter.

In the version you have shown <Startup> is the generic argument, this is the syntax for passing a type at compile time as a special argument to a method.

The non-generic overload like this:

/// ...
.UseStartup(typeof(Startup))
// ...

This overload allows you to decide at runtime what Type to use, whereas the common use case will be to pass a known one at compile time with the generic version.

Stuart
  • 5,358
  • 19
  • 28