博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
创建一个随机对象列表
阅读量:4984 次
发布时间:2019-06-12

本文共 3135 字,大约阅读时间需要 10 分钟。

public class MyBusinessObjects     {
string[] names = new string[] { "Côte de Blaye", "Boston Crab Meat", "Singaporean Hokkien Fried Mee", "Gula Malacca", "Rogede sild", "Spegesild", "Zaanse koeken", "Chocolade", "Maxilaku", "Valkoinen suklaa","sf","34","g5","ght","7jkm","3jv","lui9","8ik","89l","lyut","34tg","fsdgh","cxvbd","ery","34ytr","y56" }; double[] prizes = new double[] { 23.2500, 9.0000, 45.6000, 32.0000, 14.0000, 19.0000, 263.5000, 18.4000, 3.0000, 14.0000 }; DateTime[] dates = new DateTime[] { new DateTime(2007, 5, 10), new DateTime(2008, 9, 13), new DateTime(2008, 2, 22), new DateTime(2009, 1, 2), new DateTime(2007, 4, 13), new DateTime(2008, 5, 12), new DateTime(2008, 1, 19), new DateTime(2008, 8, 26), new DateTime(2008, 7, 31), new DateTime(2007, 7, 16) }; bool[] bools = new bool[] { true, false, true, false, true, false, true, false, true, false }; public IEnumerable
GetData(int maxItems)//使用此方法获取随机对象列表 {
Random rnd = new Random(); return from i in Enumerable.Range(1, maxItems) select new MyBusinessObject(i, names[rnd.Next(25)], prizes[rnd.Next(9)], dates[rnd.Next(9)], bools[rnd.Next(9)]); } } public class MyBusinessObject : INotifyPropertyChanged {
private int id; private string name; private double unitPrice; private DateTime date; private bool discontinued; public MyBusinessObject() {
// } public MyBusinessObject(int ID, string Name, double UnitPrice, DateTime Date, bool Discontinued) {
this.ID = ID; this.Name = Name; this.UnitPrice = UnitPrice; this.Date = Date; this.Discontinued = Discontinued; } public int ID {
get {
return id; } set {
id = value; OnPropertyChanged("ID"); } } public string Name {
get {
return name; } set {
name = value; OnPropertyChanged("Name"); } } public double UnitPrice {
get {
return unitPrice; } set {
unitPrice = value; OnPropertyChanged("UnitPrice"); } } public DateTime Date {
get {
return date; } set {
date = value; OnPropertyChanged("Date"); } } public bool Discontinued {
get {
return discontinued; } set {
discontinued = value; OnPropertyChanged("Discontinued"); } } #region INotifyPropertyChanged Members public event PropertyChangedEventHandler PropertyChanged; private void OnPropertyChanged(string propertyName) {
if (this.PropertyChanged != null) {
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } } #endregion }

转载于:https://www.cnblogs.com/Laro/archive/2011/09/21/2183047.html

你可能感兴趣的文章
四种百度文库资源直接下载的方法!不用代码,不用券!一键搞定!
查看>>
数据库-包和包体
查看>>
软件的知识产权保护
查看>>
7.20-7.24
查看>>
Bower前端包管理器
查看>>
Python练习题 047:Project Euler 020:阶乘结果各数字之和
查看>>
Docker私有仓库Harbor部署与使用
查看>>
2017年4月26日
查看>>
(第十周)Beta-2阶段成员贡献分
查看>>
希尔排序与快速排序
查看>>
洛谷p1966 火柴排队 (逆序对变形,目标排序
查看>>
AutoCAD的一些优化设置
查看>>
JSP中include的两种方法
查看>>
Ubuntu使用总结
查看>>
2019春第六周编程总结
查看>>
FLASH组件在FLEX中使用
查看>>
C++指针的指针和指针的引用
查看>>
android教程之intent对象
查看>>
python 学习笔记十五 django基础
查看>>
Python爬虫入门三之Urllib库的基本使用
查看>>