怎样的string[ ]中的值转换成int?
using System;using System.IO;
class A
{
public static void Main(string[] args)
{
FileStream fs = new FileStream(@"f:\\test.txt", FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(fs);
sr.BaseStream.Seek(0, SeekOrigin.Begin);
string str1 = sr.ReadLine();
string[] str2 = new string[10];
int x;
int Count = 0;
while (str1 != null)
{
x = str1.IndexOf("R");
if (x < 0) x = 0;
str2[Count] = str1.Substring(x+7, 3);
Count++;
str1 = sr.ReadLine();
}
for (int i = 0; i < Count; i++)
{
Console.WriteLine(str2[i]);
}
}
}
运行这段代码将输出:100
怎样把100转换成int型?
或者:
Int.Parse(string); (int) int.Parse(string) 或 Convert.toInt32(string) 两个方法都可以 ls正解
int.Parse(string) 或 Convert.toInt32(string) 两个方法都可以
页:
[1]
