Solved

Mismatched Curly Braces in C#

Posted on 2006-07-05
5
670 Views
Last Modified: 2012-05-05
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
Comment
Question by:FoxProMari
5 Comments
 
LVL 14

Accepted Solution

by:
Ramuncikas earned 300 total points
ID: 17045704
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
 
LVL 9

Assisted Solution

by:daniel_balla
daniel_balla earned 100 total points
ID: 17046248
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
 
LVL 9

Assisted Solution

by:bele04
bele04 earned 100 total points
ID: 17047790
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
 
LVL 14

Expert Comment

by:Ramuncikas
ID: 17048606
#Region' and '#End Region' statements are not valid within method bodies.
At least thats what VB 2005 Express Edition says
0
 

Author Comment

by:FoxProMari
ID: 17055703
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Calling web service and its methods dynamically 2 39
ASP.NET Web API or ASP.NET Core MVC? 3 52
Runtime Error 2 28
Replace &lt; with < 14 55
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now