VS2010 生成序列图实例

今天我用一个非常非常简单的代码实例来体验一下VS2010生成序列图的过程:很简单,希望大家不要拍砖啊:)

例子:声明一个学生类,一个课程类,在主程序中让学生学一个课,就这么简单:)上代码:

课程类:

 using System;

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

namespace ConsoleApplication1
{
    class Course
    {
        public string CourseName { getset; }

        public void ResetCouseName()
        {
            this.CourseName = "R&S";
        }
    }
}

学生类:

 using System;

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

namespace ConsoleApplication1
{
    class Student
    {
        public string StudentName { getset; }

        public List<Course> SelectedCouses = new List<Course>();

        public void AddCourse(Course c)
        {

            this.SelectedCouses.Add(c);
        }

        public void ResetAllTheCourse()
        {
            foreach (var item in SelectedCouses)
            {
                item.ResetCouseName();
            }
        }
    }
}

程序入口:

 using System;

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

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Student s = new Student();
            Course chineseCourse = new Course();
            chineseCourse.CourseName = "Chinese";

            Course englishCourse = new Course();
            englishCourse.CourseName = "english";

            s.AddCourse(chineseCourse);
            s.AddCourse(englishCourse);

            foreach (Course item in s.SelectedCouses)
            {
                Console.WriteLine(item.CourseName);   
            }
            Console.Read();
        }
    }
}

最后,如果点击生成序列图

 

然后得到图: 

 

然后结束,至于序列图是什么概念,有图有真相,看图就可以明白怎么玩的了:) 

 

posted @ 2012-03-04 22:35  chunchill  阅读(4798)  评论(0编辑  收藏  举报