|
Which I have.
This is the Compare code. I suspect it has something to do with the bold text. BUt I can´t put my finger on it.
static bool Compare(SortedList SL, SortedList SL2)
{
if (SL.Count != SL2.Count)
{
return false;
}
foreach (DictionaryEntry item in SL)
{
if (!SL.ContainsKey(item.Key))
{
return false;
}
}
return true;
}
|
|
|
|
|
Is this homework?
"Run for your life from any man who tells you that money is evil. That sentence is the leper's bell of an approaching looter." --Ayn Rand
|
|
|
|
|
Not really, I am taking a course in C# but this is more of a side project I´d like to finish.
|
|
|
|
|
Here's a hint - you're reading from the SL sorted list, and then checking to see if the same sorted list contains the key. Change it to point to the right list:
foreach (DictionaryEntry item in SL)
{
if (!SL2.ContainsKey(item.Key))
{
|
|
|
|
|
|
Hmmmm....
This seems like an Equality problem...
"Run for your life from any man who tells you that money is evil. That sentence is the leper's bell of an approaching looter." --Ayn Rand
|
|
|
|
|
Equality... Equality... Equality...
A is equal to B if A = B and B = A
"Run for your life from any man who tells you that money is evil. That sentence is the leper's bell of an approaching looter." --Ayn Rand
|
|
|
|
|
But it's a list. That'll bugger things up.
A.items == B.items & B.items = A.items
Duplicates could mess you up.
pseudocode:
foreach thingy in A{
make sure thingy is in B.Thingies
}
foreach thingy in B {
make sure thingy is in A.Thingies
}
Help any?
"Run for your life from any man who tells you that money is evil. That sentence is the leper's bell of an approaching looter." --Ayn Rand
|
|
|
|
|
not really, if you could incorporate it into the Compare code I posted it may shed some light.
|
|
|
|
|
I'm not going to write code for you, call it tough love.
Again, I'll write pseudo code for you, you're supposed to be writing it to learn.
using SortedList, in this case you can go through by INDEX and check to see if the elements that life in the INDEXES match.
for(0 to elements){
if a[index] != b[index], return false.
}
return true.
Hope this helps.
"Run for your life from any man who tells you that money is evil. That sentence is the leper's bell of an approaching looter." --Ayn Rand
|
|
|
|
|
what do you mean by 0 to elements?
|
|
|
|
|
Alright.. you have two lists of KeyValuePairs.
Say they're identical.
List1 = [1,A],[2,B],[3,C],[4,D]
List2 = [1,A],[2,B],[3,C],[4,D]
When you have 2 sorted lists, you can use the index to do the check and not the foreach loop.
if(List1.Count != List2.Count) return false;
for(int i = 0 ; i < List1.Count ; i++){
if(List1[i] != List2[i]) return false;
}
return true;
And you can see when you write the problem out exactly how it happens.
Example 2 Inequal list lengths.
List1 = [1,A],[2,B],[3,C],[4,D]
List2 = [1,A],[2,B],[3,C],[4,D],[5,E]
the comparison of lengths returns false. OK.
Example 3 Inequal lists
List1 = [1,A],[2,B],[3,C],[4,D]
List2 = [1,A],[2,B],[3,C],[5,E]
remember that these are sorted, so we're COUNTING on the order.
List lengths, ok, continue.
List1[0] == List2[0] TRUE
List1[1] == List2[1] TRUE
List1[2] == List2[2] TRUE
List1[3] == List2[3] FALSE
Lists inequal, ok.
Remember that the contents of the list are important, so you have to check both the key and the value in your KeyValuePair.
B.Key == A.Key && B.Value == A.Value
Hope this helps some more.
"Run for your life from any man who tells you that money is evil. That sentence is the leper's bell of an approaching looter." --Ayn Rand
|
|
|
|
|
static bool Compare(SortedList SL, SortedList SL2)
{
if(SL.Count != SL2.Count) return false;
for(int i = 0 ; i < SL.Count ; i++)
{
if(SL[i] != SL2[i]) return false;
}
return true;
Is that right?
|
|
|
|
|
Hi all
I would like to use C# serialization classes to serialize the following, but I am quite crazy about how to do that!
I tried a lot of combination of Xml attributes, but notone was good!
Data types in variable are not the same..once they are string, then are float..etc..
Have you any idea?
Kind Regards
Emanuele
<Variable>
<Parameter>
<variable name="FirstVar"> 10.20</variable>
<variable name="SecondVar"> 10.22</variable>
<variable name="ThirdVar"> 10.23</variable>
<variable name="FourthVar"> false</variable>
<variable name="SixthVar"> 10.32</variable>
</Parameter>
</Variable>
|
|
|
|
|
Given the XML file doesn't contain information about the type, you're left to this kind of try/parse thing. When you encounter the variable value, try parsing it as a float, as a bool, and if that doesn't work, store it as a string. To see if a string contains a float or a bool or a ... use the float.TryParse, bool.TryParse, int.TryParse, etc. methods.
|
|
|
|
|
OK!
But in your opinion would it be possible to use the XML Attribute someway?
I try all possible combination with XmlRoot, XmlElement, XmlAttribute but I didn't achieve my goal of having a Serialized output like the one I wrote!
I tried with this, but then I was not able to find a suitable XmlAttribute for value without a tag!
OUPUT on FILE expected
<variable name="FirstVar">value</variable>
MY CLASS that doesn't work
class variable
{
[XmlAttribute]
String name;
}
|
|
|
|
|
Here's an example that will explain what info I'm needing:
"A user has created a cubic bezier curve and wants to add a new point in the middle of that curve."
Once the new point has been inserted, how can I calculate the (now four) control points to keep the original curvature of the line?
If you could rent a programmer a hour and a half for a dollar and a half, how much would he charge for 10 hours?
|
|
|
|
|
http://msdn2.microsoft.com/en-us/library/system.drawing.graphics.drawbezier.aspx[^]
I believe that's built in, if you didn't have that already. I don't know if that'll keep the original curvature on recalculation, didn't get a chance to try it out. Reordering by nearest neighbor may be necessary. Not too sure this will help, but I tried...
Scott
"Run for your life from any man who tells you that money is evil. That sentence is the leper's bell of an approaching looter." --Ayn Rand
|
|
|
|
|
Hi All,
I am developing an application where a client has to host a website.
In the sample / examples, this has been made so:
<br />
<br />
Create a socket, bind it to the server's port and listen for client connections<br />
Socket server = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);<br />
<br />
// Wait for a client to connect<br />
Socket clientSocket = server.Accept();<br />
<br />
<br />
// Return a static HTML page back to the client<br />
String s = "<html><head><title>Sample Website!</title></head></html>"; <br />
<br />
m_clientSocket.Send (Encoding.UTF8.GetBytes(s));
As you can see, a very simple website has been sent here.
I however, would like to design my own (much complexer with buttons, links etc.), but donot know how can I send it to the socket then, as it will certainly not fit in a simple string. Plus, it would be very difficult to get the HTML code for a website in a simple string (I dont even know whats a static and dynamic HTML page).
Hence, I request all, if you know of any method to somehow bind a VS2005 site (.aspx) to a socket, please help me.
Thank u all soo much.
|
|
|
|
|
indogerman wrote: Hence, I request all, if you know of any method to somehow bind a VS2005 site (.aspx) to a socket, please help me.
I don't know, but the simple way is to write up your website and then send the files over, not the text within. What your code there does is gets a string then gets the bytes that makes up that string. So it sends bytes rather than the string itself.
So, you open up your web page in a filestream, read some bytes, then send them.
Perhaps like this:
...
Filestream FS = new Filestream("myWebSite.htm", FileMode.Open);
byte[] buffer = new byte[1024];
while(FS.Position < FS.Length)
{
int bytesRead = FS.Read(buffer, 1024);
socket.Send(buffer, bytesRead);
}
It may not be exactly like that, thats just of the top of my head.
My current favourite word is: Bacon!
-SK Genius
|
|
|
|
|
Hi SKGenius,
Thanks a lot for your prompt help.... your idea was good, and I tried it, but it didnt work. The reason is that I am using the .NET Micro Framework , which really hardly has any classes/libraries (like for file/stream ).
So, I am still looking for a solution to send a Dynamic Webpage (HTML or .aspx) to a Client Socket.
Any Ideas?
Thanks a lot...
|
|
|
|
|
hi,
i've used a program of this site (http://www.codeproject.com/KB/system/usbeject.aspx) for deactivate an hd from an usb port... now i would like to reconnect this hd but in this code i don't try the method... Can you help me?
i explane my problem: i want to create a program that move files from an internal hd to an external hd when the first is full. After, the program had to deactivate the usb port of the external hd so the external hd turn off. When the internal hd is full again the program had to reconnect the usb so the external hd turn on... how i do it?
thanks
ps. excuse me if my english is not perfect
|
|
|
|
|
Joshua82 wrote: now i would like to reconnect this hd but in this code i don't try the method... Can you help me?
AFAIK, you can't do this through code. The drive would have to be powered off and back on again, or unplugged and plugged back it, to get the Device Manager to see it again.
|
|
|
|
|
The way I would do this is using a "Phidgets" Relay board[^] and their .NET API
|
|
|
|
|
...thank you
|
|
|
|
|