⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 1.cs

📁 东软内部材料(四)asp等相关的教学案例 
💻 CS
字号:

using System.Collections;
using System;

public struct Person
{
    public string Name;
    public int Age;
}


public class MainClass
{
	public static void Main()
	{
		Hashtable dictionary;
		Person p;

		// Create a Hastable - this is a reference type, so we use New
		// to create the object on the managed CLR heap.

		dictionary = new Hashtable();

		// Setup our Person Structure - This is value type, so we do
		// not use New, and the type is just allocated on the stack.

		p.Name = "Richard Anderson";
		p.Age = 29;

		// Add our Person value type to the dictionary.  This will cause
		// the value type to be boxed within a reference type, and added
		// to the dictionary.

		dictionary.Add( "Rich", p );

		// Setup the value type (overwriting the old values)

		p.Name = "Sam Anderson";
		p.Age = 28;
		
		// Add our Person value type to the dictionary.  Again, this will cause
		// the value type to be boxed within a reference type and adde to the
		// dictionary.

		dictionary.Add( "Sam", p );

		// Retreive a person by Name.  The CType keyword tells VB that
		// the object type returned by the Item function is a Person
		// type.  Since the Person type is a value type, the CLR knows
		// to unbox the Person type from the returned object type.

		p = (Person)dictionary["Rich"];

		// We use the Person type

		Console.WriteLine("Name is {0} and Age is {1}",
			p.Name, p.Age );
		
	}

}

⌨️ 快捷键说明

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