0

What I have:

(tcp stuff here)
data = System.Text.Encoding.ASCII.GetString(bytes, 0, i);
switch (data)
{
  case (data.Substring(0,6)=="send /":
   MessageBox.Show(data.Substring(6).....)
   break;
  case (....):
  .....
  break;
  .......
}

The error: cant implicitly convert bool to string. This is from the case statements. I would use an if statement but when I do that, It freaks out if I type something anything that is not evaluated. I did try:

if (...)
{
...
}
else if (...)
{
...
}
else
{
  continue;
}

and that didnt work. switch case seems to work better in this scenario. But unlike in VB, i cant put the substring evaluation in the case declaration. I can do this:

switch (data.Substring(length of the smallest command to be sent))

Thats fine, but I like my way better because there will be less confusion. However, there is the aforementioned error. If i did the latter way, I would have cases like this:

case"sen":

when they should be like this:

case "send /"

does anyone know if my way is possible?

2
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by echo off
0

In C# it is called switch (...) case ... not select (...) case ...
Hope this helps a bit.

Complete misspelling during posting. My friend wrote a select case in VB like this and i wanted to use it for my program and i was looking at that and my program while posting. in the program it is switch case.

0

I think it must be more something like this :

data = System.Text.Encoding.ASCII.GetString(bytes, 0, i);
string MysubStr = data.Substring(0,6);
switch (MysubStr )
{
  case "send /" :
   MessageBox.Show(data.Substring(6).....)
   break;
  case (....):
  .....
  break;
  .......
0

I think it must be more something like this :

data = System.Text.Encoding.ASCII.GetString(bytes, 0, i);
string MysubStr = data.Substring(0,6);
switch (MysubStr )
{
  case "send /" :
   MessageBox.Show(data.Substring(6).....)
   break;
  case (....):
  .....
  break;
  .......

Yes, but, what if i send "errmsg /"? Plus I have commands like cdO so it would have to be (0,2) in stead of (0,6)
the case would have to be:

case "err":

And that could get confusing.

0

Switch case doesnt evaluate bool values...it sucks but thats the truth. im just going to make my commands longer

This question has already been answered. Start a new discussion instead.
Please be thoughtful and detailed and be sure to adhere to our posting rules.