Search Results

Search found 2235 results on 90 pages for 'dictionary'.

Page 10/90 | < Previous Page | 6 7 8 9 10 11 12 13 14 15 16 17  | Next Page >

  • Modifying C# dictionary value

    - by minjang
    I'm a C++ expert, but not at all for C#. I created a Dictionary<string, STATS>, where STATS is a simple struct. Once I built the dictionary with initial string and STATS pairs, I want to modify the dictionary's STATS value. In C++, it's very clear: Dictionary<string, STATS*> benchmarks; Initialize it... STATS* stats = benchmarks[item.Key]; // Touch stats directly However, I tried like this in C#: Dictionary<string, STATS> benchmarks = new Dictionary<string, STATS>(); // Initialize benchmarks with a bunch of STATS foreach (var item in _data) benchmarks.Add(item.app_name, item); foreach (KeyValuePair<string, STATS> item in benchmarks) { // I want to modify STATS value inside of benchmarks dictionary. STATS stat_item = benchmarks[item.Key]; ParseOutputFile("foo", ref stat_item); // But, not modified in benchmarks... stat_item is just a copy. } This is a really novice problem, but wasn't easy to find an answer. EDIT: I also tried like the following: STATS stat_item = benchmarks[item.Key]; ParseOutputFile(file_name, ref stat_item); benchmarks[item.Key] = stat_item; However, I got the exception since such action invalidates Dictionary: Unhandled Exception: System.InvalidOperationException: Collection was modified; enumeration operation may not execute. at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource) at System.Collections.Generic.Dictionary`2.Enumerator.MoveNext() at helper.Program.Main(String[] args) in D:\dev\\helper\Program.cs:line 75

    Read the article

  • Control XML serialization of Dictionary<K, T>

    - by Luca
    I'm investigating about XML serialization, and since I use lot of dictionary, I would like to serialize them as well. I found the following solution for that (I'm quite proud of it! :) ). [XmlInclude(typeof(Foo))] public class XmlDictionary<TKey, TValue> { /// <summary> /// Key/value pair. /// </summary> public struct DictionaryItem { /// <summary> /// Dictionary item key. /// </summary> public TKey Key; /// <summary> /// Dictionary item value. /// </summary> public TValue Value; } /// <summary> /// Dictionary items. /// </summary> public DictionaryItem[] Items { get { List<DictionaryItem> items = new List<DictionaryItem>(ItemsDictionary.Count); foreach (KeyValuePair<TKey, TValue> pair in ItemsDictionary) { DictionaryItem item; item.Key = pair.Key; item.Value = pair.Value; items.Add(item); } return (items.ToArray()); } set { ItemsDictionary = new Dictionary<TKey,TValue>(); foreach (DictionaryItem item in value) ItemsDictionary.Add(item.Key, item.Value); } } /// <summary> /// Indexer base on dictionary key. /// </summary> /// <param name="key"></param> /// <returns></returns> public TValue this[TKey key] { get { return (ItemsDictionary[key]); } set { Debug.Assert(value != null); ItemsDictionary[key] = value; } } /// <summary> /// Delegate for get key from a dictionary value. /// </summary> /// <param name="value"></param> /// <returns></returns> public delegate TKey GetItemKeyDelegate(TValue value); /// <summary> /// Add a range of values automatically determining the associated keys. /// </summary> /// <param name="values"></param> /// <param name="keygen"></param> public void AddRange(IEnumerable<TValue> values, GetItemKeyDelegate keygen) { foreach (TValue v in values) ItemsDictionary.Add(keygen(v), v); } /// <summary> /// Items dictionary. /// </summary> [XmlIgnore] public Dictionary<TKey, TValue> ItemsDictionary = new Dictionary<TKey,TValue>(); } The classes deriving from this class are serialized in the following way: <FooDictionary xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <Items> <DictionaryItemOfInt32Foo> <Key/> <Value/> </DictionaryItemOfInt32XmlProcess> <Items> This give me a good solution, but: How can I control the name of the element DictionaryItemOfInt32Foo What happens if I define a Dictionary<FooInt32, Int32> and I have the classes Foo and FooInt32? Is it possible to optimize the class above? THank you very much!

    Read the article

  • How do I insert data from a Python dictionary to MySQL?

    - by NJTechie
    I manipulated some data from MySQL and the resulting dictionary "data" (print data) displays something like this : {'1': ['1', 'K', abc, 'xyz', None, None, datetime.date(2009, 6, 18)], '2': ['2', 'K', efg, 'xyz', None, None, None, None], '3': ['3', 'K', ijk, 'xyz', None, None, None, datetime.date(2010, 2, 5, 16, 31, 2)]} How do I create a table and insert these values in a MySQL table? In other words, how do I dump them to MySQL or CSV? Not sure how to deal with datetime.date and None values. Any help is appreciated.

    Read the article

  • MS Word custom dictionary making spellcheck slow - ideas?

    - by ezuk
    I have a user who edits technical materials. She uses MS Word's Custom Dictionary all the time for spelling; it has grown very large, and is now making spell check very slow. All of the advice I've read online says to disable the custom dictionary. This is an easy solution, but is not workable for the user, because she actually needs this dictionary. So, is there any way to optimize the custom dictionary and/or Word itself, so that a large dictionary file doesn't slow things down quite so badly? Many thanks. Update after suggestions: I ran contig on the file, and it reports just 1 frag, so that's not the issue I think. The file is 9.95KB -- 1,117 lines, each consisting of just a single word. I viewed the file using Notepad and none of the lines seems corrupted, strange, or overly long (no line seems to be over 10 chars or so). Both of your suggestions were helpful so I will upvote both; any further tips would be most welcome.

    Read the article

  • How to effectively clip the amount of entries in a dictionary?

    - by reinier
    I had a List<myClass> myList for storing a list of items. When I had to clip this (discard any amount of items above some threshold) I used: myList.RemoveRange(threshold, myList.Count - threshold); where threshold is the max amount of things the list can contain Now I've upgraded the datatype to a Dictionary<key, myClass> myDictionary How can I basically do the same: Discard all entries above some threshold. (It doesn't matter which ones are discarded) I guess I could foreach through the keys collection and manually delete all keys/value pairs. But I was hoping there was a more elegant solution.

    Read the article

  • Fastest way to store/retrieve a dictionary - SQL, text file...?

    - by AP257
    Hi all, This is a really really super dumb question, so I apologise, but I'd be grateful for some advice. I've got a text file of words and word frequencies. It's very large - theoretically we're talking millions of rows. I just want to retrieve values from the file, and do it as quickly and efficiently as possible (for a web app, in Django). My question is: what is the best way to store and retrieve the values? Should import them into SQL? Or keep the file and use grep? Or put them into a JSON dictionary...? Or some other way? Sorry for the dumb question, would be very grateful for advice!

    Read the article

  • Is there a way to use a dictionary or xml in the Application Settings?

    - by Shimmy
    I have to store a complex type in the application settings. I thought that storing it as XML would work best. The problem is I don't know how store XML. I prefer to store it as a managed XML rather than using just a string of raw XML having to parse it on each access. I managed to set the Type column of the setting to XDocument, but I was unable to set its value. Is there a way to use XDocument or XML in application settings? Update I found a way, simply by editing the .settings file with the xml editor. I changed it to a custom serializable dictionary, but I get the following error when I try to access the setting-property (I set it to a serialized representation of the default value). The property 'Setting' could not be created from it's default value. Error message: There is an error in XML document (1, 41). Any ideas will be appreciated.

    Read the article

  • How to Perform Continues Iteration over Shared Dictionary in Multi-threaded Environment

    - by Mubashar Ahmad
    Dear Gurus. Note Pls do not tell me regarding alternative to custom session, Pls answer only relative to the Pattern Scenario I have Done Custom Session Management in my application(WCF Service) for this I have a Dictionary shared to all thread. When a specific function Gets called I add a New Session and Issue SessionId to the client so it can use that sessionId for rest of his calls until it calls another specific function, which terminates this session and removes the session from the Dictionary. Due to any reason Client may not call session terminator function so i have to implement time expiration logic so that i can remove all such sessions from the memory. For this I added a Timer Object which calls ClearExpiredSessions function after the specific period of time. which iterates on the dictionary. Problem: As this dictionary gets modified every time new client comes and leaves so i can't lock the whole dictionary while iterating over it. And if i do not lock the dictionary while iteration, if dictionary gets modified from other thread while iterating, Enumerator will throw exception on MoveNext(). So can anybody tell me what kind of Design i should follow in this case. Is there any standard pattern available.

    Read the article

  • I'm doing a lot of lists and dictionary sorting...and this is causing memory errors in Python websit

    - by alex
    I retrieved data from the log table in my database. Then I started finding unique users, comparing/sorting lists, etc. In the end I got down to this. stats = {'2010-03-19': {'date': '2010-03-19', 'unique_users': 312, 'queries': 1465}, '2010-03-18': {'date': '2010-03-18', 'unique_users': 329, 'queries': 1659}, '2010-03-17': {'date': '2010-03-17', 'unique_users': 379, 'queries': 1845}, '2010-03-16': {'date': '2010-03-16', 'unique_users': 434, 'queries': 2336}, '2010-03-15': {'date': '2010-03-15', 'unique_users': 390, 'queries': 2138}, '2010-03-14': {'date': '2010-03-14', 'unique_users': 460, 'queries': 2221}, '2010-03-13': {'date': '2010-03-13', 'unique_users': 507, 'queries': 2242}, '2010-03-12': {'date': '2010-03-12', 'unique_users': 629, 'queries': 3523}, '2010-03-11': {'date': '2010-03-11', 'unique_users': 811, 'queries': 4274}, '2010-03-10': {'date': '2010-03-10', 'unique_users': 171, 'queries': 1297}, '2010-03-26': {'date': '2010-03-26', 'unique_users': 299, 'queries': 1617}, '2010-03-27': {'date': '2010-03-27', 'unique_users': 323, 'queries': 1310}, '2010-03-24': {'date': '2010-03-24', 'unique_users': 352, 'queries': 2112}, '2010-03-25': {'date': '2010-03-25', 'unique_users': 330, 'queries': 1290}, '2010-03-22': {'date': '2010-03-22', 'unique_users': 329, 'queries': 1798}, '2010-03-23': {'date': '2010-03-23', 'unique_users': 329, 'queries': 1857}, '2010-03-20': {'date': '2010-03-20', 'unique_users': 368, 'queries': 1693}, '2010-03-21': {'date': '2010-03-21', 'unique_users': 329, 'queries': 1511}, '2010-03-29': {'date': '2010-03-29', 'unique_users': 325, 'queries': 1718}, '2010-03-28': {'date': '2010-03-28', 'unique_users': 340, 'queries': 1815}, '2010-03-30': {'date': '2010-03-30', 'unique_users': 329, 'queries': 1891}} It's not a big dictionary. But when I try to do one last thing...it craps out on me. for k, v in stats: mylist.append(v) too many values to unpack What the heck does that mean??? TOO MANY VALUES TO UNPACK.

    Read the article

  • License of popular dictionary word lists (e.g. SOWPODS, TWL)? Copyright? Trademarks?

    - by BobbyJim
    (I'm not sure if this off-topic. I found a lot of voted-up questions about software licenses and this is related. Plus, I'm sure many of us have had the situation that we need to use a dictionary in our code) I'm making a (maybe commercial) word game and need to use a good word dictionary for checking words. The most common dictionaries to use are the SOWPODS or TWL lists that are used Scrabble tournaments; see here: http://www.scrabblist.com/ (I have nothing to do with this site by the way). I've seen loads of websites offering these two dictionaries for download and loads of word games advertise that they use them. However, I cannot find any licensing terms attached to these dictionaries wherever I download them. For the players of my game, I'd want to say what dictionary I'm using (e.g. "this game uses SOWPODS"). However, I'm nervous about what I can do legally. Does anyone know about if you can copyright lists of words? Does anyone know the licenses of TWL and SOWPODS? TWL and SOWPODS don't seem to have trademarks on them but I'd like to know for sure. I cannot find any good sources for this information. EDIT: Great, now the top result for "SOWPODS license" is my stackoverflow question. :)

    Read the article

  • Word frequency tally script is too slow

    - by Dave Jarvis
    Background Created a script to count the frequency of words in a plain text file. The script performs the following steps: Count the frequency of words from a corpus. Retain each word in the corpus found in a dictionary. Create a comma-separated file of the frequencies. The script is at: http://pastebin.com/VAZdeKXs Problem The following lines continually cycle through the dictionary to match words: for i in $(awk '{if( $2 ) print $2}' frequency.txt); do grep -m 1 ^$i\$ dictionary.txt >> corpus-lexicon.txt; done It works, but it is slow because it is scanning the words it found to remove any that are not in the dictionary. The code performs this task by scanning the dictionary for every single word. (The -m 1 parameter stops the scan when the match is found.) Question How would you optimize the script so that the dictionary is not scanned from start to finish for every single word? The majority of the words will not be in the dictionary. Thank you!

    Read the article

  • Dictionary object syntax?

    - by posfan12
    I'm having trouble figuring out the syntax for a JScript .NET dictionary object. I have tried private var myDictionary: Dictionary<string><string>; but the compiler complains that it's missing a semicolon and that the Dictionary object is not declared. I know JScript does have a native dictionary-like object format, but I'm not sure if there are disadvantages to using it instead of the .NET-specific construct. I.e., what if someone wants to extend my script using another .NET language?

    Read the article

  • Arrays and For Loop [closed]

    - by java
    I wrote this code: import java.io.*; public class dictionary { public static void main(String args[]) { String[] MyArrayE=new String[5]; String[] MyArrayS=new String[5]; String[] MyArrayA=new String[5]; MyArrayE[0]="Language"; MyArrayE[1]="Computer"; MyArrayE[2]="Engineer"; MyArrayE[3]="Home"; MyArrayE[4]="Table"; MyArrayS[0]="Lingua"; MyArrayS[1]="Computador"; MyArrayS[2]="Ing."; MyArrayS[3]="Casa"; MyArrayS[4]="Mesa"; System.out.println("Please enter a word"); BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String word= null; try { word= br.readLine(); } catch (IOException e) { System.out.println("Error!"); System.exit(1); } System.out.println("Your word is " + word); for(int i=0; i<MyArrayA.length; i++) { if(word.equals(MyArrayS[i])) { System.out.println(MyArrayE[i]); } } } } My Question: What about if the user inputs a word not in MyArrayS, I want to check that and print a statement like "Word does not exist". I think that it might look like: if(word!=MyArrayS) { System.out.println("Word does not exist"); }

    Read the article

  • Using string[] as a Dictionary key e.g. Dictionary<string[], StringBuilder>

    - by Nick Allen - Tungle139
    The structure I am trying to achieve is a composite Dictionary key which is item name and item displayname and the Dictionary value being the combination of n strings So I came up with var pages = new Dictionary<string[], StringBuilder>() { { new string[] { "food-and-drink", "Food & Drink" }, new StringBuilder() }, { new string[] { "activities-and-entertainment", "Activities & Entertainment" }, new StringBuilder() } }; foreach (var obj in my collection) { switch (obj.Page) { case "Food": case "Drink": pages["KEY"].Append("obj.PageValue"); break; ... } } The part I am having trouble with is accessing the Dictionary Key pages["KEY"] How do I target the Dictionary Key whose value at [0] == some value? Hope that makes sense

    Read the article

  • Document key usage in Dictionary

    - by phq
    How can I document the key usage in a Dictionary so that it shows in Visual studio when coding using that object? I'm looking for something like: /// <param name="SpecialName">That Special Name</param> public Dictionary<string,string> bar; So far the best attempt has been to write my own class: public class SpecialNameDictionary : IDictionary<string, string> { private Dictionary<string, string> data = new Dictionary<string, string>(); /// <param name="specialName">That Special Name</param> public string this[string specialName] { get { return data[specialName]; } } } But It adds a lot of code that doesn't do anything. Additionally I must retype every Dictionary method to make it compile. Is there a better way to achive the above?

    Read the article

< Previous Page | 6 7 8 9 10 11 12 13 14 15 16 17  | Next Page >