# (C#) How to do a binary string search? [closed]

I need help to do a binary search using string, I'm a beginner and I'm having this difficulty.

The compiler says that it is not possible to convert from string to int. I also do not know how to call my vector for binary search. I need to know the position of the value found

My vector structure

``````public struct tp {
public string cnpjv, nomev, portalv, empv, emailv, telv, detv, tpv, canalv;
}

public tp[] cadastro_tp = new tp[100];
``````

My binary search

``````private string button1_Click_1(string[] vetor,object sender, EventArgs e)
{
string chave = txbTp.Text;

Array.Sort(vetor);

int meio;
int Min = 0;
int Max = vetor.Length - 1;

do
{
meio = (int)(Min + Max) / 2;

if (vetor[meio] == chave)
{
return meio;
}
else
if (chave > vetor[meio])
Min = meio + 1;
else
Max = meio - 1;
}
while (Min <= Max);

return -1;
}
``````

## closed as off-topic by Alexey R., c32hedge, Ray Oei, Bence Kaulics, Kate Paulk♦Jan 14 at 19:53

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "Questions about software development unrelated to testing are off-topic here, but can be asked on Stack Overflow." – Alexey R., c32hedge, Ray Oei, Bence Kaulics, Kate Paulk
If this question can be reworded to fit the rules in the help center, please edit the question.

• Array class have BinarySearch for one dimension sorted arrays, have you tried it. BinarySearch – Nikolay Barakov Jan 14 at 8:57
• That `if` in a new line following an `else` supposed to be an `else if` or it just tabulated incorrectly? Please use parenthesis even with one line bodies. – Bence Kaulics Jan 14 at 12:13
• Welcome. Have a look here on asking. SQA is meant for testing topics. Your question seems to fit better in StackOverflow – Ray Oei Jan 14 at 18:50