C# for win32 or c++ [closed]
I know C++ windows programming is harder than C#. Because we should Create WNDCLASS and Initalize it and using API Funcs and...
But My Question is here , for windows programming ,Is C# better than C++ ?
If yes , why large programs are created with C++ .
Its not "large programs" when C++ is favored over C# managed code.
There are limits to what can be done with managed code, for instance you cannot write hardware drivers or other programs that interface with hardware. You cannot even access all of the Win32 API from purely managed code. Some programs have high performance requirements and are therefore more suited to C++. Sometimes C++ is used simply because the company developing the software has skilled C++ developers. Sometimes C++ is used because the developers don't want the software to be dependent on the .NET framework (which isn't installed out of the box on XP and earlier Windows versions). Sometimes C++ is chosen so that a cross platform application can be developed.
In broad terms, C# is easier to learn and is a more powerful and productive language & framework than C++/MFC/COM etc. But C++ is a very broad tool, and can produce solutions to many very diverse problems, from writing operating systems, real time systems, embedded applications, databases, business software, desktop software, server software, libraries/frameworks, etc, etc.
C# is better suited to a particular class of problem. It is pretty much limited to running on Windows (with the exception of Silverlight & Mono). C# suits rapid application development, which means it is better suited to one-off custom software, such as many internal applications developed within large organizations. And as I've indicated, its more suited to developing desktop and server application software over drivers and other low level software.
If you're looking at which language to start learning, a smart choice would be: C then C++ then C#. This will give you the foundation you need to become a really good object oriented programmer, with an understanding of how lucky we are to have C#! If you don't have 10 years to spare, then go ahead and start with C#. Whatever you do, don't start with C++ or you are likely to give up your programming career in despair and join the circus where things make more sense.
If I could start from scratch all the c++ projects I have done in the past, 99% of the code would be in .NET. Especially when it comes to UI. WPF, Winforms are much more powerful than MFC.
What type of program will you develop? Please elaborate and then we can make a recomendation.
** EDIT
A good example is Visual Studio itself. VS 2010 is based on WPF now.
Better? Better how? Easier? Faster?
C++ is a monster to learn, huge and complex as it is. C# is considerably "friendlier" and easier to work with. C# often lets you complete tasks faster and easier than C++, because the language and it's framework does a lot of work for you. This is part of what makes C# better than C++, and what makes C++ better than C#.
If you let C# do the work for you, that means that you as a programmer sacrifice some control. This is what sets a high-level language apart from a low-level one. For demanding applications, programmers tend to pick a language that provides the necessary amount of abstraction while still providing the desired control. This is why many demanding applications (such as video games) are written in C++. It has a fairly large array of high-level features, while still packing the horsepower to pull really low-level code for situations where you need absolute control of the hardware. It is also why many business applications and other less demanding applications are written in a high level language such as C#, since these applications have no use for low-level features, and can safely enjoy the gains of high-level ones without worrying about performance penalties.
In C#'s case, all applications created with it run in the .NET runtime environment. This is a disadvantage for programs that need to run fast, since you want to be as close to the hardware as possible. So again, C++ wins for demanding applications where either execution speed or memory usage is crucial. Also C++ can be used on a very large amount of platforms, anything from PCs to coffee machines (okay, cell phones, then), while C# is officially limited to platforms running Microsoft Windows.
As for ease of development on Windows, C# is a clear winner. There are available frameworks for C++ too, but they are not even close to C# when it comes to getting things done fast and easy. That said, it is perfectly possible to write complex GUI applications for Windows in C++ without swearing too much.
Anyway, I hope you see how little sense it makes to compare languages like this. It's much like comparing a hammer to a screwdriver. Choosing a language is about choosing the right tool for the job. Many tools overlap - you can accomplish pretty much the same in C++ and C#, which complicates the choice. If you really want to read into this (going for an "educated choice"), I suggest you read up on the individual languages. If you just wonder which language to learn, I suggest you start with C#, and learn C++ if you ever need to (or want to).
C++ and C# both are really good languages, having said that both have their own specialities.
C++ is ideal for applications which needs to highly optimized memory and cpu usage like verly low level device driver development
C# is far superior for creating business applications like accounting and database driven applications which would take ages if you try building them in C++
In short
C++ is for applications which require highly optimized memory and CPU usage.
C# is far productivity and enterprise applications
精彩评论