Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> C#

วิธีแปลงสตริงเป็น int ใน C#

กำหนดสตริง:

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);
    }
}