在 C++ 之后学习 C#
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/276884/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Learning C# after C++
提问by Cristián Romo
In a progression of languages, I have been learning C and C++. Now I would like to learn C#. I know there are some drastic differences between them - such as the removal of pointers and garbage collection. However, I don't know many of the differences between the two.
在一系列语言中,我一直在学习 C 和 C++。现在我想学习C#。我知道它们之间存在一些巨大的差异 - 例如删除指针和垃圾收集。但是,我不知道两者之间的许多差异。
What are the major differences that a C++ programmer would need to know when moving to C#? (For example, what can I use instead of STL, syntactic differences between them, or anything else that might be considered important.)
C++ 程序员在转向 C# 时需要了解的主要区别是什么?(例如,我可以使用什么来代替 STL、它们之间的语法差异或其他任何可能被认为重要的东西。)
采纳答案by Jeff Hillman
C# for C++ Developersis a great place to start. It is a table that lists the most important comparisons between the two languages.
面向 C++ 开发人员的 C#是一个很好的起点。该表格列出了两种语言之间最重要的比较。
Once you have explored some of these differences, you might choose a self-contained project you have written in the past in C++, and re-write it in C#. In your first pass, you will probably just end up translating directly across, using the same design and algorithms. As you become more comfortable with C#, you will recognize ways to take advantage of language features only available in C#, as well as the incredibly versatile .NET Framework.
一旦您探索了其中的一些差异,您可以选择一个您过去用 C++ 编写的独立项目,然后用 C# 重新编写它。在您的第一遍中,您可能最终会使用相同的设计和算法直接进行翻译。随着您对 C# 越来越熟悉,您将认识到如何利用仅在 C# 中可用的语言功能以及极其通用的 .NET Framework。
回答by Greg Hewgill
I think it's important to note that pointers weren't really removedfrom C#, but that they still exist, they are everywhere, and they are called references.
我认为重要的是要注意指针并没有真正从 C# 中删除,但是它们仍然存在,它们无处不在,它们被称为引用。
回答by denis phillips
Look at the Generic collections and LINQ (all the related technology to LINQ) for STL like functionality.
查看通用集合和 LINQ(所有与 LINQ 相关的技术)以获得类似 STL 的功能。
The number one thing to note is that ~/Destructor is c++ is nothing like the ~/finalizer in c# -- See IDisposable/using.
需要注意的第一件事是 ~/Destructor 是 C++ 与 C# 中的 ~/finalizer 完全不同——请参阅 IDisposable/using。
回答by Franci Penov
There was a similar question that has lots of pointers (pun inteded :-)) and resources about the differences between C++ and C# and what to pay attention when learning transitioning - Linux/C++ programmer to Windows/C# programmer.
有一个类似的问题,有很多关于 C++ 和 C# 之间差异的指针(双关语:-))和资源,以及学习过渡时要注意的事项 - Linux/C++ 程序员到 Windows/C# 程序员。
回答by orcmid
Charles Petzold has a .NET Book Zerothat is designed specifically for the C/C++ Windows programmer who wants to learn C# and .NET. It is a free PDF download from his site. All of the source code used in the book is available as a separate Zip-file download.
Charles Petzold 有一本.NET Book Zero,专为想要学习 C# 和 .NET 的 C/C++ Windows 程序员设计。它可以从他的网站上免费下载 PDF。本书中使用的所有源代码都可以通过单独的 Zip 文件下载。