zoukankan      html  css  js  c++  java
  • 创建一个随机对象列表

     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<MyBusinessObject> 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
    }
  • 相关阅读:
    Oracle 建用户、 表空间脚本
    Java常见Jar包的用途
    EF:无法检查模型兼容性,因为数据库不包含模型元数据。
    Eclipse -Xms256M -Xmx640M -XX:PermSize=256m -XX:MaxPermSize=768m
    CentOS远程连接Windows操作系统
    spring boot / cloud (二十) 相同服务,发布不同版本,支撑并行的业务需求
    jvm
    jvm
    spring boot / cloud (十九) 并发消费消息,如何保证入库的数据是最新的?
    spring boot / cloud (十八) 使用docker快速搭建本地环境
  • 原文地址:https://www.cnblogs.com/Laro/p/2183047.html
Copyright © 2011-2022 走看看