gpt4 book ai didi

c# - 线程 : does c# have an equivalent of the Java Runnable interface?

转载 作者:IT老高 更新时间:2023-10-28 20:52:24 37 4
gpt4 key购买 nike

c# 是否有与 Java Runnable 接口(interface)等效的接口(interface)?

如果不是,如何实现或者根本不需要?

谢谢。

最佳答案

Does c# have an equivalent of the Java Runnable interface?

是的,它是 ThreadStart

class Runner
{
void SomeMethod()
{
Thread newThread = new Thread(new ThreadStart(Run));
newThread.Start();
}

public void Run()
{
Console.WriteLine("Running in a different thread.")
}
}

相当于下面的Java代码

 class Runner implements Runnable {

void someMethod() {
Thread newThread = new Thread( this );
newThread.start();
}

public void run() {
out.println("Running in a different thread.");
}
}

关于c# - 线程 : does c# have an equivalent of the Java Runnable interface?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1923512/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com