| | |
Formatting Problems
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Jul 2009
Posts: 7
Reputation:
Solved Threads: 0
Hey I'm really new to C# - I don't understand how to properly sort out the code based on the messages that I am getting.
The messages are:
} expected
{ expected
) expected
Invalid expression term '}'
When I simply enter these characters into the place that the debugger tells me to, more errors pop up - I am using Visual Studio 2008. This is the section of code I believe I am having difficulty with:
THANKS FOR ANY HELP!
The messages are:
} expected
{ expected
) expected
Invalid expression term '}'
When I simply enter these characters into the place that the debugger tells me to, more errors pop up - I am using Visual Studio 2008. This is the section of code I believe I am having difficulty with:
C# Syntax (Toggle Plain Text)
{ try { using(FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read) { using (StreamReader sr = new StreamReader("TestFile.txt")) { String line; while ((line = sr.ReadLine()) != null) { Console.WriteLine(line); using (StreamWriter sw = new StreamWriter("TestFile.txt")) { sw.Write("\n"); sw.WriteLine("line\n"); sw.WriteLine("test"); } } } } catch (Exception e) { // Let the user know what went wrong. Console.WriteLine("The file could not be read:"); Console.WriteLine("File: " + e.FullPath + " " + e.ChangeType); Console.WriteLine("File: " + e.Name); Console.WriteLine("Folder:" + Path.GetDirectoryName(e.FullPath)); Console.WriteLine(d.Message); continue; } } } }
Last edited by Ancient Dragon; Jul 27th, 2009 at 9:17 am. Reason: add code tags
Hi,
Please use [code=language] for all the code you post here.
regarding solution for your problem, just put '}' for every '{' and same for '(' and ')'.
Please use [code=language] for all the code you post here.
regarding solution for your problem, just put '}' for every '{' and same for '(' and ')'.
Freedom in the Mind, Faith in the words.. Pride in our Souls...
Indian Developer
http://falaque.wordpress.com/
Indian Developer
http://falaque.wordpress.com/
Here is your solution:
Just replace your try catch block with my code and it will work:
Here is my code
And I have few suggestions for you:
1. While writing code every time you open a bracket immediately place it's corresponding closing bracket and then go back inside the bracket and then type. This rule applies not only to brackets but for all the codes which has corresponding opening and closing code. For example doublequotes(") and single quotes(') and all of them.
2. When you post your code on Daniweb always enclose the code in code tags like this " "
This will display as
Well goodluck
If you have any problem send messages directly at
info@bizpersonnel.com
www.bizpersonnel.com
A Software development Company
Just replace your try catch block with my code and it will work:
Here is my code
C# Syntax (Toggle Plain Text)
try { using (FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read)) { using (StreamReader sr = new StreamReader("TestFile.txt")) { String line; while ((line = sr.ReadLine()) != null) { Console.WriteLine(line); using (StreamWriter sw = new StreamWriter("TestFile.txt")) { sw.Write("\n"); sw.WriteLine("line\n"); sw.WriteLine("test"); } } } } } catch (Exception e) { // Let the user know what went wrong. Console.WriteLine("The file could not be read:"); Console.WriteLine("File: " + e.FullPath + " " + e.ChangeType); Console.WriteLine("File: " + e.Name); Console.WriteLine("Folder:" + Path.GetDirectoryName(e.FullPath)); Console.WriteLine(d.Message); continue; }
And I have few suggestions for you:
1. While writing code every time you open a bracket immediately place it's corresponding closing bracket and then go back inside the bracket and then type. This rule applies not only to brackets but for all the codes which has corresponding opening and closing code. For example doublequotes(") and single quotes(') and all of them.
2. When you post your code on Daniweb always enclose the code in code tags like this "
C# Syntax (Toggle Plain Text)
string str = "this is a string";
This will display as
C# Syntax (Toggle Plain Text)
string str = "this is a string";
Well goodluck
If you have any problem send messages directly at
info@bizpersonnel.com
www.bizpersonnel.com
A Software development Company
Sorry about enclosing tags in code blocks, i was not able to explain it properly:
Here follow this to enclose your code in the code blocks:
[code=C#]
String str = "This is a string.";
[/code]
Here follow this to enclose your code in the code blocks:
[code=C#]
String str = "This is a string.";
[/code]
My Personnel Blog:dotnetworker.blogspot.com
My Company:http://www.bizpersonnel.com
Blog:http://bizpersonnel.wordpress.com
My Company:http://www.bizpersonnel.com
Blog:http://bizpersonnel.wordpress.com
![]() |
Similar Threads
- SQL formatting problems with XML (XML, XSLT and XPATH)
- Problems with new system: random crashes (Troubleshooting Dead Machines)
- Browser Redirect/System Restore Problems/etc.... (Viruses, Spyware and other Nasties)
- formatting problems (Windows NT / 2000 / XP)
Other Threads in the C# Forum
- Previous Thread: How to Edit a Gridview ??
- Next Thread: C# problem showing a form
| Thread Tools | Search this Thread |
Tag cloud for C#
.net access ado.net algorithm array barchart bitmap box broadcast buttons c# check checkbox class client color combobox control conversion csharp custom database datagrid datagridview dataset datetime degrees development draganddrop drawing encryption event excel file files form format forms ftp function gdi+ httpwebrequest image index input install java label list listbox listener login mandelbrot math mouseclick mysql networking object operator path photoshop picturebox pixelinversion post prime programming radians regex remote remoting resource richtextbox save saving serialization server sleep socket sql statistics stream string table tcp text textbox thread time timer treeview update usercontrol validation view visualstudio webbrowser windows winforms wpf xml





