Milan Raval Milan Raval - 2 months ago 10
C# Question

The type or namespace name 'var' could not be found in WCF Service Application

When I am trying to use "var" in the WCF Service application it is giving error "The type or namespace name 'var' could not be found (are you missing a using directive or an assembly reference?)"

Answer

You get this error if you try to use var in a class member, e.g.:

public class Foo
{
    var a = 4;
}

var can only be used inside a method, not in classes, fields or method signatures.

See also: Why no var on fields?

Comments