2つの数値を比較し、大きい方、或いは小さい方を返します。
大きい数値は System.Math.Max()関数をコールします。
小さい数値は System.Math.Min()関数をコールします。
// 2つの数値を比較して大きい方を返す場合の例(小さい方が欲しい場合はMin関数を) int x = 15; int y = 20; int ans = Math.Max(x, y); MessageBox.Show("大きいのは " + ans);
2つの数値を比較し、大きい方、或いは小さい方を返します。
大きい数値は System.Math.Max()関数をコールします。
小さい数値は System.Math.Min()関数をコールします。
// 2つの数値を比較して大きい方を返す場合の例(小さい方が欲しい場合はMin関数を) int x = 15; int y = 20; int ans = Math.Max(x, y); MessageBox.Show("大きいのは " + ans);
System.Math.Sqrt()関数をコールします。
// 2の平方根を計算し、メッセージボックスで答えを表示 double ans = Math.Sqrt(2); MessageBox.Show(ans.ToString());
System.Math.Abs()関数をコールします。
引数の型はintをはじめ、byte、short、long、decimal、、、などなど
Math.Abs(-10); //-10の絶対値を取得。答えは10
MD5CryptoServiceProviderクラスを利用します。
ComputeHash関数でbyte配列を取得し
BitConverterでbyte配列を16進数文字列に変換しています。
private string GetMD5FromFile(string filename) { string ret = string.Empty; if (File.Exists(filename)) { System.Security.Cryptography.MD5CryptoServiceProvider md5 = new System.Security.Cryptography.MD5CryptoServiceProvider(); FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read); byte[] bytehash = md5.ComputeHash(fs); ret = BitConverter.ToString(bytehash).Replace("-", string.Empty); } return ret; }