• 学习总结 数据类型的应用与转换


    数据类型的应用:

    console.readline()  读出来的全是字符串类型 必须用string

    Console.WriteLine("请输入a的值:");
    string a = Console.ReadLine();
    Console.WriteLine("请输入b的值:");
    string b = Console.ReadLine();
    Console.WriteLine("a+b的和为:");

    Console.WriteLine(a+b);
    Console.ReadLine();

    类型转换:

    int类型转换为string类型两种方法(小数跟整数转换方法一样):

    Console.WriteLine("请输入a的值:");
    string a = Console.ReadLine();
    Console.WriteLine("请输入b的值:");
    string b = Console.ReadLine();
    Console.WriteLine("a+b的和为:");

    int a1 = int.Parse(a); //第一种string类型转换为int类型方法
    int b1 = Convert.ToInt32(b); //第二种string类型转换为int类型方法
    int c = a1 + b1;
    Console.WriteLine(c);
    Console.ReadLine();

    整型转换为string类型方法:


    int a = 1;
    int b = 5;
    string s = a.ToString() + b.ToString(); //整型转换为string类型方法
    Console.WriteLine(s);
    Console.ReadLine();

    数值类型与数值类型之间的转换


    double a = 1.2;
    int b = 3;
    int c = (int)a + b; //double类型前面加(int) 强制转换为int类型(小数点以后的数字全部舍去)

    Console.WriteLine(c);
    Console.ReadLine();

     

  • 相关阅读:
    html5-本地数据库的操作
    html5_storage存取实例
    html5-表单常见操作
    js操作注意事项
    php扩展地址下载
    php serialize序列化对象或者数组
    php_memcahed 使用方法
    php_memcahed telnet远程操作方法
    php_memcahed 安装
    Liunx centos 系统 修改hostname
  • 原文地址:https://www.cnblogs.com/zhoudi/p/5308367.html
Copyright © 2020-2023  润新知