0

I am using new to C#, and using Visual Studio. I cannot find a way to print text in C#; I cannot use Console.WriteLine, or Debug.Print.

Here is a screenshot of my code: https://i.stack.imgur.com/5AUP4.jpg

Here is my code:

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;
    }

  }
  }
Greg
  • 1
  • 1
  • 5
  • inheriting page class in main program – manoj Jun 23 '17 at 06:10
  • how do i do that? – Greg Jun 23 '17 at 06:11
  • https://stackoverflow.com/questions/2669463/console-writeline-does-not-show-up-in-output-window Question has same problem answer given [answer](https://stackoverflow.com/a/2669596/1756068) – manoj Jun 23 '17 at 06:14
  • 1
    You simply created the wrong kind of project, a UWP app never has a console. Pick the "Console App" project template instead. – Hans Passant Jun 23 '17 at 06:18
  • for a uwp should I use System.Diagnostics.Debug.WriteLine("hello"); instead of Console.WriteLine("Hello");? – Greg Jun 23 '17 at 06:23

1 Answers1

6

System.Diagnostics.Debug.WriteLine is the method to be used in UWP to output to the VS Output Window.

Your code should look like:

System.Diagnostics.Debug.WriteLine(a);
Zein Makki
  • 29,485
  • 6
  • 52
  • 63
  • This is a lifesaver for monogame if working with dotnet cli and the terminal –  Jan 31 '21 at 05:33