日期:<?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" />2008-6-6
学习内容:配置.net运行环境,c#中命名空间,c#.net 2005编码规范
遗留问题: visual studio.net环境中如何把文件编译成.dll文件? <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

学习总结:

1.       配置.net运行环境
第一歩:安装.net framework
第二歩:找到.net framework的安装目录下的csc.exe文件,这个文件为.net framework的编译器
第三步:将csc.exe的安装目录放到系统环境变量中
第四歩:在运行里打cmd命令,掉出dos窗口,在命令提示符下键入csc,系统显示.netframe work的相关信息
第五歩:.net运行环境配置完成
第六歩:编写**.cs文件,放在只定的目录下
7歩:在dos窗口下键入**.cs文件所在的目录,然后键入csc **.cs,系统显示编译完成提示,另一种方法是不用进入**.cs所在的目录,在命令提示符下直接键入 csc /out 生成的.exe文件输出位置   **.cs所在的目录
2.       c#中的命名空间
使用命名空间的好处:
避免命名冲突的问题(在不同命名空间下的类名等可以相同)
代码可存在多个文件中
命名空间具有扩展性,可在同一命名空间下定义多个类
可以堆砌出层次式的类组织结构
使用using 命名空间的作用:避免使用完全限定名
using System;

using System.Collections.Generic;

using System.Text;

 

namespace ConsoleApplication1

{

    class Program

    {

        static void Main(string[] args)

        {

            A.B.Hello test=new A.B.Hello();

            test.GetInfo();

        }

    }

}

// 命名空间的层次组织

namespace A

{

    namespace B

    {

       public class Hello

       {

           public void  GetInfo()

           {

                Console.WriteLine("c# 欢迎您!" );

           }

       }

    }

}

 

using System;

using System.Collections.Generic;

using System.Text;

using A.B;// 使用using语句避免了在调用时使用完全限定名

 

namespace ConsoleApplication1

{

    class Program

    {

        static void Main(string[] args)

        {

            Hello test=new Hello();

            test.GetInfo();

        }

    }

}

// 命名空间的层次组织

namespace A

{

    namespace B

    {

       public class Hello

       {

           public void  GetInfo()

           {

                Console.WriteLine("c# 欢迎您!" );

           }

       }

    }

}

 

using System;

using System.Collections.Generic;

using System.Text;

using a=A.B;// 使用别名

 

namespace ConsoleApplication1

{

    class Program

    {

        static void Main(string[] args)

        {

            a.Hello test=new a.Hello();

            test.GetInfo();

        }

    }

}

// 命名空间的层次组织

namespace A

{

    namespace B

    {

       public class Hello

       {

           public void  GetInfo()

           {

                Console.WriteLine("c# 欢迎您!" );

           }

       }

    }

}

将代码分布在不同的文件中:

using System;

using System.Collections.Generic;

using System.Text;

 

namespace ConsoleApplication1

{

    // 定义程序的入口点,并调用Class1.cs文件

    class Program

    {

        static void Main(string[] args)

        {

            Class1 test = new Class1();

            test.GetInfo();

        }

    }

}

using System;

using System.Collections.Generic;

using System.Text;

 

namespace ConsoleApplication1

{

    // 定义Class1,并在类中定义了一个GetInfo方法,Program.cs调用

    class Class1

    {

        public void GetInfo()

        {

            Console.WriteLine("c# 欢迎您!" );

        }

    }

}

.net framwork中同时编译两个文件的命令:csc Class1.cs Program.cs

另一种方法:将Class1.cs编译成.dll文件,供Program.cs调用

命令是:csc / target library Class1.cs  Class1.cs编译成.dll文件,然后编译Program.cs的命令是:csc /reference:Class1.dll Program.cs

运行命令是:/reference:Class1.dll Program.exe

3.       c#.net 2005编码规范
注释规范
变量命名规范
常量命名规范
类命名规范
资源命名规范
接口,方法,名字空间命名规范
具体内容参考 c#.net 3.0第一步 p838