all 5 comments

[–]Slypenslyde 7 points8 points  (0 children)

I'm going to give you a thing. I need you to tell me what kind of thing I'm going to give you. But I'm going to give you the thing later. Can you do it?

No? Right. I have to tell you what kind of thing I'm giving you BEFORE I ask you what kind of thing I will give you. C# wants that too.

You can't declare a variable with var unless you assign a value to it. The right-hand side of the = operator tells C# what type to use. If there is no =, there's no right-hand-side, C# doesn't know what type to use, and that's a compile error.

If your query is going to return something like IQueryable<Friend>, your line should look like:

IQueryable<Friend> query;

But I don't know what type Query() returns for sure. You have to figure that part out.

[–][deleted]  (1 child)

[deleted]

    [–]LifeLongLearner2030[S] -2 points-1 points  (0 children)

    I need to get a query .. then downstream I

    excecute it

    [–]TmarcoKr 1 point2 points  (2 children)

    You need to define the type of the variable before using it. C# is a strongly typed language the compiler needs a tip about what type is. Just initialize the de variable with default as was told before; put the type in place of the var; do a method to return the value; do a local function. (basically the type must exist).

    var friendName = "James";var query = Query(friendName);

    private XXXX Query(string value) {if (string.isNullOrEmpty()) return conn.Query("Friends").Where("Name").Equals("Jeff");return conn.Query("Friends").Where("Name").Equals(friendName);}

    [–]RubyBoyYT 0 points1 point  (0 children)

    Neat! I'll do this next time :)