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 678103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T01:06:45+00:00 2026-05-14T01:06:45+00:00

An issue came up on another forum and I knew how to fix it,

  • 0

An issue came up on another forum and I knew how to fix it, but it revealed a feature of the compiler peculiar to me. The person was getting the error “Embedded statement cannot be a declaration or labeled statement” because they had a declaration of a variable following an if statement with no brackets. That was not their intent, but they had commented out the line of code immediately following the if statement, which made the variable declaration the de facto line of code to execute. Anyway, that’s the background, which brings me to this.

The following code is illegal

if (true)
    int i = 7;

However, if you wrap that in brackets, it’s all legal.

if (true)
{
    int i = 7;
}

Neither piece of code is useful. Yet the second one is OK. What specifically is the explanation for this behavior?

  • 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-14T01:06:46+00:00Added an answer on May 14, 2026 at 1:06 am

    The C# language specification distinguishes between three types of statements (see chapter 8 for more details). In general you can have these statements:

    • labeled-statement – my guess that this is for the old-fashioned goto statement
    • declaration-statement – which would be a variable declaration
    • embedded-statement – which includes pretty much all the remaining statements

    In the if statement the body has to be embedded-statement, which explains why the first version of the code doesn’t work. Here is the syntax of if from the specification (section 8.7.1):

    if ( boolean-expression ) embedded-statement
    if ( boolean-expression ) embedded-statement else embedded-statement

    A variable declaration is declaration-statement, so it cannot appear in the body. If you enclose the declaration in brackets, you’ll get a statement block, which is an embedded-statement (and so it can appear in that position).

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

Sidebar

Related Questions

I'm currently using the jQuery fullcalendar plugin but I've came across an issue regarding
In an attempt to find another issue, my tests came up with the following
This came up in another question (kindly answered by meronix ) but I curious
I came across this issue last night where my CSS would not affect the
Just came across an issue with my Wordpress template that I can't figure out.
I came across an issue where, just to try it out, I removed an
When running some tests I came across the following issue. When using: private String
While investigating an issue with application I'm working on, I've came across one behavior
I'm starting to learn OOP in JS and I came across this issue where
I am a beginner and want to learn XSLT. I came upon an issue

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.