3 ms·
Readability is one of the reasons I try to avoid the use of the 'var' keyword in C#. It's useful in object instantiation, e.g. FooFizzBuzzProvider bar = ne
by snarfy 12y ago
Readability is one of the reasons I try to avoid the use of the 'var' keyword in C#. It's useful in object instantiation, e.g.
FooFizzBuzzProvider bar = new FooFizzBuzzProvider()
vs
var bar = new FooFizzBuzzProvider();
But in other instances it hides the underlying type too much, e.g.
var query = (from entity in dbContext.Entities
join entity2 in dbContext.Entities2.Include( e => e.Entity3)
on entity.entity2Id equals entity2.entity2Id
select new { e1 = entity, e2 = entity2.Entity3 });
It works. It's nice. But sometimes it's too nice. At some point the returned type needs serialized, or some other issue which requires a strong type. You end up rewriting the dynamic stuff with strong types anyway.
- dylukes 12y agoC#'s var keyword tells the compiler to infer the type. It still has a statically determined type so that shouldn't interfere with type-polymorphic functions such as serialization routines...