Most common or vicious mistakes in C# development

2020-02-16 19:48发布

What are the most common or vicious mistakes when experienced C++ programmers develop in C#?

标签: c# c++
13条回答
【Aperson】
2楼-- · 2020-02-16 20:38

using Hungarian Notation and other C++ naming conventions

private int m_iMyIntField;
class CWidget { ... }
查看更多
The star\"
3楼-- · 2020-02-16 20:39

Incidentally, the C# compiler has a number of heuristics in it for helping out the experienced C++ programmer who is a novice C# programmer. For example, if you say

int x[];

the compiler will helpfully point out that the [] is a part of the type in C#, so you probably meant

int[] x;

C# also allows things like putting unnecessary semicolons at the end of a class declaration so that C++ programmers who are in that habit don't get bitten by it.

查看更多
\"骚年 ilove
4楼-- · 2020-02-16 20:40

Confusing "pass by reference" and "reference type":

void GetAnArray(int input, ref string[] output);

(Compare with C++: void getAnArray(int input, std::vector<std::string>& output);)

查看更多
闹够了就滚
5楼-- · 2020-02-16 20:44
  • RAII vs IDispose
  • value type vs ref type (struct vs class, boxing and unboxing, etc.)
查看更多
家丑人穷心不美
6楼-- · 2020-02-16 20:44

Forgetting to specify access modifiers for every class member.

查看更多
地球回转人心会变
7楼-- · 2020-02-16 20:45

Writing the full namespace each time.

This is fine in C++ when you're typing std::this or boost::that. Not so great in C# when you repeat System.Windows.Forms.Whatever all over the place.

查看更多
登录 后发表回答