hashcodes.aspx

来自「Professional ASP.NET source code」· ASPX 代码 · 共 94 行

ASPX
94
字号
<%@Page Language="C#"%>
<%@ Import Namespace="System.IO" %>

<script runat=server>

	Hashtable shoppingCart;

		class Product
		{

			public override int GetHashCode()
			{
				return 1;
			}


			public override bool Equals( Object c )
			{
				return true;
			}

		};


	class ShoppingCartItem
	{


		string _productName;
		int _quantityOrdered;

//		 public  override int GetHashCode()
//		{
//			return 1;
//		}

		public override bool Equals( object x )
		{
			return true;
		}
	}
	protected void Page_Load( object sender, EventArgs e )
	{


		/*


		ShoppingCartItem c1 = new ShoppingCartItem();
		ShoppingCartItem c2 = new ShoppingCartItem();

		Hashtable ourSession;
		ourSession = new Hashtable();


		ourSession[c1] = "Wrox";
		ourSession[c2] = "Press";

		foreach( DictionaryEntry entry in ourSession )
		{
			Response.Write("<BR>Key:" + entry.Key + " Value:" + entry.Value );
		}


		Session["key"] = "value";
		Response.Write("<P>value is " + Session["KEY"] );

		ourSession["key"] = "value";
		Response.Write("<P>value is " + ourSession["KEY"] );


*/
		Product a = new Product();
		Product b = new Product();

	
		Response.Write( a.GetHashCode() );
		Response.Write( "<BR>" );
		Response.Write( b.GetHashCode() );


		Hashtable Products = new Hashtable();

		Products[a] = a;
		Products[b] = b;

		Response.Write("<BR>");
		Response.Write( Products.Count );


	}

</script>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?