Generic Struct : Generic struct « struct « C# / CSharp Tutorial






using System;
using System.Collections.Generic;

struct GenericStruct<T> 
{
   private T _Data;
   public GenericStruct(T value) { 
       _Data = value; 
   }

   public T Data
   {
      get { return _Data; }
      set { _Data = value; }
   }
}

class MainClass
{
   static void Main()
   {
      GenericStruct<int> IntData       = new GenericStruct<int>(10);
      GenericStruct<string> StringData = new GenericStruct<string>("str");

      Console.WriteLine("IntData    = {0}", IntData.Data);
      Console.WriteLine("StringData = {0}", StringData.Data);
   }
}
IntData    = 10
StringData = str








6.15.Generic struct
6.15.1.A generic struct
6.15.2.Generic Struct