Lut, je suis en train de buter sur le même problème.
Pour l'instant je me débrouille avec byteVal = System.Convert.ToByte(stringVal);
tiens voilà le code que j'ai trouvé pour convertir un string en byte. Pour int-> Byte ca doit être pareil.
public Byte ConvertStringByte(string stringVal)
{
byte byteVal =0;
try
{
byteVal = System.Convert.ToByte(stringVal);
System.Console.WriteLine("{0} as a byte is: {1}",
stringVal, byteVal);
}
catch (System.OverflowException)
{
System.Console.WriteLine(
"Conversion from string to byte
overflowed.");
}
catch (System.FormatException)
{
System.Console.WriteLine(
"The string is not formatted as a
byte.");
}
catch (System.ArgumentNullException)
{
System.Console.WriteLine(
"The string is null.");
}
return byteVal;
//The conversion from byte to string is always valid.
//stringVal = System.Convert.ToString(byteVal);
//System.Console.WriteLine("{0} as a string is {1}",byteVal, stringVal);
}
Tu pourrais me préciser le rôle de ton programme ? Par simple curiosité. Moi c'est de l'envoi sur port COM.
Sylvain
|