享受代码,享受人生

SOA is an integration solution. SOA is message oriented first.
The Key character of SOA is loosely coupled. SOA is enriched
by creating composite apps.
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

Generics Quiz

Posted on 2005-05-11 16:40  idior  阅读(3319)  评论(35编辑  收藏  举报

下面这段代码为什么无法编译?

using System;
using System.Collections.Generic;
using System.Drawing;

namespace GenicTest
{
    
class Program
    
{

        
static void Main(string[] args)
        
{
            List
<Point> pl = new List<Point>();
            pl.Add(
new Point(1010));
            pl[
0].X = 42// <-- compiler error occurs here!
            Console.WriteLine(pl[0]);

        }

    }

}

如果你对C++很熟的话, 你再试一试用标准C++ 中的vector来代替List

这个例子其实反应了net2.0泛型的又一个让人失望的地方.