返回介绍

C#

发布于 2025-02-22 22:20:03 字数 4417 浏览 0 评论 0 收藏 0

In this part of the C# tutorial, we will introduce the C# programming language.

Goal

The goal of this tutorial is to get you started with the C# programming language. The tutorial covers the core of the C# language, including variables, arrays, control structures and other core features. This tutorial uses command line compilers to build applications. It does not cover graphical interface development, or visual IDEs.

C#

C# is a modern, high-level, general-purpose, object-oriented programming language. It is the principal language of the .NET framework. It supports functional, procedural, generic, object-oriented, and component-oriented programming disciplines. The design goals of the language were software robustness, durability and programmer productivity. It can be used to create console applications, GUI applications, web applications, both on PCs and embedded systems. C# was created by Microsoft corporation. The name "C sharp" was inspired by musical notation where a sharp indicates that the written note should be made a semitone higher in pitch.

C# is a very popular language. Currently, it is one of the top 10 popular languages in the world. It was created on the Windows platform. The Mono project has created a clone for the Linux and Mac platforms. C# is a compiled language. The source code is compiled into executable (.exe) files which are executed by the .NET platform.

.NET

The .NET framework is an application software platform from Microsoft, introduced in 2002 and commonly called .NET ("dot net"). It uses an intermediate bytecode language that can be executed on any hardware platform that has a runtime engine. Programs written for the .NET Framework execute in a software environment, known as the Common Language Runtime (CLR). Common Language Runtime is an application virtual machine that provides services such as security, memory management, and exception handling. The class library and the CLR together constitute the .NET Framework. The .NET framework supports several programming languages. In addition to C#, development is possible in Visual Basic .NET, managed C++, F#, IronPython or IronRuby.

Compiling

There are two prominent C# compilers. The Microsoft C# compiler and the Mono C# compiler.

using System;

public class Simple 
{
  static void Main() 
  {
    Console.WriteLine("This is C#");
  }
}

This is a simple C# program that prints a message to the console.

On Linux, we need to install the Mono C# compiler. It is called gmcs for C# 3.0 profile and dmcs for the C# 4.0 profile. To install the Mono C# compiler, we must install the Mono platform.

$ dmcs simple.cs
$ ./simple.exe 
This is C#

We compile and run a simple C# program on Linux.

On Windows, we have two basic options. We either use the command line compiler or some version of the Visual Studio. The .NET framework is already installed on many versions of Windows OS. If not, we can download it and install it from the microsoft.com website.

On our system, the .NET framework was installed on C:\WINDOWS\Microsoft.NET\Framework\v3.5 . Here we find the csc.exe file which is the compiler of the C# language.

C:\programming\csharp>C:\WINDOWS\Microsoft.NET\Framework\v3.5\csc.exe simple.cs
C:\programming\csharp>simple.exe
This is C#

We compile and run a simple C# program on Windows.

Another option is to use a freely available Visual Studio C# Express Edition. We create a new project by selecting File/New Project or clicking Ctrl+N. From the available templates, we select a console application. (All programs in this tutorial are console programs.)

Console application
Figure: Console application

To run an example, we press the Ctrl+F5 key combination.

Sources

The following sources were used to create this tutorial:

In this part of the C# tutorial, we have introduced the C# language.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文