Hi,
How do i concat two dictionaries aka the following sample:
Dictionary<int, stringa;
Dictionary<int, stringb;
b.Add(a);
What is the easiest way to concat two dictionaries ??
BR
Peter 8 7085
"Peter Larsen [CPH]" <Pe*********@community.nospamwrote:
How do i concat two dictionaries aka the following sample:
Dictionary<int, stringa;
Dictionary<int, stringb;
What do you want to do if both dictionaries use the same integer key?
(For example, do you want to produce an <int, string[]?)
If you know that won't happen, then just use a loop and add each element
of one to the other.
Eq.
Are their any potential clashes in the key? In other words, suppose the
following:
Dictionary<int, stringa = new Dictionary<int, string>();
Dictionary<int, stringb = new Dictionary<int, string>();
a.Add(1,"a");
a.Add(2,"b");
b.Add(1, "c");
b.Add(2, "d");
You have a clash here. Although you can concat in one statement, in
Framework 3.5, you will end up with a clash in keys, which is not good. If b
is filled like so:
b.Add(3, "c");
b.Add(4, "d");
you do not end up with the same issue.
If you have clashes, you will have to loop.
--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA
Subscribe to my blog http://gregorybeamer.spaces.live.com/lists/feed.rss
or just read it: http://gregorybeamer.spaces.live.com/
*************************************************
| Think outside the box!
|
*************************************************
"Peter Larsen [CPH]" <Pe*********@community.nospamwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
Hi,
How do i concat two dictionaries aka the following sample:
Dictionary<int, stringa;
Dictionary<int, stringb;
b.Add(a);
What is the easiest way to concat two dictionaries ??
BR
Peter
I am aware about the potential danger in the sample - i'm just trying to
figure out what linq and lambda is and what it can do for me :-)
/Peter
"Cowboy (Gregory A. Beamer)" <No************@comcast.netNoSpamMwrote in
message news:Ob*************@TK2MSFTNGP06.phx.gbl...
Are their any potential clashes in the key? In other words, suppose the
following:
Dictionary<int, stringa = new Dictionary<int, string>();
Dictionary<int, stringb = new Dictionary<int, string>();
a.Add(1,"a");
a.Add(2,"b");
b.Add(1, "c");
b.Add(2, "d");
You have a clash here. Although you can concat in one statement, in
Framework 3.5, you will end up with a clash in keys, which is not good. If
b is filled like so:
b.Add(3, "c");
b.Add(4, "d");
you do not end up with the same issue.
If you have clashes, you will have to loop.
--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA
Subscribe to my blog http://gregorybeamer.spaces.live.com/lists/feed.rss
or just read it: http://gregorybeamer.spaces.live.com/
I just want to copy the items from dictionary "a" to dictionary "b".
Normally i would do something similar to this:
Dictionary<int, stringb = new Dictionary<int, string>(a);
I'm just trying to find new ways using linq...
/Peter
>
>Is it possible to do something similar to the following:
Dictionary<int, stringa = ... {add some some items}; Dictionary<int, stringb = from item in a select ... what to do here ??
It's not entirely clear to me what you actually want to do.
write an extension method!
of course if you could write static extensions you could do...
public static Concat(ref this null, Dictionary<t, kdict1, Dictionry<t, k>
dict2)
{
...
}
Dictionary<int, stringa;
Dictionary<int, stringb;
....
Dictionary<int, stringc = Dictionary.Concat(a, b);
but no one seems to agree with me about grouping related functions with
static extensions!
Dict
"Peter Larsen [CPH]" wrote:
Hi,
How do i concat two dictionaries aka the following sample:
Dictionary<int, stringa;
Dictionary<int, stringb;
b.Add(a);
What is the easiest way to concat two dictionaries ??
BR
Peter
Thank you for you comments.
I think my question has been answered by now.
/Peter
One of the best, human readible that is, explanations of Lambda expressions
is found in the book Introducing Microsoft(r) LINQ. You can read Chapter 2
from the free book offer page ( http://csna01.libredigital.com/).
It runs through Generics to Delegates to Anonymous Methods to Extension
Methods to Lambda Expressions. Once you follow the path, you should have a
decent idea of how to navigate this jungle.
--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA
Subscribe to my blog http://gregorybeamer.spaces.live.com/lists/feed.rss
or just read it: http://gregorybeamer.spaces.live.com/
*************************************************
| Think outside the box!
|
*************************************************
"Peter Larsen [CPH]" <Pe*********@community.nospamwrote in message
news:Os**************@TK2MSFTNGP05.phx.gbl...
>I am aware about the potential danger in the sample - i'm just trying to figure out what linq and lambda is and what it can do for me :-)
/Peter
"Cowboy (Gregory A. Beamer)" <No************@comcast.netNoSpamMwrote in
message news:Ob*************@TK2MSFTNGP06.phx.gbl...
>Are their any potential clashes in the key? In other words, suppose the following:
Dictionary<int, stringa = new Dictionary<int, string>(); Dictionary<int, stringb = new Dictionary<int, string>();
a.Add(1,"a"); a.Add(2,"b");
b.Add(1, "c"); b.Add(2, "d");
You have a clash here. Although you can concat in one statement, in Framework 3.5, you will end up with a clash in keys, which is not good. If b is filled like so:
b.Add(3, "c"); b.Add(4, "d");
you do not end up with the same issue.
If you have clashes, you will have to loop.
-- Gregory A. Beamer MVP, MCP: +I, SE, SD, DBA
Subscribe to my blog http://gregorybeamer.spaces.live.com/lists/feed.rss
or just read it: http://gregorybeamer.spaces.live.com/
Thanks for the links Gregory..
/Peter
"Cowboy (Gregory A. Beamer)" <No************@comcast.netNoSpamMwrote in
message news:u0*************@TK2MSFTNGP05.phx.gbl...
One of the best, human readible that is, explanations of Lambda
expressions is found in the book Introducing Microsoft(r) LINQ. You can
read Chapter 2 from the free book offer page
(http://csna01.libredigital.com/).
It runs through Generics to Delegates to Anonymous Methods to Extension
Methods to Lambda Expressions. Once you follow the path, you should have a
decent idea of how to navigate this jungle.
--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA
Subscribe to my blog http://gregorybeamer.spaces.live.com/lists/feed.rss
or just read it: http://gregorybeamer.spaces.live.com/ This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: ESPNSTI |
last post by:
Hi,
I'm trying to use a generics dictionary with a key class that implements and
needs IComparable<>.
However when I attempt to use the dictionary, it doesn't appear to use the
IComparable<> to...
|
by: Brian P |
last post by:
I want to expose a property of Dictionary<string, MyAbstractClass>.
I tried to do it this way:
private Dictionary<string, MyChildClass> _dictionary;
public Dictionary<string,...
|
by: Eran |
last post by:
Hi,
I have a huge data structure, which I previosly stored in a
Dictionary<int, MyObj>
MyObj is relatively small (2 int, 1 DateTime, 1 bool).
The dictionary I am using is quite large...
|
by: Andrew Robinson |
last post by:
I have a method that needs to return either a Dictionary<k,vor a List<v>
depending on input parameters and options to the method.
1. Is there any way to convert from a dictionary to a list...
|
by: Peter K |
last post by:
Hi
are there any benefits in using StringDictionary over Dictionary<string,
string?
It appears they achieve the same thing... (I could be wrong of course).
thanks,
Peter
|
by: Mark S. |
last post by:
Hello,
I have a series of changing string IDs that are loaded dynamically a couple
times a minute. I need to associate each ID with a different static class so
later on in the app's lifecycle it...
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |