Posts
231
Comments
64
Trackbacks
4
Kleine Funktion: ToValidByte

Hier eine kleine Funktion um ein beliebiges Objekt in einen gültigen Byte-Wert umzuwandeln:

static public byte ToValidByte(object n) {
      if(n==null) return 0;
      if(n.GetType() == typeof(string)) {
            try {
                  return byte.Parse((string)n);
            }
            catch( Exception ) {
                  return 0;
            }
      }
      if(n.GetType() == typeof(byte)) {
            return (byte)n;
      }
      if(n.GetType() == typeof(decimal)) {
            return decimal.ToByte((decimal)n);
      }
      return 0;
}

posted on Friday, April 04, 2008 12:30 PM Print
Comments
No comments posted yet.

Post Comment

Title *
Name *
Email
Url
Comment *  
Please add 6 and 3 and type the answer here: