mirror of
https://github.com/godotengine/godot-docs.git
synced 2026-01-05 22:09:56 +03:00
[.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:
@@ -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.
|
||||
|
||||
@@ -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::
|
||||
|
||||
|
||||
Reference in New Issue
Block a user