Reputation: 15
Know I cast a byte to the code that I have commented but I still have the same error
public override bool StartPing(string ip)
{
base.Init();
try
{
this.sock.ReceiveTimeout = 5000;
this.sock.Connect(ip, 5055);
this.PingBytes[this.PingBytes.Length - 1] = this.PingId;
this.sock.Send(this.PingBytes);
//this.PingBytes[this.PingBytes.Length - 1] = (byte)this.PingId - 1;
}
catch (Exception value)
{
this.sock = null;
Console.WriteLine(value);
}
return false;
}
I'm not that good with setting the format yet so please bear with me.
Upvotes: 0
Views: 3300
Reputation: 5049
The whole expression has to be casted :
(byte) (this.PingId - 1);
Otherwise PingId
is casted to byte and then 1 is subtracted from it and as 1 is an int the byte is promoted back to an int.
Upvotes: 4