Visual Studio 2017 C#ToInt32方法 [英] Visual Studio 2017 C# ToInt32 Method

查看:100
本文介绍了Visual Studio 2017 C#ToInt32方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是C#的新手,我正在测试我构建的应用程序,需要5个数字的值,用3个空格分隔。 没有必要为我的作业演示一个负整数,但我想知道为什么我不能使用负整数。 我是否需要额外的
语句来允许负整数? 我想我认为一个32位整数允许负数?  Visual Studio将我重定向到语句

I am new to C# and I'm testing the app I built requiring a 5-digit value separated by 3 spaces.  It is not necessary to demonstrate a negative integer for my assignment, but am wondering why I cannot use negative integers.  Would I need an additional statement to allow negative integers?  I guess I thought a 32-bit integer allows negative numbers?  Visual Studio redirected me to the statement

int number =
Convert 。ToInt32( 控制台 .ReadLine());

提前感谢您阅读我的代码!

Thanks in advance for reading my code!

  class Program

    {

        static void Main(string [] args)

        {

            Console.Write("输入5位数字:");

            int number = Convert.ToInt32(Console.ReadLine());



             Console.WriteLine("您选择的号码是{0}。",数字);
$


        ;     int digit1,

                digit2,&
                digit3,

                digit4,

                digit5;
$


            digit1 = number / 10000;

            number = number%10000;

            digit2 = number / 1000;

            number = number%1000;

            digit3 = number / 100;

            number = number%100;

            digit4 = number / 10;

            number = number%10;

            digit5 = number / 1;

            number = number%1;



            string space3 ="   " ;;


            Console.WriteLine(" {1} {0} {2} {0} {3} {0} {4} {0} {5}",space3,digit1,digit2,digit3,digit4,digit5);

            Console.ReadLine();

        }
    }¥b $ b}

 class Program
    {
        static void Main(string[] args)
        {
            Console.Write("Enter a 5 Digit Number: ");
            int number = Convert.ToInt32(Console.ReadLine());

            Console.WriteLine("The Number You Chose is {0}.", number);

            int digit1,
                digit2,
                digit3,
                digit4,
                digit5;

            digit1 = number / 10000;
            number = number % 10000;
            digit2 = number / 1000;
            number = number % 1000;
            digit3 = number / 100;
            number = number % 100;
            digit4 = number / 10;
            number = number % 10;
            digit5 = number / 1;
            number = number % 1;

            string space3 = "   ";

            Console.WriteLine("{1}{0}{2}{0}{3}{0}{4}{0}{5}", space3, digit1, digit2, digit3, digit4, digit5);
            Console.ReadLine();
        }
    }
}

推荐答案


盯着我的代码帮我意识到了这些原因。 此应用仅允许使用5位数的单个数字。 
单独的数字-1-2-3-4-5不是
。 谢谢你看我愚蠢的问题。我自己就回答了。  

Staring at my code helped my realize the whys.  This app only allows a single number with 5-digits.  Separate numbers -1-2-3-4-5 are not identified within this app.  Thanks for looking at my silly question. I just answered it myself.  


这篇关于Visual Studio 2017 C#ToInt32方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆