【发布时间】:2013-06-01 13:05:25
【问题描述】:
我大约 2 周前开始编程,我的朋友说如果我需要任何帮助,我可以向你们寻求帮助。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int x;
string s;
do
{
Console.WriteLine("input a number in the range of 0 -100");
s = Console.ReadLine();
x = s.ToInt32();
}
while (x < 0 || x > 100);
Console.WriteLine("ok you have chosen");
Console.ReadKey();
}
}
}
我第一次遇到x=s.ToInt32(我读到int 应该包含一个数字而不是string 或字母..)并且错误:
'string' does not contain a definition for 'ToInt32' and no extension method 'ToInt32'
accepting a first argument of type 'string' could be found (are you missing a using
directive or an assembly reference?)
C:\Users\user\Documents\Visual Studio11\Projects\ConsoleApplication1\ConsoleApplication1\Program.cs 19 23 ConsoleApplication1
【问题讨论】:
-
试试 x = Convert.ToInt32(s);
-
您需要更改问题的名称以更接近您的问题
-
啊...好。没有人提出扩展方法。我为你们感到骄傲。
-
很高兴我们能帮上忙 :) 勾选那个小复选标记,找出您认为提供了最佳答案的人。
-
@ShaiRoemi (请注意,您不必“接受”最高投票的答案。)同时投票(通过单击答案旁边的向上箭头)您找到的任何答案有帮助。欢迎使用 Stack Exchange。
标签: c#