接口的实现方式分为显示实现 和隐式实现
隐式实现:
public interface IReview
{
void GetReviews();
}
class Program
{
static void Main(string[] args)
{
IReview rv = new Review();
rv.GetReviews(); //显示11
Review rv1 = new Review();
rv1.GetReviews(); //显示11
}
}
public class Review : IReview
{
public void GetReviews()
{
Console.WriteLine("11");
}
}
显式实现:
public interface IReview
{
void GetReviews();
}
class Program
{
static void Main(string[] args)
{
IReview rv = new Review();
rv.GetReviews(); //显示11
Review rv1 = new Review();
rv1.GetReviews(); //异常:没有方法
}
}
public class Review : IReview
{
void IReview.GetReviews()
{
Console.WriteLine("11");
}
}