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条回答
虎瘦雄心在
2楼-- · 2020-02-16 20:25
  1. Using structs in favour for classes all the time.
  2. Using in, out and ref parameters all the time (This is a result of point 1).
  3. Using int values as error conditions instead of using exceptions
  4. Using the virtual keyword instead of override keyword.
  5. Thinking that char is an 8 bit signed value.
查看更多
何必那么认真
3楼-- · 2020-02-16 20:26

Attempting to implement const correctness on strings.

查看更多
Summer. ? 凉城
4楼-- · 2020-02-16 20:30

One that got me, and I believe a lot of non C++ people too, was leaking memory due to registered events keeping an object alive.

IDisposable grated to begin with (and still does if I'm honest) but was pretty obviously going to be a difference when going from native to managed code so it is not something I'd expect C++ developers to actually fall foul of, they just won't like it.

查看更多
Deceive 欺骗
5楼-- · 2020-02-16 20:31
  • the difference between struct and class in the two
  • the difference between a using alias and a typedef
  • when do my objects get collected? how do I destroy them now?
  • how big is an int? (it is actually defined in C#)
  • where's my linker? (actually, Mono does have a full AOT linker for some scenarios)
查看更多
家丑人穷心不美
6楼-- · 2020-02-16 20:35

I've seen many C++ coders code in a COM style in C#, trying to deal with the inadequacies of the language. C# provides lots of a type safe support for your enums and there are usually nicer APIs then P/Invoking back down to C++.

The other thing I've seen catch most people out is that C# generics are not templates.

查看更多
Emotional °昔
7楼-- · 2020-02-16 20:36

Calling GC.Collect.

查看更多
登录 后发表回答