【发布时间】:2020-07-07 14:03:05
【问题描述】:
我想问一下,假设我有一个 cshtml 代码
@model List<Product>
<!DOCTYPE html>
<html lang="en">
<head>
这样就没有问题了。我的问题是我可以写IEnumerable<Product> 而不是List<Product> 在这两种情况下我的程序都可以工作,那么我应该更喜欢哪一个?为什么?
【问题讨论】:
-
如果您只想遍历模型,请使用
IEnumerable<T>,因为它更通用,并且允许后面的代码更改并传递除List<T>之外的其他内容。
标签: c# .net asp.net-core razor