What is "??=" classified as, because it does not obey "Operator" syntax highlighting. RRS feed

  • Question

  • Title says it all.

    Using VS2019, it suggested using the:

    item ??= new MyItem();
    instead of
    item = item ?? new MyItem();
    But as soon as I accepted that change the "??=" operator was not interpreted as an "operator" and therefore has the exact same syntax highlight color as "item" which is a trifle annoying.

    So, if it "isn't" an operator, what is it?
    If it "is" an operator, that's a bug!


    Jaeden "Sifo Dyas" al'Raec Ruiner

    "Never Trust a computer. Your brain is smarter than any micro-chip."
    PS - Don't mark answers on other people's questions. There are such things as Vacations and Holidays which may reduce timely activity, and until the person asking the question can test your answer, it is not correct just because you think it is. Marking it correct for them often stops other people from even reading the question and possibly providing the real "correct" answer.

    Friday, May 29, 2020 10:43 PM

All replies

  • The documentation states that it is an assignment operator.

    This is a signature. Any samples given are not meant to have error checking or show best practices. They are meant to just illustrate a point. I may also give inefficient code or introduce some problems to discourage copy/paste coding. This is because the major point of my posts is to aid in the learning process.

    Saturday, May 30, 2020 1:22 AM
  • Hi Jaeden,

    Welcome to MSDN forum.

    I check the document and it clarifies that “??=” is an operator, after that I test on my side, but actually when I try to change the color of “??=” operator, I find this option: Tools > Options… > Environment > Fonts and Colors > Operator, it works on “item = item ?? new MyItem();” code line but not on “item ??= new MyItem();” code line.

    So, I consider this is a potential issue or may be a new feature that VS doesn’t support currently. I recommend you report this issue to VS Product Team directly from Help > Send Feedback > Report a Problem…

    Feel free to contact me if you have any concern.

    Best Regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Monday, June 1, 2020 9:26 AM