Hooked on LINQ

Hooked on LINQ - Developers' Wiki
for .NET Language Integrated Query

Companion book for this site
LINQ to Objects Using C# 4.0:
Using and Extending LINQ to Objects and Parallel LINQ (PLINQ)
Quick Search

Advanced Search »
Back to C# Language Enhancements.

The var syntax for implicitly typing variables extends to declaring arrays. This allows the compiler to infer the type of the array elements at compile-time from the members in the initialization expression. In general terms it allows us to change:

int[] a = new int[] { 1, 10, 100, 1000 };
double[] b = new double[] { 1, 1.5, 2, 2.5 };
string[] c = new string[] { "hello", null, "world" };

To:

var a = new[] { 1, 10, 100, 1000 };
var b = new[] { 1, 1.5, 2, 2.5 };
var c = new[] { "hello", null, "world" };



Edit

References

Google search: Implicitly Types Arrays C#

If you would like to comment on this page, click on the Discuss button located on the top-right of each page. Feel free to edit any mistakes or omissions you find. If you have an objection or find in-appropriate content then contact the administrator. This website is not affiliated with Microsoft®, all content and opinions are those of the specific author and some advice, solutions and article may contain unintentional errors - please use care. Other websites by this author: Focused Objective, Geek Speak Decoded.