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>
......
[System.Runtime.Serialization.DataMemberAttribute()]
public Information Archive {
get {
&n ......
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.OleDb;
/// <summary>
/// Data ......
添加引用
using System.Data.OracleClient;
主要用到了两个类
System.Data.OracleClient.OracleConnection 表示一个到数据库的连接。此类无法继承。
System.Data.OracleClient.OracleCommand 表示针对数据库执行的 SQL 语句或存 ......
从ContainerControl类继承的子类作为容器窗体,可以容纳除Form类对象外的其余窗体对象。
在所有容器窗体内,最基本的就是顶级容器Form类以及面板容器Panel类。这两者的主要区别为:前者具有Windows标准框架(标题栏,最大化、最小化和关闭按钮,窗体边框,可调整尺寸),并且可以独立存在;后者只是一块区域,并且必须依附 ......