bool b1 = true;
bool b2 = false;
Console.WriteLine(b1 + "_" + b2);
//char(字符)
char ch = 'A';
Console.WriteLine("ch的值为"+ch);
//string(字符串)
string str = "我要认认真真学CSharp";
Console.WriteLine(str);
#endregion
int sbyteSize = sizeof(sbyte);
Console.WriteLine("sbyte所占的字节数为:" + sbyteSize);
int shortSize = sizeof(short);
Console.WriteLine("short所占的字节数为:" + shortSize);
int intSize = sizeof(int);
Console.WriteLine("int所占的字节数为:" + intSize);
int longSize = sizeof(long);
Console.WriteLine("long所占的字节数为:" + longSize);
Console.WriteLine("*********************************************");
int byteSize = sizeof(byte);
Console.WriteLine("byte所占的字节数为:" + byteSize);
int uintSize = sizeof(uint);
Console.WriteLine("uint所占的字节数为:" + uintSize);
int ushortSize = sizeof(ushort);
Console.WriteLine("ushort所占的字节数为:" + ushortSize);
int ulongSize = sizeof(ulong);
Console.WriteLine("ulong所占的字节数为:" + ulongSize);
Console.WriteLine("*********************************************");
int floatSize = sizeof(float);
Console.WriteLine("float所占的字节数为:" + floatSize);
int doubleSize = sizeof(double);
Console.WriteLine("double所占的字节数为:" + doubleSize);
int decimalSize = sizeof(decimal);
Console.WriteLine("decimal所占的字节数为:" + decimalSize);
Console.WriteLine("*********************************************");
int boolSize = sizeof(bool);
Console.WriteLine("bool所占的字节数为:" + boolSize);
int charSize = sizeof(char);
Console.WriteLine("char所占的字节数为:" + charSize);
}
}
}
![](https://img-blog.csdnimg.cn/e0f23b21cbe84a63b49c62001aac294e.png)
## 常量
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CSharp入门_常量
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(“常量”);
//常量使用关键字const
const int c = 1;
Console.WriteLine(“c的值为”+c);
//常量特点:必须初始化,不可以更改
//使用常量的场景:声明一些常用的不变的量,如π
}
}
}
![](https://img-blog.csdnimg.cn/fd1de7f120964a248575495879dd579e.png)
## 转义字符
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace CSharp入门_转义字符
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(“转义字符”);
/*
* 转义字符的使用
*/
//单引号 ’
string str1 = “‘哈哈哈’”;
Console.WriteLine("str1 = "+str1);
//双引号 "
string str2 = ““CSharp太好学啦!””;
Console.WriteLine("str2 = " + str2);
//换行 \n
string str3 = ““CSharp\n太好学啦!””;
Console.WriteLine("str3 = " + str3);
//斜杠 \
string str4 = ““CSharp\太好学啦!””;
Console.WriteLine("str4 = " + str4);
/*
* 下面的是不太常用的转义字符
*
*/
//制表符 \t (空一个tab键)
string str5 = "我要好好学\t编程";
Console.WriteLine("str5 = " + str5);
//光标退格 \b (光标退一格进行覆盖)
string str6 = "我要好好学\b编程";
Console.WriteLine("str6 = "