您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

将参数传递给线程的 C# 程序

2025/12/9 11:03:06发布25次查看
要使用线程,请在代码中添加以下命名空间 -
using system.threading;
首先,您需要在 c# 中创建一个新线程 -
thread thread = new thread(threaddemo);
上面,threaddemo是我们的线程函数。
现在将参数传递给线程 -
thread.start(str);
上面设置的参数是 -
string str = "hello world!";
示例让我们看看在 c# 中将参数传递给线程的完整代码。
实时演示using system;using system.threading;namespace sample { class demo { static void main(string[] args) { string str = "hello world!"; // new thread thread thread = new thread(threaddemo); // passing parameter thread.start(str); } static void threaddemo(object str) { console.writeline("value passed to the thread: "+str); } }}
输出value passed to the thread: hello world!
以上就是将参数传递给线程的 c# 程序的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product