Hi we can not define in c# variable like this
if((var input = db.table.FirstOrDefault()) != null)
{
// and here I could use my 'input' variable
}
but i can do it this way
for(var input = db.table.FirstOrDefault(); input != null; input = null)
{
//opeartion
}
Can anyone tell me why? Woudn’t that be nice if we could do it using if ?
This is because writing
is exactly the same like writing
accoring to the C# specification.
This means that there is no any return value, so there is nothing to check
!=nullagainst.Yes, I think it’s possible to trick this, to make some changes in compiler, but probabbly it doesn’t worth effort.