Last active
January 4, 2016 07:59
-
-
Save s2kw/8592202 to your computer and use it in GitHub Desktop.
staticでgenericなやつは都度生成される。的なコード。
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.Collections.Generic; | |
namespace ConsoleApplication1 | |
{ | |
public static class SampleClass <T> | |
{ | |
public static T Member {get;set;} | |
static SampleClass() | |
{ | |
Console.WriteLine("initialization."); | |
} | |
public static void Output() | |
{ | |
Console.WriteLine (Member.ToString ()); | |
} | |
} | |
class Program{ | |
static void Main (string[] args) | |
{ | |
SampleClass<string>.Member = "string"; | |
SampleClass<int>.Member = 8; | |
SampleClass<float>.Member = 123.4f; | |
if (false) { | |
SampleClass<double>.Member = 123.412341234; | |
} | |
SampleClass<string>.Output(); | |
SampleClass<int>.Output(); | |
SampleClass<float>.Output(); | |
SampleClass<double>.Output(); | |
} | |
} | |
} | |
/* | |
結果 | |
initialization. | |
initialization. | |
initialization. | |
string | |
8 | |
123.4 | |
initialization. | |
0 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment