当前位置:首页 > 网上商城 > 正文内容

数据字典是什么呀??谁能举个最简单的例子??是例子哦!!

淘梦者2022-02-08 12:56:11网上商城50

Dictionary,表示键和值的集合。
用泛型类举例吧
Dictionary) 泛型类
using System;
using System.Collections.Generic;

public class Example
{
public static void Main()
{
// Create a new dictionary of strings, with string keys.
//
Dictionary openWith =
new Dictionary();

// Add some elements to the dictionary. There are no
// duplicate keys, but some of the values are duplicates.
openWith.Add(txt, notepad.exe);
openWith.Add(bmp, paint.exe);
openWith.Add(dib, paint.exe);
openWith.Add(rtf, wordpad.exe);

// The Add method throws an exception if the new key is
// already in the dictionary.
try
{
openWith.Add(txt, winword.exe);
}
catch (ArgumentException)
{
Console.WriteLine(An element with Key = txt already exists.);
}

// The Item property is another name for the indexer, so you
// can omit its name when accessing elements.
Console.WriteLine(For key = rtf, value = {0}.,
openWith[rtf]);

// The indexer can be used to change the value associated
// with a key.
openWith[rtf] = winword.exe;
Console.WriteLine(For key = rtf, value = {0}.,
openWith[rtf]);

// If a key does not exist, setting the indexer for that key
// adds a new key/value pair.
openWith[doc] = winword.exe;

// The indexer throws an exception if the requested key is
// not in the dictionary.
try
{
Console.WriteLine(For key = tif, value = {0}.,
openWith[tif]);
}
catch (KeyNotFoundException)
{
Console.WriteLine(Key = tif is not found.);
}

// When a program often has to try keys that turn out not to
// be in the dictionary, TryGetValue can be a more efficient
// way to retrieve values.
string value = ;
if (openWith.TryGetValue(tif, out value))
{
Console.WriteLine(For key = tif, value = {0}., value);
}
else
{
Console.WriteLine(Key = tif is not found.);
}

// ContainsKey can be used to test keys before inserting
// them.
if (!openWith.ContainsKey(ht))
{
openWith.Add(ht, hypertrm.exe);
Console.WriteLine(Value added for key = ht: {0},
openWith[ht]);
}

// When you use foreach to enumerate dictionary elements,
// the elements are retrieved as KeyValuePair objects.
Console.WriteLine();
foreach( KeyValuePair kvp in openWith )
{
Console.WriteLine(Key = {0}, Value = {1},
kvp.Key, kvp.Value);
}

// To get the values alone, use the Values property.
Dictionary.ValueCollection valueColl =
openWith.Values;

// The elements of the ValueCollection are strongly typed
// with the type that was specified for dictionary values.
Console.WriteLine();
foreach( string s in valueColl )
{
Console.WriteLine(Value = {0}, s);
}

// To get the keys alone, use the Keys property.
Dictionary.KeyCollection keyColl =
openWith.Keys;

// The elements of the KeyCollection are strongly typed
// with the type that was specified for dictionary keys.
Console.WriteLine();
foreach( string s in keyColl )
{
Console.WriteLine(Key = {0}, s);
}

// Use the Remove method to remove a key/value pair.
Console.WriteLine(nRemove(doc));
openWith.Remove(doc);

if (!openWith.ContainsKey(doc))
{
Console.WriteLine(Key doc is not found.);
}
}
}

分享给朋友:

相关文章

为什么支付宝推荐优先用花呗付款?

为什么支付宝推荐优先用花呗付款?

本质:养猪。 把猪养大了,然后好杀掉。 本来你有100块钱,买了100块钱的商品之后,你就没有钱了。 又看上一件商品,这时候你会咬紧牙关,等有钱了再买。 现在有了花呗。 同样的你有100块钱,用花呗付款了。你还是有100块钱,花呗里欠的钱你...

上海钢银电子商务股份有限公司是什么性质企业?

上海钢银电子商务股份有限公司是什么性质企业?

上海钢银电子商务股份有限公司是民营上市公司。于2008年正式注册成立,是国内大型B2B钢铁全产业链智慧服务平台,也是国内钢铁电商第一个千亿平台。 钢银电商凭借多年的行业深耕和智慧服务,逐渐发展成为国内产业互联网的标杆性企业。 2015年12...

现在苏宁的商品线上线下是一个价吗

现在苏宁的商品线上线下是一个价吗

标价一样,但是线上长期是活动价,线下就没有!!所以这么说吧,一年365天,有360天线上便宜!!!苏宁这么大的公司老是玩这些文字游戏,迟早会完蛋的! 苏宁易购网上和实体店价格一样吗 价格不会完全一样。虽然目前苏宁也有规定说实体店的价格和易购...

苹果手机壳官网正品?

苹果手机壳官网正品?

苹果手机壳正品可以在苹果官网下单购买过,也可以在苹果天猫旗舰店下单,也可以在京东自营平台购买,还有唯品会苹果自营店,还有拼多多苹果自营店下单购买!这些平台是苹果官方授权的所以都是正品!价格和线下苹果店品质都是一样的! 京东买iphone12...

专属的时尚购物网客服电话什么

专属的时尚购物网客服电话什么

我来给你说。公司免费客服客服电话:0571-8758-2591(退款、投诉、退货、认证、差评、提现、无法上下架、账户疑问、解绑、资金疑问等==) 在这互联网高速开展的年代,网购已经成为许多人最重要的购物方法,吃的穿的用的,许多人觉得逛街费事...

我在网上买的是电子票,可以在三亚免税店购物吗

我在网上买的是电子票,可以在三亚免税店购物吗

  你好!  可以购物的!只要拿你的身份证和航班号码去前台那边办个购物牌,就可以在免税店里购物了,但东西要在飞机场才能拿到货的!  温馨小提示(*^__^*) : 三亚适合旅游,选择自助游的朋友可以从行、住、吃、玩、购等五个方面着手;  首...