当前位置: 首页 > 图文教程 > .Net技术 > C# > My Prototype in C#

C#
C#和Java的区别
提高C#编程水平的50个要诀
GridView 删除/更新/取消
c#线程
C#泛型有什么好处
总体了解C#
C#2.0匿名函数
GridView中添加一个CheckBox列
C#2.0介绍之Iterators(迭代器)
.NET与Java间进行Web Service交互的选择
C# 2010命名和可选参数的新特性
利用C#远程存取Access数据库
C#中foreach基础使用方法
C#中用鼠标移动页面功能的实现
C# 4.0中泛型协变性和逆变性详解
C#:C# .Net中的类型相互转换教程
C#:C#中的基元类型
C#:语言中的重要知识详细介绍与解释
C#:浅谈C#中的集合对象(Collections)
C#:C#发起邮件会议

My Prototype in C#


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-14   浏览: 82 ::
收藏到网摘: n/a

//MyPrototype
using System;
using System.Collections;
//abstract PageStylePrototype Class 'Prototype
abstract class PageStylePrototype
{  
 //Fields
 protected string stylestring;
 //Properties
 public string StyleString
 {
   get{return stylestring;}
   set{stylestring=value;}
 }
 //Methods
 abstract public PageStylePrototype Clone();
};
//---PageStyle Class---
class PageStyle:PageStylePrototype
{
 //Constructor
 public PageStyle(String stylestr)
 {
  StyleString=stylestr;
 }
 override public PageStylePrototype Clone()
 {
  return (PageStylePrototype)this.MemberwiseClone();
 }

 public void DisplayStyle()
 {
  Console.WriteLine(StyleString);
 }

};
//--------------------------------------------End of Style Class
//StyleManager Class
class StyleManager
{
 //Fields
 protected Hashtable styleht=new Hashtable();
 protected PageStylePrototype styleref;

 //Constructors
    public StyleManager()
 {
        styleref=new PageStyle("thefirststyle");
  styleht.Add("style1",styleref);

  styleref=new PageStyle("thesecondstyle");
  styleht.Add("style2",styleref);
  
  styleref=new PageStyle("thethirdstyle");
  styleht.Add("style3",styleref);
 }

 //Indexers
 public PageStylePrototype this[string key]
 {
  get{ return (PageStylePrototype)styleht[key];}
  set{ styleht.Add(key,value);}
 }
};
//--------------------------------------------End of StyleManager Class
//TestApp
class TestApp
{
 public static void Main(string[] args)
 {
  StyleManager stylemanager =new StyleManager();

  PageStyle stylea =(PageStyle)stylemanager["style1"].Clone();
  PageStyle styleb =(PageStyle)stylemanager["style2"].Clone();
  PageStyle stylec =(PageStyle)stylemanager["style3"].Clone();

  stylemanager["style4"]=new PageStyle("theforthstyle");

  PageStyle styled =(PageStyle)stylemanager["style4"].Clone();
  
  stylea.DisplayStyle();
  styleb.DisplayStyle();
  stylec.DisplayStyle();
  styled.DisplayStyle();

  while(true){}
 }
};