C# 问题合集

Console.ReadLine()奇怪的没有运行

源码简易部分:

    public static void Main()
    {
        int flat;
        Console.Write("input your want operation:");
        flat = Console.Read();
        if (flat == 'a')
        {
            Console.WriteLine("input you want add chapter number?");
            string num = Console.ReadLine();
            Console.WriteLine(num);
        }
    }

问题描述:
string num = Console.ReadLine();似乎并没有执行,直接跳过。

推测原因:
flat = Console.Read();的影响下,导致结果。改成flat = Console.ReadLine();ok!!

无法引用System.Windows.Forms

经了解,.net 6.0框架的WPF应用 是无法直接使用此引用。
需要在右键项目,然后点击 编辑项目文件 中添加<UseWindowsForms>true</UseWindowsForms>

    <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net6.0-windows</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    <UseWPF>true</UseWPF>
    <UseWindowsForms>true</UseWindowsForms>
  </PropertyGroup>

然而,这个方法,会导致大量winForm与WPF的冲突。所以PASS
改为:
<FrameworkReference Include="Microsoft.WindowsDesktop.App.WindowsForms" />

    <ItemGroup>
        <FrameworkReference Include="Microsoft.WindowsDesktop.App.WindowsForms" />
    </ItemGroup>
posted @ 2024-08-08 18:48  no_no  阅读(27)  评论(0)    收藏  举报