日期:2014-05-17  浏览次数:20825 次

基础知识不扎实,有段代码难以理解,求解

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace staticTest
{
    class Program
    {
        public static List<string> StrList;
        static void Main(string[] args)
        {
            StrList = new List<string>();
            ThreadPool.QueueUserWorkItem(new WaitCallback(ReadStr));

            while (true)
            {
                StrList = new List<string>();
                var length = Int32.Parse(Console.ReadLine());
                for (int i = 0; i < length; i++)
                {
                    StrList.Add(i.ToString());
                }
                Console.WriteLine("初始化{0}个元素", StrList.Count);
            }
        }

        static void ReadStr(object args)
        {
            var rds = new ReadStrList(StrList);
            while (true)
            {
                rds.Read();
                Thread.Sleep(5000);
            }
        }

        public class ReadStrList
        {
            List<string> _StrList;
            public ReadStrList(List<string> strList)
            {
                this._StrList = strList;
            }

            public void Read()
            {