我的第二个程序--讲解程序执行顺序

一、

1.默认创建的控制台程序,只有一个Program.cs,还有Properties和引用两个项目,如图:

 

2.我们定义一个新的类。Another.cs

代码如下:

Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TestInt
{
    
public class Another
    {
        
public void GetName()
        {
            Console.WriteLine(
"Hello,My name is Another");
        }
    }
}

在这里,我们仅仅只是定义了Another这个类,但是还没开始使用它。

3. 使用Another类。

回到Program.cs里面,增加一下内容

Code
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

// namespace的名字是可以更改的.
namespace TestInt
{
    
//这个类是默认创建的。
    class Program
    {
        
static void Main(string[] args)
        {
            
//实例化一个Another类,这个实例化的变量就是:objAnother
            
//也可以这样理解:Another是"类",objAnother是类的一个"对象"(一个"复制品",也可以叫一个"实例")。
            
//"类",“对象”,“实例”都是名词,知道这个意思就OK了
            Another objAnother = new Another();

            
//我们可以"实例化"更多的Another对象
            Another objAnother1 = new Another();
            Another objAnother2 
= new Another();

            
//获得名字:
            objAnother.GetName();
            
//输出:Hello,My name is Another


            Console.ReadLine();
//让输出屏幕停住一会,等你按了任意键后在关闭。
        }
    }
}

按下F5运行,

得到结果:

 

OK,it's over

二、用调试来看执行顺序:

1.给Another类放置一个断点

2.给Program.cs里面放置一个类:

3.按下F5后,如下图:

4.按下F10后,如图:

继续按F10,直到程序结束。

 

Ok, my story is over.

 

posted @ 2009-05-19 10:12  无尽思绪  阅读(287)  评论(0编辑  收藏  举报