类似于线程的C#数据结构(存储方法调用)
我正在编写一个模拟程序,我正在寻找一种存储方法调用列表的方法,类似于线程的工作方式(Thread.add(Object.method))。然后我想删除这些方法调用,并将它们添加到线程对象中。C#中是否有任何内置的数据结构可以做到这一点?或者有没有办法让我做一个我想要的 我正在寻找一种存储方法调用列表的方法 您可以创建委托列表(对方法的引用),如下所示:类似于线程的C#数据结构(存储方法调用),c#,multithreading,data-structures,C#,Multithreading,Data Structures,我正在编写一个模拟程序,我正在寻找一种存储方法调用列表的方法,类似于线程的工作方式(Thread.add(Object.method))。然后我想删除这些方法调用,并将它们添加到线程对象中。C#中是否有任何内置的数据结构可以做到这一点?或者有没有办法让我做一个我想要的 我正在寻找一种存储方法调用列表的方法 您可以创建委托列表(对方法的引用),如下所示: public delegate void DoSomething(); public class Program { static v
public delegate void DoSomething();
public class Program
{
static void Main()
{
List<DoSomething> actions = new List<DoSomething>();
actions.Add(TestMethod);
actions.Add(delegate {
// Anonymous Method 1
});
actions.Add(delegate {
// Anonymous Method 2
});
}
static void TestMethod()
{
}
}
public delegate void DoSomething();
公共课程
{
静态void Main()
{
列表操作=新建列表();
actions.Add(TestMethod);
操作。添加(委托){
//匿名方法1
});
操作。添加(委托){
//匿名方法2
});
}
静态void TestMethod()
{
}
}
希望能有帮助
我正在寻找一种存储方法调用列表的方法
您可以创建委托列表(对方法的引用),如下所示:
public delegate void DoSomething();
public class Program
{
static void Main()
{
List<DoSomething> actions = new List<DoSomething>();
actions.Add(TestMethod);
actions.Add(delegate {
// Anonymous Method 1
});
actions.Add(delegate {
// Anonymous Method 2
});
}
static void TestMethod()
{
}
}
public delegate void DoSomething();
公共课程
{
静态void Main()
{
列表操作=新建列表();
actions.Add(TestMethod);
操作。添加(委托){
//匿名方法1
});
操作。添加(委托){
//匿名方法2
});
}
静态void TestMethod()
{
}
}
希望能有帮助
我正在寻找一种存储方法调用列表的方法
您可以创建委托列表(对方法的引用),如下所示:
public delegate void DoSomething();
public class Program
{
static void Main()
{
List<DoSomething> actions = new List<DoSomething>();
actions.Add(TestMethod);
actions.Add(delegate {
// Anonymous Method 1
});
actions.Add(delegate {
// Anonymous Method 2
});
}
static void TestMethod()
{
}
}
public delegate void DoSomething();
公共课程
{
静态void Main()
{
列表操作=新建列表();
actions.Add(TestMethod);
操作。添加(委托){
//匿名方法1
});
操作。添加(委托){
//匿名方法2
});
}
静态void TestMethod()
{
}
}
希望能有帮助
我正在寻找一种存储方法调用列表的方法
您可以创建委托列表(对方法的引用),如下所示:
public delegate void DoSomething();
public class Program
{
static void Main()
{
List<DoSomething> actions = new List<DoSomething>();
actions.Add(TestMethod);
actions.Add(delegate {
// Anonymous Method 1
});
actions.Add(delegate {
// Anonymous Method 2
});
}
static void TestMethod()
{
}
}
public delegate void DoSomething();
公共课程
{
静态void Main()
{
列表操作=新建列表();
actions.Add(TestMethod);
操作。添加(委托){
//匿名方法1
});
操作。添加(委托){
//匿名方法2
});
}
静态void TestMethod()
{
}
}
希望对您有所帮助您可以保存一份
操作
委托列表<代码>列表=新列表()代码>您可以保存操作
委托的列表<代码>列表=新列表()代码>您可以保存操作
委托的列表<代码>列表=新列表()代码>您可以保存操作
委托的列表<代码>列表=新列表()代码>谢谢。这正是我需要的!请注意,您实际上不需要定义新的委托,因为有操作
、操作
和许多通常负责此类委托的函数。谢谢。这正是我需要的!请注意,您实际上不需要定义新的委托,因为有操作
、操作
和许多通常负责此类委托的函数。谢谢。这正是我需要的!请注意,您实际上不需要定义新的委托,因为有操作
、操作
和许多通常负责此类委托的函数。谢谢。这正是我需要的!请注意,您实际上不需要定义新的委托,因为有操作
、操作
和许多通常负责此类委托的函数。