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

Clarify behavior of OfType() with null values #7375

Merged
merged 4 commits into from
Jun 5, 2024

Conversation

matthiaslischka
Copy link
Contributor

OfType<T> does not take all elements that can be cast. It skips null.
And consequently the hint that Cast<T> would instead throw is a bit misleading too.

new List<string> {"Mango", null, "Orange"}.OfType<string>();
// --> ["Mango", "Orange"]
	
new List<string> {"Mango", null, "Orange"}.Cast<string>();
// --> ["Mango", null, "Orange"]

BR Matthias

@opbld33
Copy link

opbld33 commented Nov 10, 2021

Docs Build status updates of commit 0ce71d4:

✅ Validation status: passed

File Status Preview URL Details
samples/snippets/csharp/VS_Snippets_CLR_System/system.Linq.Enumerable/CS/enumerable.cs ✅Succeeded View
samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Linq.Enumerable/VB/Enumerable.vb ✅Succeeded View
xml/System.Linq/Enumerable.xml ✅Succeeded View

For more details, please refer to the build report.

Note: Broken links written as relative paths are included in the above build report. For broken links written as absolute paths or external URLs, see the broken link report.

For any questions, please:

@BillWagner
Copy link
Member

ping @KathleenDollard

@matthiaslischka
Copy link
Contributor Author

Any updates on that? Not sure what's up with the Snippets 5000 check - not related to the change.

@BillWagner
Copy link
Member

closing and reopening for a fresh build (I Think the out-of-support versions have been addressed)

@BillWagner BillWagner closed this Dec 10, 2021
@BillWagner BillWagner reopened this Dec 10, 2021
@BillWagner
Copy link
Member

Hi @matthiaslischka

I looked everything over. I'll approve the changes once we have a clean build.

The issue with the snippets build is that it's using netcoreapp2.2, which is out of support. Can you update that to net6.0? These samples would still compile, and then I'll merge it.

@opbld31
Copy link

opbld31 commented Dec 10, 2021

Docs Build status updates of commit 0ce71d4:

✅ Validation status: passed

File Status Preview URL Details
samples/snippets/csharp/VS_Snippets_CLR_System/system.Linq.Enumerable/CS/enumerable.cs ✅Succeeded View
samples/snippets/visualbasic/VS_Snippets_CLR_System/system.Linq.Enumerable/VB/Enumerable.vb ✅Succeeded View
xml/System.Linq/Enumerable.xml ✅Succeeded View

For more details, please refer to the build report.

Note: Broken links written as relative paths are included in the above build report. For broken links written as absolute paths or external URLs, see the broken link report.

For any questions, please:

@gewarren gewarren enabled auto-merge (squash) June 5, 2024 19:24
Copy link

Learn Build status updates of commit 3e70262:

✅ Validation status: passed

File Status Preview URL Details
snippets/csharp/System.Linq/Enumerable/AggregateTSource/enumerable.cs ✅Succeeded View
snippets/csharp/System.Linq/Enumerable/AggregateTSource/Enumerable.csproj ✅Succeeded
snippets/visualbasic/VS_Snippets_CLR_System/system.Linq.Enumerable/VB/Enumerable.vb ✅Succeeded View
snippets/visualbasic/VS_Snippets_CLR_System/system.Linq.Enumerable/VB/Enumerable.vbproj ✅Succeeded
xml/System.Linq/Enumerable.xml ✅Succeeded View

For more details, please refer to the build report.

For any questions, please:

Copy link

Learn Build status updates of commit f134982:

✅ Validation status: passed

File Status Preview URL Details
snippets/csharp/System.Linq/Enumerable/AggregateTSource/enumerable.cs ✅Succeeded View
snippets/csharp/System.Linq/Enumerable/AggregateTSource/Enumerable.csproj ✅Succeeded
snippets/visualbasic/VS_Snippets_CLR_System/system.Linq.Enumerable/VB/Enumerable.vb ✅Succeeded View
snippets/visualbasic/VS_Snippets_CLR_System/system.Linq.Enumerable/VB/Enumerable.vbproj ✅Succeeded
xml/System.Linq/Enumerable.xml ✅Succeeded View

For more details, please refer to the build report.

For any questions, please:

@gewarren gewarren merged commit 0e1f982 into dotnet:main Jun 5, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants