1、整数类型-8种-常用的:
int 32位 范围: -2^31~+2^31-1
long 64位 范围:-2^63~+2^63-1
2、用于科学计算的浮点类型-2种:
float 32位 范围: -2^31~+2^31-1 有效数字:7位
duble(常用) 64位 范围:-2^63~+2^63-1 有效数字:15~16位
2-1、字面值(有默认类型)
整数:int
小数:double
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{ string name;
//double num=1.123456789123456789; // float-32位,double-64,decimal-128位-金融领域
Console.WriteLine(10.2225); //默认为Double浮点型
Console.ReadLine();
//Console.WriteLine("你的名字是{0}:", name);
//Console.ReadLine();
}
}
}
3、金融计算的浮点类型-1种:
decimal (小数的、小数) 128位 有效数字:28~29位
4、布尔类型-1种:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{ string name;
//double num=1.123456789123456789; // float-32位,double-64,decimal-128位-金融领域
bool a = true; //只有真与假2种类型
Console.WriteLine(a); //默认为Double浮点型
Console.ReadLine();
//Console.WriteLine("你的名字是{0}:", name);
//Console.ReadLine();
}
}
}
5、字符类型-1种:char--1个字符,而string可以理解为char的集合
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{ string name;
//double num=1.123456789123456789; // float-32位,double-64,decimal-128位-金融领域
//bool a = true; //只有真与假2种类型
char a = 'r'; //为单引号
Console.WriteLine(a); //默认为Double浮点型
Console.ReadLine();
//Console.WriteLine("你的名字是{0}:", name);
//Console.ReadLine();
}
}
}
6、字符串类型-1种:string--多个字符,string可以理解为char的集合
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{ string name;
//double num=1.123456789123456789; // float-32位,double-64,decimal-128位-金融领域
//bool a = true; //只有真与假2种类型
char a = 'r'; //为单引号
string b = "123wer";
Console.WriteLine(a); //
Console.WriteLine(b); //
Console.ReadLine();
//Console.WriteLine("你的名字是{0}:", name);
//Console.ReadLine();
}
}
}
7、字符串的关键特征-不可变性
没有机制来修改字符串中的内容,比如小写转大写,只能新建一个字符串,让它成为旧字符串的大写版
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{ string name;
//double num=1.123456789123456789; // float-32位,double-64,decimal-128位-金融领域
//bool a = true; //只有真与假2种类型
//char a = 'r'; //为单引号
string str1;
string str = "123wer";
str1= str.ToUpper();
Console.WriteLine(str1); //
Console.ReadLine();
//Console.WriteLine("你的名字是{0}:", name);
//Console.ReadLine();
}
}
}
8、string与StringBuilder 的区别(引入一个stopwatch秒表测试)
StringBuilder的用法:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Stopwatch 定时器 = new Stopwatch();
定时器.Start();
StringBuilder sb = new StringBuilder(); //大量的字符串修改用StringBuilder效率比较高
for(int i=0;i<10000;i++)
{
sb.Append(i.ToString()); //添加到后面
}
定时器.Stop();
Console.WriteLine(定时器.ElapsedMilliseconds);
//string str1;
//string str = "123wer";
//str1= str.ToUpper();
// Console.WriteLine(str1); //
// Console.ReadLine();
//Console.WriteLine("你的名字是{0}:", name);
Console.ReadLine();
}
}
}