我有这个界面:
public interface IEntity
{
int Id{get;set;}
}
一个类:
public class Customer: IEntity
{
public int Id { get; set; }
public string Name { get; set; }
public int Age { get; set; }
}
这是我的使用方式:
void Main()
{
List<Customer> list = new List<Customer>();
IEntity obj = null;
obj = new Customer() {Id = 4, Name="Jenny", Age =41};
list.Add(obj as Customer); /*Line #1*/
list.Add((Customer)obj); /*Line #2*/
}
哪种被认为是最佳实践:第一行还是第二行?