小编Bra*_*ing的帖子

C#字符串插值,格式可变

我需要使用字符串插值格式化变量,格式字符串是另一个变量:

这是我的示例代码:

static void Main(string[] args)
{
    int i = 12345;

    Console.WriteLine($"Test 1: {i:N5}");

    var formatString = "N5";

    Console.WriteLine($"Test 2: {i:formatString}");
}
Run Code Online (Sandbox Code Playgroud)

测试1工作,测试2不起作用.

测试2的确切语法是什么?

c#

6
推荐指数
3
解决办法
4400
查看次数

Visual Studio 2022 - 添加 System.Runtime 假程序集

简单测试项目:xUnit,针对Net 6.0 环境:

  • Windows 10 21h1,19043.1348
  • Visual Studio 2022 Enterprise 17.0.0(通过 Visual Studio 安装程序安装 Net 6 和 Net 5 sdk)

添加System.Runtime的假程序集,编译错误:

1>------ Rebuild All started: Project: TestProject1, Configuration: Debug Any CPU ------
Restored D:\TestProject1\TestProject1\TestProject1.csproj (in 570 ms).
1>D:\TestProject1\TestProject1\obj\Debug\net6.0\Fakes\sr\f.cs(94904,16): error CS1503: Argument 1: cannot convert from 'string' to 'System.Runtime.Serialization.SerializationInfo' [D:\TestProject1\TestProject1\obj\Debug\net6.0\Fakes\sr\f.csproj]
1>D:\TestProject1\TestProject1\obj\Debug\net6.0\Fakes\sr\f.cs(94904,31): error CS1615: Argument 2 may not be passed with the 'ref' keyword [D:\TestProject1\TestProject1\obj\Debug\net6.0\Fakes\sr\f.csproj]
1>GENERATEFAKES : error : project compilation failed with exit code 1
1>D:\TestProject1\TestProject1\obj\Debug\net6.0\Fakes\sr\f.cs(94904,16): error CS1503: Argument 1: cannot …
Run Code Online (Sandbox Code Playgroud)

unit-testing

6
推荐指数
1
解决办法
2948
查看次数

标签 统计

c# ×1

unit-testing ×1