Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 236 Vote(s) - 3.51 Average
  • 1
  • 2
  • 3
  • 4
  • 5
C# declare empty string array

#1
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.

What's wrong?
Reply

#2
You can try this

string[] arr = {};
Reply

#3
Arrays' constructors are different. Here are some ways to make an empty string array:

var arr = new string[0];
var arr = new string[]{};
var arr = Enumerable.Empty<string>().ToArray()

(sorry, on mobile)
Reply

#4
If you must create an empty array you can do this:

string[] arr = new string[0];

If you don't know about the size then You may also use `List<string>` as well like

var valStrings = new List<string>();

// do stuff...

string[] arrStrings = valStrings.ToArray();
Reply

#5
Your syntax is wrong:

string[] arr = new string[]{};

or

string[] arr = new string[0];
Reply

#6
Those curly things are sometimes hard to remember, that's why there's excellent [documentation](

[To see links please register here]

):

// Declare a single-dimensional array
int[] array1 = new int[5];
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through