Last active
August 29, 2015 13:56
-
-
Save baba-s/9286602 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq; | |
/// <summary> | |
/// 列挙型に関する汎用クラス | |
/// </summary> | |
public static class EnumCommon | |
{ | |
private static readonly Random mRandom = new Random(); // 乱数 | |
/// <summary> | |
/// 指定された列挙型の値をランダムに返します | |
/// </summary> | |
public static T Random<T>() | |
{ | |
return Enum.GetValues(typeof(T)) | |
.Cast<T>() | |
.OrderBy(c => mRandom.Next()) | |
.FirstOrDefault(); | |
} | |
/// <summary> | |
/// 指定された列挙型の値の数返します | |
/// </summary> | |
public static int GetLength<T>() | |
{ | |
return Enum.GetValues(typeof(T)).Length; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment