I have a dictionary as described in the question. My Foo class looks like this:
class Foo {
List<Bar> Bars {get;set;}
}
I want to run through the dictionary, and assign the KeyValuePair value to the Key's Bars property. Is that possible?
I have something like this but it's a little wonky:
List<Foo> foos = new List<Foo>();
foreach(...
Hi all,
This might be a very silly / stupid question, but, my defence is that I am a beginner!
Suppose I have a dictionary in c# :
Dictionary<int,string> D = new Dictionary<int,string>();
If I wanted to add all values (which is string) instead of looping and appending all values to a stringBuilder, i do:
string.Join(",",D.values...
I have dictionary, like
Dictionary<string, bool> accValues = new Dictionary<string, bool>()
And I want to get bool value for specific key. I can do it via foreach, like
foreach (KeyValuePair<string, bool> keypair in accValues)
{
if (keypair.Key == "SomeString")
{
return ...
When is it acceptable for an indexer to automatically add items to a collection/dictionary? Is this reasonable, or contrary to best practices?
public class I { /* snip */ }
public class D : Dictionary<string, I>
{
public I this[string name]
{
get
{
I item;
if (!this.TryGetValue(name, out...
Currently, I have a static factory method like this:
public static Book Create(BookCode code) {
if (code == BookCode.Harry) return new Book(BookResource.Harry);
if (code == BookCode.Julian) return new Book(BookResource.Julian);
// etc.
}
The reason I don't cache them in any way is because BookResource is sensitive to cultu...
Hello.
My dictionary declared as below
public static Dictionary<object, DataInfo> DataDic = new Dictionary<object, DataInfo>();
public class DataInfo
{
public string DSPER; // Data Sample Period
public int TOTSMP; // Total Samples to be made
public int REPGSZ; // Report Group Size
...
I'm trying out some MVC stuff and I was wondering if there's some way to edit dynamic fields.
So to try this I added a keyed collection called CustomFields. I've tried both Hashtable and Dictionary.
In the view I then wrote:
<%:Html.TextBoxFor(model => model.CustomFields["x"])%>
This then generated this HTML:
<input id="CustomFields...
I want to use a Dictionary(Of Key, Value), and the Key is not a base type, but a class like:
Public Class MyKey
Sub New(ByVal packet As String, ByVal sent As Boolean)
Me.packet = packet.ToUpper.Trim
Me.sent = sent
End Sub
Private packet As String
Private sent As Boolean
End Class
Now to have the Dicti...
I'm working with Outlook 2003. I was wondering if anyone knew a way to create your own custom dictionary complete with word replacement, suggestions etc. Sort of like an International Dictionary, e.g. "English (U.S.)".
The main problem I'm trying to solve is to replace corporate speak words with simpler terms. So this is why the include...
How do I create a dictionary in python that is passed to a function so it would look like this:
def foobar(dict):
dict = tempdict # I want tempdict to not point to dict, but to be a different dict
#logic that modifies tempdict
return tempdict
How do I do this?
...
I'm working with a large set of hierarchical taxonomic terms, where each term ("203") has a matching "term203" movie clip on the stage, and am having trouble getting a recursive function to return all of a given term's descendants.
There is a main Dictionary() object with the following nested organization for each term:
{ [object Movie...
Currently I'm using the following class as my key for a Dictionary collection of objects that are unique by ColumnID and a nullable SubGroupID:
public class ColumnDataKey
{
public int ColumnID { get; private set; }
public int? SubGroupID { get; private set; }
// ...
public override int GetHashCode()
{
var h...
If I understand correctly, in Python 2, iter(d.keys()) was the same as d.iterkeys(). But now, d.keys() is a view, which is in between the list and the iterator. What's the difference between a view and an iterator?
In other words, in Python 3, what's the difference between
for k in d.keys()
f(k)
and
for k in iter(d.keys())
f...
I want to pass a fairly generic set of data through a WCF method. The data is basically just a hierarchical set of key/value pairs, but it's nested to an arbitrary level. I originally considered passing it though as a single string and doing XML or JSON or similar encoding/decoding at either end, but since the WCF transport is XML anyw...
Hi
I'm trying to populate a Dictionary object in GWT with data from the server. The Dictionary takes a javascript as input, but I want to send in a String. (acctually its an hashmap.toString). How do I create an javascript object from my string (in java ) that Dictionary will accept?
Thanks
...
I use a static function to create a PDO object.
It accepts 2 params:
a string and an object which contains the connection settings (dns, user, pass).
in order to prevent unnecessarily creating duplicate PDO connections with the same name, I tried to create a multi-key dictionary to cache the PDO object in.
Here is what I did:
incl...
The function class:
def play_best_hand(hand, wordDict):
tempHand = hand.copy()
points = 0
for word in wordDict:
for letter in word:
if letter in hand:
tempHand[letter] = tempHand[letter] - 1
if tempHand[letter] < 0:
return False
if wordDict[word] > points:
...
I have this:
dictionary = { (month, year) : [int, int, int] }
I'd like to get a list of tuples/lists with the ordered data(by month and year):
#example info
list = [(8,2010,2,5,3),(1,2011,6,7,8)...]
I've tried several times but I can't get to a solution.
Thanks for your help.
...
App.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="1" value="An error occured.\r\nPlease try again later." />
</appSettings>
</configuration>
Code:
Dictionary<string, string> keyValuePairs = new Dictionary<string, string>();
string key = "1";
keyValuePairs.Add(key, ConfigurationManage...
I have two dictionaries like
Dictionary<String, String> one = new Dictionary<string, string>
{
{ "A", "1" },
{ "B", "2" },
{ "C", "3" },
{ "D", "4" },
{ "E", "5" },
{ "F", "6" },
{ "G", "7" },
{ "H", "8" }
};
Dictionary<String, String> two = new Dictionary<string, string>
{
{ "A", "1" },
{ "B", "...