About 81,200 results
Open links in new tab
  1. c# - Options for initializing a string array - Stack Overflow

    Sep 3, 2013 · string[] myString = new string[]{"string1", "string2"}; or. string[] myString = new string[4]; myString[0] = "string1"; // etc. Advanced: From a List. list<string> = new list<string>(); //... read this in from somewhere string[] myString = list.ToArray(); From StringCollection

  2. C# | Arrays of Strings - GeeksforGeeks

    Nov 19, 2019 · Declaring the string array: There are two ways to declare the arrays of strings as follows. Example: Initialization of Arrays of Strings: Arrays can be initialized after the declaration. It is not necessary to declare and initialize at the same time using the new keyword.

  3. c# - All possible array initialization syntaxes - Stack Overflow

    Feb 10, 2018 · These are the current declaration and initialization methods for a simple array. string[] array = new string[2]; // creates array of length 2, default values string[] array = new string[] { "A", "B" }; // creates populated array of length 2 string[] array = { "A" , "B" }; // creates populated array of length 2 string[] array = new[] { "A", "B ...

  4. How to Initialize, assign and return a string array in c#

    Oct 5, 2017 · string[] sArray = new string[] {"hi", "hello", "foo"}; Or you can also do this: string str1 = "hi"; string str2 = "this"; string str3 = "is"; string str4 = "sample array"; string[] sArray = {str1, str2, str3, str4};

  5. How to Initialize String Array With Default Values In C# - C#

    The most basic way to initialize a string array with default values is to use the new keyword and specify the size of the Array. This will create a new string array with all elements set to null by default.

  6. C# Arrays - W3Schools

    However, you should note that if you declare an array and initialize it later, you have to use the new keyword: // Declare an array string[] cars; // Add values, using new cars = new string[] {"Volvo", "BMW", "Ford"};

  7. How to Initialize a String Array in C# - Tutorial Kart

    To initialize a String Array in C#, declare a variable of type string [] and assign the comma separated values enclosed in flower braces to the array variable. In the following example, we initialize a string array in a variable arr, and print the contents of this array to console. Program.cs.

  8. String Array in C# | Learn Initialization of String Array and …

    Mar 17, 2023 · There are two ways to initialize a string array. 1. At the time of declaration: 2. After declaration: Values to string array can be assigned at the time of initialization or by using index number. Example: OR. Some of the examples are given below: 1. Accessing array elements using the index number. Code: Output: 2.

  9. Creating string array in C# - A-Z Tech

    Oct 18, 2018 · The examples below show declaring, initializing, and accessing string arrays in different ways. An example of a string array. In this example, an array is declared and initialized without specifying the array size. The values are also assigned at the time of declaration.

  10. How to Create an Array of Strings in C# - webdevtutor.net

    Jul 22, 2024 · In this guide, we will walk through the process of creating and manipulating arrays of strings in C#. Initializing an Array of Strings. To create an array of strings in C#, you can use the following syntax: string[] stringArray = new string[] { "Apple", "Banana", "Orange", "Grapes" };

Refresh