Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7054667
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:39:17+00:00 2026-05-28T03:39:17+00:00

Is this a bug or am I interpreting the ‘??’-operator wrong? Check out the

  • 0

Is this a bug or am I interpreting the ‘??’-operator wrong? Check out the get property below and the comments.

I’m using C# .NET 3.5

    private List<MyType> _myTypeList;

    private List<MyType> MyTypeList
    {
        get
        {
            //The two code lines below should each behave as the three under, but they don't?
            //The ones uncommented are working, the commented result in my list always returning empty (newly created I suppose).

            //return _myTypeList ?? new List<MyType>();
            //return _myTypeList == null ? new List<MyType>() : _myTypeList;

            if (_myTypeList == null)
                _myTypeList = new List<MyType>();
            return _myTypeList;
        }
    }

EDIT: Sorry to everybody who looked at the question when it was freshly asked, there where some errors in it that got to confuse everyone.

Thanks for all the great and fast feedback! I’ve now understood the error I made. Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T03:39:18+00:00Added an answer on May 28, 2026 at 3:39 am

    This line:

    return _myTypeList == null ? new List<MyType>() : _myTypeList;
    

    Is equivalent to:

        if (_myTypeList == null)
            return new List<MyType>();
        return _myTypeList;
    

    Not to:

        if (_myTypeList == null)
            _myTypeList = new List<MyType>();
        return _myTypeList;
    

    The version with ??, which you added later, is so unreadable that I won’t analyze it. Let’s get ? right first.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For the life of me I cannot get this bug figured out - I
UPDATE 2011.09.13 This bug has been resolved by Adobe. The example code below now
I have a problem with Jaxb enumerations that is related to this bug https://jaxb.dev.java.net/issues/show_bug.cgi?id=708
I'm having this bug I can't figure out and it is making my head
I get this bug when I use constants as default parameters and want to
Is this bug in Parallel.For? public class DataPoint { public int Game { get;
Any suggestions or workarounds for this bug? http://dev.ckeditor.com/ticket/6436 i really need to get around
I have been chasing this bug around, and I just don't get it. Have
I can't figure out a good way to fix this bug. If I uncheck
I'm currently pulling my hair out solving this bug :/ I have already tried

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.