Search Results

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

Page 14/90 | < Previous Page | 10 11 12 13 14 15 16 17 18 19 20 21  | Next Page >

  • How to show that the double-checked-lock pattern with Dictionary's TryGetValue is not threadsafe in

    - by Amir
    Recently I've seen some C# projects that use a double-checked-lock pattern on a Dictionary. Something like this: private static readonly object _lock = new object(); private static volatile IDictionary<string, object> _cache = new Dictionary<string, object>(); public static object Create(string key) { object val; if (!_cache.TryGetValue(key, out val)) { lock (_lock) { if (!_cache.TryGetValue(key, out val)) { val = new object(); // factory construction based on key here. _cache.Add(key, val); } } } return val; } This code is incorrect, since the Dictionary can be "growing" the collection in _cache.Add() while _cache.TryGetValue (outside the lock) is iterating over the collection. It might be extremely unlikely in many situations, but is still wrong. Is there a simple program to demonstrate that this code fails? Does it make sense to incorporate this into a unit test? And if so, how?

    Read the article

  • How to bind Dictionary with ComboBox and textbox?

    - by younevertell
    I have a Dictionary, where Person is a class, defined below String role; public class Person { public string firstname{ get; set; } public string lastname{ get; set; } public string city{ get; set; } } my question is how to bind the Dictionary key: String with a ComboBox, menwhile. have the Dictionary value: Person connected with three textboxes. That is, once a key is selected in the ComboBox, the corresponding value, firstname, lastname, city are shown in the three textboxes respectively? Thanks in advance!

    Read the article

  • Remove certain keys from a dictionary in python

    - by Margaret
    I'm trying to construct a dictionary that contains a series of sets: {Field1:{Value1, Value2, Value3}, Field2{Value4}} The trouble is, I then wish to delete any fields from the dictionary that only have one value in the set. I have been writing code like this: for field in FieldSet: if len(FieldSet[field]) == 1: del(FieldSet[field]) But receive the error "RuntimeError: dictionary changed size during execution". (Not surprising, since that's what I'm doing.) It's not the be-all and end-all if I have to knock together some sort of workaround, but is it possible to do this?

    Read the article

  • Using LINQ to remove dupicates in dictionary and the count of those duplicates

    - by Robert
    I have some code that returns unique elements in my dictionary, but I would also like to return the count of the duplicate elements. Basically change dictionary[key, uniqueelement] to dictionary[uniqueelement, count]. Here is my code that just returns the unique elements. var uniqueItems = deviceInstances.Children.GroupBy(pair => pair.Value.Information.UnderlyingDeviceType) .Select(group => group.First()) .ToDictionary(pair => pair.Key, pair => pair.Value.Information.UnderlyingDeviceType.ToString());

    Read the article

  • Problem with dictionary key in Python

    - by Hossein
    Hi all, For some project I have to make a dictionary in which the keys are urls,among which I have this url: http://www.microsoft.com/isapi/redir.dll prd=windows&sbp=mediaplayer&ar=Media&sba=Guide&pver=6.2 the url is too long to fit in here I guess in one single line. there is a space between .dll and prd. I can build a dictionary without any errors this url is also a key. but for some reason when I want to extract the values associated to this key(url). I cannot, I get and error "error key:...." Does someone know what is wrong with this url? Are dictionary keys sensitive to some stuff? thanks

    Read the article

  • Preventing dictionary attacks on a web application

    - by Kevin Pang
    What's the best way to prevent a dictionary attack? I've thought up several implementations but they all seem to have some flaw in them: Lock out a user after X failed login attempts. Problem: easy to turn into a denial of service attack, locking out many users in a short amount of time. Incrementally increase response time per failed login attempt on a username. Problem: dictionary attacks might use the same password but different usernames. Incrementally increase response time per failed login attempt from an IP address. Problem: easy to get around by spoofing IP address. Incrementally increase response time per failed login attempt within a session. Problem: easy to get around by creating a dictionary attack that fires up a new session on each attempt.

    Read the article

  • Taking 2 attributes from XElement to create a dictionary LINQ

    - by AndyC
    I'm trying to take one attribute to use as the key, and another to use as the value. If I use (xDoc is an XDocument object in the example): Dictionary<string, XElement> test = xDoc.Descendants() .Where<XElement>(t => t.Name == "someelement") .ToDictionary<XElement, string>(t => t.Attribute("myattr").Value.ToString()); I get a dictionary with the myattr value as key (which is what I want) but the entire XElement object as the value. What I want to do, is to select a second attribute to set as the value property on each dictionary item, but can't seem to figure that out. Is it possible to do all of this in 1 Linq statement? Curiousity has caught me! Cheers!

    Read the article

  • How can I apply indexer to Dictionary VALUES (C#3.0)

    - by Newbie
    I have done a program string[] arrExposureValues = stock.ExposureCollection[dt] .Values.ToArray(); for(int i=0;i<arrExposureValues .length;i++) Console.WriteLine(arrExposureValues[i]); Nothing wrong and works fine. But is it possible to do something like the below for(int i=0;i<stock.ExposureCollection[dt].Count;i++) Console.WriteLine(stock.ExposureCollection[dt].Values[i]); This is just for my sake of knowledge (Basically trying to accomplish the same in one line). Note: ExposureCollection is a dictionary object Dictionary<DateTime, Dictionary<string, string>> First of all I have the doubt if it is at all possible! I am using C#3.0. Thanks.

    Read the article

  • Selecting dictionary items by key efficiently in Python

    - by user248237
    suppose I have a dictionary whose keys are strings. How can I efficiently make a new dictionary from that which contains only the keys present in some list? for example: # a dictionary mapping strings to stuff mydict = {'quux': ..., 'bar': ..., 'foo': ...} # list of keys to be selected from mydict keys_to_select = ['foo', 'bar', ...] The way I came up with is: filtered_mydict = [mydict[k] for k in mydict.keys() \ if k in keys_to_select] but I think this is highly inefficient because: (1) it requires enumerating the keys with keys(), (2) it requires looking up k in keys_to_select each time. at least one of these can be avoided, I would think. any ideas? I can use scipy/numpy too if needed.

    Read the article

  • Add a whole dictionary to Android

    - by SaulBack
    I want to add an entire medical dictionary to my android (Moto Droid). I would like to be able to send text messages and have the medical words be in the predictable text. Is it possilbe? Is there an app to accomplish this? My friends Blackberry can do it, and it makes me so jealous.

    Read the article

  • What meta tag or microdata should I use for a dictionary web application?

    - by vonPetrushev
    I have a web application that serves as a dictionary, and it ranks good at google when searching for a rare word in my language (the dictionary's target language). I want the result to appear in the define: some-word, as well as in the search results when someone uses the filter tool Dictionary. Should I add some special meta-tag in the head of the html? How about microdata? Does google have a special webmaster tool for registering dictionaries like: wordnetweb.princeton.edu or en.wiktionary.org ?

    Read the article

  • How to merge two didctionaries in C# with duplicates

    - by user320587
    Hi, Is there a way in C# to merge two dictionaries? I have two dictionaries that may has the same keys, but I am looking for a way to merge them so, in the end there is a dictionary with one key and the values from both the dictionaries merged. I found the following code but it does not handle duplicates. Dictionary Mydictionary<string, string[]> = new Dictionary<string, string[]>(); Mydictonary.Union(secondDictionary).ToDictionary( pair => pair.Key, pair => pair.Value);

    Read the article

  • Hashtable with MultiDimensional Key in C#

    - by scottschulthess
    I'm basically looking for a way to access a hashtable value using a two-dimensional typed key in c#. Eventually I would be able to do something like this HashTable[1][false] = 5; int a = HashTable[1][false]; //a = 5 This is what I've been trying...hasn't worked Hashtable test = new Hashtable(); test.Add(new Dictionary<int, bool>() { { 1, true } }, 555); Dictionary<int, bool> temp = new Dictionary<int, bool>() {{1, true}}; string testz = test[temp].ToString();

    Read the article

  • .NET values lookup

    - by Maciej
    Hi, I have a feeling of missing something obvious. UDP receiver application. It holds a collection of valid UDP sender IPs - only guys with IP on that list will be considered. Since that list must be looked at on every packet and UDPs are so volatile, that operation must be maximum fast. Good choice is Dictionary but it is a key-value structure and what I actually need here is a dictionary-like (hash lookup) key only structure. Is there something like that? Small annoyance rather than a bug but still. I can still use Dictionary Thanks, M.

    Read the article

  • Looking for a syntactic shortcut for accessing dictionaries

    - by Sisiutl
    I have an abstract base class that holds a Dictionary. I'd like inherited classes to be able to access the dictionary fields using a convenient syntax. Currently I have lots of code like this: string temp; int val; if (this.Fields.TryGetValue("Key", out temp)) { if (int.TryParse(temp, out val)) { // do something with val... } } Obviously I can wrap this in utility functions but I'd like to have a cool, convenient syntax for accessing the dictionary fields where I can simply say something like: int result = @Key; Is there any way to do something like this in C# (3.5)?

    Read the article

  • Retrieving selected data from DataGrid with IEnumerable<IDictionary> (Silverlight)

    - by RemiX
    I have an application that can dynamically load data into a DataGrid. What's needed is an object of IEnumerable<IDictionary>, and a List<Dictionary<string,object>> is supplied (each Dictionary in the list has exactly the same keys). The data is loaded into the DataGrid and shown, but now I want to retrieve the data the user has clicked on. Using datagrid.SelectedItem, Silverlight complains it cannot evaluate the variable, not even when type-casted. I tried keeping the List<Dictionary<string,object>> and retrieving the right data from it using datagrid.SelectedIndex, but this index changes when the DataGrid is sorted. Does anyone know a solution to this problem?

    Read the article

  • LINQ Equivalent query

    - by GilliVilla
    I have a List<string> List<string> students; students.Add("123Rob"); students.Add("234Schulz"); and a Dictionary<string,string> Dictionary<string, string> courses = new Dictionary<string, string>(); courses .Add("Rob", "Chemistry"); courses .Add("Bob", "Math"); courses .Add("Holly", "Physics"); courses .Add("Schulz", "Botany"); My objective now is to get a List with the values - {Chemistry,Botany} . In other words, I am trying to get the LINQ equivalent of select value from [courses] where [courses].key in ( select [courses].key from courses,students where [students].id LIKE '%courses.key%' ) How should the LINQ query be framed?

    Read the article

  • Dynamic name of NSMutableDictionary?

    - by Bruno
    Hi everyone I load from a txt file many info, and I would like, if possible, to dynamically create NSmutable dictionary with the elements of the txt. For example, each is like that: id of element | date | text What I'm asking is the equivalent of the NSString stringWithFormat:. Can we do the same for an Mutable Dictionary? To be more practical, let's say the NSString *date is equal to "23/12/2009" (for europe). I want to create a dictionary called 23/12/2009 without declaring *23/12/2009 but just something like dictionaryWithFormat: @"%@", date]; I'm stuck on this, and I don't even know if it is possible. If not, what's the best way to approach that? Thanks everyone Regards

    Read the article

  • Binding Dictionary<T> to a WPF ListBox

    - by Joan Venge
    Given a dictionary of <string, Drink>, how would you bind the dictionary.Values to a WPF ListBox, so that the items use the .Name property? struct Drink { public string Name { get; private set; } public int Popularity { get; private set; } public Drink ( string name, int popularity ) : this ( ) { this.Name = name; this.Popularity = popularity; } }

    Read the article

  • Finding anagaram(s) of dictionary words

    - by Codenotguru
    How can I take an input word (or sequence of letters) and output a word from a dictionary that contains exactly those letters? Does java has an English dictionary class (list of words) that I can use, or are there open source implementations of this? How can I optimize my code if this needs to be done repeatedly?

    Read the article

  • flex Dictionary dataProvider?

    - by paleozogt
    I have a Dictionary that I'd like to bind as the dataProvider for an mx:ComboBox. e.g., when I do this: mydict[somenewkey]= somenewval; I'd like the combobox to update its contents. The problem is that Dictionary doesn't seem to be Bindable. If I were using an Array, I'd use ArrayCollection. But there doesn't seem to be a corresponding DictionaryCollection or HashCollection. What to do?

    Read the article

  • SQL Command Result to Dictionary C# .NET 2.0

    - by Joel
    I have a simple SQL query (using SqlCommand, SqlTransaction) in .NET 2.0 that returns a table of integer-string pairs (ID, Name). I want to get this data into a dictionary like Dictionary. I can get the result into a DataTable, but even iterating over it, I'm not sure how to do the typing and all that stuff. I feel like this must be a common problem but I haven't found any good solutions. Thanks in advance.

    Read the article

  • Return number of matches from c# dictionary

    - by Rickard Haake
    Hello! I have a dictionary with non unique values and I want to count the matches of a string versus the values. Basically I now do dict.ContainsValue(a) to get a bool telling me if the string a exists in dict, but I want to know not only if it exists but how many times it exists (and maybee even get a list of the keys it exists bound to) Is there a way to do this using dictionary, or should I look for a different collection? /Rickard Haake

    Read the article

  • Bind DataGrid to Dictionary in ASP.NET

    - by mcoolbeth
    In ASP.NET, binding a DataGrid to a list of objects is super-easy. I end up with a row for each object in the list, and any cell in a given row is bound to a property of the corresponding object. However, suppose one of the properties of my object is a dictionary, and each is expected to contain a specific key. Is there any way to bind one of my DataGridColumns to that dictionary key? Thanks.

    Read the article

  • Generic Dictionary C#

    - by pm_2
    I have a class that inherits from a generic dictionary as follows: Class myClass : System.Collections.Generic.Dictionary<int, Object> I have added a list of values to this in a particular order, but I now wish to change that order. Is there any way (without removing and re-adding) that I could effectively re-index the values; so change the object at index 1 to now be at index 10 for example? For example, this doesn't work: myClass[1].Index = 10;

    Read the article

< Previous Page | 10 11 12 13 14 15 16 17 18 19 20 21  | Next Page >