关于list类型
List我查看帮助,
表示可通过索引访问的对象的强类型列表。 提供用于对列表进行搜索、排序和操作的方法。
[SerializableAttribute]
public class List<T> : IList<T>, ICollection<T>,
IEnumerable<T>, IList, ICollection, IEnumerable
问题:我看得还是一头雾水,public List<Order> GetAllOrders() 是什么意思?
using System;using System.Collections.Generic;using System.Linq;using System.Text;using NorthwindPrjModel;using System.Data.SqlClient;namespace NorthwindPrjDAL{ public class OrderDAL { public List<Order> GetAllOrders() { string sql = "SELECT OrderID,Freight,ShipName,ShipAddress,ShipCity,ShipCountry FROM Orders"; SqlDataReader sdr = SqlHelper.GetReader(sql); List<Order> orders = new List<Order>(); while (sdr.Read()) { Order order = new Order(); order.OrderID = sdr.GetInt32(0); order.Freight = sdr.GetDecimal(1); order.ShipName = sdr.GetString(2); order.ShipAddress = sdr.GetString(3); order.ShipCity = sdr.GetString(4); order.ShipCountry = sdr.GetString(5); orders.Add(order); } sdr.Close(); return orders; } public List<string> GetShipCountries() { string sql = "select distinct ShipCountry from orders"; SqlDataReader sdr = SqlHelper.GetReader(sql); List<string> countries = new List<string>(); while (sdr.Read()) { countries.Add(sdr.GetString(0)); } sdr.Close(); return countries; } }}