ToString Help

  • Thread starter Thread starter Maxime
  • Start date Start date
M

Maxime

Hi i have a fonction who check word in dictionnaire but when i use ToString he convert my word of 4 char in a string of 13 char ? Why



string[] dic; // Dictionnairy in memory

public void isDic(char[] aWord)

{

Array.Sort(aWord);

for(int i=0;i<dic.Length;i++)

{

if(aWord.Length == dic.Length)

{

char[] cWord = dic.ToCharArray();

Array.Sort(cWord);

if(aWord.ToString().CompareTo(cWord.ToString())==0)

{

lOut.Text += dic + " ";

}

}

}

lOut.Text += " FIN";

}



Thanks Max
 
Maxime said:
Hi i have a fonction who check word in dictionnaire but when i use
ToString he convert my word of 4 char in a string of 13 char ? Why

char[].ToString() doesn't do what you think it does. Use

new String(char[]) to convert an array of characters into a string.
 
Hi, thanks Jon it's work
but there is it a way to compare a char[] to a char[] ?

thanks
Max

Jon Skeet said:
Maxime said:
Hi i have a fonction who check word in dictionnaire but when i use
ToString he convert my word of 4 char in a string of 13 char ? Why

char[].ToString() doesn't do what you think it does. Use

new String(char[]) to convert an array of characters into a string.
 
Maxime said:
Hi, thanks Jon it's work
but there is it a way to compare a char[] to a char[] ?

Well, this springs to mind:

static bool CharArraysEqual (char[] x, char[] y)
{
if (x.Length != y.Length)
{
return false;
}
for (int i=0; i < x.Length; i++)
{
if (x != y)
{
return false;
}
}
return true;
}
 
Thanks alot!

Jon Skeet said:
Maxime said:
Hi, thanks Jon it's work
but there is it a way to compare a char[] to a char[] ?

Well, this springs to mind:

static bool CharArraysEqual (char[] x, char[] y)
{
if (x.Length != y.Length)
{
return false;
}
for (int i=0; i < x.Length; i++)
{
if (x != y)
{
return false;
}
}
return true;
}
 
Back
Top