コガネブログ

平日更新を目標に Unity や C#、Visual Studio、ReSharper などのゲーム開発アレコレを書いていきます

【C#】指定した値が組み込みの値型かどうかを確認する方法

概要

// すべて True
Debug.Log( typeof( bool ).IsValueType );
Debug.Log( typeof( byte ).IsValueType );
Debug.Log( typeof( sbyte ).IsValueType );
Debug.Log( typeof( char ).IsValueType );
Debug.Log( typeof( decimal ).IsValueType );
Debug.Log( typeof( double ).IsValueType );
Debug.Log( typeof( float ).IsValueType );
Debug.Log( typeof( int ).IsValueType );
Debug.Log( typeof( uint ).IsValueType );
Debug.Log( typeof( long ).IsValueType );
Debug.Log( typeof( ulong ).IsValueType );
Debug.Log( typeof( short ).IsValueType );
Debug.Log( typeof( ushort ).IsValueType );

// string は False
Debug.Log( typeof( string ).IsValueType );