c# 将枚举作为键值的形式存储
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
namespace 将枚举作为键值的形式存储
{
enum Myenum
{
First=3,
Second,
Third
}
class Program
{
static void Main(string[] args)
{
//用hashtable可以实现吗? NameValueCollection可以实现吗?
Dictionary<string, int> dictionary = new Dictionary<string, int>();
string [] enumArray=Enum.GetNames(typeof(Myenum));
for (int i = 0; i < enumArray.Length; i++)
{
dictionary.Add(enumArray[i],(int) Enum.Parse(typeof(Myenum), enumArray[i]));
}
Console.WriteLine(dictionary["First"]);
Console.WriteLine(dictionary["Second"]);
Console.WriteLine(dictionary["Third"]);
Console.Read();
}
}
}
相关文档:
用c#给PDA做了一个PC端的通讯程序,需要保存两个参数。用Delphi时,是保存在ini文件中,c#读写XML比较方便,就用xml文件来保存了。
class CXmlClass
{
private string XmlFilePath;
/// <summary>
/// 下载到PDA的TXT文件路径
/// </summary>
......
已知有一个XML文件(bookstore.xml)如下:
<?xml version="1.0" encoding="gb2312"?>
<bookstore>
<book genre="fantasy" ISBN="2-3631-4">
<title>Oberon's Legacy</title>
<author>Corets, Eva</author>
<price>5.95</price> ......
C# access日期查询加#
if (((string)((ComboBoxItem)cmbField.SelectedItem).Value).Equals("System.DateTime"))
{
//判断日期的;
& ......
//以下来自:http://msdn.microsoft.com/zh-cn/library/sf985hc5.aspx
abstract(C# 参考)
更新:2007 年 11 月
abstract 修饰符可以和类、方法、属性、索引器及事件一起使用。在类声明中使用 abstract 修饰符以指示某个类只能是其他类的基类。标记为抽象或包含在抽象类中的成员必须通过从抽象类派生的类来实现。
示例 ......
从ContainerControl类继承的子类作为容器窗体,可以容纳除Form类对象外的其余窗体对象。
在所有容器窗体内,最基本的就是顶级容器Form类以及面板容器Panel类。这两者的主要区别为:前者具有Windows标准框架(标题栏,最大化、最小化和关闭按钮,窗体边框,可调整尺寸),并且可以独立存在;后者只是一块区域,并且必须依附 ......