C#编程入门1

//引入命名空间
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


/*
 * 多行注释
 * 这是1707A班的第一个程序
 * 
 */

//这是一个单行注释

//namespace  命名空间
namespace FirstProject
{
    //class  类
    class Program
    {
        /// <summary>
        /// 这是一个块注释
        /// 这是一个方法   方法又叫做函数
        /// 下面的方法是Main方法  是程序的唯一入口
        /// </summary>
        /// <param name="args">这是一个字符串数组类型的参数</param>
        static void Main(string[] args)
        {
            //控制台输出的快捷键  cw + Tab两次
            //括号中的双引号是英文的
            //Console.WriteLine(); 是控制台的输出指令   就是在屏幕上显示内容
            //运行 Ctrl + F5
            //每一行代码都要用;号结尾 ;必须是英文的
            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 基本的数据类型
{
    //C#常用的关键字
    /*
     * 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);
            //这是字符串常量 就是一段文本
            //字符串的长度取值范围是大于等于0的
            Console.WriteLine("凤兮凤兮归故乡");

            //这是一个字符常量   字符的长度必须是1
            Console.WriteLine('男');

            //字符常量和字符串常量的区别:
            //羊肉和羊肉串的关系
            //用""扩起来的就是字符串
            //用''扩起来的就是字符
            Console.WriteLine("男");
            Console.WriteLine('男');
            //布尔值就两个  true 和 false 
            Console.WriteLine(true);
            //Console.WriteLine();  表示一个换行
            Console.WriteLine();
            Console.WriteLine(false);


            //在屏幕上打印出yy 后并换行
            Console.WriteLine("nn");
            //只在屏幕上打印出123  不会换行
            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-(28次方-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
    {
        /*
         * 做一个类似注册的一个界面
            用户名  密码  性别  年龄  工资 家庭住址  是否已婚
            打印出这样的内容"谢谢{0}的配合,请确认您的用户名{1},密码:{2},性别:{3},婚姻:{4},其他信息我们将会做为隐私!!"
         */
        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);

        }
    }
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值