Generics Quiz

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

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泛型的又一个让人失望的地方.

原文地址:https://www.cnblogs.com/idior/p/153243.html