Stack User Stack User - 1 year ago 122
C# Question

how to assign empty to string array in c#

How can I assign empty to string array in c#?

string [] stack; //string array

how to assign

stack = ""; //this statement gives error cannot implicitly convert to type string to string []

Answer Source

You cannot use:

string[] stack = "";

Since stack in here is an array of string. If you want to initialize empty string for each elements in array, you can use LINQ with Enumerable.Range to get the result, assume there are 10 items in here:

 string[] stack = Enumerable.Range(0, 10)
                            .Select(i => string.Empty)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download