Differences and linkages between C + + and C #

Source: Internet
Author: User
Tags c constructor

C++and C # differences and Links C constructor C language syntax structure, c++and C # Basically the same, only the following aspects are different:1, inheritance: C + + supports multiple inheritance, C # classes can only inherit implementations from one base class, but multiple interfaces may be implemented.2, arrays: The syntax for declaring C # arrays and declaring C + + arrays is different. In C #, the "[]" tag appears after the array type.3, data type: in C + + the bool class can be converted to an integral type, but the bool type and other types in C # (especiallyint) is not converted.LongType: in C #,LongData type is -, and in C + + for +-bit4、structType: In C #, classes and structs are semantically different.structis a value type, andclassis a reference type.5、SwitchStatement: With the C + +SwitchStatements, C # does not support from a CaseLabel goes through another CaseLabel. The C + + switch followed by a parameter must be of type int, while C # allows string type 6,DelegateType: Delegate vs. C + +the function pointers in are basically similar, but the former has type safety and is safe. 7, all objects in C # can only be accessed by the keyword "New"To create, C + +the "class name _ Object name" method changes to declare a reference in C #. 8, exception handling: C # introducesfinallystatement, which is not in C + +, C + + allows any type to be thrown, while C # specifies that the throw type is an object derived from System.Exception.9, C # operators: C # supports other operators, such as isAndtypeof。 It also introduces the different functions of some logical operators.Ten、StaticUse: The static method can only be called by the class name, changing the static variable. One, C # replaces the C + + initialization list method on a constructed base class. A, the main method and the main function in C + + and Java are declared differently, main instead of Main13, method parameters: C # supportrefAnd outparameter, which supersedes the pointer passing arguments by reference. -, pointers can only be used in unsafe unsafe mode in C #. the, and execute overloaded operators in different ways in C #. -, String: C # string differs from C + + string. -, there are no global methods and global variables in C #: Methods and variables must be contained in a type declaration, such asclassOrstructIn -, there are no header files and #include directives in C #:usingDirectives are used to refer to other types in namespaces that are not fully qualified type names. +, local variables in C # cannot be used before initialization. -, destructor: In C #, the call time of a destructor cannot be controlled because the destructor is called automatically by the garbage collector.  +, constructor: similar to C + +, if you do not provide a class constructor in C #, the default constructor is automatically generated for you. The default constructor initializes all fields to their default values. A, in C #, method parameters cannot have default values.    If you want to achieve the same effect, you need to use method overloading. C+ + at the beginning of the design to provide advanced object-oriented features, while providing good performance. However, in order to ensure compatibility with previous programs and developers, C + + is almost completely compatible with the C language. The C language itself is a high-level abstraction of modern computers, with direct access to addresses, access to almost any memory address through pointers, and the structure of heaps and stacks waiting. Of course, C + + has such a feature. With the gradual development of C + +, the introduction of generic programming generic programming technology and STL Standard Template Library, the difference between C + + and C is getting larger. Basically, C + + is designed to efficiently write large-scale high-performance applications (often some relatively low-level applications) using object-oriented technology or generic techniques. It is undeniable that no language can be closer to Windows itself than C + +. C + + is more targeted at the bottom of the computer, and C # is more focused on support for upper-level applications. At present, most of the large-scale games are made in C + +, while the network application, application software of the half is occupied by C # and Java. C # can do, C + + may not be able to do, C + +can do, C # is not necessarily good to do. C # is reduced by the underlying virtual machine mechanismMemory leaks and security issues that are often prone to/c++ in the language, at the expense of slower running times. The same is because the complexity of programming languages is simplified (C # is much simpler than C + +), which greatly increases the efficiency of developers. In addition, C # has a large class library of. NET, which is an advantage of C + +not have. So C # is a great fit for developing applications that handle business in the enterprise. At the same time, all of Microsoft's operating systems, server programs, desktop-side programs are unified to the. NET Platform.    Historically, a similar scenario (referring to Microsoft technology) has occurred in the course of Microsoft transitioning from a 16-bit platform to a 32-bit platform. C # is a purely object-oriented language, C+ + is process-oriented as well as Object oriented. C # supports garbage collection, and C + + does not support garbage collection. C # requires virtual machines, and C + + does not require virtual machines. C # 's execution file is the median code, called managed code, executed through the NGWS Runtime. In addition to C #, you can also use other programming languages (such as Visual Basic, C + +) to make managed code. C # uses platform-independent type,c++type is affected by the platform. C # calls the Win32 API in a cumbersome way, C+ + This is better than it. However, C # powerful network operation, the code is much lower than C + +, we abandoned the socket, instead of WinInet or MFC encapsulated network class, such as CHttpFile, or not C # simple.    C # 's Fool-like class library operations and the perfect nature of object-oriented programming make it the most popular language on the Windows platform. C # does not pass the Win32 API in one way, through System.Diagnostics.Process to find the process, and then kill, and C+ +, we have countless options, such as process memory 0, unload module, message Flood, handle forced shutdown, forced release of its heap and so on, even injected into the internal raise an exception, it will end. Protection process, no matter the kernel or the application layer, C # must not do, C + +have their own high-end places, other languages can not get involved.     So it's no surprise that you don't have antivirus software in C #. C # Extremely simple interface operation, it is very comfortable to look at the code, he has too many places, C+ + cannot get involved at all. No one takes C + + to do Web Services, super large amounts of data, garbage collection is basically 0 of C + + to do, is simply asking for trouble. C # WebForm, and JSP occupy a vast expanse of the Web, C + + cannot. C # is a profound language, the class library is powerful. C # focuses more on the application of software engineering, the use of various design patterns, C + +focus on implementing the function. The outlook for C # is good, I personally am optimistic about it, MSDN magazine each issue may be 80% c#,c+ + is not much, Microsoft's focus may be on C #, and hopefully C # will gradually replace C + +. but will C + + be so easily replaced? No way. Like a management, you let him take over the development of the people, let him from the dry to the same time to do these two things, will it be so simple? C + + vitality of at least 7-8 years, and then gradually fade out, but as long as the pursuit of free people exist, C + + will not disappear; as long as the operating system is written in C + +, C + +Will not go away. Develop database, tend to use C #, do Windows bottom, I'm sure C+ +. C # LINQ to SQL lets people who do not understand the database can go to the database, auxiliary some third-party libraries, can play a powerful role. Completely replace C + +, such as the operating system is written in C #, C # can develop all components of the system when it comes to the time, at least now C # still can not develop ISAPI, driver. Turn from: http://jasonshieh.iteye.com/blog/1005113

Differences and linkages between C + + and C #

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.