|
One way is to first sort the lists, then you can easily loop through them side by side and compare them.
Pseudo code:
sort A
sort B
loop {
get a from A
get b from B
if a < b
"Only in A: " + a
advance A
else if b < a
"Only in B: " + b
advance B
else
advance A
advance B
}
You have to keep track of when the lists end, also. I did not include that in the pseudo code, for simplicity.
---
single minded; short sighted; long gone;
|
|
|
|
|
Thanks.
I should also mention that the lists could be different lengths.
Kathy.
|
|
|
|
|
KatNel wrote: I should also mention that the lists could be different lengths.
I took for granted that they could be, as you want the items that are present in only one of the lists.
---
single minded; short sighted; long gone;
|
|
|
|
|
here's my final:
private void diff2()
{
List<string> aList = new List<string>();
aList.Add("a");
aList.Add("d");
List<string> bList = new List<string>();
bList.Add("z");
bList.Add("a");
CompareLists(aList, bList,
delegate(string a) { Console.WriteLine(a + " only in list a"); },
delegate(string b) { Console.WriteLine(b + " only in list b"); },
delegate(string c) { Console.WriteLine(c + " in both"); }
);
}
delegate void InList(string inputValue);
private void CompareLists(List<string> al, List<string> bl, InList onlyA, InList onlyB, InList both)
{
int a = 0;
int b = 0;
al.Sort();
bl.Sort();
while ((a < al.Count) && (b < bl.Count))
{
int cp = al[a].CompareTo(bl[b]);
if (cp < 0)
onlyA(al[a++]);
else if (cp > 0)
onlyB(bl[b++]);
else
{
++a;
both(bl[b++]);
}
}
while (a < al.Count)
onlyA(al[a++]);
while (b < bl.Count)
onlyB(bl[b++]);
}
|
|
|
|
|
Below a quite different approach in pseudocode:
Collection common=new Collection();
foreach(object i in a.Clone()) {
if (b.Contains(i)) {
a.Remove(i);
b.Remove(i);
common.Add(i);
}
}
At the end, you have three collections: common holds the common items,
a and b only keep the non-common items.
a.Clone is necessary since we want to modify a while enumerating.
Luc Pattyn
|
|
|
|
|
I was trying to schedule the computer to go into standby / hibernate mode. After a specified duration I wanted the PC to come out of standby. I wanted to automatically send my computer to standby between specific times of the day.
Its easy enough to send the computer into standby, how do you bring it out?
Does anyone know how to accomplish this?
Thanks in advance.
|
|
|
|
|
I would like to know how can i move with IEnumerator movenext and moveback, that is forward and back in the list iterated.
|
|
|
|
|
IEnumerator only supports moving in a logically forward direction. Further, the Reset() method is optional and may not be supported by all instances of IEnumerator .
/ravi
|
|
|
|
|
Hey
Does anyone have an idea to implent something like paint? I need to create a program like Pictionary or iSketch.net but I have no idea to implement the drawing area.
Greetings
K.
|
|
|
|
|
|
Perhaps the Scribble[^] sample will help you get started?
/ravi
|
|
|
|
|
Thanks guys, I'll look into that.
|
|
|
|
|
|
http://www.getpaint.net/index2.html[^]
I haven't really looked at Paint.NET source but I can imagine there's a lot to learn.
"Throughout human history, we have been dependent on machines to survive. Fate, it seems, is not without a sense of irony. " - Morpheus
|
|
|
|
|
Hello,
I have a tab control and on one of the tabs I have the ListView control that has the ItemCheck event. When application starts, the tab that contains the ListView does not have focus. But if I select that tab, the ItemCheck event fires all the time, but only the first time I select the tab. If I start switching the tabs the event does not fire anymore.
What's going on? How can I suppress that event firing for the first time?
Thank you.
|
|
|
|
|
According to MSDN, "the ItemCheck event occurs when the check state of an item changes or when the CheckBoxes property is set to true". Perhaps the first instance of the event occurs when you set the list view's CheckBoxes property?
/ravi
|
|
|
|
|
I´m working with large xml files(about 100MB) and what I have to do is:
- first validate the xml file against a schema
- then insert data from the file to a database
What is the most efficient way to do this? Can anyone help me with this?
cellardoor
|
|
|
|
|
Efficient at 100 megs may not be that big of an issue. System.Xml.XmlReader is the fast method for reading. System.Xml.XmlValidatingReader will validate.
File Not Found
|
|
|
|
|
Using a DOM reader like XmlDocument is the standard way to read/edit xml documents (at least I think...) because you can use XPATH and stuff. However, if you read a 100MB xml document with a dom reader your program will be suddenly using 100MB of ram. I'm pretty sure you don't want that...
/\ |_ E X E GG
|
|
|
|
|
Yeah, Ennis Ray Lynch, Jr. is right, you want to use a sax based reader like XmlReader because a DOM based reader like XmlDocument would be too slow.
/\ |_ E X E GG
|
|
|
|
|
Thanks I´ll try it
cellardoor
|
|
|
|
|
The following link should be helpful for the validation part: Validating XML Data with XmlReader[^]
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Using Visual Studio 2005, I'm creating an application with floating tool bars similar to that of Photoshop (or most any application with floating tool bars) that share focus amongst each other. I have my tool bars in separate forms, and I call form.Show(ownerForm), to display the toolbar, where ownerForm is the main application's form. The problem is that only one form, the application's main form or the tool bar, can have focus at a time. Is there a property or method I can call to give focus to both the tool bar and the application's main form at the same time?
Skip
|
|
|
|
|
i think if you develop the toolbar as a usercontrol not as a frame it will give you an advantage. cz if you did it as a user control and add it to the first frame it will be as any normal control in your frame. this will allow you to have a double focus. you can drag and drop from it and .........
i am not very sure about the idea i gave you but i think it will be a starting point for you.
good luck
|
|
|
|
|
In VS2005 C#,How to make first item of the Combobox as default selection?
I have tried Combobox.selectedIndex=-1.But its not working.
Is there anyother way?
Thanks in advance
|
|
|
|