国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發(fā) > 綜合 > 正文

Numeric Parse Method

2024-07-21 02:16:37
字體:
供稿:網(wǎng)友
the parse method converts a string that represents a .net framework numeric base type to an actual .net framework numeric base type. it takes the following forms, where xxx is the name of the numeric base data-type class:

public static xxx parse(string s);
public static xxx parse(string s, numberstyles style);
public static xxx parse(string s, numberstyles style, numberformatinfo info);
the parse method takes a combination of three parameters: the string to be converted, one or more values from the numberstyles enumeration , and a numberformatinfo class. all numeric strings produced by the parse method, except hexadecimal strings, will always be parsable by this method. because the parse method assumes that all string input represents a base-10 value, no non base-10 values are parsable. it will also not parse strings that represent the values nan, positiveinfinity, or negativeinfinity of the single and double classes because they are not real numbers.

the following example converts a string to an int value, increments that value, and displays the result.

[c#]
string mystring = "12345";
int myint = int.parse(mystring);
myint++
console.writeline(myint);
//results in "12346"
the numberstyles enumeration is usefull if you have a string that contains non-numeric characters that you want converted into a .net framework numeric base type. for example, a string that contains commas, parentheses, or currency symbols cannot be converted to an int value under the parse method if the numberstyles enumeration is not used. the following code is invalid and will raise an exception with the message, "the input string wasn't in the correct format."

[c#]

string mystring = "123,456";
int myint = int.parse(mystring);
console.writeline(myint);
//raises exception
when you apply the numberstyles enumeration with the allowthousands flag, the parse method will ignore the comma that raised the exception in the previous example. the following example uses the same string as the previous example, but does not raise an exception.

[c#]

string mystring = "123,456";
int myint = int.parse(mystring, numberstyles.allowthousands);
console.writeline(myint);
//results in "123456"
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 渭南市| 全椒县| 凤翔县| 安义县| 台中县| 浦城县| 洛阳市| 丰顺县| 三都| 色达县| 屯门区| 郸城县| 仙游县| 江城| 喀喇| 白河县| 德安县| 南康市| 万年县| 体育| 改则县| 如皋市| 浦东新区| 溆浦县| 台湾省| 波密县| 溧水县| 高邑县| 凤冈县| 辽中县| 新干县| 崇义县| 维西| 西藏| 贵德县| 开江县| 综艺| 安义县| 常熟市| 弋阳县| 姚安县|