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

    Sep 3, 2013 · You have several options: string[] items = { "Item1", "Item2", "Item3", "Item4" }; string[] items = new string[] { "Item1", "Item2", "Item3", "Item4" }; string[] items = new string[10]; …

  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 · In case you want to initialize a fixed array of pre-initialized equal (non- null or other than default) elements, use this: var array = Enumerable.Repeat(string.Empty, 37).ToArray();

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

    Oct 5, 2017 · First of all you need to set arrays max length before fill indexes... Maybe can use List<string> and returns. After then still need string array you will use List.ToArray(). string[] sArray; try. string str1 = "hi"; string str2 = "this"; string str3 = "is"; string str4 = "sample array"; sArray = new string[] { str1, str2, str3, str4 };

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

  6. How to Initialize String Array With Default Values In 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.

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

    In this C# Tutorial, we learned how to initialize a string array, with examples. 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.

  8. How to initialize a string array in C#? - Blog - Silicon Cloud

    In C#, there are several ways to initialize a string array: Initialize a string array with specified elements using curly braces {}. Initialize an empty string array with a specified size using the new keyword, and then assign values using indexes.

  9. Initializing an Array in C# - DEV Community

    May 14, 2024 · string[] array = ["A", "B"]; This is the newest way to initialize an array in C# 12, simple and straightforward. It's also similar to the way arrays are initialized in Python and JavaScript. This makes it easier for developers familiar …

  10. Array of Strings in C# - Delft Stack

    Oct 12, 2023 · We can initialize an array by adding elements one by one with the help of an index, or we can initialize it all together. If an array is declared before, we have to use the new …

  11. Some results have been removed
Refresh