Reputation: 347
I have the following:
var dbColumns = null;
dbColumns = dbColumnsCollection.Where(s => s.Field1 == "test");
but get an error "cannot assign to an implicitly typed variable"
How can I initialize the variable dbColumns ?
thanks
Upvotes: 0
Views: 338
Reputation: 2167
This is because C# is strongly type. And var is used for anonymous programming. Thus declaring a null for a var cannot and will not work.
So Code like this just won't work out because the compiler can't detect the datatype of dbColumns.
var dbColumns = null;
Two ways to declare dbColumns,
First if you want to retain the variable then use
var dbColumns = (IEnumerable<PocoClass>)null;
or the reliable good ol way
IEnumerable<PocoClass> dbColumns = null
EDIT:
You may also still use IQueryable
if you are still building the LINQ query.
Upvotes: 4