如何使用startwith选项获取哈希表中的特定键值 [英] how to get particular keyvalue in hashtable using startwith option

查看:87
本文介绍了如何使用startwith选项获取哈希表中的特定键值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi


如何根据startwith关键字获得散列表中的特定值,

Ex:am search keyword" FET"将从哈希表中获取FETAvgas

Hi
how can i get particular value in hashtable based on startwith keyword,
Ex: am search keyword "FET" will get FETAvgas from hashtable

推荐答案

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace ConsoleApplication4
{
class Program
{

static void Main(string[] args)
{
Hashtable hashtable = new Hashtable();
hashtable[1] = "FETAvgas";
hashtable[2] = "GETAvgas";
hashtable[13] = "PETAvgas";
hashtable[3] = "FET1Avgas";

foreach (DictionaryEntry entry in hashtable)
{
Console.WriteLine("{0}, {1}", entry.Key, entry.Value);
}

var smallJobs = hashtable.Values.Cast().Where(x => x.StartsWith("FET"));

List Result = smallJobs.ToList();

Console.WriteLine("Results Starts with FET:");
foreach(string items in Result)
{
Console.WriteLine("{0}", items);
}

Console.ReadLine();
}
}
}


这篇关于如何使用startwith选项获取哈希表中的特定键值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆