close[x]


C#

C#-Home C#-Environment setup C#-Basic syntax C#-Comment C#-Variable C#-Data type C#-Type cast C#-User input C#-Operator C#-Math C#-Boolean C#-Decision C#-Switch C#-Loop C#-Break/Continue C#-Array C#-String C#-Namespace C#-Index C#-Method C#-Class/Object C#-Constructor C#-Encapsulation C#-Inheritance C#-Polymorphism C#-Abstraction C#-Interface C#-Get/Set C#-Enums C#-Exception C#-File I/O C#-Modifiers I/O C#-SQL



learncodehere.com



C# - Environment Setup

C# is execute server-side for a different kind of application like console, window forms or web applications, etc. .

To use C# for .Net application, you need two things :

  • The .NET Framework
  • Integrated Development Environment (IDE)

  • The .NET Framework

    The .Net framework platform helps you to write Windows applications, Web applications and Web services applications.

    C#, C++, Visual Basic, Jscript, COBOL, etc used .NeT framework to functional as well as to communicate with each other.


    Integrated Development Environment (IDE)

    An IDE (Integrated Development Environment) is used to edit and compile code.

    Visual Studio is an IDE provided by Microsoft to write the code in languages such as C#, F#, VisualBasic, etc.

    We will use Visual Studio Community, which is free to download from visualstudio.microsoft.com/vs/

    C# can be used in a window-based, web-based, or console application.


    Installing C#

    Once the Visual Studio Installer is downloaded and installed, choose the .NET workload and click on the Modify/Install button.

    csharp environmental setup

    After the installation is complete, click on the Launch button to get started with Visual Studio.



    On the start window, choose Create a new project.

    Then click on the "Install more tools and features" button.

    Choose "Console App (.NET Core)" from the list and click on the Next button.

    csharp environment setup

    Enter a name for your project, and click on the Create button.

    Visual Studio will generate 'Hello World!'code for your project.

    Program.cs will be created as default a C# file in Visual Studio

    csharp environment setup


    Run the program by pressing the F5 button on your keyboard (or click on "Debug" -> "Start Debugging"). This will compile and execute your code.


    Example : Simple C#

    using System;
    namespace HelloWorld
    {
      class Program
      {
        static void Main(string[] args)
        {
          Console.WriteLine("Code Always!");    
        }
      }
    } 
    

    When the above code is compiled and executed, it produces the following result −

    Result

    Code Always!