如何將字串轉換為 C# 中的 int?


假設我們的字串是 −

string str ="9999";

現在,使用 Int32.Parse() 將字串轉換為整數 −

int n = Int32.Parse(str);

現在顯示整數值,如以下程式碼所示 −

示例

using System;
class Demo {
   static void Main() {
      string str ="9999";
      int n = Int32.Parse(str);
      Console.WriteLine(n);
   }
}

更新日期:22-Jun-2020

295 次瀏覽

開啟你的 職業生涯

完成課程即可獲得資格認證

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