此类库中的两个类可以达成这一的一些效果:每次打开网页展现不同的标语、问候语,根据语录内容随机出题,随机显示新闻等等。当然XML格式的定制或者根据不同的XML文件适当修改类字段还是必要的。

using System;
using System.Xml;
 
namespace Quotations
{
    public class QuotationManager
    {
        private XmlDocument quoteDoc;
        private int quoteCount;
 
        public QuotationManager(string fileName)
        {
            quoteDoc = new XmlDocument();
            quoteDoc.Load(fileName);
            quoteCount = quoteDoc.DocumentElement.ChildNodes.Count;
        }
 
        public Quotation GetRandomQuote()
        {
            int i;
            Random x = new Random();
            i = x.Next(quoteCount - 1);
            return new Quotation(quoteDoc.DocumentElement.ChildNodes[i]);
        }
    }
}

相关文章:

  • 2022-02-11
  • 2022-12-23
  • 2022-12-23
  • 2021-08-15
  • 2022-12-23
  • 2021-12-05
  • 2021-12-07
猜你喜欢
  • 2021-04-01
  • 2022-12-23
  • 2022-01-28
  • 2021-11-22
  • 2022-12-23
  • 2021-07-31
  • 2021-06-05
相关资源
相似解决方案