[.NET] Use collection expressions

As of C# 12 we can now use collection expressions to reduce some boilerplate when initializing collections.
This commit is contained in:
Raul Santos
2024-12-21 03:26:14 +01:00
parent 6d5fd9acc8
commit cea78730d0
14 changed files with 69 additions and 65 deletions

View File

@@ -139,7 +139,11 @@ It will connect and fetch a website.
Debug.Assert(http.GetStatus() == HTTPClient.Status.Connected); // Check if the connection was made successfully.
// Some headers.
string[] headers = { "User-Agent: Pirulo/1.0 (Godot)", "Accept: */*" };
string[] headers =
[
"User-Agent: Pirulo/1.0 (Godot)",
"Accept: */*",
];
err = http.Request(HTTPClient.Method.Get, "/ChangeLog-5.php", headers); // Request a page from the site.
Debug.Assert(err == Error.Ok); // Make sure all is OK.

View File

@@ -127,7 +127,7 @@ But what if you need to send data to the server? Here is a common way of doing i
.. code-tab:: csharp
string json = Json.Stringify(dataToSend);
string[] headers = new string[] { "Content-Type: application/json" };
string[] headers = ["Content-Type: application/json"];
HttpRequest httpRequest = GetNode<HttpRequest>("HTTPRequest");
httpRequest.Request(url, headers, HttpClient.Method.Post, json);
@@ -147,7 +147,7 @@ For example, to set a custom user agent (the HTTP ``User-Agent`` header) you cou
.. code-tab:: csharp
HttpRequest httpRequest = GetNode<HttpRequest>("HTTPRequest");
httpRequest.Request("https://api.github.com/repos/godotengine/godot/releases/latest", new string[] { "User-Agent: YourCustomUserAgent" });
httpRequest.Request("https://api.github.com/repos/godotengine/godot/releases/latest", ["User-Agent: YourCustomUserAgent"]);
.. danger::