var 数组的数组
我不知道这是否可能,但我正在使用 LINQ 查询并将对象结果存储在隐式变量或 var 中,如下所示:
var List= from Person in GlobalVariables.Person List where Person.TeamID == CurrTeam select Person;
我要求的是有什么方法可以创建一个 var 数组吗? (意味着每一行都会存储另一个对象数组)
当我尝试它时,它不会将 var 识别为有效类型。有什么办法可以做到这一点或替代方案吗?
I do not know if this is even possible, but I am using a LINQ query and storing my object results in an implict variable or var like this:
var List= from Person in GlobalVariables.Person List where Person.TeamID == CurrTeam select Person;
What I am asking for is there any way to make an array of vars? (Meaning each row will have another array of objects stored in it)
When I try it it does not recognize var as a valid type. Any way on how to do this or an alternative?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
var
不是类型。这是一种方法,不说它是什么类型的。这称为隐式类型 - 编译器可以推断实际类型是什么。C# 仍然是一种强类型语言。
在 C# 中,您可以拥有数组的数组(交错数组),如果这就是你所需要的。
var
is not a type. It is a way to not say what the type it. This is known as implicit typing - the compiler can infer what the actual type is.C# is still a strongly typed language.
You can have an array of array (jagged array) in C#, if that's what you need.
在这种情况下,这里 var 实际上是一些具有泛型类型
Person
的集合类型,您当然可以在此声明一个Person
对象数组case(只需将 linq 表达式包装在 (..) 中并添加.ToArray()
例如。也许您想要的是一个可以容纳任何对象的
object
数组类型或某些基类型的数组Person
甚至是dynamic[]
。In this case here var is really some collection-type with generic type
Person
and you can of course declare an array ofPerson
-Objects in this case (just wrapp the linq-expression in (..) and add.ToArray()
for example.Maybe what you want is either a array of
object
that can hold any type or a array of some base-type ofPerson
or even adynamic[]
.在这种情况下,我不确定您到底想要什么,但有一个猜测:
列表现在将是一个
Person[]
(假设 Person 是 Person 类型。)I'm not sure exactly what you're after in this case, but here's one guess:
The List will now be a
Person[]
(assuming Person is of type Person.)