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

C#
C#:小编详谈ASP.NET和JSP技术
C#:小编详谈StringBuilder
C#:使用CSS的8种技巧
C#:C#开发技巧之将图片存入数据库
C#:C#技术点之利用Image制作小动画
C#:C#开发技巧之如何根据年份判断十二生肖
C#:如何制作自动播放的MP3播放器
c#:C#技术利用鼠标绘图
C#:禁用鼠标左键
C#:如何使用匿名方法
C#:小编教你如何实现特殊形状的窗体
C#:在C#应用程序控制输入法
C#:小编教大家实现堆栈
C#:C#中数组知识点的精华
C#:小编谈C#中TextBox控件的应用技巧
C#:小编教大家设置货币值中使用的小数位数
C#:C#中实现倒计时功能
C#:小编教大家创建一个数字时钟
C#:小编教大家如何向ListView控件添加搜索功能
C#:小编浅谈如何在DataGridView控件中验证数据输入

My Prototype in C#


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-14   浏览: 83 ::
收藏到网摘: 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){}
 }
};