Home  >  Article  >  Backend Development  >  C# equivalent of Java's double bracket initialization?

C# equivalent of Java's double bracket initialization?

WBOY
WBOYforward
2023-09-07 14:01:05860browse

C# 相当于 Java 的双括号初始化?

Double bracket initialization in Java does the same job as single bracket initialization in C#.

Double brackets create and initialize objects in a single Java expression.

Let us say the following is in Java -

Example

List<String> list = new List<String>() {{
   add("One");
   add("Two");
   add("Three");
   add("Four");
}}

is the same as the collection initializer in C# -

List<String> list = new List<String>() {"One","Two", &ldquo;Three&rdquo;, &ldquo;Four&rdquo;};

The above is the detailed content of C# equivalent of Java's double bracket initialization?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete