Most common or vicious mistakes in C# development for experienced C++ programmers

后端 未结 13 1476
没有蜡笔的小新
没有蜡笔的小新 2020-12-23 19:10

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

相关标签:
13条回答
  • 2020-12-23 19:53

    Attempting to implement const correctness on strings.

    0 讨论(0)
  • 2020-12-23 19:54

    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.

    0 讨论(0)
  • 2020-12-23 19:57

    Calling GC.Collect.

    0 讨论(0)
  • 2020-12-23 19:57

    Forgetting to specify access modifiers for every class member.

    0 讨论(0)
  • 2020-12-23 19:59

    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.

    0 讨论(0)
  • 2020-12-23 19:59

    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.

    0 讨论(0)
提交回复
热议问题