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#程序设计有所帮助。
0
投稿
猜你喜欢
- Mybatis selectKey返回新增用户的id值一、需求:新增用户后,同时还要返回当前新增用户的id值id是由数据库的自动增长来实现的
- 要想了解Java * ,首先要了解什么叫做代理,熟悉设计模式的朋友一定知道在Gof总结的23种设计模式中,有一种叫做代理(Proxy)的对
- 这篇文章主要介绍了spring boot如何配置请求的入参和出参json数据格式,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一
- 最近开发项目中,有个在屏幕上任意拖动的悬浮窗功能,其实就是利用 WindowManager的api来完成这个需求,具体的实现的功能如下:1.
- 背景我在准备使用 JVM 的命令时候观察程序的动态,但是发现 Main 函数启动就退出了,所以也没办法直接观察,于是想到了如何让 Main
- 什么是Kotlin?Kotlin是一种可以在 Java 虚拟机 (JVM) 上运行的开源编程语言。该语言可以在许多平台上运行。它是一种将面向
- 0x00:前言参考之前的《MyBatis 中 SqlMapConfig 配置文件详解》记了一下 MyBatis 中的核心配置文件各个标签的作
- 关于springmvc上传图片的方法小编给大家整理了两种方法,具体内容如下所示:第一种:(放在该项目下的物理地址对应的位置)a. 路径写法:
- arthas能够更改日志的级别,下面是logger的用法查看logger信息,更新logger level查看所有logger信息logge
- 所以对于应用层用着还不是很方便。最近做一个项目顺便就封装了一个调用默认打印机的类。虽说有几个小bug,但对于目前来说,已经满足需求了。以后不
- 1. 为什么写这篇文章?事情是这样的,在 2021年6月10日早上我在CSDN上发布了文章《你真的懂Java怎么输出Hello World吗
- 比如在窗体中显示时间:错误思路一:我在窗体结构函数中写入一个死循环,每隔一秒显示一次当前时间public Form6() &n
- SharedPreferences介绍:SharedPreferences是Android平台上一个轻量级的存储类,主要是保存一些常用的配置
- 计数排序是非比较的排序算法,用辅助数组对数组中出现的数字计数,元素转下标,下标转元素计数排序优缺点优点:快缺点:数据范围很大,比较稀疏,会导
- 类注解@component 标注类,泛指各种组件,类不属于各种分类的时候,用它做标注。@Service 标注类,声明该类为业务层组件,用于处
- 系统: lc android4.4 在做前后摄像头录像的时候,发现会出现花屏的时候,但不是必现,可能会在某一次重启之后会出现,而且出现之后会
- 这篇文章主要介绍了Java如何基于ProcessBuilder类调用外部程序,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的
- 一、前言我们在日常学习中,对一个java代码有问题,不知道jvm内部怎么进行解析的时候;有个伟大壮举就是反编译,这样就可以看到jvm内部怎么
- 一、概述本质上,这是一个包含有可选值的包装类,这意味着 Optional 类既可以含有对象也可以为空。Optional 是 Java 实现函
- Collectors.toMap空指针问题在工作中遇到了一个List转Map的时候的一个NullPointException.情形很简单,问