我有这个界面:
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*/
}
哪个被认为是最佳实践:第 1 行或第 2 行?