zoukankan      html  css  js  c++  java
  • C#类型转换测试小程序

    
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    namespace TestStringToNum
    {
    class Program
    {
    static void Main(string[] args)
    {
    String str
    = "15.23";
    int i = 2;
    float f = 1.2f;
    Double du
    = 0.33;

    Type tDouble
    = du.GetType();
    Type tInt
    = i.GetType();
    Type tFloat
    = f.GetType();

    try
    {
    du
    = Double.Parse(str);
    }
    catch (Exception e)
    {
    Console.WriteLine(e.Message.ToString());
    }
    try
    {
    i
    = int.Parse(str);
    }
    catch (Exception e)
    {
    Console.WriteLine(e.Message.ToString());
    }
    try
    {
    f
    = float.Parse(str);
    }
    catch(Exception e)
    {
    Console.WriteLine(e.Message.ToString());
    }
    }
    }
    }
  • 相关阅读:
    A
    B
    A
    A
    B
    C
    有趣的平方和的推导
    一篇写的非常好的匈牙利算法文章
    2014 UESTC Training for Data Structures G
    2014 UESTC Training for Data Structures H
  • 原文地址:https://www.cnblogs.com/gavinsp/p/2026586.html
Copyright © 2011-2022 走看看