昨天开始的第一篇博客被我这个菜鸟找不到了,那就从今天开始吧废话也不多说了,good good study, day day up!

首先总结一下昨天所学:

  • 从程序的开头开始吧,首先是引用,这里总结一下using的用法:1,。将外部命名空间引入到程序中。2。隐式的调用dispode()释放当前对象
  • 命名空间:命名空间可以嵌套,从里到外的调用
  • Main方法:程序的入口点;从参数角度看有无参型和有参型,有参的参数为string[] args.Main函数是程序的入口点,若有参数,通过其他程序给它传值,不能自己调用自己。从返回值类型看有void和int类型(有返回值的也只能是int类型)(只要方法不是void类型的都需要return 方法是什么类型就return什么类型)

  • .NETFramework:由两部分组成:类库和CLR

  • .NET Framework一次运行两次编译:第一次编译将c#程序编译成中间语言.exe和 .dll文件;第二次编译将.exe和 .dll文件编译成二进制文件(jit)
    第一次靠编译语言,第二次把中间语言编译成机器语言   。第一次编译发在开发过程;第二次编译发生在客户端即运行阶段。

  • 为什么要两次编译?跨平台,方便程序员调用不同语言.不同的语言实现共同开发 可以根据速度和性能的不同选择编译方式。适合两种架构:
    C/S/架构:适合使用一个方法编译哪个
    B/s架构:适合一次编译成。EXE文件

程序小结:

  1. 通过创建快键方式来给程序送参数,也可以通过另个的应用程序调用。
  2. 创建一个KILL进程的小程序
  3. //阻止某些程序的小程序(停止进程)
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.IO;
    using System.Threading;
    using System.Diagnostics;
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                while (true)
                {
                    Thread.Sleep(2000);//使用thread需引用using System.Threading;
                    foreach (Process pro in Process.GetProcesses())
                    {
                        if (pro.ProcessName == "qq")
                        {
                            pro.Kill();
                           
                        }
                    
                }
            }
        }
    }

4.计算代码量的小程序:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace CodesComputer
{
    class Program
    {
        static void Main(string[] args)
        {

//返回给定路径下的代码总行数
            string path = @"F:\我的项目\Service供热\ProvideHeatSystem\CoalitionSystem\Coalition";
            Console.WriteLine(GetCodeCount(path));
        }
        /// <summary>
        /// 递归方法
        /// </summary>
        /// <param name="path">路径</param>
        /// <returns>代码量</returns>
        static int GetCodeCount(string path)
        {
            int count = 0;
            //遍历当前路径下的子文件夹
            foreach (string str in Directory.GetDirectories(path))
            {
                count += GetCodeCount(str);

}
            //遍历当前路径下子文件
            foreach (string str in Directory.GetFiles(path))
            {
                if (Path.GetExtension(str).ToLower() == ".cs")
                {
                    string[] countstrs = File.ReadAllLines(str);
                    foreach (string line in countstrs)
                    {
                        if (line.Trim() != "" && !line.StartsWith("using ") && line != "{" && line != "}")
                        {
                            count++;
                        }
                    }
                }
            }
            return count;
        }
    }
}