[英]What does the angle bracket syntax mean in C#
I am reading this book, and it tries to use initializer to Create the DB each time the application runs, so the code snippet is like this:我正在阅读这本书,它尝试在每次应用程序运行时使用初始化程序来创建数据库,因此代码片段是这样的:
protected void Application_Start() {
Database.SetInitializer(new DropCreateDatabaseAlways<MusicStoreDB>());
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
}
I can't understand this part:我无法理解这一部分:
new DropCreateDatabaseAlways<MusicStoreDB>()
What is this syntax?这是什么语法? what does
<MusicStoreDB>()
mean? <MusicStoreDB>()
是什么意思?
I know it's not a fancy question, but I need help here.我知道这不是一个花哨的问题,但我在这里需要帮助。
Thanks.谢谢。
That syntax is called generics .该语法称为泛型。 In a nutshell (a very tiny nutshell), imagine that your app had more than 1 database (eg MusicStoreDB, MovieStoreDB, etc), you could use the same DropCreateDatabaseAlways class with the different db types.
简而言之(非常小),假设您的应用程序有 1 个以上的数据库(例如 MusicStoreDB、MovieStoreDB 等),您可以使用具有不同 db 类型的相同 DropCreateDatabaseAlways 类。 In other words, generics let you define classes and functions that can act on many different types, for example
换句话说,泛型允许您定义可以作用于许多不同类型的类和函数,例如
List<int>, List<string>, List<MyAwesomeClass>
DropCreateDatabaseAlways is the database intializer base class. DropCreateDatabaseAlways 是数据库初始化器基类。 MusicStoreDB is the database which will be dropped and re-created everytime the application starts.
MusicStoreDB 是每次应用程序启动时都会删除并重新创建的数据库。
DropCreateDatabaseAlways<MusicStoreDB>()
is the code that does that DropCreateDatabaseAlways<MusicStoreDB>()
是执行此操作的代码
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.