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 @   no_no  阅读(5)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
点击右上角即可分享
微信分享提示