Click here to Skip to main content
15,899,937 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi
how can i get particular value in hashtable based on startwith keyword,
Ex: am search keyword "FET" will get FETAvgas from hashtable
Posted
Updated 4-Aug-15 1:43am
v2
Comments
stibee 31-Jul-15 3:33am    
Is there a reason that you are using a hashtable? Whats about using a dictionary instead?
Karthik Harve 4-Aug-15 7:55am    
if this code is tested, submit this as an answer. so that it will helpful for others.

1 solution

C#
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();
}
}
}
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900