课程: Learning C#

今天就学习课程吧!

今天就开通帐号,24,600 门业界名师课程任您挑!

String parsing

String parsing

- [Instructor] In this example, we're going to see how to parse the contents of a string into native C# data types and again, this is a pretty common operation that programs have to perform. Your program might be given something like numerical data in string format and you need to convert it into an actual number. So let's take a look in the Parsing folder. Let's open the code up. So here in my code, I have a few string variables defined that represent different number types. So I've got an integer, a floating point number, a number with a comma in it for thousands, and then the same thing but with a decimal value. So the different basic data types in C# provide a parse function that you can use to parse a string into that particular type. And you can also specify that certain formats are allowed as well. So let's start off with a simple integer example. Now, the reason I'm going to put this inside a try catch…

内容