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

【范围运算符】输出结果有误 & 内容重复 #32

Open
F-park opened this issue Oct 15, 2023 · 0 comments
Open

【范围运算符】输出结果有误 & 内容重复 #32

F-park opened this issue Oct 15, 2023 · 0 comments

Comments

@F-park
Copy link

F-park commented Oct 15, 2023

输出结果有误

在小标题选取从结尾位置开始的一段范围中,文档代码如下

int[] numbers = new[] { 0, 10, 20, 30, 40, 50 };
int amountToTakeFromEnd = 3;
int[] subset = numbers[^amountToTakeFromEnd..];
Display(subset);  // output: 20 30 40

output 的结果应为 30 40 50

内容重复

我发现选取从结尾位置开始的一段范围省略右操作数基本一致,不知道是否为有意为之。文档代码如下

int[] numbers = new[] { 0, 10, 20, 30, 40, 50 };
int[] subset = numbers[^3..];
Display(subset);  // output: 30 40 50

其他的一些小建议

选取数组中的范围中的四组代码通过只使用一次的变量来使用范围运算符,感觉降低了可读性

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant