Docs: C# Tutorial: Handling Null and ?? and ?. Operators

Created on 23 Feb 2016  路  12Comments  路  Source: dotnet/docs

This would cover the newer operators like ?? and ?. that work well when programming with reference types that may be null. I鈥檓 not sure I like the title yet.

Area - C# Guide Technology - C# Null safety P1 doc-idea up-for-grabs

All 12 comments

Hi @BillWagner after the great PGI session I'd like to take a first shot at this. And this seems like a nice small one to get the hang of it. And it seems about time that this is picked up.. ;)

Ant pointers on this still being relevant and how to proceed?

Thanks for reaching out @jfversluis

I apologize for the late response, I was enjoying the holidays. 馃巹 馃嵕

Let's start with an outline (either as a comment here, or as a WIP labelled PR.)

I'd like readers to learn techniques for writing concise and clear code using ?? and ?. instead of a series of nested if / else statements. Beyond that, I haven't worked through organizing the topic yet.

No problem @BillWagner ! As you should! And a happy new year to you 馃帀

I'll see what I can do! Thanks!

@jfversluis Have you started working on this one ? Do you need any help ?

Hi @sputier I'm so sorry, this totally got away from me! But maybe we could have a little chat on tips and best practices if you have some experience?

Hi @jfversluis ! Of course, if I can help you, I will ! For this first contribution, I would only suggest you to keep things simple : explain everything thinking a beginner could read and understand what you wrote :-)

Feel free to ping me (here or on twitter : Same @) if you have any question. If I have the answer you need, I'll be glad to give it to you !

First idea for an outline below.

Null coalescing and operator

Introduction

Null coalescing (??)

Sample

Remarks

Null operator (?.)

Sample

Remarkts

Conclusion

I don't think there is much more to it? Or am I missing anything?

@jfversluis If you don't omit comparing if syntax with each of these operators before introducing the samples, I think this outline will be a good start for the article. Feel free to update it if you notice anything that should be highlighted (language version ?).

If you feel a bit insecure about what you wrote, you can create a WIP (work in progress) PR (i.e. labeled "[WIP] ...."), so the community may help you reviewing it.

Since @jfversluis droped the ball, I'm going to take over from him to tackle this issue 馃槃

Hi @BillWagner !

This issue still makes sense? I saw an article about ?? operator and another about ? reference types null operator.

The idea is join both subjects or what?

@lucasnobredev It still makes sense.

We cover those features well in the reference. However, we don't have tutorials, or How To articles on using ??, ?. and ?[] to work with variables that may have the null value.

Closing this because of a new direction in the C# guide. We should create a new tutorial for handling nullability in modern versions of C#. The additions of:

  • nullable reference types
  • nullable annotations
  • These and related operators

all mean the correct tutorial is how to handle null values in your application.

It's not how to use a specific operator (which is handled well already in the C# language reference.

Closing, as the new plan is being created.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Manoj-Prabhakaran picture Manoj-Prabhakaran  路  3Comments

ite-klass picture ite-klass  路  3Comments

JagathPrasad picture JagathPrasad  路  3Comments

gmatv picture gmatv  路  3Comments

sime3000 picture sime3000  路  3Comments