相关疑难解决方法(0)

int.Parse()和Convert.ToInt32之间的主要区别是什么

  • int.Parse()和之间的主要区别是Convert.ToInt32()什么?
  • 哪一个是首选

c#

467
推荐指数
8
解决办法
27万
查看次数

在控制台应用程序中将字符串解析为Int32

大约两周前我开始编程,我的朋友说如果我需要的话,我可以请求你们帮忙.

    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();
                }
        }
    }
Run Code Online (Sandbox Code Playgroud)

我第一次x=s.ToInt32遇到这个(我读过它int应该包含一个数字,而不是一个string或字母..)和错误:

'string' does not contain a definition for 'ToInt32' and no extension method 'ToInt32' …
Run Code Online (Sandbox Code Playgroud)

c#

-2
推荐指数
1
解决办法
1068
查看次数

标签 统计

c# ×2