0

I'm trying to make a console program in C# that is independent from using System or any other libraries, that includes Console.WriteLine();. I'm making an SDK written in C# (almost like what Unity 3D does). However I don't know how to make a custom text printer. I've found no articles on the web or Stackoverflow questions related to what I want to do. There has to be someway of doing this, or Console.WriteLine(); wouldn't exist.

Here is my code so far, but I don't know how much it will help:

public static class GPrint
{
    public static void Print(string str)
    {



    }
}

I've explored almost all of the obvious stuff like string.something() and str.something(), but there seems to be nothing related to printing a string on the screen.

Is there any way I can make a simple Console.WriteLine() clone without using the provided System namespace?

Thanks in advance!

GreenJames
  • 21
  • 1
  • 8
  • 6
    Just out of curiosity, why do you need this? – Mahdi Jan 02 '17 at 19:30
  • 3
    I really don't understand why you would like to do this because the `Console` class is contained in the `mscorlib.dll` which is basically included in any console application. The `String` class is also located in `mscorlib`. (`string` is just an alias for `System.String`.) So if you don't want to use `System`, you can't use `string.Something()` as well. In other words: Without using `mscorlib` you can't even do the simplest things. – haindl Jan 02 '17 at 19:35
  • Create windows form or Wpf with one big multiline textbox and print it there without `Console.WriteLine`. – Fabio Jan 02 '17 at 19:37
  • 1
    You might be interested in the source code of Microsofts Console class: https://referencesource.microsoft.com/#mscorlib/system/console.cs,f907d79481da6ba4 – Odrai Jan 02 '17 at 19:37
  • 2
    @Fabio The OP wants to do this without using **any** libraries, so he can't really create anything using WinForms or WPF. He basically would need to create his own whole .NET framework. – haindl Jan 02 '17 at 19:41
  • @Mahdi I'm making an SDK written in C# (almost like what Unity 3D does). – GreenJames Jan 02 '17 at 19:51
  • I would also like to add that I basically want to make a cross-platform C#. I want the features of C#, not the .Net stuff. – GreenJames Jan 02 '17 at 20:02

1 Answers1

4

System.Console, an abstraction over stdin/stdout is so inherent to processes that the .NET team decided to incorporate it into the common object runtime library (mscorlib).

In other words, letting a process receive input and emit output over the standard streams is so ingrained into the runtime and the base class library, that it it not possible, or at least not feasible, to have one without the other.

It's not like you can run a .NET console application omit loading the .NET Framework altogether, just because you're not using System.Console or any other class from the System namespace.

See also Hans' answer in Is mscorlib.dll/mscoree.dll loaded when .NET application runs:

Technically it is possible to not get mscorlib.dll loaded [...] Practically that only works if you provide a substitute

If you're not looking to omit mscorlib altogether, but really just are curious about writing to the console without using System.Console, see MSDN: Console Functions. You'll have to use Platform Invoke. This will come at a price though: your application will then only run on Windows, unless the platform you're running on substitutes the relevant DLLs.

Community
  • 1
  • 1
CodeCaster
  • 147,647
  • 23
  • 218
  • 272
  • 3
    Ha! you beat me to it. He is essentially asking how to write a c# program without using the .NET Framework. The whole point of using a higher level language IS to not have to write lower level code. – JuanR Jan 02 '17 at 19:45