初学c#,望各位大侠指教,求助急!!!!!
本人初学C#,可以说是一窍不通,看着书上弄了一个演示Lock语句实现同步数组的例子,但是运行的时候不出现结果,也不显示任何的错误信息,疑问中。。。。以下是程序代码段,希望大侠们帮忙啊,55555555555
using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Threading;
using System.Text;
namespace arraySample
{
class Program
{
static void Main(string[] args)
{
string[] csharpBooks = new string[100];
for (int i = 0; i < 100; i++)
{
csharpBooks[i] = "book" + i;
}
OperateArray oparray = new OperateArray(csharpBooks);
Thread checkArray = new Thread(oparray.CheckArray);
checkArray.Start();
Thread setArray = new Thread(oparray.SetArray);
setArray.Start();
Console.ReadLine();
}
}
public class OperateArray
{
private string[] bookArray;
public OperateArray(string[] array)
{
bookArray = array;
}
public void CheckArray()
{
lock (bookArray)
{
for (int i = 0; i <= bookArray.GetUpperBound(0); i++)
{
if (i > 10 && i / 10 == 0)
{
Console.WriteLine(bookArray[i]);
}
else
{
Console.WriteLine(bookArray[i]+"");
}
}
}
}
public void SetArray()
{
lock (bookArray)
{
foreach (string bookitem in bookArray)
{
Console.WriteLine(bookitem);
}
}
}
}
}