C# 4.0 C#队列-如何为每个队列点添加结构
C#队列和每个位置都有一个整数和字符串的集合?我知道如何创建整数或字符串队列,但如何创建在每个队列点中具有多个数据类型的队列C# 4.0 C#队列-如何为每个队列点添加结构,c#-4.0,C# 4.0,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.E
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);
// ...
}
结构ABC{int val1;int val2;}
静态void Main(字符串[]args){
System.Collections.Generic.Queue Queue=新的System.Collections.Generic.Queue();
排队(ABC);
// ...
}
您需要创建结构实例,为其赋值,然后对其进行排队。第二个问题是您没有使用公共字段/属性
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);
// ...
}
struct ABC{public int val1;public int val2;}
静态void Main(字符串[]args){
System.Collections.Generic.Queue Queue=新的System.Collections.Generic.Queue();
ABC queuable=newabc(){val1=3,val2=39};
排队。排队(可查询);
// ...
}
当然,您也可以使用语句添加
,以导入System.Collections.Generic
命名空间来稍微清理代码。创建一个符合您需要的对象,并使用泛型<代码>队列
这就是我拥有的:结构ABC{int val1;int val2;}静态void Main(字符串[]args){System.Collections.Generic.Queue Queue=new System.Collections.Generic.Queue();Queue.Enqueue(ABC);不确定如何将ABC添加到队列中,或如何将整数放入val1和val2中。