Announcement

Collapse
No announcement yet.

Null-conditional Operators inside if statments not resolving correctly

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

    Null-conditional Operators inside if statments not resolving correctly

    Hi,

    When using an EnumerableInstance as below (selectedFiles), the following statement resolves incorrectly:

    if (selectedFiles?.Count() == 0)
    The above does not work. The if statement will resolve to true every time, regardless of the value returned by count.

    Additional brackets are required to get the if statement to resolve correctly, as below:

    if ((selectedFiles?.Count()) == 0)

    #2
    Hi AndyFasettoDev,

    Welcome to Bridge! Thanks for informing us of this defect.

    Could you share a link to Deck which reproduces this issue? Then we know 100% that we're dealing with the exact same scenario.

    Comment


      #3
      Hi

      I guess such issue is already reported and fixed
      https://github.com/bridgedotnet/Bridge/issues/2211

      Related to the following forum thread:
      http://forums.bridge.net/forum/bridg...eferenceequals
      Last edited by geoffrey.mcgill; 2017-02-02 @ 07:13 PM.

      Comment


        #4
        I was not able to reproduce the issue. Moving thread to general Help forum.

        http://deck.net/8bcf7ae73f52143b46772a6f2b74278e

        public class Program
        {
            public static void Main() => new Program().Init();
            
            public void Init()
            {
                var list1 = new List<int>();
                
                list1.Add(55);
                
                this.Log<int>(list1);
                
                var list2 = new List<string>();
                
                list2.Add("test1");
                list2.Add("test2");
                
                this.Log<string>(list2);
                
                var list3 = new List<bool>();
                
                this.Log<bool>(list3);
            }
            
            void Log<T>(List<T> list)
            {
                if (list?.Count() == 0)
                {
                    Console.WriteLine("empty");
                }
                else
                {
                    Console.WriteLine("not empty, count: " + list.Count);
                }
            }
        }

        Comment

        Working...
        X