// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; namespace E { public class Program { public static void Main(string[] args) { byte b = 123; object o = b; Console.WriteLine("Cast to byte works: " + (byte)o); try { Console.WriteLine("Cast to int works: " + (int)o); } catch { Console.WriteLine("Cast to int did not work"); } Console.WriteLine("Cast to byte cast to int works: " + (int)(byte)o); } } }