HashTable problem-Pls guide

G

Guest

Hello Everybody:
I have created a multiclient server application. I am storing the client information and the thread hashcode in a hashtable. I want to send the information back to the client from the server by selecting the thread hashcode from the hashtable and sending the information to the same client.. THe code I have developed is as follows:

try
{

int key = System.Int32.Parse(txtThreadCode.Text);
if(threadhashtable.ContainsKey(key))

{

Object objData = txtDataRx.Text;
byte[] byData = System.Text.Encoding.ASCII.GetBytes(objData.ToString ());


m_socWorker.Send (byData);
}
}
catch(SocketException se)
{
MessageBox.Show (se.Message );
}

When I put the threadhashtable variable "key" in the Watch window . The error which I got was

key error: identifier 'key' out of scope

What should I do to rectify this error. Pls guide..

Thanks,

Rahil
 
S

Stoitcho Goutsev \(100\) [C# MVP]

Hi KapilShah.

It depends where you set the breakpoint.The scope for the *key* variable is
the *try* block. Thus, if you set the breakpoint in the catch block, for
example, then the *key* is out of scope.

If you want to check that variable in the catch block declare it outside the
try block

int key;
try
{
key = System.Int32.Parse(txtThreadCode.Text);
.....
}
catch
{
......
}

--
HTH
B\rgds
100 [C# MVP]

KapilShah said:
Hello Everybody:
I have created a multiclient server application. I am storing the client
information and the thread hashcode in a hashtable. I want to send the
information back to the client from the server by selecting the thread
hashcode from the hashtable and sending the information to the same client..
THe code I have developed is as follows:
try
{


int key = System.Int32.Parse(txtThreadCode.Text);
if(threadhashtable.ContainsKey(key))

{

Object objData = txtDataRx.Text;
byte[] byData = System.Text.Encoding.ASCII.GetBytes(objData.ToString ());


m_socWorker.Send (byData);
}
}
catch(SocketException se)
{
MessageBox.Show (se.Message );
}

When I put the threadhashtable variable "key" in the Watch window . The error which I got was

key error: identifier 'key' out of scope

What should I do to rectify this error. Pls guide..

Thanks,

Rahil
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top