I’m using Visual Studio 2022 (with ReSharper 2024.1 but I don’t think that’s relevant) developing in .NET 8. My minimal repro is this: I have a DataTable
object named dataTable
, and these two lines of code:
var err = (
from DataRow r in dataTable.Rows
select (r.Field<string>(0), r.Field<string>(1))
).First();
var wut = (
dataTable.Rows.Cast<DataRow>()
.Select(r => (r.Field<string>(0), r.Field<string>(1)))
).First();
My understanding is that the LINQ query-syntax style (from
… select
) seen in err
is simply ‘syntactic sugar’ for the actual method calls seen in wut
. I asked ReSharper to convert the first to the second; but I agree with what it’s done. Both lines, I thought, would do the same thing: get the first row of dataTable
, pull out the first two columns as string
s, and put those strings into a tuple. Therefore, I would expect err
and wut
to have the same inferred type.
But they don’t.
err
is a (string, string)
, whereas wut
is a (string?, string?)
.
What am I missing? Is this a failure of my expectation, a failure of ReSharper’s query-syntax-to-method-chain conversion, or something else?