How to write a C Sharp program

Author: Helen Garcia
Date Of Creation: 19 April 2021
Update Date: 1 July 2024
Anonim
How to Program in C# - BASICS (E01)
Video: How to Program in C# - BASICS (E01)

Content

C # is a great programming language, and all the tools you need to get started is free and easy to use. While C # is often associated with Microsoft and closed source by everyone, free software advocates simply use DotGNU, which provides more or less the same basic functionality and allows you to explore and modify the kernel without any restrictions. The instructions below describe both the FOSS-centric approach and the Windows-centric one. C # also works with the .NET framework.

Steps

Method 1 of 3: Configure (Windows)

  1. 1 Go here to download a free copy of Visual C # 2010 Express Edition. A 2012 version is also available, but download the 2010 version better if you are looking for general C # development.
    • The 2012 version also does not support Windows 7/8.
  2. 2 Run the downloaded executable file and follow these steps:
    • Further.
    • I agree → Next.
    • Select MSDN, not SQL → Next.
    • Install.

Method 2 of 3: Create your first program

  1. 1 Start Visual C # 2010 Express Edition.
  2. 2 Click File → New → Project.
  3. 3 Select Visual C # -> Windows -> Console Application.
  4. 4 Click OK.You should see the following:

      using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication1 {class Program {static void Main (string [] args) {}}}

  5. 5 Under static void Main (string [] args)and after the first curly brace, type in the following:

      Console.WriteLine ("Hello, World!"); Console.ReadLine ();

  6. 6 The result should look something like this:

      using System; using System.Collections.Generic; using System.Text; namespace ConsoleApplication1 {class Program {static void Main (string [] args) {Console.WriteLine ("Hello, World!"); Console.ReadLine (); }}}

  7. 7 Click the Run [►] button on the toolbar.
    Congratulations! You've just created your first C # program!
  8. 8 This program should bring up a console window that says “Hello World!».
    • If this is not the case, then you are mistaken somewhere.

Method 3 of 3: Setting Up (Freeware)

  1. 1 You will need CVS and GNU compilers. They are included in most Linux distributions.
  2. 2 Go to the DotGNU project website (http://www.gnu.org/software/dotgnu/), which provides a FOSS implementation of C #. Read the chapter on installation. Even beginners can easily follow these instructions.
  3. 3 You can either select the sources and build your own C # IDE from scratch, or try out the pre-compiled distributions first. The project is fairly easy to create from source, so we recommend that you try this path first.
  4. 4 Try to run some examples that are already compiled (.exe). For example, FormsTest.exe will show a large collection of different GUI controls. The pnetlib / samples folder contains the ilrun.sh script capable of running compiled executable files like this: sh ./ilrun.sh forms / FormsTest.exe (from the same folder).
  5. 5 On Linux, you can use KWrite or gedit to edit C # code. Recent versions of both editors support syntax highlighting for this language.
  6. 6 Learn how to compile the short example described in the "Windows" section. If there is not enough documentation on the project website, search the Internet. If it doesn't help, ask a question on the project website.
  7. 7 Congratulations, you now know about two types of C # code implementations and are not tied to any one C # provider!

Tips

  • When you install Visual C # 2010/2012 express, it will either download automatically or ask you for permission.
  • Visual C # 2005/2008 Express Editions comes with the option to install Microsoft MSDN 2005 Express Edition. This is great help and can be accessed through Help: Contents or by highlighting a keyword and pressing F1.It is highly recommended to download and install the MSDN library.
  • There are better C # implementations than those described here. The Mono project might interest you.

Recommended Books

  • ISBN 0-7645-8955-5: Visual C # 2005 Express Edition Starter Kit - Newbie
  • ISBN 0-7645-7847-2: Beginning Visual C # 2005 - Novice
  • ISBN 0-7645-7534-1: Professional C # 2005 - Intermediate +