473,405 Members | 2,300 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

novice question

Hi,

i am learning c# at home in my spare time (what a life), and i am working
through some examples. I run the following code and i get the following
error when the if condition is not met.
An unhandled exception of type System.FormatException' occurred in
mscorlib.dll

string charval="Hello.";

string pharVal="How are you?";

string input;

try

{

Console.WriteLine("Hey,,,,, {0} {1}",pharVal,charval);

input=Console.ReadLine();

if (input=="1")

Console.WriteLine("Hello {0}", input);

else

Console.WriteLine("Back again? {0)", input);

}

finally

{

}

Sorry if this is a bit too basic - but i just can't work out why the value
of 2 is not acceptable.
Nov 17 '05 #1
5 1111
gordon wrote:
i am learning c# at home in my spare time (what a life), and i am working
through some examples. I run the following code and i get the following
error when the if condition is not met.
An unhandled exception of type System.FormatException' occurred in
mscorlib.dll
The problem is in this line:
Console.WriteLine("Back again? {0)", input);


You meant {0}, not {0)

Jon

Nov 17 '05 #2
Yes of course Jon - thanks - i didnt pick that up.

I wish the debugger was more descriptive.

Doug
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:11*********************@g47g2000cwa.googlegro ups.com...
gordon wrote:
i am learning c# at home in my spare time (what a life), and i am working
through some examples. I run the following code and i get the following
error when the if condition is not met.
An unhandled exception of type System.FormatException' occurred in
mscorlib.dll


The problem is in this line:
Console.WriteLine("Back again? {0)", input);


You meant {0}, not {0)

Jon

Nov 17 '05 #3
Gordon,

Don't worry about posting basic questions, there is always someone who will
be happy to help. This is an easy one to miss - in the WriteLine after the
else, the format specifier should be {0}, not {0) !
--
Chris Ballard
MCSD.NET
"gordon" wrote:
Hi,

i am learning c# at home in my spare time (what a life), and i am working
through some examples. I run the following code and i get the following
error when the if condition is not met.
An unhandled exception of type System.FormatException' occurred in
mscorlib.dll

string charval="Hello.";

string pharVal="How are you?";

string input;

try

{

Console.WriteLine("Hey,,,,, {0} {1}",pharVal,charval);

input=Console.ReadLine();

if (input=="1")

Console.WriteLine("Hello {0}", input);

else

Console.WriteLine("Back again? {0)", input);

}

finally

{

}

Sorry if this is a bit too basic - but i just can't work out why the value
of 2 is not acceptable.

Nov 17 '05 #4
it seems you have an incorrect bracket in your second statement

Console.WriteLine("Back again? {0)", input);
should be
Console.WriteLine("Back again? {0}", input);

hence the change of ')' to '}'
"gordon" wrote:
Hi,

i am learning c# at home in my spare time (what a life), and i am working
through some examples. I run the following code and i get the following
error when the if condition is not met.
An unhandled exception of type System.FormatException' occurred in
mscorlib.dll

string charval="Hello.";

string pharVal="How are you?";

string input;

try

{

Console.WriteLine("Hey,,,,, {0} {1}",pharVal,charval);

input=Console.ReadLine();

if (input=="1")

Console.WriteLine("Hello {0}", input);

else

Console.WriteLine("Back again? {0)", input);

}

finally

{

}

Sorry if this is a bit too basic - but i just can't work out why the value
of 2 is not acceptable.

Nov 17 '05 #5
"gordon" <go**********@optusnet.com.au> wrote in message
news:43***********************@news.optusnet.com.a u...
Yes of course Jon - thanks - i didnt pick that up.

I wish the debugger was more descriptive.
For future reference.
Any time You get a System.FormatException start looking at your format string.
Unfortunately, it is not validated at compile time.
I realize that the format string may not be known 'til run time, but in general, the string is a
string literal and COULD easily be validated.

Oh well
Bill

Doug
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:11*********************@g47g2000cwa.googlegro ups.com...
gordon wrote:
i am learning c# at home in my spare time (what a life), and i am working
through some examples. I run the following code and i get the following
error when the if condition is not met.
An unhandled exception of type System.FormatException' occurred in
mscorlib.dll


The problem is in this line:
Console.WriteLine("Back again? {0)", input);


You meant {0}, not {0)

Jon


Nov 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Christopher Richards | last post by:
It is possible to be able to receive email alerts (say, from Google News) and publish them to a web page automatically? I am a novice as far as PHP goes, but I can open and write to a file and...
5
by: Marian | last post by:
Hi, I am totaly novice in .NET and I am studying a book about this. There was mentioned "assembly". I did not understand, how function does it has . I would like to know the exact run of code...
2
by: George | last post by:
Is this group for a novice C++ programmers?
21
by: AES/newspost | last post by:
My understanding -- I'm not an expert -- is that on (some? many? all?) standard Internet servers a URL can point to a subdirectory name followed by a backslash, and that links to this URL will...
6
by: ronwer | last post by:
Hello, The title doesn't completely cover the question I have, but it's a bit more complicated problem we have. We are using a database, based on Acces, but developed by a third party...
3
by: herrcho | last post by:
Here is the code.. #define NAME "MEGATHINK, INC" #define ADDRESS "10 Megabuck Plaza" #define PLACE "Megapolis, CA 94904" int main() { starbar(); printf("%s\n",NAME);
2
by: Dmitry Sazonov | last post by:
I'm novice here and I'm sorry for stupid question. We are trying to understand web services architecture, is it better than TIBCO.Randevouz and does webservices fit our needs. I understand, I...
1
by: Christo | last post by:
I have a question please this is just theory at the moment I am a novice java programmer Is it possible for me to write information to a hashmap and then once it has been written to extract a...
1
by: TwistedSpanner | last post by:
Hello all, For the record I am a complete java novice. I have to write a program to generate/output to screen 10 simple maths question and output a final score . The question is as follows ...
9
by: Kelii | last post by:
I've been trying to get this piece to work for a few hours, but have given up. I hope someone out there can help, I think the issue is relatively straightforward, but being a novice, I'm stumped....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.