Skip to content

Unsafe.SkipInit and out parameter #57490

Answered by EgorBo
sakno asked this question in Q&A
Aug 16, 2021 · 1 comments · 2 replies
Discussion options

You must be logged in to vote

In my view, cases where TryParse fails are (expected to be) rare so it's not that important to optimize. And returning junk in out doesn't look safe. E.g.

TryParse(input, out MyStruct ms);
if (ms.Id != 0) // Id will be some random value in case of failed TryParse
{
...

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@stephentoub
Comment options

@IS4Code
Comment options

Answer selected by sakno
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants