C. The relationship between C + + and C #, take “putting elephants in the refrigerator” as an example

Time:2021-10-16

I have to use it recentlyunityDo things related to virtual simulation. Of course, its popularity is still in the game industry, such asGlory of KingsIt was developed using unity.

useunityWe have to learnC#Language, I always thought that C # is an upgraded version of C + +, because C + + is an improved version of C, butC#The relationship with the first two is equivalent toJavaandJavaScript, it doesn’t matter.

C language

CLanguage is a languageProcess orientedComputer programming language is different from object-oriented programming languages such as C + +, c#, Java and so on. The design goal of C language is to provide a programming language that can compile and process low-level memory in a simple way, produce only a small amount of machine code and run without any running environment support.

And it is a very excellent and important language,WindowLiunxUXIXThe system is written in C language, which shows its importance.

C++

C++It is a static, compiled, general, case sensitive and irregular programming language, which supports procedural programmingobject-orientedProgramming and generic programming.

It is considered to be an intermediate language, which combines the characteristics of high-level language and low-level language.

OOP (object oriented) language features:

  • Encapsulation: a mobile phone is composed of many components, including processor, memory, input and output settings, screen, battery, etc. assembling these things together is a mobile phone, which is encapsulation.
  • Inheritance: Lao Tzu gave birth to a son. If the son inherits Lao Tzu’s characteristics, he has inheritance.
  • PolymorphismI am the son of my parents at home, the staff of the company in the company, the Shenzhen people in Shenzhen, and the different ways of calling the same method in the object-oriented language, which is polymorphism.

C Sharp

Also calledC#, is a modern, universal, object-oriented programming language, developed by Microsoft and approved by ECMA and ISO.

As for its name, let’s look at its origin:

  • Microsoft to saveVisual BasicUnfinished business
  • PlagiarizejxxLanguage and namedj++
  • After being sued, he learned to be smart and lied that he was an improvement of C language
  • NamedC#

Yes, it isJavaLanguage, now c# and java have amazing similarities.

The relationship between the three

Classic case: put the elephant in the refrigerator

C. The relationship between C + + and C #, take

C:

C language is an extremely cold person, so the answers are cold:

Me: Hello, C language. I want to put the elephant in the refrigerator and help me do it, okay?

C: OK

Me: what are we going to do?

C: Guess

Me: Er… Should we create an elephant first?

C: Yes

Me: how to create?

C: Guess

I had to look through the documents. Oh, malloc is a piece of memory.

Me: OK, I’ll use malloc and apply for a space for elephants, okay?

C: OK

Me: Er… How do elephants build?

C: Guess

I… Went to see the structure of the elephant

Me: OK… I defined an elephant’s data structure. What do I do next?

C: Guess

There was an unspeakable feeling in my heart…

Me: Oh, well, I create a refrigerator. The steps should be similar to that of an elephant.

C: Um

I looked through the structure of the refrigerator and defined the struct of a refrigerator.

Me: Well, the refrigerator has been constructed. How to put it?

C: Hum

I… Silently input how to put the elephant into the refrigerator C on the stack overflow.

I: I finally found the answer. Define a method to put the elephant’s nose, eyes and ears in. OK, it’s all in. C. You output it and have a look.

C: Perm, perm, perm

Me: ha ha, ha ha, C. you are not high and cold at last

。。。

Me: Hey, why don’t you talk? C? Do you have a fever?

Pour up a basin of water immediately.

end.

C++:

C + + is a knowledgeable child, relatively young and not so cold.

Me: C shit, shall we put the elephant in the fridge?

C + +: roll

Don’t you speak very cold?

Me: Well, I’m wrong, dear C + +, let’s put the elephant in the fridge.

C + +: OK, the data types of elephants and refrigerators have been defined. You need to construct one respectively.

Me: OK.

So I read the document and learned to use new to construct

Me: OK, dear C + +, I want to build an elephant.

C + +: OK, there are 13 methods to construct elephants. Which one do you choose?

I…

Me: let me introduce you.

C + +: OK, you can first construct on the stack. The advantage of this is that it can facilitate resource management, and the syntax is better. You can use raii. If you don’t know anything about raii, you can check it on cppreference. Of course, you can also construct on the heap, you can construct a big elephant, and…….

A month later, C + + finally finished. I also have a beard… He went on working after shaving

Me: OK, C + +, I’ll build an elephant on the stack.

C + +: you don’t love me anymore.

I:???

C + +: you didn’t say “honey”.

I…

Me: Well, dear C + +, I want to simply construct an elephant.

C + +: OK, you can choose to build an African elephant, an American elephant or an Antarctic elephant. You can set the color of the elephant. You can set the size of the elephant’s butt. What do you want about the elephant’s gender and sexual orientation……

Me: I just want a simple, default one.

C + +: OK, we have constructed one. You can choose how to initialize it. There are 13 initialization methods. It is recommended to use the latest unified initialization.

I…

I: unified initialization

C + +: OK, we can build a refrigerator.

Me: OK…

After a month’s choice, the refrigerator was finally constructed.

C + +: OK, the refrigerator provides the addelephant method, which can be used directly.

Me: Wow, great. OK, I’ll use this method.

C + +: this method provides a variety of overloads, which can be copied, moved or forwarded directly. It saves constructing an elephant before moving into the refrigerator.

I:… Why didn’t you say it earlier

C + +: why didn’t you ask earlier.

Me: just use the mobile one.

C + +: OK, use STD:: move to turn the constructed elephant into an R-value reference.

I looked confused, but I did it anyway.

Me: OK

C + +: OK, start putting it into the refrigerator. It’s very fast.

suddenly

C + +: report errors. Molecules and atoms are not convertible types. There are 1556 errors such as the + operator between panda and Edison.

I………

Me: look for information on the Internet and say it’s almost the last line. OK, have a look. Well, it seems that there is an error on line 31. What is the error? The error message didn’t say anything clearly. Just change it. Compile and run.

C + +: OK, I’ve put the female African elephant with a hip circumference of 12 meters, a left arm of 13 meters and a right arm of 14 meters. She likes male elephants and doesn’t get married and have children. She has a good tutor since childhood. She is familiar with the four books and Five Classics into a refrigerator with an orange color, 50 meters high, 60 meters wide, 300 meters thick and a temperature of minus 300 degrees. The brand of refrigerant is Huche brand and a rated voltage of 220V.

I… A long sigh of relief.

C#:

Me: I want to put the elephant in the fridge.

C #: good master, my father Microsoft has written about elephants and refrigerators. You just need to new.

Me: OK, new, put it in the fridge.

C #: OK, it has been put in. The expansion method of the refrigerator addelephant < > method is used.

Me: Well, you did a good job. Can you put it a little faster? C + + just put it very fast.

C #: not for your safety.

Me: Er… Then I’d like to adjust the size of the elephant’s ears.

C #: sorry, it can’t be adjusted. You can set the shape of the elephant’s ears. Many kinds of ear shapes have been defined for you. You can also adjust the elephant’s skin color. Many kinds of skin colors have been defined for you.

Me: forget it, that’s it.

C #: OK. If you need speed or grasp every detail of the elephant, you can also see my brother, C + + / CLR, who can complete these functions you put forward. You can also bring him to me. We can work together. You can also export the work completed by C + + to binary form, which I can use directly.

Me: OK, thanks. No.

C #: OK, I wish you a happy life.

Over!

Your likes, comments and concerns are the greatest encouragement to Xiaobian o (∩ ∩) O

I amGeek ape soldierThe official account of geeks and records shows that independent developers learn to grow and move towards wealth and freedom.