Skip to content

Instantly share code, notes, and snippets.

@ellenia
Last active May 19, 2017 20:18
Show Gist options
  • Save ellenia/773b8b7953b76026b1a8f9f85ce17f50 to your computer and use it in GitHub Desktop.
Save ellenia/773b8b7953b76026b1a8f9f85ce17f50 to your computer and use it in GitHub Desktop.
namespace Casting
{
enum ShirtSize
{
Small = 1,
Medium = 2,
Large = 3,
ExtraLarge = 4,
ExtraExtraLarge = 5,
}
class Program
{
static void Main(string[] args)
{
byte byteValue1 = 200;
int integerValue1 = byteValue1;
Console.Write("Byte Value1: {0}", byteValue1);
Console.WriteLine(" IntegerValue1: {0}", integerValue1);
int integerValue2 = 250;
byte byteValue2 = (byte)integerValue2;
Console.WriteLine();
Console.Write("Byte Value2: {0}", byteValue2);
Console.WriteLine(" IntegerValue2: {0}", integerValue2);
ShirtSize size = ShirtSize.Medium;
int integerSize = (int)size;
Console.WriteLine();
Console.Write("Integer Size: {0}", integerSize);
Console.WriteLine(" Enum Size: {0}", size);
object objInteger = 100;
int integerValue = (int)objInteger;
Console.WriteLine();
Console.WriteLine("Casted Integer: {0}", integerValue);
Person person;
person.Name = "John Doe";
person.Address = "123 Tech St, WA";
person.Age = 23;
object objPerson = person;
Person newPerson = (Person)objPerson;
Console.WriteLine();
Console.WriteLine("{0} {1} {2}", newPerson.Name, newPerson.Address, newPerson.Age);
Console.ReadKey();
}
}
}
namespace Numbers
{
class Program
{
static void Main(string[] args)
{
int integer1 = 100;
int integer2 = 200;
int integer3 = 257;
byte byte1 = (byte)integer1;
byte byte2 = (byte)integer2;
byte byte3 = (byte)integer3;
Console.WriteLine("Integer Value:{0} Byte Value: {1}", integer1, byte1);
Console.WriteLine("Integer Value:{0} Byte Value: {1}", integer2, byte2);
Console.WriteLine("Integer Value:{0} Byte Value: {1}", integer3, byte3);
Console.ReadKey();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment