string a="abc";
lock(a){....};在实际使用中我发现锁定的不是a对象,而是以a对象作为标识的{}内的代码块..
但发现资料上是像图中那样说的,是我没理解正确呢还是资料错误?请高手解惑.
using System;using System.Threading;class Program { static void Main(string[] args) { Student s = new Student { Name="yh"}; Thread t=new Thread (new ThreadStart(()=>{lock (s) { Thread.Sleep(100000); }})); t.Start(); Thread.Sleep(1000); Console.WriteLine(s.Name);//这里没有等锁的线程结束才执行..所以我觉得资料说的不对..你们认为呢? Console.ReadKey(); } }internal class Student { public string Name { get; set; }