First time here? You are looking at the most recent posts. You may also want to check out older archives or the tag cloud. Please leave a comment, ask a question and consider subscribing to the latest posts via RSS. Thank you for visiting! (hide this)


There are 2 entries for the tag c

String to Enum

This might seems a pretty trivial problem, but every time I've to get an Enum given its name I forgot how to do it, and I've to look for it on Google. So, is there a better way to remember something you always forget than writing a post about it? Back to the problem: going from an Enum to its numeric value or its string representation is quite easy: /* Enum to string */ string stringValue = enumVal.ToString(); /* Enum to numeric value */ int numericVal = (int) enumVal; And going from a numeric value to the Enum is quite as easy: /* Numeric value...

Convert a Unix timestamp to a .NET DateTime

The POSIX time, or Unix time, is the number of seconds elapsed from the midnight of January 1st 1970 in UTC coordinates. This timestamp is used in all *nix languages; probably you will never need to use a Unix timestamp in .NET, but if you have to interact with other application or sites, maybe built in PHP or Java, you will probably have to deal with it. But .NET doesn't have a method to convert a Unix timestamp to a DateTime and viceversa (or I didn't find it), so I had to implement it. static DateTime ConvertFromUnixTimestamp(double timestamp) { ...