0

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?

1
  • You're misunderstanding var. Please show us what you're trying to write? Commented Sep 19, 2011 at 17:55

3 Answers 3

7

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Ok. Then i need to find out what is the type of the result of this statement "from Person in GlobalVariables.Person List where Person.TeamID == CurrTeam select Person" So that i can use it as type for my array
0

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[].

Comments

0

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.)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.