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

后端 未结 13 1475
没有蜡笔的小新
没有蜡笔的小新 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:34
    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.
    0 讨论(0)
  • 2020-12-23 19:38
    • 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)
    0 讨论(0)
  • 2020-12-23 19:38

    using Hungarian Notation and other C++ naming conventions

    private int m_iMyIntField;
    class CWidget { ... }
    
    0 讨论(0)
  • 2020-12-23 19:43
    • RAII vs IDispose
    • value type vs ref type (struct vs class, boxing and unboxing, etc.)
    0 讨论(0)
  • 2020-12-23 19:44

    Thinking that "garbage collection" = "I never have to worry about object lifetime at all". For instance, opening a FileStream and forgetting to close it.

    Or:

    1. Allocating a lot of objects
    2. Putting them in a big global dictionary (usually after "I know, I'll make a cache")
    3. Wondering why the application's memory usage always goes up and never down ("but it's supposed to garbage collect!")
    0 讨论(0)
  • 2020-12-23 19:45

    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);)

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