Chapter145:CreatingaConsole ApplicationusingaPlain-TextEditorand theC#Compiler(csc.exe)
- 14/06/2024
- C# Programming
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).
- OpentheRundialog,byusingthekeyboardshortcut WindowsKey + R
- Typenotepad,thenhit Enter
- Pastetheexamplecodebelow,intoNotepad
- SavethefileasConsoleApp.cs,bygoingtoFile →Save As…,thenenteringConsoleApp.csinthe’FileName’textfield,thenselectingAllFilesasthefile-type.
- ClickSave
CompilingtheSourceCode
- OpentheRundialog,using WindowsKey + R
- 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 postsRecent Posts
- Chapter153:C#Script 22/06/2024
- Chapter 152: Unsafe Code in.NET 21/06/2024
- Chapter151:ASP.NETIdentity 20/06/2024