HostOnNet Blog

First C# Program

I was installing .NET on a Windows 2012 R2 server, wanted to check .NET version installed. Never tried C# before. To make a C# program, open notepad or whatever text editor you have, copy following content

using System;
using Microsoft.Win32;

public class GetDotNetVersion
{
   static void Main(string[] args)
   {
        Console.WriteLine("Version: " + Environment.Version.ToString());
   }
}   

Save it was 1.cs

Now you need to compile it to .EXE format, this is done by .NET command line tool called “csc”.

If you have .NET 4.5, add following folder to your PATH

C:\Windows\Microsoft.NET\Framework64\v4.0.30319

Your exact folder name may wary depending on the version of .NET you have installed.

Now run

csc 1.cs

That will create 1.exe file. Now run it with

.\1.exe

Posted in Windows