|
Hi,
I created a hash table with 3 elements.
hashtbl.Add(1, "aaa");
hashtbl.Add(2, "bbb");
hashtbl.Add(3, "ccc");
When I'm trying to modify the hash table as following,
hashtbl[2] ="xxx";
hashtable's length increased by 1.
After the above statement, hashtbl looks as following.
hashtbl[2, "xxx"]
hashtbl[1, "aaa"]
hashtbl[2, "bbb"]
hashtbl[3, "ccc"]
How can I restrict the hash table to add a new element with the same index, 2? I would like to get hashtable as below after the modification.
hashtbl[1, "aaa"]
hashtbl[2, "xxx"]
hashtbl[3, "ccc"]
Thanks in advance..
|
|
|
|
|
Is this using the built-in HashTable class? I would recommend using Dictionary<int, string>[^] instead. Your problem may have been due to some weirdness while boxing.
|
|
|
|
|
Thank you Vega02. Its worked and come to know about Dictionary class.
|
|
|
|
|
Vega02 wrote: Your problem may have been due to some weirdness while boxing.
That is exactly the reason for the problem. The HashTable class uses reference types as identifiers, so if you try to use value types as identifiers, they are boxed first.
Each time you box the value 2, it becomes a new object on the heap, containing the value. As they are separate objects, they have different hash codes.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Shouldn't the hash codes be the same, since they represent the same underlying value? It doesn't matter that they're boxed value types. They don't have reference equality, but they still have value equality, hence they should have the same hash code.
|
|
|
|
|
Vega02 wrote: Shouldn't the hash codes be the same, since they represent the same underlying value?
No, the values are boxed in a type Object, and the hash code of the Object is not based on the boxed value.
The GetHashCode method of the Object type is not suitable for use as key in a hash table. From the documentation:
"the default implementation of this method must not be used as a unique object identifier for hashing purposes"
MSDN Library: Object.GetHashCode method[^]
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
|
hi
As you told that you use msaccess database then no requirement to include database seprately. to deploy your project do the following..
1. File -> New Project -> Choose Other Project -> then Setup project
2. In the application folder add all the files available into your bin folder including the database file also.
Yogesh Agarwal
|
|
|
|
|
Hello,
I'm trying to make connection between a C# client to a C++ server.
Since I'm new at C/S I just downloaded sample programs, and tested them.
I downloaded the C++ server (and client) from:
http://www.codeproject.com/KB/IP/client_server_socket.aspx
The communication succeeded.
I also downloaded C# C/S from:
http://www.codeproject.com/KB/IP/tcpclientserver.aspx
It also worked.
But when I tried to make a connection from the C# client to the C++ server it didn't work (later on I also tried other versions of servers and clients in both languages – none worked).
What I see is that the client succeeded to connect to the server, but it didn’t succeed to send anything to the server, and the server stayed blocked waiting for the client's message (I encountered a version in which the server did get a message, i.e. was released from the blocking condition, but the message was empty).
BTW, when I changed the code such that only the server sends a message to the client - everything worked.
I don't know what problem to look for, nor if there is any known problems in this scenario.
I will really appreciate any help or idea what to do.
Thanks,
Itzik
|
|
|
|
|
Probably you need to examine what the code does in both instances to make sure they are communicating on the same port, and expecting to send/recieve data in the same format.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Thanks for your reply.
I checked it over and over ):
The ports are OK (The server does get the connection from the client).
Regarding the formats: the server is not released from the blocking situation of waiting for data (receive). So, is it possible that C# sends different format for simple strings (UTF, or something else) than C++, and is this format change can cause that the 'receive' function stays blocked?
modified on Tuesday, March 4, 2008 11:56 AM
|
|
|
|
|
Hi,
I am using Crystal Report Designer in my C# project. and kindly let me know, how may I create PDF file on button press?
"Is there any ready made samples about my said subject?"
Thank you in advance
(Riaz)
|
|
|
|
|
Most PDF librarys probably come with a sample that does what you want. You can't create a PDF without a PDF library.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Adding to Christian's reply, you need to use a library that would enable you to create PDF files on the fly. You may try iTextSharp[^].
Nobody can give you wiser advice than yourself. - Cicero
.·´¯`·->Rajesh<-·´¯`·.
Codeproject.com: Visual C++ MVP
|
|
|
|
|
|
Hi there,
I have to get processes info for a system but I m having an Exception "Access is denied" in this code,
<br />
try<br />
{<br />
processes = Process.GetProcesses(mcName);<br />
int nThreadsCount = 0;<br />
foreach (Process p in processes)<br />
{<br />
<br />
string[] prcDetails = new string[]{p.ProcessName,<br />
p.Id.ToString(),<br />
p.StartTime.ToShortTimeString(),<br />
p.TotalProcessorTime.Duration().Hours.ToString()+":"+p.TotalProcessorTime.Duration().Minutes.ToString()+":"+p.TotalProcessorTime.Duration().Seconds.ToString(),<br />
p.Threads.Count.ToString(),<br />
p.HandleCount.ToString()};<br />
<br />
nThreadsCount += p.Threads.Count;<br />
<br />
}<br />
}<br />
catch (Exception ex)<br />
{<br />
MessageBox.Show(ex.Message); <br />
}
When I commented the statement
p.StartTime.ToShortTimeString(),
then next statement which is also getting-time-related property
p.TotalProcessorTime.Duration().Hours.ToString()
is also causing same exception.
Here is the Sysem Trace:
" at System.Diagnostics.ProcessManager.OpenProcess(Int32 processId, Int32 access, Boolean throwIfExited)\r\n at System.Diagnostics.Process.GetProcessHandle(Int32 access, Boolean throwIfExited)\r\n at System.Diagnostics.Process.GetProcessTimes()\r\n at System.Diagnostics.Process.get_StartTime()\r\n at CustomizedTaskManager.frmmain.LoadAllProcessesOnStartup() in E:\\MyProjects\\Programing\\C#\\Task Manager\\CustomizedTaskManager\\CustomizedTaskManager\\Form1.cs:line 100"
best regards,
|
|
|
|
|
What process are you trying to get to ? I guess access is denied.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hi there,
Thanx for reply Graus.
This process is causing the exception.
Name: msdtc
MS DTCconsole program
ImagePath: C:\WINDOWS\system32\msdtc.exe
I m running this code in Vs 2005, While same code is running succesfully in VS 2003. I can't understand this weird behaviour.
Here is complete code of my method, u can test it on VS03.
public static void ListAllProcesses()<br />
{<br />
Process[] processes = null;<br />
string mcName = ".";<br />
try<br />
{<br />
processes = Process.GetProcesses(mcName); <br />
foreach (Process p in processes)<br />
{<br />
<br />
Console.Write("\nProcessName: " + p.ProcessName);<br />
Console.Write("\tID: " + p.Id.ToString());<br />
Console.Write("\tStartTime: " + p.StartTime.ToShortTimeString());<br />
Console.Write("\tCPUTime: " + p.TotalProcessorTime.Duration().Hours.ToString()+":"+p.TotalProcessorTime.Duration().Minutes.ToString()+":"+p.TotalProcessorTime.Duration().Seconds.ToString()); <br />
<br />
}<br />
}<br />
catch (Exception ex)<br />
{<br />
MessageBox.Show(ex.Message); <br />
}<br />
}
best regards,
Cyber Friend
|
|
|
|
|
|
Remote sensing image(b&W - captured by satellite), segmentation of the image is separeted by roads, trees, buildings, water levles done in C#.net or vb.net. Any possible ways to implement this.
|
|
|
|
|
Yes, I have no doubt.
There are tons of image processing books that cover image segmentation. What sort of answer were you hoping for ?
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
Hi all,
Wanna create a new website with 3/n tier.I want to keep all the business logic and DAL in different projects, in the same solution.
Please tell me the most efficient way to do this
should I add a new windows project to solution and start coding at the same place or
create an individual project and after successfully building it add it to my solution
or any other efficient way is there other than these two. Please give me your suggestions.
With Thanks & Regards
Amit Sk Sharma
modified on Tuesday, March 4, 2008 12:52 AM
|
|
|
|
|
Wow. I'm not sure if you're serious. You can do whatever you like, although it stands to reason that the process with the least steps is to create the project within the existing solution, you'll lose valuable micro seconds if you do it the other way.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
That's the thing I wish to know; do this effects the functioning/ performance or it's just like to add a project having logic with it.
With Thanks & Regards
Amit Sk Sharma
|
|
|
|
|
Well, I'm not sure how you think it could affect anything. Code is code. The way it builds won't change by how it was added to a solution, in fact, the two methods you suggest, each create exactly the same thing, a project that gets built within the context of a solution.
Christian Graus - Microsoft MVP - C++
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|