using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace FirstProject
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello World");
Console.WriteLine("nn");
Console.WriteLine("swz");
}
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
C#中常用的关键字
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 基本的数据类型
{
/*
* abstract 抽象
* as 像
* base 基础
* bool 布尔
* break 中断
* byte 字节
* case 案例
* catch 捕捉
* char 字符
* checked 检查
* class 类
* const 常数
* continue 继续
* decimal 表示金额的浮点类型
* default 默认
* delegate 委托
* do 做
* double 双精度
* else 否则
* enum 枚举
* event 事件
* extern 额外的
* false 错误的
* finally 最后的
* float 单精度的浮点
* for 循环
* foreach 循环每一个
* goto 跳转
* if 如果
* in 在...里面
* int 整数
* interface 接口
* internal 内部的
* is 是
* lock 锁
* long 长整型
* namespace 命名空间
* new 新的,隐藏
* null 空
* object 物体,对象
* operator 操作符
* out 出来
* override 重写
* params 参数
* private 私有
* protected受保护的
* public 公开的
* readonly 只读的
* ref 引用
* return 返回
* sbyte 字节
* sealed 密封
* short 短整型
* static 静态的
* string 字符串
* struct 结构
* switch 开关
* this 这个 本身
* throw 抛出
* true 正确的
* try 尝试
* typeof 类型
* uint 整型
* ulong 整型
* ushort 短整型
* using 使用
* virtual 虚拟的
* void 空
* while 当
*/
class Program
{
static void Main(string[] args)
{
Console.WriteLine(100);
Console.WriteLine(12.5);
Console.WriteLine("凤兮凤兮归故乡");
Console.WriteLine('男');
Console.WriteLine("男");
Console.WriteLine('男');
Console.WriteLine(true);
Console.WriteLine();
Console.WriteLine(false);
Console.WriteLine("nn");
Console.Write("123");
Console.WriteLine("*****************");
Console.Write("123456\n");
}
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
声明变量和基本的数据类型
using System
using System.Collections.Generic
using System.Linq
using System.Text
using System.Threading.Tasks
namespace 数据类型和变量
{
class Program
{
static void Main(string[] args)
{
//声明变量
int temp
//初始化 或者是赋值
temp = 12
//变量相当于一个容器
// 声明变量并初始化
byte num1 = 12
byte num2 = 5
//声明变量的时候是不能重复命名
short num3 = 13
Console.WriteLine(num3)
int num4 = 15
Console.WriteLine(num4)
long num5 = 100
Console.WriteLine(num5)
Console.WriteLine(num1 * num2)
//byte short int long 都可以表示整数 但是他们的取值范围不一样
Console.WriteLine("---------------------------")
//byte的取值范围是0-255 或者就是0-(2的8次方-1)
Console.WriteLine(byte.MinValue)
Console.WriteLine(byte.MaxValue)
Console.WriteLine("short的取值范围")
Console.WriteLine(short.MinValue)
Console.WriteLine(short.MaxValue)
Console.WriteLine("int的取值范围")
Console.WriteLine(int.MinValue)
Console.WriteLine(int.MaxValue)
Console.WriteLine("long的取值范围")
Console.WriteLine(long.MinValue)
Console.WriteLine(long.MaxValue)
Console.WriteLine("---------------------")
//sbyte ushort uint ulong
Console.WriteLine(sbyte.MinValue)
Console.WriteLine(sbyte.MaxValue)
Console.WriteLine("ushort的取值范围")
Console.WriteLine(ushort.MinValue)
Console.WriteLine(ushort.MaxValue)
Console.WriteLine("uint的取值范围")
Console.WriteLine(uint.MinValue)
Console.WriteLine(uint.MaxValue)
Console.WriteLine("ulong的取值范围")
Console.WriteLine(ulong.MinValue)
Console.WriteLine(ulong.MaxValue)
Console.WriteLine("下面是浮点数")
//float double decimal
//浮点数就是我们通常说的小数
float height = 1.80f
Console.WriteLine(height)
double price = 12.5
Console.WriteLine(price)
decimal money = 123456.12M
//float 类型是一个单精度的浮点数 能精确到小数点后的5-6位
//double l类型是一个双精度的浮点数 能精确到小数点后14-15位
//decimal 类型 能精确到小数点后128位
Console.WriteLine(float.MinValue)
Console.WriteLine(float.MaxValue)
Console.WriteLine(double.MinValue)
Console.WriteLine(double.MaxValue)
Console.WriteLine(decimal.MinValue)
Console.WriteLine(decimal.MaxValue)
Console.WriteLine("---------------布尔值-----------")
bool isTrue = true
Console.WriteLine(isTrue)
isTrue = false
Console.WriteLine(isTrue)
//布尔类型的值只有两个 true 或者false
Console.WriteLine("----------------字符----------")
//字符的长度只能是1 多了少了都不行 并且是用单引号括起来的
char gender = '男'
Console.WriteLine(gender)
char level = 'A'
Console.WriteLine(level)
//总结:声明变量的时候的格式: 类型 变量名 = 常量或变量名
//在程序里面 = 不是正真意义上的等号 而是赋值号
//变量名遵循的是小驼峰命名法
//小驼峰命名法:首单词的首字母要小写其他单词的首字符全大写 剩下字母全小写
//变量名是不能重复声明 但是可以重复使用
Console.WriteLine("***************字符串***********")
string username = "花开一诺"
string password = "123456789"
//我们打印一个变量的时候,控制台上显示的是变量中保存的内容
Console.WriteLine(username)
Console.WriteLine(password)
//以下代码和上面的变量username是不同的,下面的标识一个常量"username"
Console.WriteLine("username")
Console.WriteLine("**********模拟登陆的界面*********")
Console.WriteLine("请输入用户名:")
//下面的代码是用来接收键盘上的数据
username = Console.ReadLine()
//把username从键盘上接收到的数据打印出来
Console.WriteLine("请输入密码")
password = Console.ReadLine()
//下面的{数字} 表示一个占位符
//占位符 索引是从0开始的,以后依次递增
Console.WriteLine("控制台接收的用户名是:{0},密码是:{1}",username,password)
Console.WriteLine("数字1:{0},数字2:{1},数字3:{2}",56,78,99)
}
}
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
控制台的输入输出
using System
using System.Collections.Generic
using System.Linq
using System.Text
using System.Threading.Tasks
namespace 练习
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("请输入用户名:")
string username = Console.ReadLine()
Console.WriteLine("请输入密码:")
string password = Console.ReadLine()
Console.WriteLine("请输入性别:")
//char gender = char.Parse(Console.ReadLine())
string genderStr = Console.ReadLine()
char gender = char.Parse(genderStr)
Console.WriteLine("请输入年龄:")
int age = int.Parse(Console.ReadLine())
Console.WriteLine("请输入您的薪资")
double salary = double.Parse(Console.ReadLine())
Console.WriteLine("请输入家庭住址")
string address = Console.ReadLine()
Console.WriteLine("是否已婚")
bool isMarray = bool.Parse(Console.ReadLine())
//Console.WriteLine("谢谢{0}的配合,请确认您的用户名{1},密码:{2},性别:{3},婚姻:{4},其他信息我们将会做为隐私!!",username,username,password,gender,isMarray)
Console.WriteLine("谢谢{0}的配合,请确认您的用户名{0},密码:{1},性别:{2},婚姻:{3},其他信息我们将会做为隐私!!", username, password, gender, isMarray)
}
}
}