C # Guide, revisit the basics and look far away! (1) C # language Introduction

Source: Internet
Author: User
Tags garbage collection instance method

1.c# (Read sharp) is an easy-to-use, modern programming language that is not only object-oriented, but also type-safe. C # originates from the C-language family, and it's easy to get ready to use in a very short time.

2. C # is an object-oriented language . In addition, C # further supports component-oriented programming. contemporary software design is increasingly dependent on software components in the form of self-described standalone feature packs. key features of such components include the provision of properties, methods, and events for the programming model, the attributes that provide declarative information for the component, and their own documents. C # provides language constructs to directly support these concepts, making C # a very natural language that can be used to create and use software components.

3. Multiple C # features help to build reliable and durable applications: garbage collection automatically reclaims memory that is not accessed by unused objects; exception handling provides a structured and extensible way to perform error detection and recovery; C # language Type-safe design prohibits reading uninitialized variables, indexing arrays outside the range, or performing unchecked type conversions.

4. C # uses a unified type system All C # types, including int and double primitive types, inherit from one root object type . Therefore, all types share a common set of operations, and any type of value can be stored, transmitted, and processed consistently. in addition, C # supports user-defined reference types and value types, enabling object dynamic allocation and inline storage of lightweight structures.

5. To ensure that C # programs and libraries evolve in a compatible way over time, the C # design emphasizes versioning . many programming languages pay little attention to this issue, so when you introduce a new version of a dependent library, programs written in those languages have more disruptive behavior. because of more emphasis on versioning, the directly affected C # Design aspects include separate virtual and override modifiers, rules on method overload resolution, and support for explicit interface member declarations.

Hello World

The "Hello, World" program has historically been used to introduce programming languages. The C # code for this program is shown below:

C # replication
using System;class Hello{    static void Main() { Console.WriteLine("Hello, World"); }}

C # source files have a file name extension that is typically .cs . assuming that the "Hello, World" program is stored in a file hello.cs , you can use the following command line to compile the program:

console copy
csc hello.cs

This generates the Hello.exe executable assembly. run this application to generate the following output:

console copy
Hello, World

Important

cscThe compile command implements the full framework and may not be applicable to all platforms.

"Hello, world" begins with the reference   System   namespace   using   directives.   namespace provides a layered approach to organizing C # programs and libraries.   namespaces contain types and other namespaces. For example, the System   namespace contains many types, such as   referenced in a program, Console   class, and many other namespaces (such as   IO   and   collections ).   using   directives.   Because of the use of   using   directives, so the program can use   Console.WriteLine   as   System.Console.WriteLine   shorthand.

The "Hello, World" program declares Hello a class with only one member, that is, a Main method. The Main method is declared with a static modifier. An instance method can this reference a specific enclosing object instance using a keyword, while a static method can run without referencing a particular object. by convention, Main a static method is the entry point of a program.

The output of the program is generated by the methods of the System classes in the namespace Console WriteLine . This class is provided by the standard class library. By default, the compiler automatically references the standard class library.

There's a lot more to be covered about C #. The following topics outline the C # language elements. with these overviews, you can learn the basic information about all elements of the C # language and get the information you need to gain insight into the elements of the C # language:

  • Program Structure
    • Learn about key organizational concepts in the C # language: programs , namespaces , types , members , and assemblies.
  • Types and variables
    • Learn about value Types , reference types , and variables in the C # language.
  • An expression
    • Expressions are constructed on the basis of operands and operators . the expression generates a value.
  • Statement
    • statement is used to represent the operation of a program.
  • Classes and objects
    • The class is the most basic C # type. the object is a class instance. class is generated using members , this topic also describes this.
  • Structure
    • Unlike classes, structs are data structures that belong to value types.
  • Array
    • An array is a data structure that contains many variables accessed by a computed index.
  • Interface
    • An interface defines a contract that can be implemented by classes and structs. An interface can contain methods, properties, events, and indexers. The interface does not provide the implementation code for the defined member, only the members that must be provided by the class or struct that implements the interface.
  • Enumeration
    • An enumeration type is a unique value type that contains a set of named constants.
  • Commissioned
    • A delegate type represents a reference to a method with a specific argument list and return type. a delegate allows you to treat a method as an entity that can be assigned to a variable and passed as a parameter. delegates are similar to the concept of function pointers in some other languages, but unlike function pointers, delegates are not only object-oriented, but also type-safe.
  • Characteristics
    • Using attributes , programs can specify additional declarative information about types, members, and other entities.

C # Guide, revisit the basics and look far away! (1) C # language Introduction

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.