简体   繁体   English

c# - {string [0]}是什么意思?

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

Setup: 设定:

Having a dumb day. 有一个愚蠢的一天。

I have the following code: 我有以下代码:

UserRoles = Roles.GetRolesForUser(username);

Problem: 问题:

If username is an empty string ("", user not logged in), then when I check the value of UserRoles in the immediate window it shows: 如果username是一个空字符串(“”,用户未登录),那么当我在立即窗口中检查UserRoles的值时,它显示:

{string[0]}

Question: 题:

What is {string[0]} ? 什么是{string[0]}

How can I replicate this value to test my code for the case of an unlogged in user (username == "")? 如何复制此值以测试我的代码是否存在用户未登录的情况(用户名==“”)?

NOTE: I have googled for this but to no avail. 注意:我已经谷歌搜索但无济于事。

GetRolesForUser返回一个角色数组,因此立即窗口中的“String [0]”只意味着它知道返回类型是一个数组(在本例中为字符串),但是没有条目(因为没有返回任何角色)空白用户。

It's an empty array of strings. 这是一个空字符串数组。 You can create an empty string array like 您可以创建一个空字符串数组

string[] emptyArray = new string[0];

If you look at the documentation of Roles.GetRolesForUser(string) you will see that it returns an array of strings: string[] 如果你看一下Roles.GetRolesForUser(string)的文档,你会看到它返回一个字符串数组: string[]

{string[0]} means that you have an array with zero elements. {string[0]}表示您有一个零元素的数组。

It is how the immediate window shows an empty array of strings: 立即窗口显示空字符串数组的方式如下:

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

In your test code you could Mock IRoles and have GetRolesForUser(username) return new string[] {} 在你的测试代码中你可以模拟 IRoles并让GetRolesForUser(用户名)返回新的字符串[] {}

它表示该值是一个包含0个元素的字符串数组

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM