Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syntax Error in array parenthesis in C# official doc #41000

Closed
luthentic opened this issue May 18, 2024 · 4 comments · Fixed by #41026
Closed

Syntax Error in array parenthesis in C# official doc #41000

luthentic opened this issue May 18, 2024 · 4 comments · Fixed by #41026
Assignees
Labels
doc-bug Problem with the content; needs to be fixed [org][type][category] okr-health Content-health KR: Concerns article defects/freshness or build warnings. Pri3 📌 seQUESTered Identifies that an issue has been imported into Quest.

Comments

@luthentic
Copy link

luthentic commented May 18, 2024

Describe the issue or suggestion

https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/builtin-types/value-tuples#code-try-3

there are syntax errors on the declaration

must be corrected int[] xs = {4,7,9};
int[] ys = {-9, 0, 67, 100};

int[] xs = [4, 7, 9];
var limits = FindMinMax(xs);
Console.WriteLine($"Limits of [{string.Join(" ", xs)}] are {limits.min} and {limits.max}");
// Output:
// Limits of [4 7 9] are 4 and 9

int[] ys = [-9, 0, 67, 100];
var (minimum, maximum) = FindMinMax(ys);
Console.WriteLine($"Limits of [{string.Join(" ", ys)}] are {minimum} and {maximum}");
// Output:
// Limits of [-9 0 67 100] are -9 and 100

(int min, int max) FindMinMax(int[] input)
{
if (input is null || input.Length == 0)
{
throw new ArgumentException("Cannot find minimum and maximum of a null or empty array.");
}

// Initialize min to MaxValue so every value in the input
// is less than this initial value.
var min = int.MaxValue;
// Initialize max to MinValue so every value in the input
// is greater than this initial value.
var max = int.MinValue;
foreach (var i in input)
{
    if (i < min)
    {
        min = i;
    }
    if (i > max)
    {
        max = i;
    }
}
return (min, max);

}


Associated WorkItem - 256835

@dotnet-bot dotnet-bot added the ⌚ Not Triaged Not triaged label May 18, 2024
@rextor92
Copy link
Contributor

Hey, check this article on arrays and its note on collection expressions.

It is valid code, but it requires C# 12 and it seems sample runner doesn't support that. You will be able to run the code locally with .NET 8.

BillWagner added a commit that referenced this issue May 21, 2024
Fixes #41000

This one sample uses an array, and is run in the try.net syntax.
@BillWagner BillWagner self-assigned this May 21, 2024
@BillWagner BillWagner added doc-bug Problem with the content; needs to be fixed [org][type][category] 🗺️ reQUEST Triggers an issue to be imported into Quest. labels May 21, 2024
@dotnet-bot dotnet-bot removed the ⌚ Not Triaged Not triaged label May 21, 2024
@BillWagner
Copy link
Member

I did open a PR to fix this so that it runs in the online sandbox.

Note: I'll make a set of updates once the service is updated with the C# 12 bits.

@dotnet-policy-service dotnet-policy-service bot added the okr-health Content-health KR: Concerns article defects/freshness or build warnings. label May 21, 2024
@luthentic
Copy link
Author

luthentic commented May 21, 2024 via email

@luthentic
Copy link
Author

luthentic commented May 21, 2024 via email

@sequestor sequestor bot added 📌 seQUESTered Identifies that an issue has been imported into Quest. and removed 🗺️ reQUEST Triggers an issue to be imported into Quest. labels May 22, 2024
BillWagner added a commit that referenced this issue May 28, 2024
Fixes #41000

This one sample uses an array, and is run in the try.net syntax.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
doc-bug Problem with the content; needs to be fixed [org][type][category] okr-health Content-health KR: Concerns article defects/freshness or build warnings. Pri3 📌 seQUESTered Identifies that an issue has been imported into Quest.
Projects
No open projects
Status: ✅ Done
Development

Successfully merging a pull request may close this issue.

4 participants