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();
}
}
}
相关文档:
需要引用的类名空间
using System.Security.Cryptography;
using System.IO;
using System.text;
/// <summary>
/// 加密
// ......
1、用MySQLDriverCS连接MySQL数据库
先下载和安装MySQLDriverCS,地
址:
http://sourceforge.net/projects/mysqldrivercs/
在安装文件夹下面找到
MySQLDriver.dll
,然后将
MySQLDriver.dll
添加引用到项目中
注:我下载的是版本是
MySQLDriverCS-n-EasyQueryTools-4.0.1-DotNet2.0.exe
using
S ......
新建一个专门用来创建验证码图片的页面ValidateCode.aspx
它的后台cs文件代码如下:
PageLoad
private void Page_Load(object sender, System.EventArgs e)
{
string checkCode = CreateRandomCode(4);
Session["CheckCode"] = checkCode;
CreateImage(checkCode);
......
添加引用
using System.Data.OracleClient;
主要用到了两个类
System.Data.OracleClient.OracleConnection 表示一个到数据库的连接。此类无法继承。
System.Data.OracleClient.OracleCommand 表示针对数据库执行的 SQL 语句或存 ......