shareddemo.cs

来自「C#高级编程第6版随书源代码 值得下载」· CS 代码 · 共 42 行

CS
42
字号
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;

namespace Wrox.ProCSharp.Assemblies.Sharing
{
   public class SharedDemo
   {
      private List<string> quotes;
      private Random random;

      public SharedDemo(string filename)
      {
         quotes = new List<string>();
         Stream stream = File.OpenRead(filename);
         StreamReader streamReader = new StreamReader(stream);
         string quote;
         while ((quote = streamReader.ReadLine()) != null)
         {
            quotes.Add(quote);
         }
         streamReader.Close();
         stream.Close();
         random = new Random();
      }

      public string GetQuoteOfTheDay()
      {
         int index = random.Next(1, quotes.Count);
         return quotes[index];
      }

      public string GetAssemblyFullName()
      {
         return Assembly.GetExecutingAssembly().FullName;
      }

   }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?