0
votes

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?

3
You're misunderstanding var. Please show us what you're trying to write?SLaks

3 Answers

7
votes

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.

var myVar = "a string"; // type of myVar is System.String

You can have an array of array (jagged array) in C#, if that's what you need.

0
votes

In this case here var is really some collection-type with generic type Person and you can of course declare an array of Person-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 of Person or even a dynamic[].

0
votes

I'm not sure exactly what you're after in this case, but here's one guess:

var List= (from Person in GlobalVariables.PersonList 
           where Person.TeamID == CurrTeam 
           select Person).ToArray();

The List will now be a Person[] (assuming Person is of type Person.)