Hooked on LINQ

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

Quick Search

Advanced Search »

Implicitly Typed Arrays

Modified: 2008/01/27 19:22 by t_magennis - Categorized as: Language
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 ommissions 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 un-intentional errors - please use care. Powered by ScrewTurn Wiki version 2.0.33. Some of the icons created by FamFamFam.