Chapter145:CreatingaConsole ApplicationusingaPlain-TextEditorand theC#Compiler(csc.exe)

No Comments

Section 145.1: Creating a Console application using a Plain- TextEditorandtheC#Compiler

In order to use a plain-text editor to create a Console application that is written in C#, you’ll need the C# Compiler. The C# Compiler (csc.exe), can be found at the following location:

%WINDIR%\Microsoft.NET\Framework64\v4.0.30319\csc.exe

N.B.Dependinguponwhichversionofthe.NETFrameworkthatisinstalledonyoursystem,youmayneedto change the path above, accordingly.

SavingtheCode

The purpose of this topic is not to teach you how to write a Console application, but to teach you how to compile one [to produce a single executable file], with nothing other than the C# Compiler and any Plain-Text Editor (such as Notepad).

  1. OpentheRundialog,byusingthekeyboardshortcut         WindowsKey  + R
  2. Typenotepad,thenhit Enter
  3. Pastetheexamplecodebelow,intoNotepad
  4. SavethefileasConsoleApp.cs,bygoingtoFile →Save As…,thenenteringConsoleApp.csinthe’FileName’textfield,thenselectingAllFilesasthefile-type.
  5. ClickSave

CompilingtheSourceCode

  1. OpentheRundialog,using         WindowsKey  + R
  2. Enter

%WINDIR%\Microsoft.NET\Framework64\v4.0.30319\csc.exe/t:exe

/out:”C:\Users\yourUserName\Documents\ConsoleApp.exe””C:\Users\yourUser

Name\Documents\ConsoleApp.cs”

Enter:

Now, go back to where you originally saved your ConsoleApp.csfile. You should now see an executable file (ConsoleApp.exe).Double-clickConsoleApp.exetoopenit.

That’sit!Yourconsoleapplicationhasbeencompiled.Anexecutablefilehasbeencreatedandyounowhavea working Console app.

usingSystem;

namespaceConsoleApp

{

classProgram

{

privatestaticstringinput=String.Empty;

staticvoidMain(string[]args)

{

gotoDisplayGreeting;

DisplayGreeting:

{

Console.WriteLine(“Hello!Whatisyourname?”);

input=Console.ReadLine();

if(input.Length>=1)

{

Console.WriteLine(

“Hello,”+

input+

“,enter’Exit’atanytimetoexitthisapp.”);

gotoAwaitFurtherInstruction;

}

else

{

gotoDisplayGreeting;

}

}

AwaitFurtherInstruction:

{

input=Console.ReadLine();

if(input.ToLower()==”exit”)

{

input=String.Empty;

Environment.Exit(0);

}

else

{

gotoAwaitFurtherInstruction;

}

}

}

}

}

About us and this blog

We are a digital marketing company with a focus on helping our customers achieve great results across several key areas.

Request a free quote

We offer professional SEO services that help websites increase their organic search score drastically in order to compete for the highest rankings even when it comes to highly competitive keywords.

Subscribe to our newsletter!

More from our blog

See all posts
No Comments

Leave a Comment