您的位置:首页 > 产品设计 > UI/UE

C# NameValueCollection

2012-03-21 22:07 381 查看
一个简单的例子

NameValueCollection markStatus = new NameValueCollection();

string[] values = null;

markStatus.Add("Very High", "80");

markStatus.Add("High", "60");

markStatus.Add("medium", "50");

markStatus.Add("Pass", "40");

foreach (string key in markStatus.Keys)

{

values = markStatus.GetValues(key);

foreach (string value in values)

{

MessageBox.Show (key + " - " + value);

}

}
复制代码

微软网站上的例子

using System;

using System.Collections;

using System.Collections.Specialized;

public class SamplesNameValueCollection { public static void Main() {

// Creates and initializes a new NameValueCollection.

NameValueCollection myCol = new NameValueCollection();

myCol.Add( "red", "rojo" );

myCol.Add( "green", "verde" );

myCol.Add( "blue", "azul" );

myCol.Add( "red", "rouge" );

// Displays the values in the NameValueCollection in two different ways.

Console.WriteLine( "Displays the elements using the AllKeys property and the Item (indexer) property:" );

PrintKeysAndValues( myCol );

Console.WriteLine( "Displays the elements using GetKey and Get:" );

PrintKeysAndValues2( myCol );

// Gets a value either by index or by key.

Console.WriteLine( "Index 1 contains the value {0}.", myCol[1] );

Console.WriteLine( "Key \"red\" has the value {0}.", myCol["red"] );

Console.WriteLine();

// Copies the values to a string array and displays the string array.

String[] myStrArr = new String[myCol.Count];

myCol.CopyTo( myStrArr, 0 );

Console.WriteLine( "The string array contains:" );

foreach ( String s in myStrArr )

Console.WriteLine( " {0}", s );

Console.WriteLine();

// Searches for a key and deletes it.

myCol.Remove( "green" );

Console.WriteLine( "The collection contains the following elements after removing \"green\":" );

PrintKeysAndValues( myCol );

// Clears the entire collection.

myCol.Clear();

Console.WriteLine( "The collection contains the following elements after it is cleared:" );

PrintKeysAndValues( myCol );

}

public static void PrintKeysAndValues( NameValueCollection myCol ) {

Console.WriteLine( " KEY VALUE" );

foreach ( String s in myCol.AllKeys )

Console.WriteLine( " {0,-10} {1}", s, myCol[s] );

Console.WriteLine();

}

public static void PrintKeysAndValues2( NameValueCollection myCol ) {

Console.WriteLine( " [INDEX] KEY VALUE" );

for ( int i = 0; i < myCol.Count; i++ )

Console.WriteLine( " [{0}] {1,-10} {2}", i, myCol.GetKey(i), myCol.Get(i) );

Console.WriteLine();

}

}

/*

This code produces the following output.

Displays the elements using the AllKeys property and the Item (indexer) property:

KEY VALUE

red rojo,rouge

green verde

blue azul

Displays the elements using GetKey and Get:

[INDEX] KEY VALUE

[0] red rojo,rouge

[1] green verde

[2] blue azul

Index 1 contains the value verde.

Key "red" has the value rojo,rouge.

The string array contains:

rojo,rouge

verde

azul

The collection contains the following elements after removing "green":

KEY VALUE

red rojo,rouge

blue azul

The collection contains the following elements after it is cleared:

KEY VALUE

*/

将权限管理、工作流管理做到我能力的极致,一个人只能做好那么很少的几件事情。

About



吉日嘎拉(蒙古语为吉祥如意),2000年毕业于黑龙江大学计算机系软件专业,目前定居杭州,典型的IT软件土鳖一个,外号“软件包工头”。

通用权限管理系统组件(GPM - General Permissions Manager)自2003年开始发布,目前是国内注册用户和免费盗版用户最多的权限管理系统,是各种信息管理系统开发中彻底的权限解决方案。本组件支持多种主流数据库(Oracle、sqlsever、db2、mysql),功能强大,使用方便,代码简洁,思路严谨,被广大支持者称为权限管理系统中的“走火入魔级权限管理系统”。

精心维护通用权限管理系统组件(GPM - General Permissions Manager)有8年多,3年的不断推广,20万行经典的业务逻辑积累,经过上万次的调试修正,经历了四百个付费客户,上百软件公司的实战开发。

11年以上开发经验,外企工作5年,上市公司3年,独立经营软件公司2年,主持研发部门管理工作4年以上。

将权限管理、工作流做到我能力的极致,一个人只能做好那么很少的几件事情。



QQ:252056973,Mail:jirigala_bao@hotmail.com

访问者分布


通用权限管理模块的严谨设计定位、精心编码实现、不断维护推广、持续优化改进,主要是为了实现一个可以高度重复利用劳动成果的工具软件并有偿提供给所需的人们,另想成为国人值得骄傲的知名软件功能模块。

可供国内管理类开发人员在日常工作中进行灵活二次开发利用的模块,开发管理类软件的必备工具之一,我们的目标就是让程序员早点儿回家休息。

淘宝店地址:http://jirigala.taobao.com
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  职场 休闲 null