Online archive of questions on various topics answered by our experts. You can also ask a question (registration is required)
+100 votes
What sets C and C# apart from each other?
by (4.3k points)

2 Answers

+36 votes
 
Best answer
Short answer... C# is "managed" code and C is not. C allows you direct access to memory; where as C# does not ("managed" feature). C also tends to be multi-platform (Linux,Unix,MacOS, Windows,etc..) where as C# is generally limited to whatever os the .NetFramework supports (win2000 and later)
by (4.2k points)
selected by
0 votes
Differences between C++ and C#. . . . C# is a distinct language from C++. C++ is designed for general object oriented programming in the days when the typical computer was a standalone machine running a command line-based user interface, C# is designed specifically to work with the .Net and is geared to the modern environment of Windows and mouse-controlled user interface, networks and the internet.. . . . Microsoft has defined C# as follows:. . "C# is a simple, modern, object oriented, and type-safe programming language derived from C and C++. C# (pronounced 'C sharp') is firmly planted in the C and C++ family tree of languages, and will immediately be familiar to C and C++ programmers. C# aims to combine the high productivity of Visual Basic and the raw power of C++.". . . . However it is also undeniable that the two languages are very similar in both their syntax and in that they are both designed to facilitate the same paradigm of programming, in which code is based around hierarchies of inherited classes.. . . . Below I will briefly summarize the overall differences and similarities between the two languages. If you are a C++ programmer, these points will give you the most important differences between the two languages at a glance. . . . . Environment. . C++ was designed to be a low-level platform-neutral object-oriented programming language. C# was designed to be a somewhat higher-level component-oriented language. The move to a managed environment represents a sea change in the way you think about programming. C# is about letting go of precise control, and letting the framework help you focus on the big picture.. With the managed environment of .NET, you give up that level of control. When you choose the type of your object, the choice of where the object will be created is implicit. Simple types (int, double, and long) are always created on the stack (unless they are contained within other objects), and classes are always created on the heap. You cannot control where on the heap an object is created, you can't get its address, and you can't pin it down in a particular memory location. (There are ways around these restrictions, but they take you out of the mainstream.). The very structure of C# reflects the underlying framework. There are no multiple inheritances and there are no templates because multiple inheritances are terribly difficult to implement efficiently in a managed, garbage-collected environment, and because generics have not been implemented in the framework.. . . Compile Target. . C++ code usually compiles to assembly language. C# by contrast compiles to Intermediate language (IL), which has some similarities to java byte code. The IL is subsequently converted to native executable code by a process of Just-In-Time compilation. The emitted IL code is stored in a file or a set of files known as an assembly. An assembly essentially forms the unit, in which IL code id packaged, corresponding to a DLL, or executable file that would be created by C++ compiler.. . . Memory Management. . C# is designed to free the developers from the bookkeeping tasks to do with the memory management. That means in C# you do not have to explicitly delete memory that was allocated dynamically on the heap, as you could in C++. Rather, the garbage collector periodically cleans up memory that is no longer needed.. Lets have two C++ variable declarations. . int j = 30;. Myclass *pMine=new Myclass. . Here the contents of j are stored on the stack. This is exactly that exists with C# value types. Our Myclass instance is, however stored on the heap, and the pointer to it is on the stack. This is basically the situation with C# reference type, except that in C# the syntax dresses the pointer up as a reference. The equivalent of C# is:. . Int j=30;. Myclass mine=new Myclass(). . This code has pretty much the same effect in terms of where the objects are stored as does the above C++ code - the difference is t
by (4.5k points)
...