Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

C#

what dose new string mean in C#

what dose new string mean in C#

1 Answer

Damien Watson
Damien Watson
27,419 Points

The keyword 'new' is used to Instantiate a class, it's saying "give me a new version of string[]". In the context you are describing, there is a class of type 'string' which is to be an array 'string[]'. You are setting the variable 'fields' to equal a new instance of it, initialising it with 4 items.

Any time you want to instantiate a class, you need to use 'new'. Does this help?

in this context when using arrays static string[] fields = new string[4];