第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

我如何能傳入一個(gè)引用類(lèi)型,或者能在函數(shù)內(nèi)部改變的外部變量 , 怎么改?

我如何能傳入一個(gè)引用類(lèi)型,或者能在函數(shù)內(nèi)部改變的外部變量 , 怎么改?

飲歌長(zhǎng)嘯 2022-07-15 17:13:58
using System;using System.Threading;public class Work{public static void Main(){// To start a thread using a shared thread procedure, use// the class name and method name when you create the// ParameterizedThreadStart delegate. C# infers the// appropriate delegate creation syntax:// new ParameterizedThreadStart(Work.DoWork)//Thread newThread = new Thread(Work.DoWork);// Use the overload of the Start method that has a// parameter of type Object. You can create an object that// contains several pieces of data, or you can pass any// reference type or value type. The following code passes// the integer value 42.//newThread.Start(42);// To start a thread using an instance method for the thread// procedure, use the instance variable and method name when// you create the ParameterizedThreadStart delegate. C# infers// the appropriate delegate creation syntax:// new ParameterizedThreadStart(w.DoMoreWork)//Work w = new Work();newThread = new Thread(w.DoMoreWork);// Pass an object containing data for the thread.//newThread.Start("The answer.");}public static void DoWork(object data){Console.WriteLine("Static thread procedure. Data='{0}'",data);}public void DoMoreWork(object data){Console.WriteLine("Instance thread procedure. Data='{0}'",data);}}上面是我找來(lái)的一個(gè)例子thread函數(shù)的參數(shù)是 object類(lèi)型
查看完整描述

3 回答

?
回首憶惘然

TA貢獻(xiàn)1847條經(jīng)驗(yàn) 獲得超11個(gè)贊

應(yīng)該不能改吧,我一直用一個(gè)比較笨的方法。在類(lèi)中另開(kāi)一個(gè)元素,然后就不用傳參數(shù)了。修改的用//----- 加以標(biāo)注

using System;
using System.Threading;

public class Work
{
public static void Main()
{
// To start a thread using a shared thread procedure, use
// the class name and method name when you create the
// ParameterizedThreadStart delegate. C# infers the
// appropriate delegate creation syntax:
// new ParameterizedThreadStart(Work.DoWork)
//
Thread newThread = new Thread(Work.DoWork);

// Use the overload of the Start method that has a
// parameter of type Object. You can create an object that
// contains several pieces of data, or you can pass any
// reference type or value type. The following code passes
// the integer value 42.
//
newThread.Start(42);

// To start a thread using an instance method for the thread
// procedure, use the instance variable and method name when
// you create the ParameterizedThreadStart delegate. C# infers
// the appropriate delegate creation syntax:
// new ParameterizedThreadStart(w.DoMoreWork)
//
Work w = new Work();
newThread = new Thread(w.DoMoreWork);

// Pass an object containing data for the thread.
//
newThread.Start("The answer.");
}

public static void DoWork(object data)
{
Console.WriteLine("Static thread procedure. Data='{0}'",
data);
}

public int changeInDoMoreWork = 0; //--------
public void DoMoreWork(object data)
{
changeInDoMoreWork=8; //------------
Console.WriteLine("Instance thread procedure. Data='{0}'",
data);
}
}


查看完整回答
反對(duì) 回復(fù) 2022-07-18
?
瀟瀟雨雨

TA貢獻(xiàn)1833條經(jīng)驗(yàn) 獲得超4個(gè)贊

你的表達(dá)我不是太理解,thread的參數(shù)可以用委托,委托可以捆綁引用類(lèi)型的。

查看完整回答
反對(duì) 回復(fù) 2022-07-18
?
忽然笑

TA貢獻(xiàn)1806條經(jīng)驗(yàn) 獲得超5個(gè)贊

參數(shù)前面加上 ref 吧

查看完整回答
反對(duì) 回復(fù) 2022-07-18
  • 3 回答
  • 0 關(guān)注
  • 128 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)