-1

What is the meaning of <> here:

WebHost.CreateDefaultBuilder(args)
  .UseStartup<Startup>()
  .Build()

Startup is a class but I have only come across <> in enumerable types like lists etc. Please can someone refer to the C# topic I need to look up as googling C# <> produces garbage.

James
  • 7,343
  • 9
  • 46
  • 82

1 Answers1

1

It is a C# generic. It means that any type can go there as needed, and the same operation will be done on the object. This is often used in C# collections, because the collections are just a way to store the data without caring for what's inside.

Another way to achieve the same effect is called boxing, which is when a type is cast to its base Object type. However, using items that are boxed requires casting them back into their original datatype, which can cause issues if an unexpected type shows up. On the other hand, creating a generic method with <T> ensures that the operation is performed on a certain type at runtime.

See https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/generics/ for more information.

Denis G. Labrecque
  • 1,023
  • 13
  • 29