Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3313140
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:04:49+00:00 2026-05-17T22:04:49+00:00

I have the following variable declarations at the top of my main function string

  • 0

I have the following variable declarations at the top of my main function

string brand;
double price;
var itemList6 = from i in myStore.items
    where i.price <= price && i.brand == brand
    orderby i.type
    select i;

Later on in the program I ask the user for a brand and a price, put them in the appropriate variables, and then run the query. However, the compiler won’t let me run this, because I am using unassigned variables in the query. Is the only way to solve this by initializing the variables? I generally try to not initialize variable if I don’t need an initial value since I find it confusing (trying to understand later where/why I used that default value).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T22:04:50+00:00Added an answer on May 17, 2026 at 10:04 pm

    You have to assign a value to the variables before you construct the LINQ query.

    The reason is that the compiler is using the variables to construct the query. Even though the query won’t be executed, the compiler requires variables to be assigned before use, and the compiler sees building the query expression as use.

    My recommendation is just to put some nominal default/temp value in there.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Running Jmeter on XP, I have the following scenario: Declare the variable ServerName with
I have the following classes/traits in Scala trait Write[-T] { def add(elem : T);
I have bash script that I use regularly in my job to automate a
In a book I found following (translation): Initialization means assigning the value of the
Given the following input file: a = 2 b = 3 c = a
Using exuberant-ctags 5.8 for gcc 4.4.3 c89 I am just started using exuberant-ctags and
I kind of posted a similar question a couple of days ago but that
I am a little confused as to how passing pointers works. Let's say I
How is it possible to create various cached versions of a user control based
Why can't I observe the editing property of an instance of UITableViewController ? I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.