C# int.Parse 方法
使用 C# 中的 int.Parse 方法,將數字的字串表示形式轉換為整數。如果無法轉換字串,則 int.Parse 方法將返回異常
假設你有一個數字的字串表示形式。
string myStr = "200";
現在,要將它轉換為整數,請使用 int.Parse()。它將轉換。
int.Parse(myStr);
示例
using System.IO;
using System;
class Program {
static void Main() {
int res;
string myStr = "200";
res = int.Parse(myStr);
Console.WriteLine("String is a numeric representation: "+res);
}
}輸出
String is a numeric representation: 200
廣告
資料結構
網路
關係型資料庫管理系統
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP