2017-02-03 99 views
0

C#队列和每个位置都有一个整数和一个字符串的集合?我知道如何创建一个整数或字符串队列,但是如何创建一个在每个队列点都有多个数据类型的队列?C#队列 - 如何将结构添加到每个队列点

struct ABC { int val1; int val2; } 

static void Main(string[] args) { 
    System.Collections.Generic.Queue<ABC> queue = new System.Collections.Generic.Queue<ABC>(); 
    queue.Enqueue(ABC); 
// ... 
} 
+0

创建一个符合您需求的对象,并使用泛型。 '队列'https://msdn.microsoft.com/en-us/library/7977ey2c(v=vs.110).aspx – ps2goat

+0

这就是我的: – Unity

+0

struct ABC { int val1; int val2; } 静态无效的主要(字符串[]参数) { System.Collections.Generic.Queue 队列=新System.Collections.Generic.Queue (); queue.Enqueue(ABC); – Unity

回答

0

您需要创建一个结构实例,为其赋值,然后对其进行排队。第二个问题是你没有使用公共字段/属性。

struct ABC { public int val1; public int val2; } 

static void Main(string[] args) { 
    System.Collections.Generic.Queue<ABC> queue = new System.Collections.Generic.Queue<ABC>(); 

    ABC queuable = new ABC() { val1 = 3, val2 = 39}; 

    queue.Enqueue(queuable); 
    // ... 
} 

当然,你也可以添加using报表导入System.Collections.Generic命名空间来清理一下代码了。