C# 泛型: 我要說完全的失望啊….!!!!

來源:互聯網
上載者:User

好吧,先讓再沮喪一會兒,然後再開始這個文章 
昨天終於從emule上把whidbey alpha拉下來了,2.6G啊,今天裝上後,迫不及待地試了一下C#中的泛型,然,我要哭!   這功能也太弱了吧,才多久啊,C#的泛型就沒新鮮東西可玩了,這對於從C++轉到C#的我來說,這哪裡能稱得上泛型啊!!除了做個容器(呼!即便做container也不見得方便)一無用處啊。當初在msdn上看到那個泛型的constraint就覺得不妙,果不其然。號稱從clr支援泛型,然實作出來的東西,功能上一點也不見得比java高明到哪裡去(效率是C#泛型要高很多,具體的我下次再寫吧)。最誇張的是執行個體化的類型竟然必須有一個無參建構函式,暈啊!
sigh..... Bruce Eckel的話還真是中肯啊

太傷心了,寫不下去了,先把我的第一個C#泛型的實驗程式帖出來吧,回頭我會寫一篇詳細的 Take a Close Look at C# Generics

using System;

namespace ConsoleApplication1
{
      interface ITest
     {
            void testMethod();
      }

      class testType : ITest
     {
              //public testType(int i) {}
             public void testMethod()
             {
                   Console.WriteLine("testing");
             }
   
     }
 
      
     class test<T> where T:ITest,new()
    {
           public test(int i)
          {
                dataT = new T();
                dataInt = i;
           }
           public void foo()
           {
                 dataT.testMethod();
            }
            public T DataT
           {
                  get { return dataT; }
            }
            public int DataInt
           {
                 get { return dataInt; }
           }
           private T dataT;
           private int dataInt;
     }
     class Class1
     {
            [STAThread]
            static void Main(string[] args)
           {
   
                 test<testType> ti = new test<testType>(4);
                 //Console.WriteLine(ti.DataT);
                ti.foo();
                Console.WriteLine(ti.DataInt);
             }
      }
}

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.