您可以在这里快速查找:


 
您的位置: 编程学习 > asp.net教程 > 200509
文章分类

Java技术
2005: 03 04 05 06 07 08
09 10 11 12
2006: 01 02

Asp.net
2005: 07 08 09 10 11 12
2006: 01 02

VB编程
2006: 02

Asp编程
2005: 11 12
2006: 01 02

C++/VC
2005: 10 11 12
2006: 01 02

Delphi
2005: 12
2006: 01 02

其它

 本文章适合所有读者

My Prototype in C#

beautyispower

//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){}
 }
};