[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 687
  • Last Modified:

Mismatched Curly Braces in C#

Hello,

Does anyone know of a trick or a good way to figure out how to find the missing opening or closing brace in your code?

I have a function that is about 1500 lines long and contains several IF-THEN-ELSE structures and I'm having the worse time trying to figure out what's missing.  Any suggestions will be GREATLY appreciated.  TIA

-Mari

0
Mariyam
Asked:
Mariyam
3 Solutions
 
RamuncikasCommented:
Suggestons:
#1 Code formatting
Try well-format you ceode. Like:
if (a == b)
   {
      .... //code here
    }
and not like

if (a==b){
.... //code here }
if (a==b)
{
... //code here }

#2 Comments & uncomment step by step
Comment all of the code inside a function and then uncomment line by line/block by block and compile in between.

#3 Comment the end of block
Put comment on every closing brace. Like
//checking if a==b
if (a==b)
   {
    ... //code here
   } //end of checking if a==b

Combinations possible

Good luck :)

0
 
daniel_ballaCommented:
Hi FoxProMari,
Did you try Edit.FormatSelection in VS? That would pretty-format the code and you should see it straight away.
Otherwise, I guess a more elegant solution would be to write a regular expression to find it, but I don't have such an example ready.

Cheers!
0
 
bele04Commented:
You can try to regionize your code so that you don't have to view them all at once.  Like you region a set of if else statements, for ex:

#region
if(condition)
{
//code
}
else
{
//code
}
#endregion

This way you can divide your code into different sections and it'll be much easier to debug it since you'll only be dealing with the section inside the enclosed region.
0
 
RamuncikasCommented:
#Region' and '#End Region' statements are not valid within method bodies.
At least thats what VB 2005 Express Edition says
0
 
MariyamAuthor Commented:
Hello,

Thanks to all who answered.  I ended up pulling out each section of code and putting it into a function using the Switch command to ascertain which function to execute.  I started to do it this way but ended up going off on a tangent and this mess is the result of that adventure.

If none of you mind, I'll split the points among you because they all look like good suggestions.  Hopefully I'll get to test them on a more manageable block of code :-)

Thanks again!

-Mari
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now