数据类型和数据转换

一.基本数据类型:1.整型 byte 无符号8位数

                     Short 有符号16位数

                     int    有符号32位数

                     long  有符号64位数

2.浮点型  float

                       Double 精度大

                       Decimal 精度高

             3.字符型 char

             4.布尔型 bool  true或false

引用类   1.字符串型  string

         2.日期时间  DateTime

         3.枚举类型 ENUM用户自定义

         4.结构类型 struct 用户自定义

引用类型

  1. 字符串类型  string a =”hello”; string b = “b”
  2. 类类型 object 所有其他类型的最终基类
  3. 接口类型 interface
  4. 数组类型 一维和多维数组,如int[]和int [,,,,]

二.变量

变量的定义:

数据类型 变量名

 数据类型  变量1,变量2,···变量n;

数据类型  变量名=值

Int b,c;

int a, b,c;

a=1;b=2;c=3;

 int a =1;

变量名前加关键字(不能赋值,只能取值);

const 常量

const int a =1;

三.类型转换

字符串转换为变量(值类型)

static void Main(string[] args)

        {

            Console.Write("请输入变量a的值:");

            string a = Console.ReadLine();

            Console.Write("请输入变量b的值:");

            string b = Console.ReadLine();

            Console.WriteLine("a+b的和为");

            int a1 = int.Parse(a);

            int b1 = Convert.ToInt32(b);

            int c = a1 + b1;

            Console.WriteLine(c);

        }

变量转换为字符串

static void Main(string[] args)

        {

           int a = 1;

            int b = 5;

            string s = a.ToString() + b.ToString();

            Console.WriteLine(s);

        }

数值类型的转换

static void Main(string[] args)

        {

double a = 1.2;

            int b = 3;

            int c = (int)a + b;

            Console.WriteLine(c);

            Console.ReadLine();  }

原文地址:https://www.cnblogs.com/kellybutterfly/p/5344464.html