Wednesday, September 28, 2016

How to Cast int to enum and back in C#?

How to Cast int to enum and back in C#

To cast an int to enum just do the bellow

MyEnum foo = (MyEnum)myInt;                        

To cast to enum from a string value do the below


MyEnum foo = (MyEnum) Enum.Parse(typeof(MyEnum), myString)

Tuesday, September 27, 2016

How do I convert byte[] to stream in C#?

The easiest way to convert a byte array to a stream is using the MemoryStream class:

Stream stream = new MemoryStream(byteArray);