c# - 字符串插值中的变量对齐组件

标签 c# string string-interpolation

alignment component是这个例子中的-20:

$"{value, -20}"

有没有办法制作这样的内插字符串:

$"{值,对齐}"

alignment 是变量吗?

最佳答案

不幸的是,alignment 不能是一个变量。 alignment 必须是常量表达式。这是来自 docs 的相关部分

alignment: The constant expression whose value defines the minimum number of characters in the string representation of the result of the interpolated expression. If positive, the string representation is right-aligned; if negative, it's left-aligned. For more information, see Alignment Component.

关于c# - 字符串插值中的变量对齐组件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51524619/

相关文章:

ruby 1.9 如何将数组转换为不带括号的字符串

c# - 有没有一种方法可以在 C# 中将内插字符串拆分为多行,同时在性能方面在运行时执行相同的操作

c# - 我可以使用 C# 方法(带参数)的结果作为另一个方法的默认参数吗?

c++ - 将 char 指针值等同于某个 char 时出现段错误

mysql模式匹配两个不同表中的前5个字符,然后将数据输入到单独的列中

regex - 删除R中两种字符串模式之间的字母

python - 不明白这个 ConfigParser.InterpolationSyntaxError

c# - 你能在Web.Config中输入 "using"吗?

c# - 单击 GridView 查找所选行

javascript - C# 不显示完整的 IP 地址