坐等高手解答!C#中Hashtable中每一个Key对应的Value都是一个Hashtable,请问该如何遍历此Hashtable?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了坐等高手解答!C#中Hashtable中每一个Key对应的Value都是一个Hashtable,请问该如何遍历此Hashtable?相关的知识,希望对你有一定的参考价值。

参考技术A Hashtable ht=new Hashtable(); //创建一个Hashtable实例

ht.Add("E","e");//添加key/value键值对
ht.Add("A","a");
ht.Add("C","c");
ht.Add("B","b");

遍历哈希表需要用到DictionaryEntry Object,代码如下:
foreach(DictionaryEntry de in ht) //ht为一个Hashtable实例

MessageBox.Show(de.Key.ToString());//de.Key对应于key/value键值对key
MessageBox.Show(de.Value.ToString());//de.Key对应于key/value键值对value

c编程中main函数中使用了库文件中定义的函数,编译时却提示该函数未定义,这是啥问题,坐等高手解答

c源码如下
#include<pthread.h>
#include<stdio.h>
#include<stdlib.h>
#define REPEAT_NUM 5
#define DELAY_TIME_LEVELS 10.0
#define THREAD_NUM 3

void * phrd_func(void *arg)

void * thrd_ret;
int count=0;
int delay_time=0;
int thread_num=(int)arg;
printf("thread %d is starting\n");
for(count=0;count<REPEAT_NUM;++count)

delay_time=(int)(rand()*DELAY_TIME_LEVELS/(RAND_MAX))+1;
sleep(delay_time);
printf("thread %d :iob %d : delay %ds\n",thread_num,count,delay_time);

printf("thread %d finishde\n",thread_num);
pthread_exit(NULL);

int main()

void * thrd_ret;
pthread_t thread[THREAD_NUM];
int no,ret;
srand(time(NULL));
for(no=0;no<THREAD_NUM;++no)

ret=pthread_create(&thread[no],NULL,phrd_func,(void *)no);
if(ret!=0)

printf("error pthresd\n");
exit(ret);


printf("creat threads sucess : waiting threads finished\n");
for(no=0;no<THREAD_NUM;no++)

ret=pthread_join(thread[no],&thrd_ret);
if(!ret)

printf("thread %d joined\n",no);

else

printf("thread %d joined failed\n",no);


return 0;

编译报告如下
[lyc@localhost lyc]$ gcc a.c
/tmp/cco2MhOv.o(.text+0x108): In function `main':
: undefined reference to `pthread_create'
/tmp/cco2MhOv.o(.text+0x168): In function `main':
: undefined reference to `pthread_join'
collect2: ld returned 1 exit status
pthread.h如下:
/* Function for handling threads. */

/* Create a thread with given attributes ATTR (or default attributes
if ATTR is NULL), and call function START_ROUTINE with given
arguments ARG. */
extern int pthread_create (pthread_t *__restrict __threadp,
__const pthread_attr_t *__restrict __attr,
void *(*__start_routine) (void *),
void *__restrict __arg) __THROW;
/* Terminate calling thread. */
extern void pthread_exit (void *__retval)
__THROW __attribute__ ((__noreturn__));

/* Make calling thread wait for termination of the thread TH. The
exit status of the thread is stored in *THREAD_RETURN, if THREAD_RETURN
is not NULL. */
extern int pthread_join (pthread_t __th, void **__thread_return) __THROW;
求高手解答

参考技术A 原因:
头文件 pthread.h 没有包含到源文件中
解决方法:
1)将 pthread.h 复制到源文件相同的文件夹中
2)修改为:#include "pthread.h"追问

我这样尝试了,但还是不行

追答

也许pthread.h 文件本身有问题了

参考技术B 添加编译选项-lpthread,因为pthread不是标准的编译链接的库,需要自己添加 参考技术C 你编译 a.c 怎么涉及到 cco2MhOv.o 或 cco2MhOv.c ?

头文件除了 #include <pthread.h>
是否还要 #include <sys/types.h>本回答被提问者和网友采纳

以上是关于坐等高手解答!C#中Hashtable中每一个Key对应的Value都是一个Hashtable,请问该如何遍历此Hashtable?的主要内容,如果未能解决你的问题,请参考以下文章

c编程中main函数中使用了库文件中定义的函数,编译时却提示该函数未定义,这是啥问题,坐等高手解答

新手坐等c#控制台console输出的数据保存到txt中。。。。

C# Hashtable和Dictionary区别

C#中错误提示应为get或set访问器,求高手解答。急~~~

C# 集合 — Hashtable 线程安全

急求高手解答!!!!!!!C#中checkbox判断哪些被选中并执行后续操作~