PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, December 12, 2022

[FIXED] Why would you leave the brackets in the code without a condition?

 December 12, 2022     c#, syntax     No comments   

Issue

Why would you leave the open and close brackets in the code without the condition first? I've seen examples in C# where the code does compile when you have something like this:

{
  Console.WriteLine("Hey");
}

Is this just bad syntax? or something else?


Solution

New brackets means new scope. For example if you want to create variable, which should exists only in specific part of code you can surround it with brackets:

{
   var a = 1;
   {
      var b = 2;
      //here 'a' and 'b' exist
   }
   //only 'a' exists
   {
      var b = 2;
      //again 'a' and 'b' exist
   }
   //again only 'a' exists
}


Answered By - MagliaRosa
Answer Checked By - Mildred Charles (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing