C# equivalent of Java's double bracket initialization?

WBOY
Release: 2023-09-07 14:01:05
forward
857 people have browsed it

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");
}}
Copy after login

is the same as the collection initializer in C# -

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

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template