question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

LINQ immediate query execution not caught for type checking

See original GitHub issue

Environment data

dotnet --info output: .NET Command Line Tools (1.0.0-preview2-1-003177)

Product Information: Version: 1.0.0-preview2-1-003177 Commit SHA-1 hash: a2df9c2576

Runtime Environment: OS Name: ubuntu OS Version: 16.04 OS Platform: Linux RID: ubuntu.16.04-x64

VS Code version: Version 1.9.1 Commit f9d0c687ff2ea7aabd85fb9a43129117c0ecf519 Date 2017-02-08T23:44:55.542Z Shell 1.4.6 Renderer 53.0.2785.143 Node 6.5.0

C# Extension version: 1.7.0

Steps to reproduce

Make a LINQ interrogation over a array, using an immediate query execution operator: ToArray

        public static void Main(string[] args)
        {
            int[] fib = new [] {0,1,1,2,3,5};
            IEnumerable<int> fib2 = fib.Where(x => x > 2).ToArray();
            Console.WriteLine($"{fib2[0]");
        }

Expected behavior

Catch type changing from collection to array here: IEnumerable<int> fib2 = fib.Where(x => x > 2).ToArray();.

Actual behavior

Catches type change here: Console.WriteLine($"{fib2[0]");.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:22 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
DustinCampbellcommented, Feb 16, 2017

I’m not sure what you might be nullify-er.

There are a couple of fixes I could imagine. Here’s a couple:

  1. Use var to infer the type of fib2 as an int[]. After all, why does it need to be of type IEnumerable<int>?
var fib2 = fib.Where(x => x > 2).ToArray();
Console.WriteLine($"{ fib2[0] }");
  1. Don’t call ToArray() at all.
var fib2 = fib.Where(x => x > 2);
Console.WriteLine($"{ fib2.First() }");
0reactions
DustinCampbellcommented, Feb 16, 2017

No problem!

Read more comments on GitHub >

github_iconTop Results From Across the Web

LINQ immediate query execution not caught for type checking ...
Should (?) catch type changing from collection to array here: IEnumerable<int> fib2 = fib.Where(x => x > 2).ToArray(); . Catches type change here:...
Read more >
How to tell if an IEnumerable<T> is subject to deferred ...
This I thought would tell me if the collection was 'deferred' or not. It turns out that the enumerator created by the Select...
Read more >
Deferred Execution of LINQ Query - TutorialsTeacher
Deferred execution means that the evaluation of an expression is delayed until its realized value is actually required. It greatly improves performance by ......
Read more >
Deferred vs Immediate Query Execution in LINQ | DotNetCurry
In LINQ, queries have two different behaviors of execution: immediate and deferred. In this article, we will take a quick overview of how ......
Read more >
LINQ Query: Benefits of Deferred Execution | HackerNoon
Since the query does not need to be immediately executed, you can build it up in several steps, perhaps passing through additional conditional ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found