Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning C# 3.0 : An Introduction to Object Oriented Programming ISBN: 978-0-470-26129-3
This is the forum to discuss the Wrox book Beginning C# 3.0 : An Introduction to Object Oriented Programming by Jack Purdum; ISBN: 9780470261293
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning C# 3.0 : An Introduction to Object Oriented Programming ISBN: 978-0-470-26129-3 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old May 6th, 2009, 12:46 PM
Registered User
 
Join Date: May 2009
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Question TryParse() Method

Hi! First off, your book is really great. Its definitely helping me learn and its not boring me. Thank you for authoring this book.

Ok, so I'm referring to Chapter5: Understanding Reference Data Types and I got confused with the first topic with String Variables. You said that data entered in the textbox is textual data. Does this mean that I ALWAYS have to use the TryParse method so that I can use this textual data (which is in fact a numerical data), into mathematical manipulation? Does this mean that I can't skip the input verification process ("flag = int....")?

In other words, is there no way that I can straight away assign the inputed data to a variable aside from the TryParse method?

I'm confused as I am new to programming. Please help.
Reply With Quote
  #2 (permalink)  
Old May 7th, 2009, 03:58 PM
Friend of Wrox
Points: 1,104, Level: 13
Points: 1,104, Level: 13 Points: 1,104, Level: 13 Points: 1,104, Level: 13
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2008
Location: Indianapolis, IN, USA.
Posts: 224
Thanks: 0
Thanked 30 Times in 29 Posts
Default Using TryParse()

You are correct in that all data entered into a textbox is string data. As such, it cannot be manipulated directly as numeric data. You must use a conversion method to change the data in the textbox to a numeric.

There are alternatives. For example, you could use int.Parse() to perform the conversion of the text data to an integer. That the good news. The bad news is when the user enters non-numeric data, the code could throw an exception and crash your program. (Exceptions are covered in Chatper 11.) The TryParse() method, however, prevents most exceptions and is safer than the simple Parse() method. (That's why I introduced it in Chapter 6, because I didn't want to get into exception handling until later.)

I hope this answers your question.
__________________
Jack Purdum, Ph.D.
Author: Beginning C# 3.0: Introduction to Object Oriented Programming (and 14 other programming texts)
Reply With Quote
The Following User Says Thank You to DrPurdum For This Useful Post:
afterzero (May 10th, 2009)
  #3 (permalink)  
Old May 10th, 2009, 10:15 AM
Registered User
 
Join Date: May 2009
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Thumbs up Thank you

Question was answered clearly. Thank you very much. I am just too excited to learn and can't wait for the following chapters. But yeah, it answered my question clearly.

Thanks a lot!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
About Method VeradisSanthanam ASP.NET 2.0 Basics 1 June 19th, 2007 06:52 AM
method amit_p_patel VB How-To 2 May 25th, 2007 01:46 AM
TryParse issues rpjamess1 Visual Basic 2005 Basics 0 December 1st, 2006 10:54 AM
Best method rastham SQL Server 2000 2 February 15th, 2006 11:59 PM
Method StanArtis BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 1 December 6th, 2004 05:09 AM



All times are GMT -4. The time now is 10:58 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.