黑马程序员-我的入学笔记1-关于C#.net基础

---------------------- <a href="http://edu.csdn.net"target="blank">ASP.Net+Android+IO开发S</a>、<a href="http://edu.csdn.net"target="blank">.Net培训</a>、期待与您交流! ----------------------

  我的入学笔记,当我看到黑马要求我们写学习笔记时,我也想过要写牛一些的笔记,但随着我不断的学习,我觉得黑马的用意,应该是让我们养成写笔记做总结的一个习惯,其实写总结是我们很好的复习的一个过程,加强了我们所学习的东西.作为程序员,我觉得最重要的应该是我们所敲的代码,那些概念性的东西很重要,但我们毕竟不用出书,所以我把笔记与程序相结合,一些比较重要的东西我写在了注释中,下面是我的第一篇笔记:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//这里是调用了命名空间,以后需要进一步的学习

namespace _01基础知识_往往是最重要的_//定义命名空间 空间名不能以数字开头

{   
    class Program
//定义了一个类
    {
        static void Main(string[] args)//定义一个main方法(是程序的入口接口)
        { 

             关于C#.net

            /* .net(dotnet)一般指.NetFremework框架,是一种平台

              C#(sharp)是基于这种平台的一种编程语言,.net上可以用其他编程语言进行编程

             另外现今的Java也是比较流行的一种语言,它只基于Java平台
             .net能够开发1.桌面应用程序 Winform 2.Internet应用程序ASP.net 3.移动平台wp7
             客户机/服务器模式 Clinet/Server  浏览器/服务器模式 Browser/Server 
             IDE 集成开发环境 (Integrated Development)就是VS */
           /*  解决方案包含多个项目,项目中包括多个类,类中包括多个程序块
*/

         

    1,     #region语言的基本框架了解

             /* C++.net C#.net F# 等编程语言 第一层
              * .NetFramework 类库(FCL)    第二层
              * 公共语言运行库(CLR)        第三层
              * 微软操作系统                 第四层 
              * 概念性的东西很重要,最后的真正软件开发,也更容易理解 */

            #endregion

          #region一些输出
            Console.WriteLine("Hello! Word.");
            Console.Write("I can do");
            Console.Write(" it!\n\n");//console.write不换行
            Console.WriteLine("追影,加油!黑马,等着我。NO.1\n");
            Console.WriteLine("*******************************");
            Console.WriteLine("*       这是新的开始          *");
            Console.WriteLine("*******************************\n");
            #endregion

   2,     #region变量的定义
            int number = 24;
            double PI = 3.14;
            char sex = '男';//支持中文 
            string name = "绝影";
            name = "追影";//可以重复赋值
            decimal money = 1000.50M;/
/M用来特指decimal类型

            string zsName = "张三", lsName = "李四";/区分大小写
            int zsAge = 23, lsAge = 25;//变量没有使用过,会有警告,不影响程序的运行,只是资源的浪费
       
   

           /*变量有它独到的命名方法,便于理解变量的意义
             * 匈牙利命名法 strName intNumber,前半部是变量类型
             * SystemNumber 每个单词开头都大写,一般用于全局变量或类名
             * zsName lsName 骆驼命名法,中文与英文相结合
             * PI 简称全用大写,一般用在全局变量 */

            #endregion

  3,      #region +号符和站位符的应用
            //这是有关输出方面的格式
            Console.WriteLine(zsName + "和" + lsName);
            Console.WriteLine("他们的年龄分别是" + zsAge + "," + lsAge);
            Console.WriteLine("\n使用占位符:number={0},PI={1},sex是{3},name是{2}",
               number, PI, name, sex, money);//变量可以是不同类,占位符很好用
            //占位符与加号符的想结合,最后的输出是:我叫追影,今年24,我有1000.5
            Console.WriteLine("{0},{1},我有" + money, "我叫" + name, "今年" + number);

            #endregion

   4,     #region 简单的交换
            int a = 10, b = 3, temp;
            temp = b; b = a; a = temp;//或者是 t=a,a=b,b=t
            Console.WriteLine("\na和b进行了交换 a={0},b={1}", a, b);
            #endregion

   5,      #region 输入符和转义符
            Console.Write("\n你的目标是什么:");
            string input= Console.ReadLine();
            Console.WriteLine("\n吊\b很好,\"{0}\"是个不错的目标",input);//\b表示退一格
            Console.WriteLine("\n\\1\t2\t3\t4\t5");
            Console.WriteLine("\\11\t222\t333\t444\t555\n"); //\n \b \t制表符很好用 开头对齐
            Console.WriteLine(@"我的存储位置是""D:\visual studio 2010\Projects\备战黑马第一天""");
            //@符号在前取消/的功能 可以用“”代替一个“
            #endregion

   6,    #region 练习+ - * / % 算数运算符
            int oneNumber = 10, twoNumber = 20;
            int sumNumber = oneNumber + twoNumber;
            int r = 5;
            double sYuan = r * r * PI;
            int tshirtPrice = 35, trousersPrice = 120;
            int sumPrice = tshirtPrice * 3 + trousersPrice * 2;
            int zsumPrice = (int)(sumPrice * 0.88);//这里用到强制转换(不是什么都可以强制转换)
            Console.WriteLine("\n圆的面积等于" + sYuan);
            Console.WriteLine("oneNumber+twoNumber=" + sumNumber);
            Console.WriteLine("总价是{0},打完8.8折后是{1}", sumPrice, zsumPrice);
            #endregion

  7,      #region自动/强制转换及初次了解Convert.ToInt32()
           
 /* 类型的自动转换 必须是在不失去精度的情况下
              * 类型必须兼容
              * double可以转向int int不能转向double 
              * int=int*double(可以)double=int*int(不可以),字符串是不能强制转换的
              * 转换遵循由大往小转换的规则 */


            a = 10; b = 3;
            double mod = a / b;//它的值不是3.3333,而是3.应该注意,a和b的类型一致,所以必然是int类型
            //解决方案 double mod = a /(b*1.0)

            int intPI = (int)(PI);
            double doublePI = (double)(money);//double转换符
            Console.WriteLine("\nmod的值其实是" + mod);
            Console.WriteLine("强制转换PI为int类型" + intPI);
            Console.WriteLine("强制转换money为double类型" + doublePI);//这里都转换成功了,遵循了由大往小
            string inAge = "24";//这里是字符串
            int intAge = Convert.ToInt32(inAge);//初次用到了调用了类的方法,以后会更多的接触
            int nowAge = 2013 - intAge;
            Console.WriteLine("\n我出生的年份是" + nowAge);

            //Convert.ToString 把任何类型转换成字符串
            string strAge = Convert.ToString(intAge);
            Console.WriteLine("将任何类型转换成字符串" + strAge);
            #endregion

   8,    #region 练习2 /符与取余符%的利用。第一题的输入输出,通过以后的学习可以进一步的完善。
            //第一题 输入输出 求总值平均值 主要是字符串转换成数值 


            Console.Write("\n你好!请输入你的姓名:");
            string nameYou = Console.ReadLine();
            try
            {
                Console.Write("你的语文成绩是多少:");
                int chinese = Convert.ToInt32(Console.ReadLine());
                Console.Write("你的数学成绩是多收:");
                int math = Convert.ToInt32(Console.ReadLine());
                int sumChenji = chinese + math;
                double pinJun = 1.0 * sumChenji / 2
                Console.WriteLine("{0}你好,你的总成绩是{1},平均分是{2}", nameYou, sumChenji, pinJun);
            }
            catch
            {
                Console.Write("你的语文成绩是多少:");
                int chinese = Convert.ToInt32(Console.ReadLine());
                Console.Write("你的数学成绩是多收:");
                int math = Convert.ToInt32(Console.ReadLine());
                int sumChenji = chinese + math;
                double pinJun = 1.0 * sumChenji / 2;\
                Console.WriteLine("{0}你好,你的总成绩是{1},平均分是{2}", nameYou, sumChenji, pinJun);
            }
           
 //通过以后的学习 进一步完善 输入输出,还有关于try/catch


            int zhou = 46;
            int zhouShu = zhou / 7;
            int tianShu = zhou % 7;
            Console.WriteLine("\n{0}天是{1}周零{2}天", zhou, zhouShu, tianShu);
            int miao = 107653;
            int fen = miao / 60;
            int miaoZ = miao % 60;
            int shi = fen / 60;
            int fenZ = fen % 60;
            int tian = shi / 24;
            int shiZ = shi % 24;
            Console.WriteLine("{0}秒合为{1}天,{2}小时,{3}分钟,{4}秒", miao, tian, shiZ, fenZ, miaoZ);
            #endregion

  9,      #region 一元表达式++ +=等 一元有更高的效率,逻辑思路是重点
            //一元在循环中的利用(很好用)
            int Age = 24;
            int sumO = Age++ - 4;//这里注意后加还没加,在表达式后才自加 
            Console.WriteLine("\nAge++后的值是{0},但sumO的值是{1}", Age, sumO);
            
            //初次涉及关系运算符( < >,<=,>=,!=,==)及布尔类型ture,fasle(布尔类型的申明,bool a)
            bool t = Age > sumO;
            bool f = Age < sumO;
            Console.WriteLine("当24大于20时是{0},当小于时是{1}", t, f);

           
/* 逻辑运算符 && || ! 与/或/非 
             * 与 真真为真 真假为假 假真为假 假假为假
             * 或 真真为真 真假为真 假真为真 假假为假
             * 非 非真为假 非假为真 */


            Console.Write("输入你的语文成绩:");
            int yuWen = Convert.ToInt32(Console.ReadLine());
            Console.Write("输入你的数学成绩:");
            int shuXue = Convert.ToInt32(Console.ReadLine());
            bool t1 = yuWen > 90 && shuXue > 90;
            bool t2 = yuWen > 100 || shuXue > 100 || (yuWen > 90 && shuXue > 90);
            Console.WriteLine("当两门都大于90是为{0},当有一门大于100也为{1}", t1, t2);


            // 如何分辨瑞年,以后可以写在类的方法中,方便调用
            Console.WriteLine("\n请输入一个年份:");
            int year1 = Convert.ToInt32(Console.ReadLine());
            bool ruiYear = (year1 % 400 == 0) || ((year1 % 4 == 0) && (year1 % 100 != 0));
            Console.WriteLine("你输入的年份{0}是瑞年吗:It's {1}", year1, ruiYear);


           
/* 逻辑思路问题有意思但要分清楚,逻辑与:当第一个条件为假时后一个条件并没有执行
               逻辑或:当第一个条件为真的时候后一个条件并没有执行 */

            int y = 10, x = 5;
            bool z = ++y > 20 && ++x > 2;
            Console.WriteLine("\ny自加后是{0},但x并没有执行所以是{1}", y, x);
            bool v = ++y > 9 || ++x > 2;
            Console.WriteLine("同理 y自加后是{0},但x并没有执行所以还是{1}", y, x);
           #endregion

  10,     #region 判断语句if if/else 及嵌套 和if elseif else
            Age = 28;
            if (Age > 29)
            {
                Console.WriteLine("\n成立");
                Console.WriteLine("再成立");
            }
            else
            { Console.WriteLine("\n不成立"); }//不加大括号 默认只运行第一句话
            // if else 可以进行嵌套
            
            // if elseif else 更加便于理解

            int ife = 30;
            if (ife > 80)
                Console.WriteLine("ife>80");
            else if (ife > 60)
                Console.WriteLine("ife>60");
            else if (ife > 30)
                Console.WriteLine("ife>30");
            else
                Console.WriteLine("ife<=30");


            if (ife > 60)
                Console.WriteLine("ife>50");
            else                                    //在else中嵌套
            {
                if (ife > 50)
                    Console.WriteLine("ife>50");
                else
                    Console.WriteLine("ife<50");
            }
           #endregion


   11,      #region 判断语句的练习,以后利用循环进行改进
            Console.WriteLine("请输入密码:");
            if (Console.ReadLine() == "888888")
                Console.WriteLine("密码正确,登陆成功");
            else
            {
                Console.WriteLine("请重新输入密码:");
                if (Console.ReadLine() == "888888")
                    Console.WriteLine("密码正确,登陆成功");
                else
                    Console.WriteLine("密码输入有误");
            }

            Console.WriteLine("\n请输入用户名:");//利用循环次数可以让用户有几次的输入机会,直到输入正确
           
string yongHu = Console.ReadLine();//利用循环、选择,输入用户名正确后再输入密码,两个条件都满足后登陆
            Console.WriteLine("请输入密码");   // 有待改进
            string miMa = Console.ReadLine();

            if (yongHu == "admin" && miMa == "888888")
                Console.WriteLine("输入正确");
            else if (yongHu != "dimin")
                Console.WriteLine("用户名不正确");
            else
                Console.WriteLine("密码不正确");

            Console.WriteLine("\n请输入你的年龄");
            int yAge = Convert.ToInt32(Console.ReadLine());
            if (yAge > 18)
                Console.WriteLine("可以查看");
            else if (yAge >= 10)
            {
                Console.WriteLine("你可以查看,请输入Yes或No");
                if (Console.ReadLine() == "Yes")
                    Console.WriteLine("可以查看");
                else if (Console.ReadLine() == "No")
                    Console.WriteLine("退出,你放弃查看");
            }
            else
                Console.WriteLine("不允许查看");
          #endregion

  12,    #region switch/case 的使用(小技巧,标签 flag=true)
            Console.WriteLine("\n请输入李四的年终评定:(A--E)之间");
            input =Console.ReadLine();
            
            bool flag = true;//小技巧 标签 flag=true 如果经过一个语句flag=false 表示运行了这条语句
                             //则下边的一条语句是否执行看前一个是否运行过 条件为if(flag=true)

            int gongZi=5000;

            switch(input)
            {   case "A":
                    gongZi+=500;
                    break;
                case "B":
                    gongZi+=200;
                    break;
                case "C":
                    break;
                case "D":
                    gongZi-=200;
                    break;
                default:
                    Console.WriteLine("你的输入有误");
                    flag=false;
                    break;
                case "F":
                    gongZi-=500;
                    break;
            }
             if (flag==true)
                 Console.WriteLine("你的工资是"+gongZi);
            #endregion

   13,    #region
输入年份月份,得到那个月的天数,以后可以封装成方法
            Console.WriteLine("\n请输入年份:");
            int intNian = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("请输入月份:");
            int intYue = Convert.ToInt32(Console.ReadLine());

            switch (intYue)//括号中也可以是个表达式
            {
                case 4:
                case 6:
                case 8:
                case 10:
                case 12:
                    Console.WriteLine("{0}年{1}月有31天", intNian, intYue);
                    break;
                case 2:
                    if (intNian % 400 == 0 || intNian % 4 == 0 && intNian % 100 != 0)
                        Console.WriteLine("{0}年{1}月有29天", intNian, intYue);
                    else
                        Console.WriteLine("{0}年{1}月有28天", intNian, intYue);
                    break;
                default:
                    Console.WriteLine("{0}年{1}月有30天", intNian, intYue);
                    break;
            }
            #endregion

          Console.ReadKey(); 
        }
    }
}

  我没有写太多的注释,因为之前有学过C语言,过程性的东西还比较了解,学习才刚刚开始,后面的才是重点,努力中.

---------------------- <a href="http://edu.csdn.net"target="blank">ASP.Net+Android+IO开发S</a>、<a href="http://edu.csdn.net"target="blank">.Net培训</a>、期待与您交流! ----------------------

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值