Home>

A brief introduction to the C#language

According to Microsoft's official website,c#is an object-oriented language tailored for the .net platform,It is similar to java. It is a language born from the evolution of c++ (extracting the advantages of c++ and abandoning some low-level operations that trouble developers)As well.The main language of the net platform, c#, also draws on some features of other languages.Such as:vb6 class attributes.

c#is like c++, java, vb6, a mixture of these languages,Drawing on the essence of multiple languages,Then take a look at those advantages of c#:

1.c#is a completely object-oriented language,Using object-oriented thinking allows us to use real-world things to model our computer software development model,Make our code more organized,Better division of labor,And maintenance.

2.c#abandoned pointers as in C++,It is greatly reduced the complexity of program development,There is also a garbage collector to manage memory,The programmer does not need to destroy memory like using the C++ delete keyword.No need to worry about the release of memory to reduce the complexity of development.

3. Support interface-based programming technology,Can achieve loosely coupled systems,Facilitate future software upgrades and extensions.Just wait and list!

Second, my first c#program

you guessed right! It's hello world. OK, open Microsoft Visual Studio Development Tools

Step 1:Top left corner Click:File->New->Project

Second step, select from the tree menu on the left side of the pop-up dialog:visual c#->console application->name named myhelloworld

Step 3:Type the following code in the editing area

My first program helloworld

using system;
namespace myhelloworld
{
  class program
  {
    static void main (string [] args)
    {
      console.writeline ("hello world ...");
    }
  }
}

The fourth step is ctrl + f5. The effect is as follows:

This will output a sentence on the console:hello world ..... Then our first program is complete.Let's analyze it initially.

Three, preliminary analysis of my first c#program1. First look at the first line of code:

using system;

This line of code means importing a namespace named system.You will ask at this time,What is a namespace?

Namespace:A namespace is a grouping of related types within a program.<Advanced programming from c#and .net 3.0>

For example:

For example, pens, computers, etc. are all office supplies.mp4 game consoles and so on are all entertainment products. So good, now I need to finish writing a program,What I need at this time is office supplies,At this time I need to bring my office supplies,Use as needed (such as using a notebook for programming). Then bringing my office supplies at this time is an import action,And office supplies are name spaces,After the work is done, I need to play games again.We can take entertainment supplies and use them.At this time, we imported another namespace named entertainment products.Contains:mp4 game consoles and more.

The code is represented as follows:

using office supplies;
using entertainment;

2. After understanding the namespace, continue to look at the following code

The third line

namespace myhelloworld //Define your own namespace

After understanding the namespace, the third one is easy to understand.Is to define your own namespace,Tell others about those types that your namespace wraps in the future.

class program //is your application class
static void main (string [] args) //entry point of the program

Now you can understand program as your program,The main () method is the entry point of your program,When the program runs, it will find the main () (entry point) method to execute the code in it.

The entry point method wrote console.writeline ("hello world ...");as follows:

console.writeline ("hello world ...");

The meaning is to output a sentence on the console:hello world ... Then continue to analyze this code to connect the concepts learned above.

The first is the console class:it represents a console window.This window class uses a function (method) writeline, which means that the console window writes a sentence,What is the content of the words?This is the content between the parentheses after the writeline method.Such as:writeline (content)

After analyzing the code, we will go back and think about the function implemented by our program, that is, what the program does is to output a string with the content of hello world to the console.Then we need to use the console class (console) when implementing this function, then where is the console class,At this time we are looking at the first line of our code,using system;yes the console class belongs to the system namespace,So when we want to use the console, we need to import its namespace first.In this way, we have the types required by our program.We just need to call the type method to do the corresponding operation. .

Fourth, guide your pseudocode

After understanding the above concepts,According to my example and explanation above,Write a pseudo code,Help everyone understand better:

using office supplies;
//Use computer so import office supplies name space
using entertainment;
//Use the game console to import the entertainment supplies name space
/*
Inclusion relationship:
     Office Supplies:Pen Computer Book
     Entertainment:mp4 game console
* /
namespace my office
{
  class program
  {
    static void main (string [] args)
    {
      //Use computer as my job
       Computer.run code ();
      //After completion, I need to play the game console
       Game console. Run game ();
    }
  }
}
c
  • Previous ThinkPHP lets /Public not parse (direct output) in templates
  • Next MySQL 5016 garbled solution