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

更新於:2020 年 6 月 23 日

19K+ 瀏覽次數

開啟你的 職業生涯

完成課程並獲得認證

開始學習
廣告
© . All rights reserved.