亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

C# 關于lock關鍵字的疑惑...高手請進...

C# 關于lock關鍵字的疑惑...高手請進...

揚帆大魚 2018-07-26 12:05:17
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; }
查看完整描述

1 回答

  • 1 回答
  • 0 關注
  • 849 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號