C#将HashTable中键列表或值列表复制到一维数组的方法
作者:heishui 发布时间:2022-01-05 22:12:12
标签:C#,HashTable
本文实例讲述了C#将HashTable中键列表或值列表复制到一维数组的方法。分享给大家供大家参考。具体如下:
下面的示例说明如何将 Hashtable 中键的列表或值的列表复制到一维 Array 中。
using System;
using System.Collections;
public class SamplesHashtable {
public static void Main() {
// Creates and initializes the source Hashtable.
Hashtable mySourceHT = new Hashtable();
mySourceHT.Add( "A", "valueA" );
mySourceHT.Add( "B", "valueB" );
// Creates and initializes the one-dimensional target Array.
String[] myTargetArray = new String[15];
myTargetArray[0] = "The";
myTargetArray[1] = "quick";
myTargetArray[2] = "brown";
myTargetArray[3] = "fox";
myTargetArray[4] = "jumped";
myTargetArray[5] = "over";
myTargetArray[6] = "the";
myTargetArray[7] = "lazy";
myTargetArray[8] = "dog";
// Displays the values of the target Array.
Console.WriteLine( "The target Array contains the following before:" );
PrintValues( myTargetArray, ' ' );
// Copies the keys in the source Hashtable to the target Hashtable, starting at index 6.
Console.WriteLine( "After copying the keys, starting at index 6:" );
mySourceHT.Keys.CopyTo( myTargetArray, 6 );
// Displays the values of the target Array.
PrintValues( myTargetArray, ' ' );
// Copies the values in the source Hashtable to the target Hashtable, starting at index 6.
Console.WriteLine( "After copying the values, starting at index 6:" );
mySourceHT.Values.CopyTo( myTargetArray, 6 );
// Displays the values of the target Array.
PrintValues( myTargetArray, ' ' );
}
public static void PrintValues( String[] myArr, char mySeparator ) {
for ( int i = 0; i < myArr.Length; i++ )
Console.Write( "{0}{1}", mySeparator, myArr[i] );
Console.WriteLine();
}
}
/*
This code produces the following output.
The target Array contains the following before:
The quick brown fox jumped over the lazy dog
After copying the keys, starting at index 6:
The quick brown fox jumped over B A dog
After copying the values, starting at index 6:
The quick brown fox jumped over valueB valueA dog
*/
希望本文所述对大家的C#程序设计有所帮助。


猜你喜欢
- 在编写程序时经常会使用到调用可执行程序的情况,本文将简单介绍C#调用exe的方法。在C#中,通过Process类来进行进程操作。 Proce
- 前言spring中解析元素最重要的一个对象应该就属于 BeanDefinition了;这个Spring容器中最基本的内部数据结构;它让xml
- 随着目前微信越来越火,所以研究微信的人也就越来越多,这不前一段时间,我们公司就让我做一个微信公众号中问卷调查发红包功能,经过一段时间的研究,
- 今天一个读者问我关于Android通过调用Webservice实现天气预报这篇文章的源码下载后出现的错误Could not find cla
- 我们今天来聊下如何做实时通讯(先给知识点,实现原理,最后给出实现实时通信的具体代码--使用工具 android studio)现在先说下用到
- 编写规范目的:能够在编码过程中实现规范化,为以后的程序开发中养成良好的行为习惯。1、 项目名全部小写2、 包名全部小写3、 类名首字母大写,
- 本文实例讲述了Java统计字符串中字符出现次数的方法。分享给大家供大家参考,具体如下:package com.wenzhi;import j
- 本文实例为大家分享了Flutter自定义圆盘取色器的具体代码,供大家参考,具体内容如下下面展示一些 内联代码片。圆盘取色器效果图完整代码im
- 1、在java的构造方法中提供了 异常链.. 也就是我们可以通过构造方法不断的将 异常串联成一个异常链... 之所以需
- 面试官经常喜欢问Spring中的bean是不是线程安全的这个问题用来考察对Spring 中Bean作用域的理解,先说结论,Spr
- Android 中Activity 之间传递参数1.传递简单数据在A Activity中findViewById(R.id.startBAc
- 暴露您view中所有影响可见外观的属性或者行为。•通过XML添加和设置样式•通过元素的属性来控制其外观和行为,支持和重要事件交流的事件 *
- 在有些需求中会遇到,当鼠标滑过某个UI物体上方时,为了提醒用户该物体是可以交互时,我们需要添加一个动效和提示音。这样可以提高产品的体验感。解
- 一、背景动态插件化编程是一件很酷的事情,能实现业务功能的 解耦 便于维护,另外也可以提升 可扩展性 随时可以在不停服务器的情况下扩展功能,也
- Java——获取字符串编码格式判断一个字符串的编码格式: public static St
- 前言在工作总常常需要用到缓存,而redis往往是首选,但是短期的数据缓存一般我们还是会用到本地缓存。本文提供一个我在工作中用到的缓存工具,该
- 前言 之前unity5.x在代码中写了debug.log..等等,打
- 很久没写文章了,一方面是最近几个月比较忙,没太多时间,另一方面是最近拖延症严重,写文章的想法总是一拖再拖。今天找一个小案例写一下,与懒惰对抗
- 学习大佬们开发安全小工具,打包jar解决错误: 找不到或无法加载主类 main1 Maven方式遇到报错”找不到或无法加载主类 main“解
- 一、NIOjava.nio全称java non-blocking IO,是指jdk1.4 及以上版本里提供的新api(New IO) ,为所