C# 我无法使用Debug.Print或Console.WriteLine,因为我得到了错误;名称';控制台';在当前上下文中不存在。”;如何打印文本?

C# 我无法使用Debug.Print或Console.WriteLine,因为我得到了错误;名称';控制台';在当前上下文中不存在。”;如何打印文本?,c#,visual-studio,C#,Visual Studio,我正在使用C#的新版本,并使用Visual Studio。我找不到用C#打印文本的方法;我无法使用Console.WriteLine或Debug.Print 以下是我的代码截图: 这是我的密码: using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.InteropServices.WindowsRuntime; using Windows.F

我正在使用C#的新版本,并使用Visual Studio。我找不到用C#打印文本的方法;我无法使用Console.WriteLine或Debug.Print

以下是我的代码截图:

这是我的密码:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The Blank Page item template is documented at 
https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409

namespace Gregoua_Technologies
 {
/// <summary>
/// An empty page that can be used on its own or navigated to within a 
Frame.
/// </summary>
public sealed partial class MainPage : Page
{
    public MainPage()
    {
        this.InitializeComponent();
    }
    public static void Main()
    {
        int x = 1;
        int y = 3;
        int a = Foo(x, y);
        Console.WriteLine(a);
    }
    public static int Foo(int x, int y)
    {
        return x / y;
    }

  }
  }
使用系统;
使用System.Collections.Generic;
使用System.IO;
使用System.Linq;
使用System.Runtime.InteropServices.WindowsRuntime;
使用Windows基金会;
使用Windows。
使用Windows.UI.Xaml;
使用Windows.UI.Xaml.Controls;
使用Windows.UI.Xaml.Controls.Primitives;
使用Windows.UI.Xaml.Data;
使用Windows.UI.Xaml.Input;
使用Windows.UI.Xaml.Media;
使用Windows.UI.Xaml.Navigation;
//空白页项模板被记录在
https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
名称空间Gregoua_技术
{
/// 
///一个空页,可以单独使用,也可以在
框架
/// 
公共密封部分类主页面:第页
{
公共主页()
{
this.InitializeComponent();
}
公共静态void Main()
{
int x=1;
int y=3;
int a=Foo(x,y);
控制台写入线(a);
}
公共静态intfoo(intx,inty)
{
返回x/y;
}
}
}

System.Diagnostics.Debug.WriteLine是在UWP中用于输出到VS输出窗口的命令

您的代码应该如下所示:

System.Diagnostics.Debug.WriteLine(a);

System.Diagnostics.Debug.WriteLine
是在UWP中用于输出到VS输出窗口的命令

您的代码应该如下所示:

System.Diagnostics.Debug.WriteLine(a);

在主程序中继承page类如何做到这一点?问题和答案是一样的,因为你只是创建了一个错误的项目,UWP应用程序从来没有控制台。选择“控制台应用程序”项目模板。对于uwp,我应该使用System.Diagnostics.Debug.WriteLine(“你好”);而不是控制台。WriteLine(“你好”);?在主程序中继承page类如何做到这一点?问题和答案是一样的,因为你只是创建了一个错误的项目,UWP应用程序从来没有控制台。选择“控制台应用程序”项目模板。对于uwp,我应该使用System.Diagnostics.Debug.WriteLine(“你好”);而不是控制台。WriteLine(“你好”);?如果使用dotnet cli和终端,这是monogame的救命稻草如果使用dotnet cli和终端,这是monogame的救命稻草