C # - What does {string [0]} mean?

Setup:

Having a dumb day.

I have the following code:

UserRoles = Roles.GetRolesForUser(username); 

Problem:

If the username is an empty string ("", the user is not logged in), then when I check the UserRoles value in the direct window, it shows:

 {string[0]} 

Question:

What is {string[0]} ?

How can I replicate this value to test my code for the case of an insecure user (username == "")?

NOTE. I have Google for this, but to no avail.

+4
source share
5 answers

GetRolesForUser returns an array of roles, so β€œString [0]” in the immediate window simply means that it knows that the return type is an array (in this case, strings), but there are null entries (since none of the roles is returned for empty user.

+9
source

This is an empty array of strings. You can create an empty array of strings, for example

 string[] emptyArray = new string[0]; 
+3
source

If you look at the Roles.GetRolesForUser (string) documentation, you will see that it returns an array of strings: string[]

{string[0]} means you have an array with null elements.

+2
source

Since the direct window displays an empty array of strings:

 [Test] public void StringsTest() { var strings = new string[] {}; } 

In your test code, you can Mock IRoles and have GetRolesForUser (username) return a new line [] {}

+1
source

This means that the value is an array of strings with 0 elements in it

+1
source

Source: https://habr.com/ru/post/1442735/


All Articles