如何在c#中为空字符串数组赋值?
string [] stack; //string array
Run Code Online (Sandbox Code Playgroud)
如何分配
stack = ""; //this statement gives error cannot implicitly convert to type string to string []
Run Code Online (Sandbox Code Playgroud)
你不能使用:
string[] stack = "";
Run Code Online (Sandbox Code Playgroud)
因为这里的堆栈是一个字符串数组.如果要为数组中的每个元素初始化空字符串,可以使用LINQ with Enumerable.Range来获取结果,假设这里有10个项目:
string[] stack = Enumerable.Range(0, 10)
.Select(i => string.Empty)
.ToArray();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
14787 次 |
| 最近记录: |