zoukankan      html  css  js  c++  java
  • 字符转int 的几种方法

    // 字符串转换成整数
                int numVal = Convert.ToInt32("26");
                numVal++;
                Console.WriteLine( numVal );
                int numVal = Int32.Parse("-105");
    Console.WriteLine( numVal );
    int j ;
    Int32.TryParse("-109",out j);
    Console.WriteLine("j 的数值是:"+j );
            
    try 
    {
        int m = Int32.Parse("abc"); // 直接使用它转换会报错。 要加上报错装置
    }catch (FormatException e)
    {
        
        Console.WriteLine(e.Message);
    }

    //这样的方式 如果有错就是返回0 

    int p ;
    Int32.TryParse("abc",out p);
    Console.WriteLine"p 的数值是:"+ p );

        
            string inputString = "abc";
            int numValue ;
            bool pared =    Int32.TryParse(inputString ,out numValue);
            // 接受的数值是0 但是返回的类型是 bool 
            
            
            Console.WriteLine"numValue 的数值是:"+ numValue );
            Console.WriteLine"返回的bool:"+ pared );

  • 相关阅读:
    练习_Python3 爬取笔趣阁最新小说章节
    Python3 map()函数
    Java图片验证码生成
    神经网络
    leetcode
    hive开发规范
    北明数科 bug
    JAVA集合~
    令人头痛的JVM
    重定向和管道符
  • 原文地址:https://www.cnblogs.com/gaitian00/p/2606310.html
Copyright © 2011-2022 走看看