HostOnNet Blog

First C# Program

Looking for Linux Server Admin or WordPress Expert? We can help.

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

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.