如下程序片段
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication1
{
class PersonComparName:IComparer
{
public static IComparer Default = new PersonComparName();
public int Compare(object x, object y)
{
if ((x is Person) && (y is Person))
{
return Comparer.Default.Compare(
((Person)x).Name, ((Person)y).Name);
}
else
{
throw new ArgumentException("one or both object to compare are not Person object.");
}
}
}
}
不是说接口不能进行实例化吗?
还有定义迭代器时:
public static IEnumaerable List()
{
yield return (.......);
}
既然不能实例化,怎么等定义变量,怎么能作为函数返回类型的?
困惑.....
待高手讲解....