Static Field Per Closed Type : Type constaint « Generic « C# / CSharp Tutorial






using System;
using System.ComponentModel;
using System.Text;

        class TypeWithField<T>
        {
            public static string field;

            public static void PrintField()
            {
                Console.WriteLine(field + ": " + typeof(T).Name);
            }

            static void Main()
            {
                TypeWithField<int>.field = "First";
                TypeWithField<int>.PrintField();
            }
        }








18.21.Type constaint
18.21.1.A reference constriant
18.21.2.A value type constriant
18.21.3.Static Field Per Closed Type