Click here to Skip to main content
15,905,068 members
Everything / Dictionary

Dictionary

dictionary

Great Reads

by chuck in st paul
This is a utility program for bulk/batch renaming of files that demonstrates using and creating events
by Jim Meadors
String manipulation of XML files
by Sandeep Mewara
A look into graph based algorithm
by barry fat
develop a web based data dictionary

Latest Articles

by Christ Kennedy
In this article, you will learn about a word-processor that makes use of multiple dictionaries, pop-up definitions and an interactive multi-button picturebox expedited with a swift Sweep And Prune algorithm.
by Sandeep Mewara
A look into graph based algorithm
by honey the codewitch
This tip shows how to create a dynamic JavaScript-like "object" to be used in web pages and T4 templates.
by honey the codewitch
A fully generic ordered dictionary class in C#

All Articles

Sort by Score

Dictionary 

24 Feb 2019 by chuck in st paul
This is a utility program for bulk/batch renaming of files that demonstrates using and creating events
10 Dec 2015 by BillWoodruff
Here's the good news: yes, you can serialize a dictionary ... unless either the Dictionary Key or Value Types are some strange beast like a WinForm Control. WCF DataContract and DataMember tools are quite powerful; you can even serialize recursive structures.Here's what the XML produced by...
19 Nov 2012 by Jim Meadors
String manipulation of XML files
22 Nov 2020 by Sandeep Mewara
A look into graph based algorithm
15 Feb 2012 by Shahin Khorshidnia
Hello1. generate 2 random varous numbers>=0 and
2 Apr 2012 by Reza Ahmadi
Hi, I presume you want to return Key rather than the Value in your dictionary, if so, you can use the following lambada expression to return "Logged" for example:object obj = objdic.Where(item => item.Value == 2).First().Key;it return "Logged" which is one of the keys in your...
18 Jan 2013 by Herman<T>.Instance
first check with Any() if it exists
6 Jun 2013 by CPallini
You don't need a Dictionary: just use a List >. e.g. List> m = new List>(); m.Add(new List()); m.Add(new List()); m.Add(new List()); m[0].AddRange( new string[] {"cat", "dog", "rat"}); m[1].Add("bus"); ...
14 Oct 2014 by Samatha Reddy G
Hi once try this codei created enum and class which is having two properties public enum projectstates { projectstate1 = 1, projectstate2 = 2, projectstate3 = 3, projectstate4 = 4 } public class projectcounterentities { ...
28 Aug 2015 by CPallini
You are comparing references to objects (they cannot be equal for differenct objects, even if they contain same data).See here: "Comparing object used as Key in Dictionary"[^].
21 Nov 2016 by Peter Leow
Check out the methods: Dictionary(TKey, TValue) Methods (System.Collections.Generic)[^]
2 Jan 2018 by Thomas Daniels
Here is a way to do it: int[] values = new int[] { 3, 3, 3 }; IEnumerator> enumerator = dictionary.GetEnumerator(); int[] keys = new int[values.Length]; for (int i = 0; i
28 Jun 2019 by OriginalGriff
First off, your Dictionary is wrong: you want a count of repeating characters, so your Key needs to be the unique part - the character - and the value should be the number of them Dictionary charCounts = new Dictionary(); Now you can check if a character exists in the...
18 Mar 2012 by Sergey Alexandrovich Kryukov
First of all, System.Collections.Generic.Dictionary has two generic parameters, not one. The access is done via the keys, so you need a type for a key and a type for a value. The key should be unique. What is it? Say, the full title of the song, then a string. If not, it could be a...
3 Apr 2012 by Clifford Nelson
It appears that you are using a stored proceedure. You really do not need the dictionary when reading the information if all you are looking for is the Version (reader["VariableValue"].ToString()). You just have to check the key for each record read and abort when you find the version. When you...
22 Apr 2012 by Sergey Alexandrovich Kryukov
I have a really fast dictionary application (with nearly O(1) complexity of the search which means it does not depends on the size of the dictionary), so I found that database cannot provide satisfactory speed, but a file with thoroughly designed indexing can.Please my past answers on the...
6 Jun 2013 by StM0n
Do you mean something like that?!var myList = new Dictionary>();myList.Add("row1", new List());myList.Add("row2", new List());myList.Add("row3", new...
29 Jan 2015 by Pikoh
If i understand what you want...why don't you just use a foreach loop? Something like:Dictionary viaSwitchesResults = new Dictionary();foreach (string fila in lstProcDetails){ string[] data=fila.Split(','); viaSwitchesResults.Add(data[0],data[1]);}
18 Feb 2015 by PIEBALDconsult
Here's an example of a class that uses two Dictionaries.I do caution you about your first criterion as I'm sure my solution will have trouble if a value's priority is changed. DumbStuff.PriorityDictionary d = new...
5 Mar 2015 by Leo Chapiro
Take a look: Quick Way to Implement Dictionary in C[^]:Section 6.6 of The C Programming Language[^] presents a simple dictionary (hashtable) data structure. I don't think a useful dictionary implementation could get any simpler than this. For your convenience, I reproduce the code here....
19 Mar 2015 by Sergey Alexandrovich Kryukov
To start with, you are doing wrong thing: "manual" localization, while .NET in general and WPF in particular suggest much more robust, reliable and "automated" way of globalization and localization based on satellite assemblies. You can start here:...
9 Apr 2015 by Sergey Alexandrovich Kryukov
Please see our constructive discussion with Sascha Lefévre in comments to Solution 1. It is not yet quite comprehensive, as not all variants of modification by key are accessible to the user. Also, exception information is not informative. It is important to remember that key and value types may...
14 Jul 2015 by Wendelius
A very brute force solution could be to use string.Split method. Something like:foreach (string element in originalstring.Split(',')) { myDictionary.Add(element.Split('=')[0], element.Split('=')[1]);}
14 Jul 2015 by CPallini
You might:remove the heading and trailing curly braces.iterate over the array obtained by splitting the remaining string using the ',' character as separator.add to the dictionary the array items obtained splitting again the item, this time using the '=' character as separator.
28 Aug 2015 by OriginalGriff
Um.AlarmMapped is a class, which means that your Dictionary consists of a reference to a class instance, and a reference to a string.So any checking against the dictionary keys to find a matych will compare class references, not class content.So if your dictionary contains these...
6 Feb 2017 by Patrice T
When it comes to speed optimization, the tool of choice is the profiler.the profiler is there to tell you how much time you spend in each part of your code and to detect bottlenecks.Profiling (computer programming) - Wikipedia[^]
6 Feb 2017 by Philippe Mori
A line like list.Single(x => x.Key == Word1); is inefficient because Linq-to-object has no way to understand that it is searching a dictionary with its key. So it will essentially enumerate all items in the dictionary until it find a match.On the other hand, TryGetValue is specifically...
9 Apr 2018 by Maciej Los
I'd suggest to use File.ReadAllLines Method (System.IO)[^] to read data from text file. [EDIT] Your class needs some improvements: According to our discussion, i've made some changes to the class: public class Signal { private string sName = string.Empty; private byte[] oData = new...
27 Apr 2019 by Richard MacCutchan
You need to look at lists and list comprehensions for suggestions. See 5. Data Structures — Python 3.7.3 documentation[^].
18 Sep 2020 by OriginalGriff
When you call ToString on anything the system looks at the instance you are calling it on, and goes back through the inheritance chain to find the "closest" implementation. If your class explicitly implements ToString then taht method will be...
22 Nov 2020 by PIEBALDconsult
Define a class, with the two values, a ToString for displaying them together, and a compare method which sorts by last then first.
24 Aug 2022 by Richard Deeming
Try: foreach (KeyValuePair pair in listAnotaci) { textBox.Rows.Add(new[] { pair.Key.ToString(), pair.Value }); }
10 Nov 2022 by Richard Deeming
You'll need to write an equality comparer: public sealed class DictionaryEqualityComparer : IEqualityComparer> { private readonly IEqualityComparer _valueComparer; public...
6 Feb 2017 by User 7407470
You are looking up 'Word1' in an inefficient way, try this ('the standard way'):for(int i = 0; i
12 Aug 2011 by #realJSOP
You mean something like this Codeproject article does:Anagrams - A Word Game in C#[^]
27 Sep 2011 by Sergey Alexandrovich Kryukov
One approach is to use available dictionary files and add entries to them. They are just the text files, so you can edit it directly, manually or programmatically. On little problem is that the files I saw so far were in KOI8-based encodings, not in Unicode (so, different encoding for each...
21 Oct 2011 by KiranBabu M
Hi all, can any one give me a sample how to update a value in dictionary based upon the key.I have a collection of frames in a Dictionarypublic Dictionary FrameID=new Dictionary ();System .IO .DirectoryInfo myimagesdir=new System...
21 Oct 2011 by Shmuel Zang
Assumption: i is the key and, newFrame is the new value.You can do it like the follwing:if (FrameID.ContainsKey(i)){ FrameID.Remove(i);}FrameID.Add(i, newFrame);
17 Apr 2012 by abdul samathu
I've created a Dictionary like Dictionary dict= new Dictionary();here Department is a class and I have `DepartmentId,Name and Code` for the departments. And in the `bool` am sending whether the person is `HOD` or not.Am adding the records to this...
18 Apr 2012 by VJ Reddy
Please see the following references.http://wordweb.info/[^]There is a free version of WordWeb subject to licensing terms, as given in their website.http://www.a-z-dictionaries.com/Open_Source_Dictionary_Downloads.html[^]http://hunspell.sourceforge.net/[^]They may be helpful.
16 May 2013 by Richard MacCutchan
Dictionaries are unordered sets, so the contents may appear in any sequence. See section 5.5 on this page[^].
14 Jun 2013 by barry fat
develop a web based data dictionary
16 Jan 2014 by yakhtarali
I have a wcf ksoap2 service that returns Dictionary>; Now at android side I want to fill my Dictionary> diction; from wcf response. I am new to wcf and android/java, I don't have idea how to do this. Please provide me some better example...
12 Dec 2018 by Meysam Toluie
Hello ExpertsIn my Project, I create many transaction and store them in dataGridView with their details.When press startbtn this code will execute:Manager manager = new Manager(GridView);ANd here is the Manager class:public class Manager { public static Dictionary...
21 Dec 2014 by Thomas Daniels
Try this:Shape conductorCable12shape = panelSheet.Drop(conductorCable12, String.Format("Key = {0}, Value = {1}", drop.Key, drop.Value));String.Format formats the string; it replaces the {0} with the key and {1} with the value.EDIT: you said in your comment that it takes 3 arguments....
20 Jan 2015 by PIEBALDconsult
I suspect you need to cast the object to the proper type, but a better solution is to change the dictionary.If you can't do that, then tryobject dict_common_setting ObjGetImgPath;... ObjGetImgPath = (dict_common_setting) Global.Dictionary_common_setting["imgpath"];or ...
18 Feb 2015 by Herbisaurus
I need a collection of objects that will: * allow get, set functionality object via a key (like in a dictionary)* I need to iterate through the collection in a sorted manner, ordered by a "Priority" value* the priority allows multiple values. * the keys can be an int or a string, it...
2 Dec 2015 by BillWoodruff
Try this:var d1List = cover_mean_dict.Keys.ToList();var d2List = Watermark_mean_dict.Keys.ToList();// returns a 'System.Collections.Generic.IEnumerablef__AnonymousType0>'var match = d1List.Select((itm1, ndx) => new {itm1, itm2 = d2List[ndx]});// testforeach (var pair in...
9 Dec 2015 by F-ES Sitecore
This cromulent code should embiggen your knowledge.public class Replacement{ public string Word { get; set; } public List Replacements { get; set; }}If you want to process the file without reading it all in memory then you can do something like thisStreamReader...
26 Dec 2015 by BillWoodruff
Context: Andreas (above) asked the OP about the "exotic" nature of his proposed data-structure. The OP replied: "I know it's really bad, and I'm trying to abstract it a bit because it is really hard to work with."As best as I can understand it, the OP is using this...
25 Apr 2016 by Karthik_Mahalingam
Add this in your second loopforeach (KeyValuePair pair in listcps) { foreach (var counterparty in cpResponse.counterpartyList) { if (noNexusCpsdict.ContainsKey(counterparty.CounterpartyId)) ...
21 Nov 2016 by Matt T Heffron
As you've probably discovered, if you Add(key, value) to a Dictionary that already has an entry with the same key, it throws an ArgumentException. It is not possible to have multiple entries with the same key.If you want to add the value if the key is not present then try...
25 Sep 2018 by Richard MacCutchan
The problem is that you have two loops, so for each character in the value you are comparing against each character in the key. That makes 25 actual tests, and 22 of them will be not equal. Chang to the following: def find_correct(words_dict): count=0 for key,value in...
27 Apr 2019 by Maciej Los
Take a look here: Convert and Loop through JSON with PHP and JavaScript Arrays/Objects — Jonathan Suh[^]
30 Jun 2019 by Virendra S from Bangalore, Karnataka
I want to display count of repeating letters in an array using dictionary. How to implement this? below is the sample code. please explain further implementation of logic. What I have tried: string[] inputArray = new string[] { "Hello1", "Hello2", "Hello3" }; var map = new...
22 Nov 2020 by George Swan
My choice would be to use a value Tuple. Like this: public List namesList = new List(); //add an item namesList.Add((txtSurname.Text, txtFname.Text));...
20 Jan 2021 by CPallini
You should overload the != operator of your Iterator class, or, alternatively use std::rel_ops (see rel_ops - C++ Reference[^]).
9 Dec 2021 by Richard MacCutchan
If you copy the dataset into a simple list you can do it with the following: products = [ [ 1, 200, 'X' ], [ 2, 300, 'A' ], [ 2, 400, 'A' ], [ 2, 200, 'A' ], [ 3, 500, 'A' ], [ 3, 400, 'A' ], [ 3, 300, 'B' ], ] for i...
23 Feb 2022 by Richard MacCutchan
Try this: for key, value in group.items(): if value in group and group[value] != "None": group[key] = group[value] print(group)
26 Sep 2022 by OriginalGriff
I'm not exactly sure what you are trying to do as your question isn't clear - there isn't "one string that is different" in your example data. So I'm going to assume that what you are trying to do is group together the Dictionary entries by the...
22 Nov 2022 by Richard Deeming
You ask the user to enter a team name, and add an entry to the dictionary using the entered value as the key. You then try to add a player to the team called "string team", regardless of what the user typed. Unless the user entered "string...
7 Dec 2022 by Richard Deeming
Quote: int count = 0; if (result.ContainsKey(file[i].Extension)) { count++; } else { count = 1; } That code does nothing useful. You declare a local variable and initialize it to 0. If the dictionary contains the extension of the...
20 Feb 2023 by 0x01AA
Solved by OP. Please see also comments to the question.
4 Jul 2023 by CIZA_1
I am trying to find intermediary activities between keys. There is different connectors between two keys and I want to find the ones which have minimum value due to a calculation which I will explain below. I have dictionaries such as dict2 =...
4 Jul 2023 by Andre Oosthuizen
I might be a little out of my depth here as Python is still an ongoing learning curve for me. From what I could gather, it looks like the logic to handle a case where there are multiple possible paths between two keys is missing. You need to...
12 Aug 2011 by Abhinav S
See Using Word's spellchecker in C#[^].
21 Oct 2011 by Mehdi Gholam
frames f = null;if(FrameID.TryGetValue(frameno, out f)){ // frameno is in dictionary FrameID[frameno] = val;}else FrameID.Add(frameno, val);
21 Oct 2011 by OriginalGriff
Just treat it as an array.This uses strings, but that's just because it is easier to see what is going on. Dictionary dict = new Dictionary(); dict.Add(0, "zero"); dict.Add(1, "one"); dict.Add(2, "two"); ...
10 Nov 2011 by codeprojecttt
How can a dictionary be sent to the client From Server ?I want to do I send the following dictionaryDictionary rates = new Dictionary(); rates.Add("usd", 47.5); rates.Add("eur", 60.4); rates.Add("ukp", 78.8);Codes do not work.Where is my problem?...
10 Nov 2011 by Joshi, Rushikesh
your code should work, if you are sending using TCP protocol then dictionary object stream should work only thing is at receiver you have to return back to dictionary object. you can use TCP Serialization.If its HTTP then you can use HTTP Serialization but only thing on receiver side you...
10 Nov 2011 by ARBebopKid
How about:var dataToSend = new DataToSend { Rates = new Dictionary() };dataToSend.Rates = (DataToSend)formatter.Deserialize(stream);
3 Jan 2012 by Howard ( Chaim) Davis
I am trying to find row of a dictionary where the values are in the list. and the the values in the list are equel to some value;The syntax is driving me crazy -- any pointersnamespace ConsoleApplication1{ internal class Program { private static void Main(string[]...
3 Jan 2012 by Wendelius
Not exactly sure what are the preferred results, but could you use something like:Dictionary> namesInfo = new Dictionary>() { {"howard", new List {{5}, {5}, {2}, {4}}}, {"John", new List{{1},{2},{3},{5}}} };var list4 =...
27 Jan 2012 by MohammadIqbal
How I can select some different resource dictionary during execution time .ie button1 click Resource dictionary1 will come into picture similarly button2 click Resource dictionary2 will come into pictureThanks in advance iqbal
30 Jan 2012 by Dean Oliver
Here's your solution. Please not you will obviously have to adapt it to your own project by way of click events on your buttons. But this is the the way to go about achieving what you wanted.http://weblogs.asp.net/psheriff/archive/2009/12/01/load-resource-dictionaries-at-runtime-in-wpf.aspx[^]
15 Feb 2012 by aidin Tajadod
If you do not insist on Dictionary, you may want to replace it with List>ex:List> kortlek = new List>(); ...kortlek.Add(new KeyValuePair("spader dam", 12));// you can reach it like this...
1 Apr 2012 by JacoBosch
Good dayI have created a two forms in my Windows application. On my Main form is a combobox and on my second(child) form is a button.I want to populate the combobox with a dictionary when the button is clicked on the child form.I have written the dictionary that is calling a short...
1 Apr 2012 by ProEnggSoft
Change the method signature of dctRplStatus to public void dctRplStatus(ComboBox cmbRplStatus)and replaceformmain.cmbRplStatus = dctRplStatus;withdctRplStatus(formmain.cmbRplStatus);ensure that formmain.cmbRplStatus has public access.
2 Apr 2012 by JacoBosch
Good dayI have created a method with a dictionary. The data of the dictionary is coming from a stored procedure.The data is as follows:ReplacementStatusID Description1 Active 2 Logged3 Head Office4 ...
2 Apr 2012 by Abhinav S
The easiest way would be to use the inbuilt ContainsValue method[^].E.g. Console.Writeline(objdic.ContainsValue("Logged"));Another way could be to use LINQ on the dictionary.
4 Apr 2012 by JacoBosch
Thanx for everybody's help. I changed my Short procedure that it must only return one value, and I used ExecuteScalar.public string SelectdicVersion() { SqlDatabase sqldb = new SqlDatabase(connectionstring);string reader = sqldb.ExecuteScalar("pSEL_Version", new...
17 Apr 2012 by milenalukic
Hi,What you will need to do is to query your dictionary using LINQList mylist = new Listmylist = dict.where(x=>x.value.deptID=yourdepID).tolist();if(mylist.count>0){// value exists// to update you will need to create a new entry// delete the old one// insert the new...
5 Jun 2012 by NeonMika
So the problem is the following:I have a Dictionary and I want to access this Dicitionary from XAML.FormatEnum has the types Small, Medium and Big, and the string contains a URL to a picture.I tried the following code:...
5 Jun 2012 by Steve Maier
You can use a converter to change the enum into whatever you need. I use this in a WP7 app to convert a status enum to an image like a green one for good or a red one for an error.WPF - Bind to Opposite Boolean Value Using a Converter[^]Piping Value Converters in WPF[^]
1 Aug 2012 by lewax00
Well you could create one...or you could use the existing Dictionary class[^].Can't really offer more than that without more details.
1 Aug 2012 by Christian Graus
dict.ContainsK...
1 Aug 2012 by lewax00
First, if you know all values are going to be of type someClass, then change it from Dictionary to Dictionary. To access the value at "532Key", just use:var value = dict["532Key"];(Note: If you leave it as-is, you'll need to cast value to the proper type...
6 Sep 2012 by Radzhab
This is Dictionary.Dictionary> Dic = new Dictionary>();I want to do so - i clicking button and the first Dic key with her values copied to List. Click again - next Dic Key and her values and etc..
6 Sep 2012 by Rickin Kane
Do as per below for framework 2.0 foreach ( var item in dicNumber) { listnumber.Add (item.Key); } using LINQ var Listname= dictionary.Keys.ToList(); check if tis solve your problem ,thanks
6 Sep 2012 by lukeer
I have an idea how to get them all at once:public static void Example(){ Dictionary> dic = new Dictionary>(); dic.Add( "first", new List(new string[] { "first first", "second first" }) ); dic.Add( ...
16 Oct 2012 by robnjoro
I have Problem Reading XML and using dictionary to store all tags and their values.I have used this code in VB.Net without problem. It fails while "adding the tag as the key and the tag's value as the value"public class ConfigReader { IDictionary dict; public...
16 Oct 2012 by fjdiewornncalwe
Lots of options.[^]. You should always attempt a search on google of your question. The search "How to read Xml Document C# to dictionary" returned 1.58 million results. The first page is full of potential solutions for you. Cheers.
21 Mar 2013 by Sandeep Mewara
It does not work like this here.Here is what is expected of enquirers:1. TRY first what you want to do! You may find that it's not that hard.2. Formulate what was done by you that looks like an issue/not working. Try them and tell if you face issues.Members will be more than happy...
5 May 2013 by boris01
There is a somoe sort of multi-key dictionary that I can safely use with multiple Tasks?I mean that I need a Dictionary with 2 keys threadsafe that I can use in multi task program.Something like that:var dictionary = new MultiDictionary();Task[]...
5 May 2013 by Mehdi Gholam
If you have to supply both keys to get your value then you are using 1 key so you can "concat" (somehow combine 2 key in the case of ints you can create a long for example etc.) the two keys and use a normal Dictionary.
6 May 2013 by Matt T Heffron
Since your question is really about the implementation of the MultiDictionary as described in: C# Multi-key Generic Dictionary[^] you should ask in the questions section in that article.
16 May 2013 by ayesha hassan
I am fairly new to Python. Infact, today is my first day in Python. I was following a tutorial and read about dictionary.But I don't know what is the order in which contents of a dictionary are displayed.Below is my code:dir =...
11 Jul 2013 by PozzaVecia
suppose I have a Dictionary resultsI need to get the key of the highest value of a Dictionary in C#, from(http://stackoverflow.com/questions/2805703/good-way-to-get-the-key-of-the-highest-value-of-a-dictionary-in-c-sharp[^]I have:var max = results.Aggregate((l, r)...
29 Aug 2013 by torin86
Hi to all!Here is my problem:Initially, I only had a project (MainProject) with a global ResourceDictionary (StyleResources), classes, etc. The project was growing, and I decided to separate the resources into new project (SecondaryProject).First question: What project type should be...
8 Oct 2013 by ProgrammerX1
The data set represents a primary index key column call it Name, and a second (item) then a third column/field (item alias). Each Name (store) may have 1,2,3,4---N number of rows (items). Here is how the dataset returned look like:Name Item Alias-------------------Store1 Beans...