C# declare empty string array

前端 未结 9 570
囚心锁ツ
囚心锁ツ 2020-12-23 12:51

I need to declare an empty string array and i\'m using this code

string[] arr = new String[0]();

But I get \"method name expected\" error.<

相关标签:
9条回答
  • 2020-12-23 13:42

    Try this

    string[] arr = new string[] {};
    
    0 讨论(0)
  • 2020-12-23 13:42

    You can try this

    string[] arr = {};
    
    0 讨论(0)
  • 2020-12-23 13:43

    If you are using .NET Framework 4.6 and later, they have some new syntax you can use:

    using System;  // To pick up definition of the Array class.
    
    var myArray = Array.Empty<string>();
    
    0 讨论(0)
提交回复
热议问题